1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 564123 Remove deprecated PathUtil that has a replacement

Change-Id: Ie2fd4ed201a2bc0c490df9b0deb43cb6d53b1876
This commit is contained in:
Jonah Graham 2020-08-18 12:21:50 -04:00
parent ef79d15071
commit a708a1dcc9
2 changed files with 6 additions and 178 deletions

View file

@ -1,178 +0,0 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.browser;
import java.io.File;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* @deprecated use {@link org.eclipse.cdt.utils.PathUtil}, instead.
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
@Deprecated
public class PathUtil {
public static boolean isWindowsFileSystem() {
String os = System.getProperty("os.name"); //$NON-NLS-1$
return (os != null && os.startsWith("Win")); //$NON-NLS-1$
}
public static IWorkspaceRoot getWorkspaceRoot() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace != null) {
return workspace.getRoot();
}
return null;
}
public static IPath getCanonicalPath(IPath fullPath) {
File file = fullPath.toFile();
try {
String canonPath = file.getCanonicalPath();
return new Path(canonPath);
} catch (IOException ex) {
}
return null;
}
public static IPath getWorkspaceRelativePath(IPath fullPath) {
IWorkspaceRoot workspaceRoot = getWorkspaceRoot();
if (workspaceRoot != null) {
IPath workspaceLocation = workspaceRoot.getLocation();
if (workspaceLocation != null && workspaceLocation.isPrefixOf(fullPath)) {
int segments = fullPath.matchingFirstSegments(workspaceLocation);
IPath relPath = fullPath.setDevice(null).removeFirstSegments(segments);
return new Path("").addTrailingSeparator().append(relPath); //$NON-NLS-1$
}
}
return fullPath;
}
public static IPath getProjectRelativePath(IPath fullPath, IProject project) {
IPath projectPath = project.getFullPath();
if (projectPath.isPrefixOf(fullPath)) {
return fullPath.removeFirstSegments(projectPath.segmentCount());
}
projectPath = project.getLocation();
if (projectPath.isPrefixOf(fullPath)) {
return fullPath.removeFirstSegments(projectPath.segmentCount());
}
return getWorkspaceRelativePath(fullPath);
}
public static IPath getWorkspaceRelativePath(String fullPath) {
return getWorkspaceRelativePath(new Path(fullPath));
}
public static IPath getRawLocation(IPath wsRelativePath) {
IWorkspaceRoot workspaceRoot = getWorkspaceRoot();
if (workspaceRoot != null && wsRelativePath != null) {
IPath workspaceLocation = workspaceRoot.getLocation();
if (workspaceLocation != null && !workspaceLocation.isPrefixOf(wsRelativePath)) {
return workspaceLocation.append(wsRelativePath);
}
}
return wsRelativePath;
}
public static IPath makeRelativePath(IPath path, IPath relativeTo) {
int segments = relativeTo.matchingFirstSegments(path);
if (segments > 0) {
IPath prefix = relativeTo.removeFirstSegments(segments);
IPath suffix = path.removeFirstSegments(segments);
IPath relativePath = new Path(""); //$NON-NLS-1$
for (int i = 0; i < prefix.segmentCount(); ++i) {
relativePath = relativePath.append(".." + IPath.SEPARATOR); //$NON-NLS-1$
}
return relativePath.append(suffix);
}
return null;
}
public static IPath makeRelativePathToProjectIncludes(IPath fullPath, IProject project) {
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
if (provider != null) {
IScannerInfo info = provider.getScannerInformation(project);
if (info != null) {
return makeRelativePathToIncludes(fullPath, info.getIncludePaths());
}
}
return null;
}
public static IPath makeRelativePathToIncludes(IPath fullPath, String[] includePaths) {
IPath relativePath = null;
int mostSegments = 0;
for (int i = 0; i < includePaths.length; ++i) {
IPath includePath = new Path(includePaths[i]);
if (includePath.isPrefixOf(fullPath)) {
int segments = includePath.matchingFirstSegments(fullPath);
if (segments > mostSegments) {
relativePath = fullPath.removeFirstSegments(segments).setDevice(null);
mostSegments = segments;
}
}
}
return relativePath;
}
/**
* @noreference This method is not intended to be referenced by clients.
*/
public static ICProject getEnclosingProject(IPath fullPath) {
IWorkspaceRoot root = getWorkspaceRoot();
if (root != null) {
IPath path = getWorkspaceRelativePath(fullPath);
while (path.segmentCount() > 0) {
IResource res = root.findMember(path);
if (res != null)
return CoreModel.getDefault().create(res.getProject());
path = path.removeLastSegments(1);
}
}
return null;
}
public static IPath getValidEnclosingFolder(IPath fullPath) {
IWorkspaceRoot root = getWorkspaceRoot();
if (root != null) {
IPath path = getWorkspaceRelativePath(fullPath);
while (path.segmentCount() > 0) {
IResource res = root.findMember(path);
if (res != null && res.exists()
&& (res.getType() == IResource.PROJECT || res.getType() == IResource.FOLDER))
return path;
path = path.removeLastSegments(1);
}
}
return null;
}
}

View file

@ -44,6 +44,7 @@
<li><a href="#oldStyleProjects">Partial removal of CDT 3.X project support.</a></li>
<li><a href="#optionsAPI">Removal of CDT Core Options API.</a></li>
<li><a href="#terminal">TM Terminal has major changes to support new color and preference functionality.</a></li>
<li><a href="#pathutil">Remove org.eclipse.cdt.core.browser.PathUtil.</a></li>
</ol>
<p>
Planned Removals after June 2022
@ -256,6 +257,11 @@
</li>
</ul>
<h3>13. <a name="pathutil">Remove org.eclipse.cdt.core.browser.PathUtil.</a></h3>
<p>
The deprecated class org.eclipse.cdt.core.browser.PathUtil has been removed. Use
org.eclipse.cdt.utils.PathUtil instead.
</p>
<hr>