Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Dec 26, 2024
1 parent dd532cf commit d1f2257
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 36 deletions.
13 changes: 12 additions & 1 deletion src/main/scala/sbtbuildinfo/JavaRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
| return null;
| }
| }
|
| private static java.net.URI internalAsUri(String uriString) {
| try {
| return new java.net.URI(uriString);
| } catch (Exception e) {
| return null;
| }
| }
|""".stripMargin

protected val buildMapLines: String =
Expand Down Expand Up @@ -153,6 +161,7 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
case TypeExpression("java.net.URL", Nil) => Some("java.net.URL")
case TypeExpression("sbt.URL", Nil) => Some("java.net.URL")
case TypeExpression("java.net.URI", Nil) => Some("java.net.URI")
case TypeExpression("sbt.URI", Nil) => Some("java.net.URI")
case TypeExpression("java.io.File", Nil) => Some("java.io.File")
case TypeExpression("sbt.File", Nil) => Some("java.io.File")
case TypeExpression("scala.xml.NodeSeq", Nil) => None
Expand Down Expand Up @@ -184,9 +193,10 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
x0 <- tpeToReturnType(arg0)
x1 <- tpeToReturnType(arg1)
} yield s"java.util.Map.Entry<$x0, $x1>"

case TypeExpression("java.time.LocalDate", Nil) => Some("java.time.LocalDate")
case TypeExpression("java.time.Instant", Nil) => Some("java.time.Instant")
case TypeExpression("sbt.librarymanagement.License", Nil) => Some("String")

case _ =>
// println(s"java other: $tpe")
Expand All @@ -209,6 +219,7 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
case op: Option[_] =>
op map { x => "java.util.Optional.of(" + quote(x) + ")" } getOrElse { "java.util.Optional.empty()" }
case url: java.net.URL => "internalAsUrl(%s)" format quote(url.toString)
case uri: java.net.URI => "internalAsUri(%s)" format quote(uri.toString)
case file: java.io.File => "new java.io.File(%s)" format quote(file.toString)
case attr: sbt.Attributed[_] => quote(attr.data)
case date: java.time.LocalDate => "java.time.LocalDate.parse(%s)" format quote(date.toString)
Expand Down
6 changes: 3 additions & 3 deletions src/sbt-test/sbt-buildinfo/caseclassrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ lazy val root = (project in file("."))
projectVer ::
""" scalaVersion: String,""" ::
""" ivyXML: scala.xml.NodeSeq,""" ::
""" homepage: scala.Option[java.net.URL],""" ::
""" licenses: scala.collection.immutable.Seq[(String, java.net.URL)],""" ::
homepageComment ::
homepageCode ::
apiMappingsDecl ::
""" isSnapshot: scala.Boolean,""" ::
""" year: scala.Int,""" ::
Expand Down Expand Up @@ -107,7 +107,7 @@ lazy val root = (project in file("."))
""" projectVersion = 0.1,""" ::
""" scalaVersion = "2.12.12",""" ::
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
""" homepage = scala.Some(new java.net.URI("http://example.com").toURL),""" ::
homepage ::
licenses ::
""" apiMappings = Map(),""" ::
""" isSnapshot = false,""" ::
Expand Down
10 changes: 5 additions & 5 deletions src/sbt-test/sbt-buildinfo/constantvalue/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ lazy val root = (project in file(".")).
scalaVersionInfo ::
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
""" val licenses: scala.collection.immutable.Seq[(String, java.net.URL)] = scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL))""" ::
homepageComment ::
homepageCode ::
licenseComment ::
licenseCode ::
""" /** The value is Map(). */""" ::
apiMappingsCode ::
""" /** The value is false. */""" ::
Expand All @@ -85,7 +85,7 @@ lazy val root = (project in file(".")).
""" )""" ::
""" }""" ::
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target = new java.io.File(") &&
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target: java.io.File = new java.io.File(") &&
(scalaVersionInfo.trim == s"""final val scalaVersion = "$sv"""") => ()
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
Expand Down
18 changes: 13 additions & 5 deletions src/sbt-test/sbt-buildinfo/javasingletonrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ lazy val root = (project in file("."))
""" public final String name = "helloworld";""" ::
""" /** The value is "2.12.12". */""" ::
""" public final String scalaVersion = "2.12.12";""" ::
""" /** The value is java.util.Optional.of(internalAsUrl("http://example.com")). */""" ::
""" public final java.util.Optional<java.net.URL> homepage = java.util.Optional.of(internalAsUrl("http://example.com"));""" ::
""" /** The value is java.util.Collections.unmodifiableList(java.util.Arrays.asList(new java.util.AbstractMap.SimpleImmutableEntry<>("MIT License", internalAsUrl("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")))). */""" ::
""" public final java.util.Collection<java.util.Map.Entry<String, java.net.URL>> licenses = java.util.Collections.unmodifiableList(java.util.Arrays.asList(new java.util.AbstractMap.SimpleImmutableEntry<>("MIT License", internalAsUrl("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))));""" ::
homepageComment ::
homepageCode ::
licensesComment ::
licensesCode ::
""" /** The value is internalAsMap(). */""" ::
apiMappingsCode ::
""" /** The value is false. */""" ::
Expand Down Expand Up @@ -105,6 +105,14 @@ lazy val root = (project in file("."))
""" }""" ::
""" }""" ::
"""""" ::
""" private static java.net.URI internalAsUri(String uriString) {""" ::
""" try {""" ::
""" return new java.net.URI(uriString);""" ::
""" } catch (Exception e) {""" ::
""" return null;""" ::
""" }""" ::
""" }""" ::
"""""" ::
""" @SuppressWarnings({"unchecked", "rawtypes"})""" ::
""" private static <K, V> java.util.Map<K, V> internalAsMap(java.util.Map.Entry... entries) {""" ::
""" java.util.Map<K, V> m = new java.util.HashMap<>();""" ::
Expand Down Expand Up @@ -151,7 +159,7 @@ lazy val root = (project in file("."))
"""""" ::
""" public final String toJson = toJsonValue(toMap());""" ::
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if (targetInfo.contains("target = new java.io.File(") &&
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target = new java.io.File(") &&
targetInfoComment.contains("/** The value is new java.io.File(") => ()
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/sbt-buildinfo/javasingletonrenderer/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
> compile
# $ exists target/src_managed/main/sbt-buildinfo/BuildInfo.java
# > show Compile/sources
# $ exists target/**/src_managed/main/sbt-buildinfo/BuildInfo.java

> check
16 changes: 12 additions & 4 deletions src/sbt-test/sbt-buildinfo/javastaticfieldsrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ lazy val root = (project in file("."))
""" public static final String name = "helloworld";""" ::
""" /** The value is "2.12.12". */""" ::
""" public static final String scalaVersion = "2.12.12";""" ::
""" /** The value is java.util.Optional.of(internalAsUrl("http://example.com")). */""" ::
""" public static final java.util.Optional<java.net.URL> homepage = java.util.Optional.of(internalAsUrl("http://example.com"));""" ::
""" /** The value is java.util.Collections.unmodifiableList(java.util.Arrays.asList(new java.util.AbstractMap.SimpleImmutableEntry<>("MIT License", internalAsUrl("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")))). */""" ::
""" public static final java.util.Collection<java.util.Map.Entry<String, java.net.URL>> licenses = java.util.Collections.unmodifiableList(java.util.Arrays.asList(new java.util.AbstractMap.SimpleImmutableEntry<>("MIT License", internalAsUrl("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))));""" ::
homepageComment ::
homepageCode ::
licensesComment ::
licensesCode ::
""" /** The value is internalAsMap(). */""" ::
apiMappingsCode ::
""" /** The value is false. */""" ::
Expand Down Expand Up @@ -103,6 +103,14 @@ lazy val root = (project in file("."))
""" }""" ::
""" }""" ::
"""""" ::
""" private static java.net.URI internalAsUri(String uriString) {""" ::
""" try {""" ::
""" return new java.net.URI(uriString);""" ::
""" } catch (Exception e) {""" ::
""" return null;""" ::
""" }""" ::
""" }""" ::
"""""" ::
""" @SuppressWarnings({"unchecked", "rawtypes"})""" ::
""" private static <K, V> java.util.Map<K, V> internalAsMap(java.util.Map.Entry... entries) {""" ::
""" java.util.Map<K, V> m = new java.util.HashMap<>();""" ::
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/multi/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lazy val app = (project in file("app"))
projectIdCode :: // project id changed in sbt 2.x
""" /** The value is "0.1". */""" ::
""" val version: String = "0.1"""" ::
""" /** The value is new java.net.URI("http://example.com").toURL. */""" ::
homepageComment ::
homepageCode ::
scalaVersionInfoComment ::
scalaVersionInfo ::
Expand Down
8 changes: 4 additions & 4 deletions src/sbt-test/sbt-buildinfo/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ lazy val root = (project in file("."))
scalaVersionInfo ::
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
homepageComment ::
homepageCode ::
licenseComment ::
licensesCode ::
""" /** The value is Map(). */""" ::
apiMappingsCode ::
Expand All @@ -83,7 +83,7 @@ lazy val root = (project in file("."))
""" )""" ::
""" }""" ::
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target = new java.io.File(") &&
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target: java.io.File = new java.io.File(") &&
(scalaVersionInfo.trim == s"""val scalaVersion: String = "$sv"""") &&
(someCpInfo.contains("/tmp/f.txt")) &&
(projectVer.contains("val projectVersion")) => ()
Expand Down
8 changes: 4 additions & 4 deletions src/sbt-test/sbt-buildinfo/skipimportscaseclass/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ lazy val root = (project in file("."))
""" name: String,""" ::
""" scalaVersion: String,""" ::
""" ivyXML: scala.xml.NodeSeq,""" ::
""" homepage: scala.Option[java.net.URL],""" ::
""" licenses: scala.collection.immutable.Seq[(String, java.net.URL)],""" ::
homagepageCode ::
licensesCode ::
apiMappingsCode ::
""" isSnapshot: scala.Boolean,""" ::
""" year: scala.Int,""" ::
Expand Down Expand Up @@ -95,8 +95,8 @@ lazy val root = (project in file("."))
""" name = "helloworld",""" ::
""" scalaVersion = "2.12.12",""" ::
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
""" homepage = scala.Some(new java.net.URI("http://example.com").toURL),""" ::
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)),""" ::
homagepageApply ::
licensesApply ::
""" apiMappings = Map(),""" ::
""" isSnapshot = false,""" ::
""" year = 2012,""" ::
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/skipimportscaseclass/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> compile
# $ exists target/scala-2.12/src_managed/main/sbt-buildinfo/BuildInfo.scala
$ exists target/**/src_managed/main/sbt-buildinfo/BuildInfo.scala

> check
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/skipimportscaseobject/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> compile
# $ exists target/scala-2.12/src_managed/main/sbt-buildinfo/BuildInfo.scala
$ exists target/**/src_managed/main/sbt-buildinfo/BuildInfo.scala

> check

Expand Down
10 changes: 5 additions & 5 deletions src/sbt-test/sbt-buildinfo/usepackageaspath/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ lazy val root = (project in file("."))
""" val scalaVersion: String = "2.12.12"""" ::
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
""" val licenses: scala.collection.immutable.Seq[(String, java.net.URL)] = scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL))""" ::
homepageComment ::
homepageCode ::
licensesComment ::
licensesCode ::
""" /** The value is Map(). */""" ::
apiMappingsCode ::
""" /** The value is false. */""" ::
Expand All @@ -69,7 +69,7 @@ lazy val root = (project in file("."))
""" )""" ::
""" }""" ::
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target = new java.io.File(") => ()
"""// $COVERAGE-ON$""" :: Nil if targetInfo.contains("target: java.io.File = new java.io.File(") => ()
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/usepackageaspath/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> compile
# $ exists target/scala-2.12/src_managed/main/foo/bar/baz/BuildInfo.scala
$ exists target/**/src_managed/main/foo/bar/baz/BuildInfo.scala

> check

0 comments on commit d1f2257

Please sign in to comment.