avoid deprecated `java.net.URL` constructor

- https://bugs.openjdk.org/browse/JDK-8295949
- 4338f527aa
This commit is contained in:
xuwei-k 2023-06-25 08:23:09 +09:00
parent 5ba9f3910a
commit c7ec22cff8
5 changed files with 9 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import xsbti.*;
@ -72,7 +73,7 @@ public class XMainConfiguration {
URL url = baseLoader.getResource(className);
String path = url.toString().replaceAll(className.concat("$"), "");
URL[] urlArray = new URL[1];
urlArray[0] = new URL(path);
urlArray[0] = new URI(path).toURL();
ClassLoader topLoader = configuration.provider().scalaProvider().launcher().topLoader();
// This loader doesn't have the scala library in it so it's critical that none of the code
// in this file use the scala library.

View File

@ -17,6 +17,7 @@ import sbt.librarymanagement.ModuleID
import sbt.internal.util.Attributed
import sbt.util.Logger
import java.net.URI
private[sbt] object APIMappings {
def extract(cp: Seq[Attributed[File]], log: Logger): Seq[(File, URL)] =
@ -38,7 +39,7 @@ private[sbt] object APIMappings {
} yield (entry, u)
private[this] def parseURL(s: String, forEntry: File, log: Logger): Option[URL] =
try Some(new URL(s))
try Some(new URI(s).toURL)
catch {
case e: MalformedURLException =>
log.warn(s"Invalid API base URL '$s' for classpath entry '$forEntry': ${e.toString}")

View File

@ -13,7 +13,7 @@ import Def._
import Keys.{ sbtVersion, state, terminal }
import java.io.{ File, FileInputStream, FileOutputStream, InputStream, IOException }
import java.net.URL
import java.net.URI
import java.nio.file.{ Files, Path }
import java.util.zip.ZipInputStream
import sbt.io.IO
@ -95,7 +95,7 @@ private[sbt] object InstallSbtn {
}
private[this] def downloadRelease(term: Terminal, version: String, location: Path): Unit = {
val zip = s"https://github.com/sbt/sbt/releases/download/v$version/sbt-$version.zip"
val url = new URL(zip)
val url = new URI(zip).toURL
term.printStream.println(s"downloading $zip to $location")
transfer(url.openStream(), location)
}
@ -133,7 +133,7 @@ private[sbt] object InstallSbtn {
private[this] def downloadCompletion(completion: String, version: String, target: Path): Unit = {
Files.createDirectories(target.getParent)
val comp = s"https://raw.githubusercontent.com/sbt/sbt/v$version/client/completions/$completion"
transfer(new URL(comp).openStream, target)
transfer(new URI(comp).toURL.openStream, target)
}
private[this] def setupShell(
shell: String,

View File

@ -32,7 +32,7 @@ package object sbt
// IO
def uri(s: String): URI = new URI(s)
def file(s: String): File = new File(s)
def url(s: String): URL = new URL(s)
def url(s: String): URL = new URI(s).toURL
implicit def fileToRichFile(file: File): sbt.io.RichFile = new sbt.io.RichFile(file)
implicit def filesToFinder(cc: Traversable[File]): sbt.io.PathFinder =
sbt.io.PathFinder.strict(cc)

View File

@ -20,7 +20,7 @@ lazy val root = (project in file("."))
),
version := "0.3.1-SNAPSHOT",
description := "An HTTP client for Scala with Async Http Client underneath.",
licenses := Seq("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt")),
licenses := Seq("Apache 2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
)),
ivyPaths := IvyPaths(
(baseDirectory in ThisBuild).value,