Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This reverts commit dc190ba.
  • Loading branch information
basil committed Oct 23, 2023
1 parent 9d29a54 commit 8c921e7
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 111 deletions.
9 changes: 1 addition & 8 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -3339,13 +3338,7 @@ private int findSeparator(String pattern) {
@Restricted(NoExternalUse.class)
static class UrlFactory {
public URL newURL(String location) throws MalformedURLException {
try {
return new URI(location).toURL();
} catch (URISyntaxException e) {
MalformedURLException mex = new MalformedURLException(e.getMessage());
mex.initCause(e);
throw mex;
}
return new URL(location);

Check warning on line 3341 in core/src/main/java/hudson/FilePath.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 3341 is not covered by tests
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -1938,11 +1939,11 @@ public String getServerName() {
String url = Jenkins.get().getRootUrl();
try {
if (url != null) {
String host = new URI(url).toURL().getHost();
String host = new URL(url).getHost();
if (host != null)
return host;
}
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {

Check warning on line 1946 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1942-1946 are not covered by tests
// fall back to HTTP request
}
return Stapler.getCurrentRequest().getServerName();
Expand Down
13 changes: 6 additions & 7 deletions core/src/main/java/hudson/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.io.Writer;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -100,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 URI(home).toURL().getUserInfo();
String auth = new URL(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 URI(home).toURL());
HttpURLConnection con = open(new URL(home));
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if (con.getResponseCode() != 200
Expand All @@ -114,7 +113,7 @@ public static int remotePost(String[] args) throws Exception {
}
}

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

{ // check if the job name is correct
HttpURLConnection con = open(new URL(jobURL, "acceptBuildResult"));
Expand All @@ -129,8 +128,8 @@ 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 URI(home +
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'").toURL());
HttpURLConnection con = open(new URL(home +
"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'"));
if (auth != null) con.setRequestProperty("Authorization", auth);
String line = IOUtils.readFirstLine(con.getInputStream(), "UTF-8");
String[] components = line.split(":");
Expand Down Expand Up @@ -194,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 URI(e.getLocation()).toURL();
location = new URL(e.getLocation());

Check warning on line 196 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 102-196 are not covered by tests
continue;
}
// otherwise failed for reasons beyond us.
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ static class UrlPluginCopier implements PluginCopier {

@Override
public void copy(File target) throws Exception {
try (InputStream input = ProxyConfiguration.getInputStream(new URI(url).toURL())) {
try (InputStream input = ProxyConfiguration.getInputStream(new URL(url))) {
Files.copy(input, target.toPath());
}
}
Expand Down Expand Up @@ -1948,15 +1948,15 @@ 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 URI(value).toURL();
URL url = new URL(value);
if (!url.getProtocol().startsWith("http")) {
return FormValidation.error(Messages.PluginManager_invalidUrl());
}

if (!url.getProtocol().equals("https")) {
return FormValidation.warning(Messages.PluginManager_insecureUrl());
}
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {

Check warning on line 1959 in core/src/main/java/hudson/PluginManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1951-1959 are not covered by tests
return FormValidation.error(e.getMessage());
}
}
Expand Down
27 changes: 12 additions & 15 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import java.io.SequenceInputStream;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.ServerSocketChannel;
import java.nio.charset.StandardCharsets;
import java.security.interfaces.RSAPublicKey;
Expand Down Expand Up @@ -85,7 +85,8 @@ public final class TcpSlaveAgentListener extends Thread {
public final int configuredPort;

/**
* @param port Use 0 to choose a random port.
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP agent listener port=" + port);
Expand Down Expand Up @@ -119,7 +120,6 @@ public int getPort() {

/**
* Gets the TCP port number in which we are advertising.
*
* @since 1.656
*/
public int getAdvertisedPort() {
Expand All @@ -128,23 +128,21 @@ public int getAdvertisedPort() {

/**
* Gets the host name that we advertise protocol clients to connect to.
*
* @since 2.198
*/
public String getAdvertisedHost() {
if (CLI_HOST_NAME != null) {
return CLI_HOST_NAME;
return CLI_HOST_NAME;
}
try {
return new URI(Jenkins.get().getRootUrl()).getHost();
} catch (URISyntaxException e) {
return new URL(Jenkins.get().getRootUrl()).getHost();
} catch (MalformedURLException e) {

Check warning on line 139 in core/src/main/java/hudson/TcpSlaveAgentListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 138-139 are not covered by tests
throw new IllegalStateException("Could not get TcpSlaveAgentListener host name", e);
}
}

/**
* Gets the Base64 encoded public key that forms part of this instance's identity keypair.
*
* @return the Base64 encoded public key
* @since 2.16
*/
Expand All @@ -167,7 +165,6 @@ public String getAgentProtocolNames() {

/**
* Gets Remoting minimum supported version to prevent unsupported agents from connecting
*
* @since 2.171
*/
public VersionNumber getRemotingMinimumVersion() {
Expand Down Expand Up @@ -231,9 +228,9 @@ public void shutdown() {

private final class ConnectionHandler extends Thread {
private static final String DEFAULT_RESPONSE_404 = "HTTP/1.0 404 Not Found\r\n" +
"Content-Type: text/plain;charset=UTF-8\r\n" +
"\r\n" +
"Not Found\r\n";
"Content-Type: text/plain;charset=UTF-8\r\n" +
"\r\n" +
"Not Found\r\n";
private final Socket s;
/**
* Unique number to identify this connection. Used in the log.
Expand Down Expand Up @@ -410,8 +407,8 @@ public boolean connect(Socket socket) throws IOException {
socket.getRemoteSocketAddress(),
new String(ping, StandardCharsets.UTF_8),
responseLength > 0 && responseLength <= response.length ?
new String(response, 0, responseLength, StandardCharsets.UTF_8) :
"bad response length " + responseLength,
new String(response, 0, responseLength, StandardCharsets.UTF_8) :
"bad response length " + responseLength,
});
return false;
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/hudson/cli/InstallPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import hudson.util.VersionNumber;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -106,7 +104,7 @@ protected int run() throws Exception {

// is this an URL?
try {
URL u = new URI(source).toURL();
URL u = new URL(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
File f = getTmpFile();
FileUtils.copyURLToFile(u, f); // TODO JENKINS-58248 proxy
Expand All @@ -115,7 +113,7 @@ protected int run() throws Exception {
pm.dynamicLoad(f);
}
continue;
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {

Check warning on line 116 in core/src/main/java/hudson/cli/InstallPluginCommand.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 107-116 are not covered by tests
// not an URL
}

Expand Down
32 changes: 15 additions & 17 deletions core/src/main/java/hudson/model/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand Down Expand Up @@ -80,7 +79,6 @@ public class DownloadService {
* the prefix for the signature validator name
*/
private static final String signatureValidatorPrefix = "downloadable";

/**
* Builds up an HTML fragment that starts all the download jobs.
*
Expand Down Expand Up @@ -110,7 +108,6 @@ public Downloadable getById(String id) {
* Confusingly, the JSONP files are given the {@code *.json} file extension, when they are really JavaScript and should be {@code *.js}.
* This method extracts the JSON from a JSONP URL, since that is what we actually want when we download from the server.
* (Currently the true JSON is not published separately, and extracting from the {@code *.json.html} is more work.)
*
* @param src a URL to a JSONP file (typically including {@code id} and {@code version} query parameters)
* @return the embedded JSON text
* @throws IOException if either downloading or processing failed
Expand All @@ -136,7 +133,6 @@ public static String loadJSON(URL src) throws IOException {

/**
* Loads JSON from a JSON-with-{@code postMessage} URL.
*
* @param src a URL to a JSON HTML file (typically including {@code id} and {@code version} query parameters)
* @return the embedded JSON text
* @throws IOException if either downloading or processing failed
Expand Down Expand Up @@ -219,13 +215,14 @@ public static class Downloadable implements ExtensionPoint {
/**
* Creates a new downloadable.
*
* @param id The ID to use.
* @param url URL relative to {@link UpdateCenter#getDefaultBaseUrl()}.
* So if this string is "foo.json", the ultimate URL will be
* something like "http://updates.jenkins-ci.org/updates/foo.json"
* <p>
* For security and privacy reasons, we don't allow the retrieval
* from random locations.
* @param id The ID to use.
* @param url
* URL relative to {@link UpdateCenter#getDefaultBaseUrl()}.
* So if this string is "foo.json", the ultimate URL will be
* something like "http://updates.jenkins-ci.org/updates/foo.json"
*
* For security and privacy reasons, we don't allow the retrieval
* from random locations.
* @param interval The interval, in milliseconds, between attempts to update this downloadable's data.
*/
public Downloadable(@NonNull String id, @NonNull String url, long interval) {
Expand Down Expand Up @@ -289,6 +286,7 @@ public String getId() {
*
* @param clazz The class to use to generate an ID.
* @return The ID generated based on the specified class.
*
* @since 2.244
*/
@NonNull
Expand Down Expand Up @@ -324,7 +322,8 @@ public List<String> getUrls() {
/**
* How often do we retrieve the new image?
*
* @return number of milliseconds between retrieval.
* @return
* number of milliseconds between retrieval.
*/
public long getInterval() {
return interval;
Expand Down Expand Up @@ -389,7 +388,7 @@ public FormValidation updateNow() throws IOException {
}
String jsonString;
try {
jsonString = loadJSONHTML(new URI(site + ".html?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)).toURL());
jsonString = loadJSONHTML(new URL(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 Expand Up @@ -417,7 +416,6 @@ public FormValidation updateNow() throws IOException {

/**
* Function that takes multiple JSONObjects and returns a single one.
*
* @param jsonList to be processed
* @return a single JSONObject
*/
Expand All @@ -427,10 +425,9 @@ public JSONObject reduce(List<JSONObject> jsonList) {

/**
* check if the list of update center entries has duplicates
*
* @param genericList list of entries coming from multiple update centers
* @param comparator the unique ID of an entry
* @param <T> the generic class
* @param comparator the unique ID of an entry
* @param <T> the generic class
* @return true if the list has duplicates, false otherwise
*/
public static <T> boolean hasDuplicates(List<T> genericList, String comparator) {
Expand Down Expand Up @@ -473,6 +470,7 @@ public static ExtensionList<Downloadable> all() {
* {@link #idFor(Class)}).
*
* @param clazz The class to use to determine the downloadable's ID.
*
* @since 2.244
*/
@CheckForNull
Expand Down
Loading

0 comments on commit 8c921e7

Please sign in to comment.