Skip to content

Commit 6361505

Browse files
committed
Fix URL deprecation in tests and snippets
Reduce warnings in the workspace.
1 parent d145b2c commit 6361505

File tree

5 files changed

+46
-56
lines changed

5 files changed

+46
-56
lines changed

examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2013 Tom Schindl and others.
2+
* Copyright (c) 2006, 2025 Tom Schindl and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,8 @@
1515
package org.eclipse.jface.snippets.dialogs;
1616

1717
import java.net.MalformedURLException;
18+
import java.net.URI;
19+
import java.net.URISyntaxException;
1820
import java.net.URL;
1921

2022
import org.eclipse.jface.dialogs.Dialog;
@@ -62,9 +64,9 @@ protected Button createButton(Composite parent, int id, String label, boolean de
6264

6365
URL url;
6466
try {
65-
url = new URL("http://www.eclipse.org/home/images/enterprise.gif");
67+
url = new URI("http://www.eclipse.org/home/images/enterprise.gif").toURL();
6668
b.setImage(ImageDescriptor.createFromURL(url).createImage());
67-
} catch (MalformedURLException e) {
69+
} catch (MalformedURLException | URISyntaxException e) {
6870
e.printStackTrace();
6971
}
7072

tests/org.eclipse.ui.tests.browser/src/org/eclipse/ui/tests/browser/internal/ExternalBrowserTestCase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2017 IBM Corporation and others.
2+
* Copyright (c) 2004, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.browser.internal;
1515

16-
import java.net.URL;
16+
import java.net.URI;
1717

1818
import org.eclipse.ui.PlatformUI;
1919
import org.eclipse.ui.browser.IWebBrowser;
@@ -28,15 +28,15 @@ public void testBrowser() throws Exception {
2828
IWorkbenchBrowserSupport wbs = PlatformUI.getWorkbench().getBrowserSupport();
2929
IWebBrowser wb = wbs.createBrowser("test2");
3030

31-
wb.openURL(new URL("http://www.ibm.com"));
31+
wb.openURL(new URI("http://www.ibm.com").toURL());
3232

3333
try {
3434
Thread.sleep(2000);
3535
} catch (Exception e) {
3636
// ignore
3737
}
3838

39-
wb.openURL(new URL("http://www.eclipse.org"));
39+
wb.openURL(new URI("http://www.eclipse.org").toURL());
4040

4141
try {
4242
Thread.sleep(2000);

tests/org.eclipse.ui.tests.browser/src/org/eclipse/ui/tests/browser/internal/InternalBrowserEditorTestCase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2019 IBM Corporation and others.
2+
* Copyright (c) 2004, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,7 +16,7 @@
1616
import static org.junit.Assert.assertEquals;
1717
import static org.junit.Assert.assertNotNull;
1818

19-
import java.net.URL;
19+
import java.net.URI;
2020

2121
import org.eclipse.swt.widgets.Display;
2222
import org.eclipse.swt.widgets.Shell;
@@ -38,10 +38,10 @@ public void testBrowser() throws Exception {
3838
IWorkbenchBrowserSupport wbs = PlatformUI.getWorkbench().getBrowserSupport();
3939
IWebBrowser wb = wbs.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, "test", "MyBrowser", "A tooltip");
4040

41-
wb.openURL(new URL("http://www.ibm.com"));
41+
wb.openURL(new URI("http://www.ibm.com").toURL());
4242
runLoopTimer(2);
4343

44-
wb.openURL(new URL("http://www.eclipse.org"));
44+
wb.openURL(new URI("http://www.eclipse.org").toURL());
4545
runLoopTimer(2);
4646

4747
wb.close();
@@ -55,7 +55,7 @@ public void testBrowserID() throws Exception {
5555
IWorkbenchBrowserSupport wbs = PlatformUI.getWorkbench().getBrowserSupport();
5656
IWebBrowser wb = wbs.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, "test", "MyBrowser", "A tooltip");
5757

58-
wb.openURL(new URL("http://www.ibm.com"));
58+
wb.openURL(new URI("http://www.ibm.com").toURL());
5959
runLoopTimer(2);
6060

6161
IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()

tests/org.eclipse.ui.tests.browser/src/org/eclipse/ui/tests/browser/internal/InternalBrowserViewTestCase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2017 IBM Corporation and others.
2+
* Copyright (c) 2004, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.browser.internal;
1515

16-
import java.net.URL;
16+
import java.net.URI;
1717

1818
import org.eclipse.swt.widgets.Display;
1919
import org.eclipse.swt.widgets.Shell;
@@ -33,10 +33,10 @@ public void testBrowser() throws Exception {
3333
IWorkbenchBrowserSupport wbs = PlatformUI.getWorkbench().getBrowserSupport();
3434
IWebBrowser wb = wbs.createBrowser(IWorkbenchBrowserSupport.AS_VIEW, "test3", "MyBrowser", "A tooltip");
3535

36-
wb.openURL(new URL("http://www.ibm.com"));
36+
wb.openURL(new URI("http://www.ibm.com").toURL());
3737
runLoopTimer(2);
3838

39-
wb.openURL(new URL("http://www.eclipse.org"));
39+
wb.openURL(new URI("http://www.eclipse.org").toURL());
4040
runLoopTimer(2);
4141

4242
wb.close();

tests/org.eclipse.ui.tests.browser/src/org/eclipse/ui/tests/browser/internal/TestInput.java

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2023 IBM Corporation and others.
2+
* Copyright (c) 2009, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -19,7 +19,8 @@
1919
import static org.junit.Assert.assertNotNull;
2020

2121
import java.net.MalformedURLException;
22-
import java.net.URL;
22+
import java.net.URI;
23+
import java.net.URISyntaxException;
2324

2425
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
2526
import org.eclipse.ui.internal.browser.WebBrowserEditorInput;
@@ -33,73 +34,60 @@ public class TestInput {
3334
private static final String ID2 = "browser.id2";
3435

3536
@Test
36-
public void testCompareWithNull() throws MalformedURLException {
37-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
38-
0, ID1);
37+
public void testCompareWithNull() throws MalformedURLException, URISyntaxException {
38+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
3939
assertNotNull(input);
4040
}
4141

4242
@Test
43-
public void testCompareWithNullURL() throws MalformedURLException {
44-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
45-
0, ID1);
46-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(null,
47-
0, ID1);
43+
public void testCompareWithNullURL() throws MalformedURLException, URISyntaxException {
44+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
45+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(null, 0, ID1);
4846
assertNotEquals(input, input2);
4947
assertNotEquals(input2, input);
5048
}
5149

5250
@Test
53-
public void testCompareWithSelf() throws MalformedURLException {
54-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
55-
0, ID1);
51+
public void testCompareWithSelf() throws MalformedURLException, URISyntaxException {
52+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
5653
assertEquals(input, input);
5754
}
5855

5956
@Test
60-
public void testCompareWithSimilar() throws MalformedURLException {
61-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
62-
0, ID1);
63-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URL(URL1),
64-
0, ID1);
57+
public void testCompareWithSimilar() throws MalformedURLException, URISyntaxException {
58+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
59+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
6560
assertEquals(input, input2);
6661
assertEquals(input.hashCode(), input2.hashCode());
6762
}
6863

6964
@Test
70-
public void testCompareWithDifferentUrl() throws MalformedURLException {
71-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
72-
0, ID1);
73-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URL(URL2),
74-
0, ID1);
65+
public void testCompareWithDifferentUrl() throws MalformedURLException, URISyntaxException {
66+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
67+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URI(URL2).toURL(), 0, ID1);
7568
assertNotEquals(input, input2);
7669
}
7770

7871
@Test
79-
public void testCompareWithDifferentId() throws MalformedURLException {
80-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
81-
0, ID1);
82-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URL(URL1),
83-
0, ID2);
72+
public void testCompareWithDifferentId() throws MalformedURLException, URISyntaxException {
73+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
74+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID2);
8475
assertNotEquals(input, input2);
8576
}
8677

8778
@Test
88-
public void testCompareWithDifferentStyle() throws MalformedURLException {
89-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
90-
0, ID1);
91-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URL(URL1),
92-
1, ID1);
79+
public void testCompareWithDifferentStyle() throws MalformedURLException, URISyntaxException {
80+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
81+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URI(URL1).toURL(), 1, ID1);
9382
assertEquals(input, input2);
9483
assertEquals(input.hashCode(), input2.hashCode());
9584
}
9685

9786
@Test
98-
public void testCompareWithStatusbarVisible() throws MalformedURLException {
99-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),
100-
0, ID1);
101-
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URL(URL1),
102-
IWorkbenchBrowserSupport.STATUS, ID1);
87+
public void testCompareWithStatusbarVisible() throws MalformedURLException, URISyntaxException {
88+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, ID1);
89+
WebBrowserEditorInput input2 = new WebBrowserEditorInput(new URI(URL1).toURL(), IWorkbenchBrowserSupport.STATUS,
90+
ID1);
10391
assertNotEquals(input, input2);
10492
}
10593

@@ -110,8 +98,8 @@ public void testHashWithNullURL() {
11098
}
11199

112100
@Test
113-
public void testHashWithNullID() throws MalformedURLException {
114-
WebBrowserEditorInput input = new WebBrowserEditorInput(new URL(URL1),0, null);
101+
public void testHashWithNullID() throws MalformedURLException, URISyntaxException {
102+
WebBrowserEditorInput input = new WebBrowserEditorInput(new URI(URL1).toURL(), 0, null);
115103
input.hashCode(); // Fails if exception thrown
116104
}
117105

0 commit comments

Comments
 (0)