Skip to content

Commit

Permalink
Merge pull request #206 from xuwei-k/new-java-net-URL
Browse files Browse the repository at this point in the history
avoid deprecated `java.net.URL` constructor
  • Loading branch information
eed3si9n authored Aug 26, 2024
2 parents 4a3b819 + 7f71fa5 commit d7aac72
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/sbtbuildinfo/JavaRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
protected val buildUrlLines: String =
""" private static java.net.URL internalAsUrl(String urlString) {
| try {
| return new java.net.URL(urlString);
| return new java.net.URI(urlString).toURL();
| } catch (Exception e) {
| return null;
| }
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sbtbuildinfo/ScalaRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class ScalaRenderer extends BuildInfoRenderer {
case mp: Map[_, _] => mp.toList.map(quote(_)).mkString("Map(", ", ", ")")
case seq: collection.Seq[_] => seq.map(quote).mkString("scala.collection.immutable.Seq(", ", ", ")")
case op: Option[_] => op map { x => "scala.Some(" + quote(x) + ")" } getOrElse {"scala.None"}
case url: java.net.URL => "new java.net.URL(%s)" format quote(url.toString)
case url: java.net.URL => "new java.net.URI(%s).toURL" format quote(url.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
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-buildinfo/caseclassrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ lazy val root = (project in file("."))
""" projectVersion = 0.1,""" ::
""" scalaVersion = "2.12.12",""" ::
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
""" homepage = scala.Some(new java.net.URL("http://example.com")),""" ::
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))),""" ::
""" 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)),""" ::
""" apiMappings = Map(),""" ::
""" isSnapshot = false,""" ::
""" year = 2012,""" ::
Expand Down
8 changes: 4 additions & 4 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.URL("http://example.com")). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
""" val licenses: scala.collection.immutable.Seq[(String, java.net.URL)] = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")))""" ::
""" /** 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))""" ::
""" /** The value is Map(). */""" ::
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
""" /** The value is false. */""" ::
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/javasingletonrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ lazy val root = (project in file("."))
"""""" ::
""" private static java.net.URL internalAsUrl(String urlString) {""" ::
""" try {""" ::
""" return new java.net.URL(urlString);""" ::
""" return new java.net.URI(urlString).toURL();""" ::
""" } catch (Exception e) {""" ::
""" return null;""" ::
""" }""" ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ lazy val root = (project in file("."))
"""""" ::
""" private static java.net.URL internalAsUrl(String urlString) {""" ::
""" try {""" ::
""" return new java.net.URL(urlString);""" ::
""" return new java.net.URI(urlString).toURL();""" ::
""" } catch (Exception e) {""" ::
""" return null;""" ::
""" }""" ::
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-buildinfo/multi/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ lazy val app = (project in file("app"))
""" val projectID: String = "com.example:root:0.1"""" ::
""" /** The value is "0.1". */""" ::
""" val version: String = "0.1"""" ::
""" /** The value is new java.net.URL("http://example.com"). */""" ::
""" val homepage = new java.net.URL("http://example.com")""" ::
""" /** The value is new java.net.URI("http://example.com").toURL. */""" ::
""" val homepage = new java.net.URI("http://example.com").toURL""" ::
scalaVersionInfoComment ::
scalaVersionInfo ::
""" override val toString: String = {""" ::
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 @@ -50,10 +50,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.URL("http://example.com")). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
""" val licenses: scala.collection.immutable.Seq[(String, java.net.URL)] = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")))""" ::
""" /** 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))""" ::
""" /** The value is Map(). */""" ::
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
""" /** The value is false. */""" ::
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/sbt-buildinfo/skipimportscaseclass/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ lazy val root = (project in file("."))
""" projectVersion = 0.1,""" ::
""" scalaVersion = "2.12.12",""" ::
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
""" homepage = scala.Some(new java.net.URL("http://example.com")),""" ::
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))),""" ::
""" 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)),""" ::
""" apiMappings = Map(),""" ::
""" isSnapshot = false,""" ::
""" year = 2012,""" ::
Expand Down
8 changes: 4 additions & 4 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.URL("http://example.com")). */""" ::
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
""" val licenses: scala.collection.immutable.Seq[(String, java.net.URL)] = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")))""" ::
""" /** 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))""" ::
""" /** The value is Map(). */""" ::
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
""" /** The value is false. */""" ::
Expand Down

0 comments on commit d7aac72

Please sign in to comment.