From 8262741d060c5eb657ea52d4b9432d846012a12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Sat, 11 Jan 2025 12:27:49 +0200 Subject: [PATCH] Fix warnings due Java 21 deprecations in o.e.debug.tests Do not create new URL but fetch it directly from bundle. Minor cleanup to specify type of collections which allows the forech cleanup to kick up too. --- .../org/eclipse/debug/tests/TestsPlugin.java | 18 ++++++++++-------- .../launching/LaunchConfigurationTests.java | 11 ++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/TestsPlugin.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/TestsPlugin.java index a3c84ff645e..d387327b6b5 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/TestsPlugin.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/TestsPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2013 Wind River Systems and others. + * Copyright (c) 2009, 2025 Wind River Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -24,7 +24,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; @@ -38,15 +37,17 @@ public class TestsPlugin { public static final String PLUGIN_ID = "org.eclipse.debug.tests"; //$NON-NLS-1$ /** - * Returns the file corresponding to the specified path from within this bundle - * @return the file corresponding to the specified path from within this bundle, or - * null if not found + * Returns the file corresponding to the specified path from within this + * bundle + * + * @return the file corresponding to the specified path from within this + * bundle, or null if not found */ - public static File getFileInPlugin(IPath path) { + public static File getFileInPlugin(String path) { try { Bundle bundle = FrameworkUtil.getBundle(TestsPlugin.class); - URL installURL = new URL(bundle.getEntry("/"), path.toString()); //$NON-NLS-1$ - URL localURL= FileLocator.toFileURL(installURL);//Platform.asLocalURL(installURL); + URL installURL = bundle.getEntry("/" + path); //$NON-NLS-1$ + URL localURL = FileLocator.toFileURL(installURL); return new File(localURL.getFile()); } catch (IOException e) { return null; @@ -55,6 +56,7 @@ public static File getFileInPlugin(IPath path) { /** * Creates a new project with the specified name + * * @return a new project with the specified name */ public static IProject createProject(String projectName) throws CoreException { diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java index f6bf5d62ca5..f13d3c3b3fb 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -38,7 +38,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -1213,7 +1212,7 @@ public void testImport() throws Exception { ILaunchConfiguration handle = wc.doSave(); assertTrue("Configuration should exist", handle.exists()); //$NON-NLS-1$ - File dir = TestsPlugin.getFileInPlugin(IPath.fromOSString("test-import")); //$NON-NLS-1$ + File dir = TestsPlugin.getFileInPlugin("test-import"); //$NON-NLS-1$ assertTrue("Import directory does not exist", dir.exists()); //$NON-NLS-1$ LaunchManager manager = (LaunchManager) getLaunchManager(); @@ -1231,12 +1230,10 @@ public void testImport() throws Exception { assertTrue("Import4 should be removed", removed.contains(handle)); //$NON-NLS-1$ // should be 5 added - List added = listener.getAdded(); + List added = listener.getAdded(); assertEquals("Should be 5 added configs", 5, added.size()); //$NON-NLS-1$ Set names = new HashSet<>(); - Iterator iterator = added.iterator(); - while (iterator.hasNext()) { - ILaunchConfiguration lc = (ILaunchConfiguration) iterator.next(); + for (ILaunchConfiguration lc : added) { names.add(lc.getName()); } assertTrue("Missing Name", names.contains("Import1")); //$NON-NLS-1$ //$NON-NLS-2$