Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Honnen2018-08-06 08:52:53 +0000
committerAndrey Loskutov2018-10-05 11:57:57 +0000
commitf38732853cc2972a36f7c8c6010da670ea3bc9d5 (patch)
treef5f427987192a175e2217026c625e577b67e5722
parentc8704fcf1e4c9699953ee8853703820bcf8c0e00 (diff)
downloadeclipse.jdt.core-f38732853cc2972a36f7c8c6010da670ea3bc9d5.tar.gz
eclipse.jdt.core-f38732853cc2972a36f7c8c6010da670ea3bc9d5.tar.xz
eclipse.jdt.core-f38732853cc2972a36f7c8c6010da670ea3bc9d5.zip
Bug 537666 - fixed false-negative in isExternalFolderPath(IPath)
An external path like c:\test\externalLib is not internal to the project "test" just because the first segment matches an existing project's name. An external path like c:\test\external.Lib is not internal to the project just because the last segment has a dot. Change-Id: Ie3d2684ebacc1a2d5904e4882b33ae8d94b22f40 Signed-off-by: Julian Honnen <julian.honnen@vector.com> Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java48
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java61
2 files changed, 102 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
index ac04223294..03ba5f523d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
@@ -279,6 +279,54 @@ public void testAddExternalLibFolder6() throws CoreException, IOException {
deleteProject("ExternalContainer");
}
}
+
+/*
+ * Bug 537666 - Ensures that an external path beginning with an existing project name is not falsely reported as internal.
+ */
+public void testAddExternalLibFolder7() throws CoreException {
+ String firstSegmentOfExternalPath = new Path(getExternalPath()).segment(0);
+ try {
+
+ IJavaProject p = createJavaProject(firstSegmentOfExternalPath, new String[0], new String[] {getExternalResourcePath("externalLib")}, "");
+ expandAll(p);
+ createExternalFolder("externalLib");
+ refresh(p);
+ assertElementDescendants(
+ "Unexpected project content",
+ firstSegmentOfExternalPath + "\n" +
+ " "+ getExternalPath() + "externalLib\n" +
+ " <default> (...)",
+ p
+ );
+ } finally {
+ deleteExternalResource("externalLib");
+ deleteProject(firstSegmentOfExternalPath);
+ }
+}
+
+/*
+ * Ensures that creating an external library folder with a dot in the name, referenced by a library entry and refreshing updates the model
+ */
+// Test is disabled, there seem to be no easy way to properly refresh exteral resources cache
+public void XtestAddExternalLibFolder8() throws CoreException {
+ try {
+ IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("external.Lib")}, "");
+ expandAll(p);
+ createExternalFolder("external.Lib");
+ refresh(p);
+ assertElementDescendants(
+ "Unexpected project content",
+ "P\n" +
+ " "+ getExternalPath() + "external.Lib\n" +
+ " <default> (...)",
+ p
+ );
+ } finally {
+ deleteExternalResource("externalLib");
+ deleteProject("P");
+ }
+}
+
/**
* Test adding a non-java resource in a package fragment root that correspond to
* the project.
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
index 9aab43325e..1fb75315ad 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
@@ -39,6 +39,7 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -110,28 +111,74 @@ public class ExternalFoldersManager {
/**
* Returns <code>true</code> if the provided path is a folder external to the project.
+ * The path is expected to be one matching the {@link IClasspathEntry#CPE_LIBRARY} case in
+ * {@link IClasspathEntry#getPath()} definition.
*/
public static boolean isExternalFolderPath(IPath externalPath) {
- if (externalPath == null)
- return false;
- String firstSegment = externalPath.segment(0);
- if (firstSegment != null && ResourcesPlugin.getWorkspace().getRoot().getProject(firstSegment).exists())
+ if (externalPath == null || externalPath.isEmpty()) {
return false;
+ }
JavaModelManager manager = JavaModelManager.getJavaModelManager();
- if (manager.isExternalFile(externalPath) || manager.isAssumedExternalFile(externalPath))
+ if (manager.isExternalFile(externalPath) || manager.isAssumedExternalFile(externalPath)) {
+ return false;
+ }
+ if (!externalPath.isAbsolute()) {
+ // can be only project relative path
return false;
+ }
+ // Test if this an absolute path in local file system (not the workspace path)
File externalFolder = externalPath.toFile();
- if (externalFolder.isFile()) {
+ if (Files.isRegularFile(externalFolder.toPath())) {
manager.addExternalFile(externalPath);
return false;
}
- if (externalPath.getFileExtension() != null/*likely a .jar, .zip, .rar or other file*/ && !externalFolder.exists()) {
+ if (Files.isDirectory(externalFolder.toPath())) {
+ return true;
+ }
+ // this can be now only full workspace path or an external path to a not existing file or folder
+ if (isInternalFilePath(externalPath)) {
+ return false;
+ }
+ if (isInternalContainerPath(externalPath)) {
+ return false;
+ }
+ if (externalPath.getFileExtension() != null/*likely a .jar, .zip, .rar or other file*/) {
manager.addAssumedExternalFile(externalPath);
+ // not existing external file
return false;
}
+ // not existing external folder
return true;
}
+ /**
+ * @param path full absolute workspace path
+ */
+ private static boolean isInternalFilePath(IPath path) {
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ // in case this is full workspace path it should start with project segment
+ if(path.segmentCount() > 1 && wsRoot.getFile(path).exists()) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param path full absolute workspace path
+ */
+ private static boolean isInternalContainerPath(IPath path) {
+ IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ // in case this is full workspace path it should start with project segment
+ int segmentCount = path.segmentCount();
+ if(segmentCount == 1 && wsRoot.getProject(path.segment(0)).exists()) {
+ return true;
+ }
+ if(segmentCount > 1 && wsRoot.getFolder(path).exists()) {
+ return true;
+ }
+ return false;
+ }
+
public static boolean isInternalPathForExternalFolder(IPath resourcePath) {
return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0));
}

Back to the top