Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid deprecated java.net.URL constructor #418

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/src/main/scala/sbt/librarymanagement/License.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sbt.librarymanagement

import java.net.URL
import java.net.URI

/**
* Commonly used software licenses
Expand All @@ -9,16 +10,16 @@ import java.net.URL
*/
object License {
lazy val Apache2: (String, URL) =
("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt"))
("Apache-2.0", new URI("https://www.apache.org/licenses/LICENSE-2.0.txt").toURL)

lazy val MIT: (String, URL) =
("MIT", new URL("https://opensource.org/licenses/MIT"))
("MIT", new URI("https://opensource.org/licenses/MIT").toURL)

lazy val CC0: (String, URL) =
("CC0-1.0", new URL("https://creativecommons.org/publicdomain/zero/1.0/legalcode"))
("CC0-1.0", new URI("https://creativecommons.org/publicdomain/zero/1.0/legalcode").toURL)

def PublicDomain: (String, URL) = CC0

lazy val GPL3_or_later: (String, URL) =
("GPL-3.0-or-later", new URL("https://spdx.org/licenses/GPL-3.0-or-later.html"))
("GPL-3.0-or-later", new URI("https://spdx.org/licenses/GPL-3.0-or-later.html").toURL)
}
4 changes: 2 additions & 2 deletions core/src/main/scala/sbt/librarymanagement/ModuleIDExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package sbt.librarymanagement

import java.net.URL
import java.net.URI

import sbt.internal.librarymanagement.mavenint.SbtPomExtraProperties
import scala.collection.mutable.ListBuffer
Expand Down Expand Up @@ -132,7 +132,7 @@ private[librarymanagement] abstract class ModuleIDExtra {
* It is not included in published metadata.
*/
def from(url: String, allowInsecureProtocol: Boolean): ModuleID =
artifacts(Artifact(name, new URL(url), allowInsecureProtocol))
artifacts(Artifact(name, new URI(url).toURL, allowInsecureProtocol))

/** Adds a dependency on the artifact for this module with classifier `c`. */
def classifier(c: String): ModuleID = artifacts(Artifact(name, c))
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/scala/sbt/librarymanagement/ResolverExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.annotation.nowarn
import scala.xml.XML
import org.xml.sax.SAXParseException
import sbt.util.Logger
import java.net.URI

final class RawRepository(val resolver: AnyRef, name: String) extends Resolver(name) {
override def toString = "Raw(" + resolver.toString + ")"
Expand Down Expand Up @@ -146,13 +147,13 @@ private[librarymanagement] abstract class ResolverFunctions {
def typesafeRepo(status: String) =
MavenRepository("typesafe-" + status, TypesafeRepositoryRoot + "/" + status)
def typesafeIvyRepo(status: String) =
url("typesafe-ivy-" + status, new URL(TypesafeRepositoryRoot + "/ivy-" + status + "/"))(
url("typesafe-ivy-" + status, new URI(TypesafeRepositoryRoot + "/ivy-" + status + "/").toURL)(
ivyStylePatterns
)
def sbtIvyRepo(status: String) =
url(s"sbt-ivy-$status", new URL(s"$SbtRepositoryRoot/ivy-$status/"))(ivyStylePatterns)
url(s"sbt-ivy-$status", new URI(s"$SbtRepositoryRoot/ivy-$status/").toURL)(ivyStylePatterns)
def sbtPluginRepo(status: String) =
url("sbt-plugin-" + status, new URL(SbtRepositoryRoot + "/sbt-plugin-" + status + "/"))(
url("sbt-plugin-" + status, new URI(SbtRepositoryRoot + "/sbt-plugin-" + status + "/").toURL)(
ivyStylePatterns
)
@deprecated(
Expand All @@ -175,7 +176,7 @@ private[librarymanagement] abstract class ResolverFunctions {
def bintrayRepo(owner: String, repo: String) =
MavenRepository(s"bintray-$owner-$repo", s"https://dl.bintray.com/$owner/$repo/")
def bintrayIvyRepo(owner: String, repo: String) =
url(s"bintray-$owner-$repo", new URL(s"https://dl.bintray.com/$owner/$repo/"))(
url(s"bintray-$owner-$repo", new URI(s"https://dl.bintray.com/$owner/$repo/").toURL)(
Resolver.ivyStylePatterns
)
def jcenterRepo = JCenterRepository
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/sbt/librarymanagement/ResolverTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.librarymanagement

import java.net.URL
import java.net.URI

import sbt.internal.librarymanagement.UnitSpec

Expand All @@ -10,7 +10,7 @@ object ResolverTest extends UnitSpec {
val pats = Vector("[orgPath]")
val patsExpected = Vector("http://foo.com/test/[orgPath]")
val patterns = Resolver
.url("test", new URL("http://foo.com/test"))(
.url("test", new URI("http://foo.com/test").toURL)(
Patterns(
pats,
pats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package sbt.internal.librarymanagement

import java.net.URL
import java.net.URI
import java.util.Collections

import org.apache.ivy.core.module.descriptor.DependencyDescriptor
Expand Down Expand Up @@ -394,15 +394,15 @@ private[sbt] object ConvertResolver {
private[this] val repo = new WarnOnOverwriteFileRepo()
private[this] val progress = new RepositoryCopyProgressListener(this);
override def getResource(source: String) = {
val url = new URL(source)
val url = new URI(source).toURL
if (url.getProtocol == IO.FileScheme)
new FileResource(repo, IO.toFile(url))
else
super.getResource(source)
}

override def put(source: File, destination: String, overwrite: Boolean): Unit = {
val url = new URL(destination)
val url = new URI(destination).toURL
try {
if (url.getProtocol != IO.FileScheme) super.put(source, destination, overwrite)
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sbt

import java.io.File
import java.net.URL
import java.net.URI

import org.apache.ivy.core.cache.ArtifactOrigin
import org.apache.ivy.core.cache.{ DefaultRepositoryCacheManager, RepositoryCacheManager }
Expand Down Expand Up @@ -69,7 +69,7 @@ private[sbt] class FakeResolver(private var name: String, cacheDir: File, module
): ArtifactDownloadReport = {

val report = new ArtifactDownloadReport(artifact.getArtifact)
val path = new URL(artifact.getLocation).toURI.getPath
val path = new URI(artifact.getLocation).toURL.toURI.getPath
val localFile = new File(path)

if (path.nonEmpty && localFile.exists) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.internal.librarymanagement

import java.net.URL
import java.net.URI
import java.io.File

import sbt.librarymanagement._
Expand Down Expand Up @@ -43,7 +43,7 @@ object DMSerializationSpec extends BasicTestSuite {
}

test("""Artifact("foo", url("http://example.com/")) should roundtrip""") {
roundtrip(Artifact("foo", new URL("http://example.com/")))
roundtrip(Artifact("foo", new URI("http://example.com/").toURL))
}

test("""Artifact("foo").extra(("key", "value")) should roundtrip""") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package sbttest

import java.net.URL
import java.net.URI
import sbt.librarymanagement._
import sbt.librarymanagement.syntax._
import verify.BasicTestSuite

class ResolverSpec extends BasicTestSuite {
test("Resolver.url") {
Resolver.url("Test Repo", new URL("http://example.com/"))(Resolver.ivyStylePatterns)
Resolver.url("Test Repo", new URI("http://example.com/").toURL)(Resolver.ivyStylePatterns)
()
}

Expand Down