Skip to content

Commit

Permalink
Use new static IPath factories and constants and only the IPath type
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Jun 25, 2023
1 parent 65bdb41 commit cf57666
Show file tree
Hide file tree
Showing 236 changed files with 2,442 additions and 1,170 deletions.
2 changes: 1 addition & 1 deletion ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Export-Package: org.eclipse.ant.core,
org.eclipse.ant.internal.core.ant;x-friends:="org.eclipse.ant.launching",
org.eclipse.ant.internal.core.contentDescriber;x-internal:=true
Require-Bundle: org.eclipse.core.variables;bundle-version="[3.1.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.25.0,4.0.0)"
org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)"
Bundle-ActivationPolicy: lazy;exclude:="org.eclipse.ant.internal.core.contentDescriber"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ClassPath: .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
Expand Down Expand Up @@ -347,7 +346,7 @@ public String getDefaultAntHome() {
IAntClasspathEntry[] entries = getDefaultAntHomeEntries();
if (entries.length > 0) {
URL antjar = entries[entries.length - 1].getEntryURL();
IPath antHomePath = new Path(antjar.getFile());
IPath antHomePath = IPath.fromOSString(antjar.getFile());
// parent directory of the lib directory
antHomePath = antHomePath.removeLastSegments(2);
return antHomePath.toFile().getAbsolutePath();
Expand Down Expand Up @@ -865,7 +864,7 @@ public IAntClasspathEntry getToolsJarEntry(IPath javaHomePath) {
*/
@Deprecated
public URL getToolsJarURL() {
IPath path = new Path(System.getProperty("java.home")); //$NON-NLS-1$
IPath path = IPath.fromOSString(System.getProperty("java.home")); //$NON-NLS-1$
IAntClasspathEntry entry = getToolsJarEntry(path);
if (entry == null) {
IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("env_var"); //$NON-NLS-1$
Expand All @@ -875,7 +874,7 @@ public URL getToolsJarURL() {
javaHome = variable.getValue("JAVA_HOME"); //$NON-NLS-1$
}
if (javaHome != null) {
path = new Path(javaHome);
path = IPath.fromOSString(javaHome);
entry = getToolsJarEntry(path);
}
}
Expand All @@ -897,7 +896,7 @@ public URL getToolsJarURL() {
* @return IAntClasspathEntry tools.jar IAntClasspathEntry or <code>null</code>
*/
public IAntClasspathEntry getToolsJarEntry() {
IPath path = new Path(System.getProperty("java.home")); //$NON-NLS-1$
IPath path = IPath.fromOSString(System.getProperty("java.home")); //$NON-NLS-1$
IAntClasspathEntry entry = getToolsJarEntry(path);
if (entry == null) {
IDynamicVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable("env_var"); //$NON-NLS-1$
Expand All @@ -907,7 +906,7 @@ public IAntClasspathEntry getToolsJarEntry() {
javaHome = variable.getValue("JAVA_HOME"); //$NON-NLS-1$
}
if (javaHome != null) {
path = new Path(javaHome);
path = IPath.fromOSString(javaHome);
entry = getToolsJarEntry(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -114,15 +113,15 @@ public static void processMinusDProperties(List<String> commands, Map<String, St
}

public static File getFileRelativeToBaseDir(String fileName, String base, String buildFileLocation) {
IPath path = new Path(fileName);
IPath path = IPath.fromOSString(fileName);
if (!path.isAbsolute()) {
if (base != null) {
File baseDir = new File(base);
// relative to the base dir
path = new Path(baseDir.getAbsolutePath());
path = IPath.fromOSString(baseDir.getAbsolutePath());
} else {
// relative to the build file location
path = new Path(buildFileLocation);
path = IPath.fromOSString(buildFileLocation);
path = path.removeLastSegments(1);
}
path = path.addTrailingSeparator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -859,8 +858,8 @@ protected void fireBuildFinished(Project project, Throwable error) {
if (fileName == null) {
fileName = "log.xml"; //$NON-NLS-1$
}
String realPath = new Path(getBuildFileLocation()).toFile().getAbsolutePath();
IPath path = new Path(realPath);
String realPath = IPath.fromOSString(getBuildFileLocation()).toFile().getAbsolutePath();
IPath path = IPath.fromOSString(realPath);
path = path.removeLastSegments(1);
path = path.addTrailingSeparator();
path = path.append(fileName);
Expand Down
2 changes: 1 addition & 1 deletion ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ant.launching;singleton:=true
Bundle-Version: 1.4.100.qualifier
Bundle-Activator: org.eclipse.ant.internal.launching.AntLaunching
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.12.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.12.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunch;
Expand Down Expand Up @@ -277,7 +276,7 @@ public static String[] parseString(String delimString, String delim) {
*/
public static IFile getFile(String fullPath) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.getFile(new Path(fullPath));
return root.getFile(IPath.fromOSString(fullPath));
}

/**
Expand All @@ -295,7 +294,7 @@ public static IFile getFileForLocation(String path, File buildFileParent) {
if (path == null) {
return null;
}
IPath filePath = new Path(path);
IPath filePath = IPath.fromOSString(path);
IFile file = null;
URI location = filePath.makeAbsolute().toFile().toURI();
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(location);
Expand All @@ -308,7 +307,7 @@ public static IFile getFileForLocation(String path, File buildFileParent) {
try {
// this call is ok if buildFileParent is null
relativeFile = FileUtils.getFileUtils().resolveFile(buildFileParent, path);
filePath = new Path(relativeFile.getAbsolutePath());
filePath = IPath.fromOSString(relativeFile.getAbsolutePath());
location = filePath.makeAbsolute().toFile().toURI();
files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(location);
if (files.length > 0) {
Expand Down Expand Up @@ -421,7 +420,7 @@ public static void linkBuildFailedMessage(String message, IProcess process) {
catch (NumberFormatException e) {
// do nothing
}
URI location = new Path(fileName).makeAbsolute().toFile().toURI();
URI location = IPath.fromOSString(fileName).makeAbsolute().toFile().toURI();
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(location);
IFile file = null;
if (files.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
Expand All @@ -43,7 +42,7 @@ public Object[] findSourceElements(String path) throws CoreException {
File osFile = new File(path);
if (osFile.exists()) {
try {
IPath canonicalPath = new Path(osFile.getCanonicalPath());
IPath canonicalPath = IPath.fromOSString(osFile.getCanonicalPath());
IFile[] files = fRoot.findFilesForLocationURI(canonicalPath.makeAbsolute().toFile().toURI());
if (files.length > 0) {
for (IFile file : files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import org.eclipse.ant.internal.launching.AntLaunchingUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IRegisterGroup;
import org.eclipse.debug.core.model.IStackFrame;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void setFilePath(String fullPath) {
if (file != null) {
fFilePath = file.getProjectRelativePath().toString();
} else {
fFilePath = new Path(fullPath).lastSegment();
fFilePath = IPath.fromOSString(fullPath).lastSegment();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
Expand Down Expand Up @@ -71,15 +70,15 @@ protected void buildMemento(Document document, Element memento) throws CoreExcep
if (antHomeLocation == null) {
memento.setAttribute("default", "true"); //$NON-NLS-1$//$NON-NLS-2$
} else {
memento.setAttribute("antHome", new Path(antHomeLocation).toString()); //$NON-NLS-1$
memento.setAttribute("antHome", IPath.fromOSString(antHomeLocation).toString()); //$NON-NLS-1$
}
}

@Override
public void initializeFrom(Element memento) throws CoreException {
String antHome = memento.getAttribute("antHome"); //$NON-NLS-1$
if (antHome != null && (antHome.length() > 0)) {
IPath path = new Path(antHome);
IPath path = IPath.fromOSString(antHome);
antHomeLocation = path.toOSString();
} else {
antHomeLocation = null;
Expand All @@ -100,9 +99,9 @@ public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration
libs.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel()));
}
} else {
IPath libDir = new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
IPath libDir = IPath.fromOSString(antHomeLocation).append("lib"); //$NON-NLS-1$
for (String name : resolveAntHome().list()) {
IPath path = new Path(name);
IPath path = IPath.fromOSString(name);
String fileExtension = path.getFileExtension();
if ("jar".equalsIgnoreCase(fileExtension)) { //$NON-NLS-1$
libs.add(JavaRuntime.newArchiveRuntimeClasspathEntry(libDir.append(path)));
Expand All @@ -116,7 +115,7 @@ public File resolveAntHome() throws CoreException {
if (antHomeLocation == null) { // using the default ant home
return null;
}
IPath libDir = new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
IPath libDir = IPath.fromOSString(antHomeLocation).append("lib"); //$NON-NLS-1$
File lib = libDir.toFile();
File parentDir = lib.getParentFile();
if (parentDir == null || !parentDir.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
Expand Down Expand Up @@ -122,7 +121,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
String path = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, new String("")); //$NON-NLS-1$
String vmver = null;
if (!path.isEmpty()) {
IPath jrePath = Path.fromPortableString(path);
IPath jrePath = IPath.fromPortableString(path);
IVMInstall vm = JavaRuntime.getVMInstall(jrePath);
if (vm instanceof AbstractVMInstall) {
AbstractVMInstall install = (AbstractVMInstall) vm;
Expand Down Expand Up @@ -745,7 +744,7 @@ private String getSWTLibraryLocation() {
try {
URL url = FileLocator.toFileURL(fragBundle.getEntry("/")); //$NON-NLS-1$
try {
IPath path = new Path(URIUtil.toURL(URIUtil.toURI(url)).getPath());
IPath path = IPath.fromOSString(URIUtil.toURL(URIUtil.toURI(url)).getPath());
path = path.removeTrailingSeparator();
fgSWTLibraryLocation = path.toOSString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.debug.core.ILaunchConfiguration;
Expand Down Expand Up @@ -102,7 +101,7 @@ public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration
for (IAntClasspathEntry userEntry : userEntries) {
entry = userEntry;
path = entry.getLabel();
IPath toolsPath = new Path(path);
IPath toolsPath = IPath.fromOSString(path);
if (toolsPath.lastSegment().equals("tools.jar")) { //$NON-NLS-1$
haveToolsEntry = true;
// replace with dynamically resolved tools.jar based on
Expand All @@ -128,18 +127,18 @@ private void addToolsJar(ILaunchConfiguration configuration, List<IRuntimeClassp
if (tools == null) {
if (path != null) {
// use the global entry
rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(path)));
rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(IPath.fromOSString(path)));
} else {
// use the default vm install to try to find a tools.jar
IVMInstall install = JavaRuntime.getDefaultVMInstall();
if (install != null) {
IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(IPath.fromOSString(install.getInstallLocation().getAbsolutePath()));
if (entry != null) {
try {
URL entryURL = entry.getEntryURL();
String pathString = resolveFileFromUrl(entryURL.getFile());
if (!pathString.isEmpty()) {
rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(pathString)));
rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(IPath.fromOSString(pathString)));
}
}
catch (MalformedURLException e) {
Expand Down Expand Up @@ -178,7 +177,7 @@ private void addSWTJars(List<IRuntimeClasspathEntry> rtes) {
AntLaunching.log(e);
continue;
}
IPath fragmentPath = new Path(urlFileName);
IPath fragmentPath = IPath.fromOSString(urlFileName);
if (fragmentPath.getFileExtension() != null) { // JAR file
fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath));
} else { // folder
Expand Down Expand Up @@ -228,9 +227,9 @@ private IRuntimeClasspathEntry getToolsJar(ILaunchConfiguration configuration) {
try {
IVMInstall install = JavaRuntime.computeVMInstall(configuration);
if (install != null) {
IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(IPath.fromOSString(install.getInstallLocation().getAbsolutePath()));
if (entry != null) {
return JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath()));
return JavaRuntime.newArchiveRuntimeClasspathEntry(IPath.fromOSString(entry.getEntryURL().getPath()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
public class ProjectHelper {

public static final IPath TEST_BUILDFILES_DIR = new Path("testbuildfiles"); //$NON-NLS-1$
public static final IPath TEST_RESOURCES_DIR = new Path("testresources"); //$NON-NLS-1$
public static final IPath TEST_LIB_DIR = new Path("testlib"); //$NON-NLS-1$
public static final IPath TEST_BUILDFILES_DIR = IPath.fromOSString("testbuildfiles"); //$NON-NLS-1$
public static final IPath TEST_RESOURCES_DIR = IPath.fromOSString("testresources"); //$NON-NLS-1$
public static final IPath TEST_LIB_DIR = IPath.fromOSString("testlib"); //$NON-NLS-1$

/**
* Creates a IProject.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IWorkbench;
Expand Down Expand Up @@ -292,7 +291,7 @@ protected String getAntHome() {
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
IAntClasspathEntry[] entries = prefs.getAntHomeClasspathEntries();
IAntClasspathEntry antjar = entries[0];
IPath antHomePath = new Path(antjar.getEntryURL().getFile());
IPath antHomePath = IPath.fromOSString(antjar.getEntryURL().getFile());
antHomePath = antHomePath.removeLastSegments(1);
return antHomePath.toFile().getAbsolutePath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.ant.tests.core.testplugin.ProjectHelper;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.IPath;
import org.junit.Test;

public class FrameworkTests extends AbstractAntTest {
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testAntClasspathEntryFromUrl() throws MalformedURLException {
IAntClasspathEntry resultedEntries[] = prefs.getAntHomeClasspathEntries();
int index = resultedEntries[entries.length].getLabel().indexOf("hub"); //$NON-NLS-1$
assertNotSame("Missing machine details", index, -1); //$NON-NLS-1$
assertFalse("Incorrect classpath entry. This would have been the value before the fix", resultedEntries[entries.length].getLabel().equals(new Path("/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue("Incorrect classpath entry", resultedEntries[entries.length].getLabel().substring(index).equals(new Path("hub/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
assertFalse("Incorrect classpath entry. This would have been the value before the fix", resultedEntries[entries.length].getLabel().equals(IPath.fromOSString("/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue("Incorrect classpath entry", resultedEntries[entries.length].getLabel().substring(index).equals(IPath.fromOSString("hub/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
Expand Down Expand Up @@ -490,7 +490,7 @@ protected AntDebugTarget resumeAndExit(AntThread thread) throws Exception {
}

protected IResource getBreakpointResource(String typeName) throws Exception {
IJavaElement element = getJavaProject().findElement(new Path(typeName + ".java")); //$NON-NLS-1$
IJavaElement element = getJavaProject().findElement(IPath.fromOSString(typeName + ".java")); //$NON-NLS-1$
IResource resource = element.getCorrespondingResource();
if (resource == null) {
resource = getJavaProject().getProject();
Expand Down
Loading

0 comments on commit cf57666

Please sign in to comment.