Skip to content

Commit

Permalink
[GR-43894] Fix for 'new URL()' deprecation.
Browse files Browse the repository at this point in the history
PullRequest: graal/13654
  • Loading branch information
ansalond committed Feb 15, 2023
2 parents e34b2cb + 06740ce commit c3f369a
Show file tree
Hide file tree
Showing 29 changed files with 152 additions and 68 deletions.
4 changes: 2 additions & 2 deletions vm/ci/ci_includes/vm.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ local jdks = common_json.jdks;
},

local builds = [
utils.add_gate_predicate(self.vm_java_17 + vm_common.gate_vm_linux_amd64 + {
utils.add_gate_predicate(self.vm_java_20 + vm_common.gate_vm_linux_amd64 + {
run: [
['mx', 'build'],
['mx', 'unittest', '--suite', 'vm'],
],
name: 'gate-vm-unittest-linux-amd64',
}, ['sdk', 'truffle', 'vm']),
utils.add_gate_predicate(self.vm_java_17 + common_json.devkits['windows-jdk17'] + vm_common.gate_vm_windows_amd64 + {
utils.add_gate_predicate(self.vm_java_20 + common_json.devkits['windows-jdk20'] + vm_common.gate_vm_windows_amd64 + {
run: [
['mx', 'build'],
['mx', 'unittest', '--suite', 'vm'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private void setupCatalog() throws Exception {
URL u = getClass().getResource(relSpec);
Handler.bind(TEST_CATALOG_URL, u);

downloader = new RemoteCatalogDownloader(this, this, new URL(TEST_CATALOG_URL));
downloader = new RemoteCatalogDownloader(this, this, SystemUtils.toURL(TEST_CATALOG_URL));
this.registry = new CatalogContents(this, downloader.getStorage(), getLocalRegistry());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public CommandTestBase() {

protected void initRemoteComponent(String relativeJar, String u, String disp, String spec) throws IOException {
clu = getClass().getResource(relativeJar);
url = new URL(u);
url = SystemUtils.toURL(u);
Handler.bind(url.toString(), clu);

File f = dataFile(relativeJar).toFile();
Expand All @@ -104,7 +104,7 @@ protected void initRemoteComponent(String relativeJar, String u, String disp, St

protected void initURLComponent(String relativeJar, String spec) throws IOException {
clu = getClass().getResource(relativeJar);
url = new URL(spec);
url = SystemUtils.toURL(spec);
Handler.bind(url.toString(), clu);

File f = dataFile(relativeJar).toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.Set;
import org.graalvm.component.installer.CommandInput;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.remote.CatalogIterable;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.Commands;
Expand Down Expand Up @@ -102,7 +103,7 @@ private void setupCatalog(String rel) throws Exception {
}
Handler.bind(TEST_CATALOG_URL, u);

downloader = new RemoteCatalogDownloader(this, this, new URL(TEST_CATALOG_URL));
downloader = new RemoteCatalogDownloader(this, this, SystemUtils.toURL(TEST_CATALOG_URL));
this.registry = new CatalogContents(this, downloader.getStorage(), getLocalRegistry());
}

Expand All @@ -122,7 +123,7 @@ private void setupCatalog2(String rel) throws IOException {
public void testRejectMismatchingCatalog() throws Exception {
setupVersion("1.0.0-rc1");

URL rubyURL = new URL("test://release/graalvm-ruby.zip");
URL rubyURL = SystemUtils.toURL("test://release/graalvm-ruby.zip");
Handler.bind(rubyURL.toString(), new URLConnection(rubyURL) {
@Override
public void connect() throws IOException {
Expand Down Expand Up @@ -150,7 +151,7 @@ public void connect() throws IOException {
public void testRejectMetaDontDownloadPackage() throws Exception {
setupVersion("0.33-dev");

URL rubyURL = new URL("test://release/graalvm-ruby.zip");
URL rubyURL = SystemUtils.toURL("test://release/graalvm-ruby.zip");
Handler.bind(rubyURL.toString(), new URLConnection(rubyURL) {
@Override
public void connect() throws IOException {
Expand All @@ -175,7 +176,7 @@ public void connect() throws IOException {
public void testCheckPostinstMessageLoaded() throws Exception {
setupVersion("0.33");
URL x = getClass().getResource("postinst2.jar");
URL rubyURL = new URL("test://release/postinst2.jar");
URL rubyURL = SystemUtils.toURL("test://release/postinst2.jar");
Handler.bind(rubyURL.toString(), x);

setupCatalog(null);
Expand All @@ -197,7 +198,7 @@ public void testCheckPostinstMessageLoaded() throws Exception {
public void testPostinstMessagePrinted() throws Exception {
setupVersion("0.33");
URL x = getClass().getResource("postinst2.jar");
URL rubyURL = new URL("test://release/postinst2.jar");
URL rubyURL = SystemUtils.toURL("test://release/postinst2.jar");
Handler.bind(rubyURL.toString(), x);

setupCatalog(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ public void testFailOnExistingFromCatalog() throws Exception {
ComponentInfo fakeInfo = new ComponentInfo("ruby", "Fake ruby", "1.0");
storage.installed.add(fakeInfo);

URL u = new URL("test://graalvm.io/download/catalog");
URL u2 = new URL(u, "graalvm-ruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/catalog");
URL u2 = SystemUtils.toURL(u, "graalvm-ruby.zip");

Handler.bind(u.toString(), getClass().getResource("catalog"));
storage.graalInfo.put(CommonConstants.CAP_GRAALVM_VERSION, "0.33-dev");
Expand Down Expand Up @@ -272,8 +272,8 @@ public void testSkipExistingFromCatalog() throws Exception {
ComponentInfo fakeInfo = new ComponentInfo("ruby", "Fake ruby", "1.0");
storage.installed.add(fakeInfo);

URL u = new URL("test://graalvm.io/download/catalog");
URL u2 = new URL(u, "graalvm-ruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/catalog");
URL u2 = SystemUtils.toURL(u, "graalvm-ruby.zip");

Handler.bind(u.toString(), getClass().getResource("catalog"));
Handler.bind(u2.toString(), getClass().getResource("graalvm-ruby.zip"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.jar.JarFile;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.UserAbortException;
import org.graalvm.component.installer.persist.MetadataLoader;
import org.graalvm.component.installer.jar.JarMetaLoader;
Expand Down Expand Up @@ -394,7 +395,7 @@ public void testLicenseRemoteDownload() throws Exception {
addLoader("license.ruby");
URL licURL = getClass().getResource("license.ruby/license.txt");

URL remoteUrl = new URL("test://somewhere.org/license.txt");
URL remoteUrl = SystemUtils.toURL("test://somewhere.org/license.txt");
Handler.bind(remoteUrl.toString(), licURL);
licensedInfo.setLicensePath(remoteUrl.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.graalvm.component.installer.CommonConstants;
import static org.graalvm.component.installer.CommonConstants.JSON_KEY_COMPONENTS;
import org.graalvm.component.installer.MemoryFeedback;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.CatalogContents;
import org.graalvm.component.installer.model.ComponentInfo;
Expand Down Expand Up @@ -74,7 +75,7 @@ private void initRemoteStorage() throws MalformedURLException {
this, getLocalRegistry(), catalogContents,
"linux_amd64",
Version.fromString("1.0.0-rc3-dev"),
new URL("http://go.to/graalvm"));
SystemUtils.toURL("http://go.to/graalvm"));
this.registry = new CatalogContents(this, remoteStorage, localRegistry);
}

Expand Down Expand Up @@ -216,7 +217,7 @@ private void assert110Components(Version v, Version min) throws Exception {
this, getLocalRegistry(), catalogContents,
"linux_amd64",
v,
new URL("http://go.to/graalvm"));
SystemUtils.toURL("http://go.to/graalvm"));
this.registry = new CatalogContents(this, remoteStorage, localRegistry);

AvailableCommand inst = new AvailableCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.graalvm.component.installer.ComponentCatalog;
import org.graalvm.component.installer.ComponentParam;
import org.graalvm.component.installer.FailedOperationException;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.UnknownVersionException;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.CatalogContents;
Expand Down Expand Up @@ -663,7 +664,7 @@ public void clearHandlerBindings() {
*/
@Test
public void testUpgradeRespectsTargetCatalogURLs() throws Exception {
URL u = new URL("test://catalog-19.3.properties");
URL u = SystemUtils.toURL("test://catalog-19.3.properties");
Handler.bind(u.toString(), dataFile("../repo/catalog-19.3.properties").toUri().toURL());

initVersion("1.0.0.0", "../repo/catalog-19.3.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.oracle.truffle.tools.utils.json.JSONArray;
import com.oracle.truffle.tools.utils.json.JSONException;
import com.oracle.truffle.tools.utils.json.JSONObject;
import java.util.Arrays;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.TestBase;
import org.graalvm.component.installer.Version;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void testConstruct() {
ap = new ArtifactParser(jo);
fail("StringIndexOutOfBoundsException expected.");
} catch (StringIndexOutOfBoundsException ex) {
assertEquals("begin 0, end -1, length 15", ex.getMessage());
assertEquals(makeSubstringExceptionMessage(0, -1, 15), ex.getMessage());
// expected
}
jo.put(JSON_KEY_DISP_NAME, JSON_VAL_DISP_NAME + SystemUtils.OS.get().getName());
Expand Down Expand Up @@ -181,6 +182,22 @@ public void testConstruct() {
assertEquals(JSON_META_VAL_SYMBOLIC_NAME, ap.getLabel());
}

private static String makeSubstringExceptionMessage(int start, int end, int length) {
String str = makeStringOfLength(length);
try {
str.substring(start, end);
} catch (StringIndexOutOfBoundsException ex) {
return ex.getMessage();
}
return null;
}

private static String makeStringOfLength(int length) {
char[] arr = new char[length];
Arrays.fill(arr, 'a');
return String.valueOf(arr);
}

@Test
public void testAsComponentInfo() {
JSONObject jo = prepareJO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.graalvm.component.installer.gds.rest;

import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.ComponentInfo;
import static org.junit.Assert.assertEquals;
Expand All @@ -52,7 +53,7 @@ public class GDSCatalogStorageTest extends CommandTestBase {
@Override
public void setUp() throws Exception {
super.setUp();
mockUrl = new URL(MOCK_URL);
mockUrl = SystemUtils.toURL(MOCK_URL);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.graalvm.component.installer.BundleConstants;
import org.graalvm.component.installer.CommandInput;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.model.ComponentInfo;
import org.graalvm.component.installer.CommonConstants;
import static org.graalvm.component.installer.CommonConstants.CAP_JAVA_VERSION;
Expand Down Expand Up @@ -197,7 +198,7 @@ public void testLoadComponentStorage() throws Exception {
@Test
public void testInterceptDownloadException() throws Exception {
String mockUrlString = "http://some.mock.url/";
URL url = new URL(mockUrlString);
URL url = SystemUtils.toURL(mockUrlString);
channel.setIndexURL(url);
IOException ioExc = new IOException("some Exception.");
FileDownloader fd = new FileDownloader("something", url, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void testMakeArtifactDownloadURL() {

@Test
public void testFillBasics() throws MalformedURLException {
FileDownloader fd = new FileDownloader(TEST_ID, new URL(testURL), this);
FileDownloader fd = new FileDownloader(TEST_ID, SystemUtils.toURL(testURL), this);
testConnector.fillBasics(fd);
Map<String, String> header = fd.getRequestHeaders();
assertEquals(GDSRESTConnector.HEADER_VAL_GZIP, header.get(GDSRESTConnector.HEADER_ENCODING));
Expand Down Expand Up @@ -370,7 +370,7 @@ protected FileDownloader obtain(String endp) {

@Override
GDSRequester getGDSRequester(String acceptLicLink, String licID) throws MalformedURLException {
return new TestGDSRequester(new URL(acceptLicLink), licID);
return new TestGDSRequester(SystemUtils.toURL(acceptLicLink), licID);
}

final class TestGDSRequester extends GDSRESTConnector.GDSRequester {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.graalvm.component.installer.ComponentCatalog;
import org.graalvm.component.installer.SoftwareChannel;
import org.graalvm.component.installer.SoftwareChannelSource;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.CatalogContents;
import org.graalvm.component.installer.model.ComponentInfo;
Expand Down Expand Up @@ -205,7 +206,7 @@ public void testSpecificJavaPresent() throws Exception {
@Test
public void testNoErrorsWithLocalCatalogs() throws Exception {
URL clu = getClass().getResource("data/catalog");
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");
Handler.bind(u.toString(),
clu);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.graalvm.component.installer.CommonConstants;
import org.graalvm.component.installer.ComponentCatalog;
import org.graalvm.component.installer.SoftwareChannel;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.CatalogContents;
import org.graalvm.component.installer.model.ComponentInfo;
Expand Down Expand Up @@ -62,7 +63,7 @@ ComponentCatalog openCatalog(SoftwareChannel ch, Version v) throws IOException {

void setupCatalogFormat1(String res) throws Exception {
URL clu = getClass().getResource(res);
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");
Handler.bind(u.toString(),
clu);
RemoteCatalogDownloader d = new RemoteCatalogDownloader(this, this, u);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testDownloadExistingFile() throws Exception {
Handler.bind("test://graalvm.io/download/truffleruby.zip",
clu);

URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");
FileDownloader dn = new FileDownloader("test",
u, this);
dn.download();
Expand All @@ -95,7 +95,7 @@ public void testDownloadComputeDigest() throws Exception {
Handler.bind("test://graalvm.io/download/truffleruby.zip",
clu);

URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");
FileDownloader dn = new FileDownloader("test",
u, this);
dn.setShaDigest(new byte[0]);
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testDownloadVerboseMessages() throws Exception {
Handler.bind("test://graalvm.io/download/truffleruby.zip",
clu);

URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");
Check check = new Check();
delegateFeedback(check);
FileDownloader dn = new FileDownloader("test",
Expand All @@ -205,7 +205,7 @@ public void testDownloadVerboseMessages() throws Exception {
@Test
public void testDownloadSlowProxy() throws Exception {
URL clu = getClass().getResource("data/truffleruby2.jar");
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");

ChunkedConnection proxyConnect = new ChunkedConnection(
u,
Expand Down Expand Up @@ -250,7 +250,7 @@ public void connect() throws IOException {
@Test
public void testDownloadFailedProxy() throws Exception {
URL clu = getClass().getResource("data/truffleruby2.jar");
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");

ChunkedConnection directConnect = new ChunkedConnection(
u,
Expand Down Expand Up @@ -299,7 +299,7 @@ public void connect() throws IOException {
@Test
public void testDownloadProxy500() throws Exception {
URL clu = getClass().getResource("data/truffleruby2.jar");
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");

ChunkedConnection directConnect = new ChunkedConnection(
u,
Expand Down Expand Up @@ -352,7 +352,7 @@ public void connect() throws IOException {
@Test
public void testDownloadFailure() throws Exception {
URL clu = getClass().getResource("data/truffleruby2.jar");
URL u = new URL("test://graalvm.io/download/truffleruby.zip");
URL u = SystemUtils.toURL("test://graalvm.io/download/truffleruby.zip");

ChunkedConnection conn = new ChunkedConnection(
u,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.List;

import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.TestBase;
import org.graalvm.component.installer.persist.ProxyResource;
import org.graalvm.component.installer.remote.ProxyConnectionFactory.Connector;
Expand All @@ -52,7 +54,7 @@ public class ProxyConnectionFactoryTest extends TestBase {

@Before
public void setUp() throws Exception {
URL u = new URL(RESOURCE_URL);
URL u = SystemUtils.toURL(RESOURCE_URL);
instance = new ProxyConnectionFactory(this, u);
// override proxies which may be loaded from testsuite environment:
instance.setProxy(true, null);
Expand Down
Loading

0 comments on commit c3f369a

Please sign in to comment.