Skip to content

Commit d7aac72

Browse files
authored
Merge pull request #206 from xuwei-k/new-java-net-URL
avoid deprecated `java.net.URL` constructor
2 parents 4a3b819 + 7f71fa5 commit d7aac72

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

src/main/scala/sbtbuildinfo/JavaRenderer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class JavaRenderer(pkg: String, cl: String, makeStatic: Boolean) extend
3333
protected val buildUrlLines: String =
3434
""" private static java.net.URL internalAsUrl(String urlString) {
3535
| try {
36-
| return new java.net.URL(urlString);
36+
| return new java.net.URI(urlString).toURL();
3737
| } catch (Exception e) {
3838
| return null;
3939
| }

src/main/scala/sbtbuildinfo/ScalaRenderer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ abstract class ScalaRenderer extends BuildInfoRenderer {
9797
case mp: Map[_, _] => mp.toList.map(quote(_)).mkString("Map(", ", ", ")")
9898
case seq: collection.Seq[_] => seq.map(quote).mkString("scala.collection.immutable.Seq(", ", ", ")")
9999
case op: Option[_] => op map { x => "scala.Some(" + quote(x) + ")" } getOrElse {"scala.None"}
100-
case url: java.net.URL => "new java.net.URL(%s)" format quote(url.toString)
100+
case url: java.net.URL => "new java.net.URI(%s).toURL" format quote(url.toString)
101101
case file: java.io.File => "new java.io.File(%s)" format quote(file.toString)
102102
case attr: sbt.Attributed[_] => quote(attr.data)
103103
case date: java.time.LocalDate => "java.time.LocalDate.parse(%s)" format quote(date.toString)

src/sbt-test/sbt-buildinfo/caseclassrenderer/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ lazy val root = (project in file("."))
107107
""" projectVersion = 0.1,""" ::
108108
""" scalaVersion = "2.12.12",""" ::
109109
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
110-
""" homepage = scala.Some(new java.net.URL("http://example.com")),""" ::
111-
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))),""" ::
110+
""" homepage = scala.Some(new java.net.URI("http://example.com").toURL),""" ::
111+
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)),""" ::
112112
""" apiMappings = Map(),""" ::
113113
""" isSnapshot = false,""" ::
114114
""" year = 2012,""" ::

src/sbt-test/sbt-buildinfo/constantvalue/build.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ lazy val root = (project in file(".")).
5757
scalaVersionInfo ::
5858
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
5959
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
60-
""" /** The value is scala.Some(new java.net.URL("http://example.com")). */""" ::
61-
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
62-
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
63-
""" 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")))""" ::
60+
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
61+
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
62+
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
63+
""" 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))""" ::
6464
""" /** The value is Map(). */""" ::
6565
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
6666
""" /** The value is false. */""" ::

src/sbt-test/sbt-buildinfo/javasingletonrenderer/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ lazy val root = (project in file("."))
9898
"""""" ::
9999
""" private static java.net.URL internalAsUrl(String urlString) {""" ::
100100
""" try {""" ::
101-
""" return new java.net.URL(urlString);""" ::
101+
""" return new java.net.URI(urlString).toURL();""" ::
102102
""" } catch (Exception e) {""" ::
103103
""" return null;""" ::
104104
""" }""" ::

src/sbt-test/sbt-buildinfo/javastaticfieldsrenderer/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ lazy val root = (project in file("."))
9696
"""""" ::
9797
""" private static java.net.URL internalAsUrl(String urlString) {""" ::
9898
""" try {""" ::
99-
""" return new java.net.URL(urlString);""" ::
99+
""" return new java.net.URI(urlString).toURL();""" ::
100100
""" } catch (Exception e) {""" ::
101101
""" return null;""" ::
102102
""" }""" ::

src/sbt-test/sbt-buildinfo/multi/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ lazy val app = (project in file("app"))
3939
""" val projectID: String = "com.example:root:0.1"""" ::
4040
""" /** The value is "0.1". */""" ::
4141
""" val version: String = "0.1"""" ::
42-
""" /** The value is new java.net.URL("http://example.com"). */""" ::
43-
""" val homepage = new java.net.URL("http://example.com")""" ::
42+
""" /** The value is new java.net.URI("http://example.com").toURL. */""" ::
43+
""" val homepage = new java.net.URI("http://example.com").toURL""" ::
4444
scalaVersionInfoComment ::
4545
scalaVersionInfo ::
4646
""" override val toString: String = {""" ::

src/sbt-test/sbt-buildinfo/simple/build.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ lazy val root = (project in file("."))
5050
scalaVersionInfo ::
5151
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
5252
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
53-
""" /** The value is scala.Some(new java.net.URL("http://example.com")). */""" ::
54-
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
55-
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
56-
""" 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")))""" ::
53+
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
54+
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
55+
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
56+
""" 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))""" ::
5757
""" /** The value is Map(). */""" ::
5858
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
5959
""" /** The value is false. */""" ::

src/sbt-test/sbt-buildinfo/skipimportscaseclass/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ lazy val root = (project in file("."))
9898
""" projectVersion = 0.1,""" ::
9999
""" scalaVersion = "2.12.12",""" ::
100100
""" ivyXML = scala.xml.NodeSeq.Empty,""" ::
101-
""" homepage = scala.Some(new java.net.URL("http://example.com")),""" ::
102-
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))),""" ::
101+
""" homepage = scala.Some(new java.net.URI("http://example.com").toURL),""" ::
102+
""" licenses = scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)),""" ::
103103
""" apiMappings = Map(),""" ::
104104
""" isSnapshot = false,""" ::
105105
""" year = 2012,""" ::

src/sbt-test/sbt-buildinfo/usepackageaspath/build.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ lazy val root = (project in file("."))
4747
""" val scalaVersion: String = "2.12.12"""" ::
4848
""" /** The value is scala.xml.NodeSeq.Empty. */""" ::
4949
""" val ivyXML: scala.xml.NodeSeq = scala.xml.NodeSeq.Empty""" ::
50-
""" /** The value is scala.Some(new java.net.URL("http://example.com")). */""" ::
51-
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URL("http://example.com"))""" ::
52-
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URL("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE"))). */""" ::
53-
""" 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")))""" ::
50+
""" /** The value is scala.Some(new java.net.URI("http://example.com").toURL). */""" ::
51+
""" val homepage: scala.Option[java.net.URL] = scala.Some(new java.net.URI("http://example.com").toURL)""" ::
52+
""" /** The value is scala.collection.immutable.Seq(("MIT License" -> new java.net.URI("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE").toURL)). */""" ::
53+
""" 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))""" ::
5454
""" /** The value is Map(). */""" ::
5555
""" val apiMappings: Map[java.io.File, java.net.URL] = Map()""" ::
5656
""" /** The value is false. */""" ::

0 commit comments

Comments
 (0)