Skip to content

Commit

Permalink
replaced 'new URL' to 'new URI' per Java 11 target codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekmaity committed Sep 18, 2023
1 parent 2afcdeb commit aeef4c1
Show file tree
Hide file tree
Showing 84 changed files with 244 additions and 244 deletions.
4 changes: 2 additions & 2 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public boolean verify(String s, SSLSession sslSession) {
}

CLIConnectionFactory factory = new CLIConnectionFactory();
String userInfo = new URL(url).getUserInfo();
String userInfo = new URI(url).getUserInfo();
if (userInfo != null) {
factory = factory.basicAuth(userInfo);
} else if (auth != null) {
Expand Down Expand Up @@ -388,7 +388,7 @@ public void close() throws IOException {

private static int plainHttpConnection(String url, List<String> args, CLIConnectionFactory factory) throws IOException, InterruptedException {
LOGGER.log(FINE, "Trying to connect to {0} via plain protocol over HTTP", url);
FullDuplexHttpStream streams = new FullDuplexHttpStream(new URL(url), "cli?remoting=false", factory.authorization);
FullDuplexHttpStream streams = new FullDuplexHttpStream(new URI(url), "cli?remoting=false", factory.authorization);
try (ClientSideImpl connection = new ClientSideImpl(new PlainCLIProtocol.FramedOutput(streams.getOutputStream()))) {
connection.start(args);
InputStream is = streams.getInputStream();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/hudson/cli/FullDuplexHttpStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public FullDuplexHttpStream(URL base, String relativeTarget, String authorizatio

this.base = tryToResolveRedirects(base, authorization);

URL target = new URL(this.base, relativeTarget);
URL target = new URI(this.base, relativeTarget);

UUID uuid = UUID.randomUUID(); // so that the server can correlate those two connections

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/hudson/cli/SSHCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SSHCLI {

static int sshConnection(String jenkinsUrl, String user, List<String> args, PrivateKeyProvider provider, final boolean strictHostKey) throws IOException {
Logger.getLogger(SecurityUtils.class.getName()).setLevel(Level.WARNING); // suppress: BouncyCastle not registered, using the default JCE provider
URL url = new URL(jenkinsUrl + "login");
URL url = new URI(jenkinsUrl + "login");
URLConnection conn = openConnection(url);
CLI.verifyJenkinsConnection(conn);
String endpointDescription = conn.getHeaderField("X-SSH-Endpoint");
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent, At
}
URLClassLoader2 classLoader;
if (usePluginFirstClassLoader) {
classLoader = new PluginFirstClassLoader2(urls.toArray(new URL[0]), parent);
classLoader = new PluginFirstClassLoader2(urls.toArray(new URI[0]), parent);
} else {
classLoader = new URLClassLoader2(urls.toArray(new URL[0]), parent);
classLoader = new URIClassLoader2(urls.toArray(new URI[0]), parent);
}
return classLoader;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -3333,12 +3333,12 @@ private int findSeparator(String pattern) {
}
}

private static final UrlFactory DEFAULT_URL_FACTORY = new UrlFactory();
private static final UrlFactory DEFAULT_URL_FACTORY = new URIFactory();

@Restricted(NoExternalUse.class)
static class UrlFactory {
public URL newURL(String location) throws MalformedURLException {
return new URL(location);
return new URI(location);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ public String getServerName() {
String url = Jenkins.get().getRootUrl();
try {
if (url != null) {
String host = new URL(url).getHost();
String host = new URI(url).getHost();
if (host != null)
return host;
}
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/hudson/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public static int remotePost(String[] args) throws Exception {
if (!home.endsWith("/")) home = home + '/'; // make sure it ends with '/'

// check for authentication info
String auth = new URL(home).getUserInfo();
String auth = new URI(home).getUserInfo();
if (auth != null) auth = "Basic " + new Base64Encoder().encode(auth.getBytes(StandardCharsets.UTF_8));

{ // check if the home is set correctly
HttpURLConnection con = open(new URL(home));
HttpURLConnection con = open(new URI(home));
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if (con.getResponseCode() != 200
Expand All @@ -113,10 +113,10 @@ public static int remotePost(String[] args) throws Exception {
}
}

URL jobURL = new URL(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/");
URL jobURL = new URI(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/");

{ // check if the job name is correct
HttpURLConnection con = open(new URL(jobURL, "acceptBuildResult"));
HttpURLConnection con = open(new URI(jobURL, "acceptBuildResult"));
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if (con.getResponseCode() != 200) {
Expand All @@ -128,7 +128,7 @@ public static int remotePost(String[] args) throws Exception {
// get a crumb to pass the csrf check
String crumbField = null, crumbValue = null;
try {
HttpURLConnection con = open(new URL(home +
HttpURLConnection con = open(new URI(home +
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'"));
if (auth != null) con.setRequestProperty("Authorization", auth);
String line = IOUtils.readFirstLine(con.getInputStream(), "UTF-8");
Expand Down Expand Up @@ -165,7 +165,7 @@ public static int remotePost(String[] args) throws Exception {
throw new IOException(e);
}

URL location = new URL(jobURL, "postBuildResult");
URL location = new URI(jobURL, "postBuildResult");
while (true) {
try {
// start a remote connection
Expand Down Expand Up @@ -193,7 +193,7 @@ public static int remotePost(String[] args) throws Exception {
} catch (HttpRetryException e) {
if (e.getLocation() != null) {
// retry with the new location
location = new URL(e.getLocation());
location = new URI(e.getLocation());
continue;
}
// otherwise failed for reasons beyond us.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1;

// use serveLocalizedFile to support automatic locale selection
rsp.serveLocalizedFile(req, new URL(wrapper.baseResourceURL, '.' + path), expires);
rsp.serveLocalizedFile(req, new URI(wrapper.baseResourceURL, '.' + path), expires);
}

//
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ protected void copyBundledPlugin(URL src, String fileName) throws IOException {
}

/*package*/ static @CheckForNull Manifest parsePluginManifest(URL bundledJpi) {
try (URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi})) {
try (URLClassLoader cl = new URIClassLoader(new URI[]{bundledJpi})) {
InputStream in = null;
try {
URL res = cl.findResource(PluginWrapper.MANIFEST_FILENAME);
Expand Down Expand Up @@ -1848,7 +1848,7 @@ static class UrlPluginCopier implements PluginCopier {

@Override
public void copy(File target) throws Exception {
try (InputStream input = ProxyConfiguration.getInputStream(new URL(url))) {
try (InputStream input = ProxyConfiguration.getInputStream(new URI(url))) {
Files.copy(input, target.toPath());
}
}
Expand All @@ -1875,7 +1875,7 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
if (StringUtils.isNotBlank(items.get(1).getString())) {
// this is a URL deployment
fileName = items.get(1).getString();
copier = new UrlPluginCopier(fileName);
copier = new URIPluginCopier(fileName);
} else {
// this is a file upload
FileItem fileItem = items.get(0);
Expand Down Expand Up @@ -1962,7 +1962,7 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
@RequirePOST public FormValidation doCheckPluginUrl(StaplerRequest request, @QueryParameter String value) throws IOException {
if (StringUtils.isNotBlank(value)) {
try {
URL url = new URL(value);
URL url = new URI(value);
if (!url.getProtocol().startsWith("http")) {
return FormValidation.error(Messages.PluginManager_invalidUrl());
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/PluginWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public String getPluginClass() {

public boolean hasLicensesXml() {
try {
new URL(baseResourceURL, "WEB-INF/licenses.xml").openStream().close();
new URI(baseResourceURL, "WEB-INF/licenses.xml").openStream().close();
return true;
} catch (IOException e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/ProxyConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private void jenkins48775workaround(Proxy proxy, URL url) {
HttpURLConnection preAuth = null;
try {
// We do not care if there is anything at this URL, all we care is that it is using the proxy
preAuth = (HttpURLConnection) new URL("http", url.getHost(), -1, "/").openConnection(proxy);
preAuth = (HttpURLConnection) new URI("http", url.getHost(), -1, "/").openConnection(proxy);
preAuth.setRequestMethod("HEAD");
preAuth.connect();
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public String getAdvertisedHost() {
return CLI_HOST_NAME;
}
try {
return new URL(Jenkins.get().getRootUrl()).getHost();
return new URI(Jenkins.get().getRootUrl()).getHost();
} catch (MalformedURLException e) {
throw new IllegalStateException("Could not get TcpSlaveAgentListener host name", e);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/WebAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Locale get() {
JVM jvm;
try {
jvm = new JVM();
new URLClassLoader(new URL[0], getClass().getClassLoader());
new URIClassLoader(new URI[0], getClass().getClassLoader());
} catch (SecurityException e) {
throw new InsufficientPermissionDetected(e);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/cli/InstallPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected int run() throws Exception {

// is this an URL?
try {
URL u = new URL(source);
URL u = new URI(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
File f = getTmpFile();
FileUtils.copyURLToFile(u, f); // TODO JENKINS-58248 proxy
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/console/UrlAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class UrlAnnotator extends ConsoleAnnotatorFactory<Object> {
@Override
public ConsoleAnnotator newInstance(Object context) {
return new UrlConsoleAnnotator();
return new URIConsoleAnnotator();
}

private static class UrlConsoleAnnotator extends ConsoleAnnotator {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public FormValidation updateNow() throws IOException {
}
String jsonString;
try {
jsonString = loadJSONHTML(new URL(site + ".html?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)));
jsonString = loadJSONHTML(new URI(site + ".html?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)));
toolInstallerMetadataExists = true;
} catch (Exception e) {
LOGGER.log(Level.FINE, "Could not load json from " + site, e);
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/hudson/model/UpdateCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ public UpdateCenterConfiguration() {
* @throws IOException if a connection can't be established
*/
public void checkConnection(ConnectionCheckJob job, String connectionCheckUrl) throws IOException {
testConnection(new URL(connectionCheckUrl));
testConnection(new URI(connectionCheckUrl));
}

/**
Expand All @@ -1230,9 +1230,9 @@ public void checkUpdateCenter(ConnectionCheckJob job, String updateCenterUrl) th
static URL toUpdateCenterCheckUrl(String updateCenterUrl) throws MalformedURLException {
URL url;
if (updateCenterUrl.startsWith("http://") || updateCenterUrl.startsWith("https://")) {
url = new URL(updateCenterUrl + (updateCenterUrl.indexOf('?') == -1 ? "?uctest" : "&uctest"));
url = new URI(updateCenterUrl + (updateCenterUrl.indexOf('?') == -1 ? "?uctest" : "&uctest"));
} else {
url = new URL(updateCenterUrl);
url = new URI(updateCenterUrl);
}
return url;
}
Expand Down Expand Up @@ -2193,7 +2193,7 @@ public InstallationJob(Plugin plugin, UpdateSite site, Authentication auth, bool

@Override
protected URL getURL() throws MalformedURLException {
return new URL(plugin.url);
return new URI(plugin.url);
}

@Override
Expand Down Expand Up @@ -2422,7 +2422,7 @@ public PluginDowngradeJob(Plugin plugin, UpdateSite site, Authentication auth) {

@Override
protected URL getURL() throws MalformedURLException {
return new URL(plugin.url);
return new URI(plugin.url);
}

@Override
Expand Down Expand Up @@ -2517,7 +2517,7 @@ protected URL getURL() throws MalformedURLException {
if (site == null) {
throw new MalformedURLException("no update site defined");
}
return new URL(site.getData().core.url);
return new URI(site.getData().core.url);
}

@Override
Expand Down Expand Up @@ -2564,7 +2564,7 @@ protected URL getURL() throws MalformedURLException {
if (site == null) {
throw new MalformedURLException("no update site defined");
}
return new URL(site.getData().core.url);
return new URI(site.getData().core.url);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public long getDataTimestamp() {

@Restricted(NoExternalUse.class)
public @NonNull FormValidation updateDirectlyNow(boolean signatureCheck) throws IOException {
return updateData(DownloadService.loadJSON(new URL(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8))), signatureCheck);
return updateData(DownloadService.loadJSON(new URI(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8))), signatureCheck);
}

private FormValidation updateData(String json, boolean signatureCheck)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/scm/RepositoryBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected static URL normalizeToEndWithSlash(URL url) {
String q = url.getQuery();
q = q != null ? '?' + q : "";
try {
return new URL(url, url.getPath() + '/' + q);
return new URI(url, url.getPath() + '/' + q);
} catch (MalformedURLException e) {
// impossible
throw new Error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen
if (isUpToDate(expected, inst))
return expected;

if (expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
if (expected.installIfNecessaryFrom(new URI(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
expected.child(".timestamp").delete(); // we don't use the timestamp
FilePath base = findPullUpDirectory(expected);
if (base != null && base != expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public String getSubdir() {
@Override
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
FilePath dir = preferredLocation(tool, node);
if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
if (dir.installIfNecessaryFrom(new URI(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
dir.act(new ChmodRecAPlusX());
}
if (subdir == null) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/util/FormFieldValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected void check() throws IOException, ServletException {
if (!value.endsWith("/")) value += '/';

try {
URL url = new URL(value);
URL url = new URI(value);
HttpURLConnection con = openConnection(url);
con.connect();
if (con.getResponseCode() != 200
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/install/SetupWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public JSONArray getPlatformPluginUpdates() {
suggestedPluginUrl = suggestedPluginUrl + (suggestedPluginUrl.contains("?") ? "&" : "?") + "version=" + version;
}
try {
URLConnection connection = ProxyConfiguration.open(new URL(suggestedPluginUrl));
URLConnection connection = ProxyConfiguration.open(new URI(suggestedPluginUrl));

try {
String initialPluginJson = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* Construct a UrlValidator with valid schemes of "http", and "https".
*
* String[] schemes = {"http","https"}.
* UrlValidator urlValidator = new UrlValidator(schemes);
* UrlValidator urlValidator = new URIValidator(schemes);
* if (urlValidator.isValid("ftp://foo.bar.com/")) {
* System.out.println("url is valid");
* } else {
Expand All @@ -60,7 +60,7 @@
* prints "url is invalid"
* If instead the default constructor is used.
*
* UrlValidator urlValidator = new UrlValidator();
* UrlValidator urlValidator = new URIValidator();
* if (urlValidator.isValid("ftp://foo.bar.com/")) {
* System.out.println("url is valid");
* } else {
Expand Down Expand Up @@ -179,7 +179,7 @@ public class UrlValidator implements Serializable {
/**
* Singleton instance of this class with default schemes and options.
*/
private static final UrlValidator DEFAULT_URL_VALIDATOR = new UrlValidator();
private static final UrlValidator DEFAULT_URL_VALIDATOR = new URIValidator();

/**
* Returns the singleton instance of this class with default schemes and options.
Expand Down
Loading

0 comments on commit aeef4c1

Please sign in to comment.