### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core.tests.compiler
Index: src/org/eclipse/jdt/core/tests/util/Util.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v
retrieving revision 1.60
diff -u -r1.60 Util.java
--- src/org/eclipse/jdt/core/tests/util/Util.java 9 Jan 2008 14:49:28 -0000 1.60
+++ src/org/eclipse/jdt/core/tests/util/Util.java 26 Feb 2008 09:54:51 -0000
@@ -328,15 +328,18 @@
}
public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException {
String sourcesPath = getOutputDirectory() + File.separator + "sources";
- File sourcesDir = new File(sourcesPath);
- flushDirectoryContent(sourcesDir);
+ createSourceDir(pathsAndContents, sourcesPath);
+ zip(new File(sourcesPath), zipPath);
+}
+
+public static void createSourceDir(String[] pathsAndContents, String sourcesPath) throws IOException {
+ flushDirectoryContent(new File(sourcesPath));
for (int i = 0, length = pathsAndContents.length; i < length; i+=2) {
String sourcePath = sourcesPath + File.separator + pathsAndContents[i];
File sourceFile = new File(sourcePath);
sourceFile.getParentFile().mkdirs();
createFile(sourcePath, pathsAndContents[i+1]);
}
- zip(sourcesDir, zipPath);
}
/**
* Delete a file or directory and insure that the file is no longer present
#P org.eclipse.jdt.core.tests.builder
Index: src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java,v
retrieving revision 1.58
diff -u -r1.58 TestingEnvironment.java
--- src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 23 Oct 2007 11:31:42 -0000 1.58
+++ src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 26 Feb 2008 09:54:52 -0000
@@ -232,6 +232,18 @@
addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false));
}
+ public void addExternalFolders(IPath projectPath, String[] folders) throws JavaModelException {
+ addExternalFolders(projectPath, folders, false);
+ }
+
+ public void addExternalFolders(IPath projectPath, String[] folders, boolean isExported) throws JavaModelException {
+ for (int i = 0, max = folders.length; i < max; i++) {
+ String folder = folders[i];
+ checkAssertion("folder name must not end with .zip or .jar", !folder.endsWith(".zip") && !folder.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ addEntry(projectPath, JavaCore.newLibraryEntry(new Path(folder), null, null, isExported));
+ }
+ }
+
public void addExternalJars(IPath projectPath, String[] jars) throws JavaModelException {
addExternalJars(projectPath, jars, false);
}
Index: src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java,v
retrieving revision 1.42
diff -u -r1.42 BuildpathTests.java
--- src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java 20 Dec 2007 16:01:14 -0000 1.42
+++ src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java 26 Feb 2008 09:54:52 -0000
@@ -13,6 +13,8 @@
import junit.framework.*;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -38,7 +40,7 @@
}
private String getJdkLevelProblem(String expectedRuntime, String path, int severity) {
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
+ Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
String jclRuntime = CompilerOptions.versionFromJdkLevel(libraryJDK);
StringBuffer jdkLevelProblem = new StringBuffer("Problem : Incompatible .class files version in required binaries. Project 'Project' is targeting a ");
@@ -258,6 +260,69 @@
}
/*
+ * Ensures that the changing a type in an external folder and refreshing triggers a rebuild
+ */
+public void testChangeExternalFolder() throws CoreException {
+ String externalLib = Util.getOutputDirectory() + File.separator + "externalLib";
+ try {
+ new File(externalLib).mkdirs();
+ Util.compile(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}"
+ },
+ new HashMap(),
+ externalLib
+ );
+
+ IPath projectPath = env.addProject("Project");
+ env.addExternalJars(projectPath, Util.getJavaClassLibs());
+ env.addExternalFolders(projectPath, new String[] {externalLib});
+
+ IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
+ env.setOutputFolder(projectPath, "");
+
+ IPath classY = env.addClass(root, "q", "Y",
+ "package q;\n"+
+ "public class Y {\n" +
+ " void bar(p.X x) {\n" +
+ " x.foo();\n" +
+ " }\n" +
+ "}"
+ );
+
+ fullBuild(projectPath);
+ expectingNoProblems();
+
+ Util.compile(
+ new String[] {
+ "p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ "}"
+ },
+ new HashMap(),
+ externalLib
+ );
+ // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=219566
+ IProject externalFoldersProject = JavaModelManager.getExternalManager().getExternalFoldersProject();
+ externalFoldersProject.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ incrementalBuild(projectPath);
+ expectingProblemsFor(
+ classY,
+ "Problem : The method foo() is undefined for the type X [ resource : range : <54,57> category : <50> severity : <2>]"
+ );
+ } finally {
+ new File(externalLib).delete();
+ }
+}
+
+/*
* Ensures that changing an external jar and refreshing the projects triggers a rebuild
* (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states)
*/
@@ -565,7 +630,7 @@
List expectedProblems = new ArrayList();
for (int i = 0; i < max; i++) {
String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
+ Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
if (libraryJDK > projectRuntimeJDKLevel) {
expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_WARNING));
@@ -580,7 +645,7 @@
expectedProblems = new ArrayList();
for (int i = 0; i < max; i++) {
String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
+ Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
if (libraryJDK > projectRuntimeJDKLevel) {
expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_ERROR));
@@ -625,7 +690,7 @@
int max = classlibs.length;
for (int i = 0; i < max; i++) {
String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
+ Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
if (libraryJDK > wkspRuntimeJDKLevel) {
expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_WARNING));
@@ -640,7 +705,7 @@
expectedProblems = new ArrayList();
for (int i = 0; i < max; i++) {
String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString();
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(path).makeAbsolute(), true);
+ Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true);
long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target);
if (libraryJDK > wkspRuntimeJDKLevel) {
expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_ERROR));
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/internal/core/DeleteResourceElementsOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeleteResourceElementsOperation.java,v
retrieving revision 1.39
diff -u -r1.39 DeleteResourceElementsOperation.java
--- model/org/eclipse/jdt/internal/core/DeleteResourceElementsOperation.java 10 May 2006 18:03:47 -0000 1.39
+++ model/org/eclipse/jdt/internal/core/DeleteResourceElementsOperation.java 26 Feb 2008 09:54:56 -0000
@@ -11,9 +11,6 @@
package org.eclipse.jdt.internal.core;
import org.eclipse.core.resources.*;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
@@ -43,7 +40,7 @@
*/
private void deletePackageFragment(IPackageFragment frag)
throws JavaModelException {
- IResource res = frag.getResource();
+ IResource res = ((JavaElement) frag).resource();
if (res != null) {
// collect the children to remove
IJavaElement[] childrenOfInterest = frag.getChildren();
@@ -51,7 +48,7 @@
IResource[] resources = new IResource[childrenOfInterest.length];
// remove the children
for (int i = 0; i < childrenOfInterest.length; i++) {
- resources[i] = childrenOfInterest[i].getCorrespondingResource();
+ resources[i] = ((JavaElement) childrenOfInterest[i]).resource();
}
deleteResources(resources, force);
}
@@ -86,7 +83,7 @@
}
if (isEmpty && !frag.isDefaultPackage()/*don't delete default package's folder: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38450*/) {
// delete recursively empty folders
- IResource fragResource = frag.getResource();
+ IResource fragResource = ((JavaElement) frag).resource();
if (fragResource != null) {
deleteEmptyPackageFragment(frag, false, fragResource.getParent());
}
@@ -132,7 +129,7 @@
error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
else if (type == IJavaElement.PACKAGE_FRAGMENT && element instanceof JarPackageFragment)
error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
- IResource resource = element.getResource();
+ IResource resource = ((JavaElement) element).resource();
if (resource instanceof IFolder) {
if (resource.isLinked()) {
error(IJavaModelStatusConstants.INVALID_RESOURCE, element);
Index: model/org/eclipse/jdt/internal/core/SourceRefElement.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceRefElement.java,v
retrieving revision 1.49
diff -u -r1.49 SourceRefElement.java
--- model/org/eclipse/jdt/internal/core/SourceRefElement.java 24 Oct 2007 13:50:51 -0000 1.49
+++ model/org/eclipse/jdt/internal/core/SourceRefElement.java 26 Feb 2008 09:54:59 -0000
@@ -187,8 +187,8 @@
/*
* @see IJavaElement
*/
-public IResource getResource() {
- return this.getParent().getResource();
+public IResource resource() {
+ return this.parent.resource();
}
/**
* @see ISourceReference
Index: model/org/eclipse/jdt/internal/core/MovePackageFragmentRootOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/MovePackageFragmentRootOperation.java,v
retrieving revision 1.17
diff -u -r1.17 MovePackageFragmentRootOperation.java
--- model/org/eclipse/jdt/internal/core/MovePackageFragmentRootOperation.java 27 Apr 2007 15:51:38 -0000 1.17
+++ model/org/eclipse/jdt/internal/core/MovePackageFragmentRootOperation.java 26 Feb 2008 09:54:59 -0000
@@ -118,7 +118,7 @@
}
protected void executeOperation() throws JavaModelException {
- IPackageFragmentRoot root = (IPackageFragmentRoot)this.getElementToProcess();
+ IPackageFragmentRoot root = (IPackageFragmentRoot) getElementToProcess();
IClasspathEntry rootEntry = root.getRawClasspathEntry();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
@@ -160,7 +160,7 @@
throws JavaModelException {
final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
- IResource rootResource = root.getResource();
+ IResource rootResource = ((JavaElement) root).resource();
if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
try {
IResource destRes;
Index: model/org/eclipse/jdt/internal/core/JavaModelOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelOperation.java,v
retrieving revision 1.69
diff -u -r1.69 JavaModelOperation.java
--- model/org/eclipse/jdt/internal/core/JavaModelOperation.java 11 Oct 2007 11:32:48 -0000 1.69
+++ model/org/eclipse/jdt/internal/core/JavaModelOperation.java 26 Feb 2008 09:54:58 -0000
@@ -145,13 +145,6 @@
protected JavaModelOperation(IJavaElement element) {
this.elementsToProcess = new IJavaElement[]{element};
}
- /**
- * A common constructor for all Java Model operations.
- */
- protected JavaModelOperation(IJavaElement element, boolean force) {
- this.elementsToProcess = new IJavaElement[]{element};
- this.force= force;
- }
/*
* Registers the given action at the end of the list of actions to run.
@@ -292,7 +285,7 @@
IResource rootResource)
throws JavaModelException {
- IContainer resource = (IContainer) fragment.getResource();
+ IContainer resource = (IContainer) ((JavaElement)fragment).resource();
try {
resource.delete(
@@ -438,13 +431,6 @@
return new DocumentAdapter(buffer);
}
/**
- * Returns the elements to which this operation applies,
- * or null
if not applicable.
- */
- protected IJavaElement[] getElementsToProcess() {
- return elementsToProcess;
- }
- /**
* Returns the element to which this operation applies,
* or null
if not applicable.
*/
Index: model/org/eclipse/jdt/internal/core/BufferManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BufferManager.java,v
retrieving revision 1.28
diff -u -r1.28 BufferManager.java
--- model/org/eclipse/jdt/internal/core/BufferManager.java 9 May 2007 18:53:13 -0000 1.28
+++ model/org/eclipse/jdt/internal/core/BufferManager.java 26 Feb 2008 09:54:55 -0000
@@ -16,7 +16,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IBuffer;
-import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IOpenable;
/**
@@ -64,8 +63,8 @@
}
}
public static IBuffer createBuffer(IOpenable owner) {
- IJavaElement element = (IJavaElement)owner;
- IResource resource = element.getResource();
+ JavaElement element = (JavaElement) owner;
+ IResource resource = element.resource();
return
new Buffer(
resource instanceof IFile ? (IFile)resource : null,
@@ -73,8 +72,8 @@
element.isReadOnly());
}
public static IBuffer createNullBuffer(IOpenable owner) {
- IJavaElement element = (IJavaElement)owner;
- IResource resource = element.getResource();
+ JavaElement element = (JavaElement) owner;
+ IResource resource = element.resource();
return
new NullBuffer(
resource instanceof IFile ? (IFile)resource : null,
Index: model/org/eclipse/jdt/internal/core/ClassFile.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v
retrieving revision 1.138
diff -u -r1.138 ClassFile.java
--- model/org/eclipse/jdt/internal/core/ClassFile.java 30 Nov 2007 15:31:22 -0000 1.138
+++ model/org/eclipse/jdt/internal/core/ClassFile.java 26 Feb 2008 09:54:55 -0000
@@ -321,7 +321,7 @@
JavaModelManager.getJavaModelManager().closeZipFile(zip);
}
} else {
- IFile file = (IFile) getResource();
+ IFile file = (IFile) resource();
return Util.getResourceContentsAsByteArray(file);
}
}
@@ -348,7 +348,7 @@
return super.getBuffer();
} else {
// .class file not on classpath, create a new buffer to be nice (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=41444)
- Object info = ((ClassFile) getClassFile()).getBinaryTypeInfo((IFile) getResource());
+ Object info = ((ClassFile) getClassFile()).getBinaryTypeInfo((IFile) resource());
IBuffer buffer = openBuffer(null, info);
if (buffer != null && !(buffer instanceof NullBuffer))
return buffer;
@@ -488,13 +488,8 @@
/*
* @see IJavaElement
*/
-public IResource getResource() {
- PackageFragmentRoot root = this.getPackageFragmentRoot();
- if (root.isArchive()) {
- return root.getResource();
- } else {
- return ((IContainer)this.getParent().getResource()).getFile(new Path(this.getElementName()));
- }
+public IResource resource(PackageFragmentRoot root) {
+ return ((IContainer) ((Openable) this.parent).resource(root)).getFile(new Path(this.getElementName()));
}
/**
* @see ISourceReference
Index: model/org/eclipse/jdt/internal/core/Openable.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Openable.java,v
retrieving revision 1.114
diff -u -r1.114 Openable.java
--- model/org/eclipse/jdt/internal/core/Openable.java 21 Sep 2007 13:16:47 -0000 1.114
+++ model/org/eclipse/jdt/internal/core/Openable.java 26 Feb 2008 09:54:59 -0000
@@ -197,7 +197,7 @@
}
break;
}
- return validateExistence(getResource()).isOK();
+ return validateExistence(resource()).isOK();
}
public String findRecommendedLineSeparator() throws JavaModelException {
IBuffer buffer = getBuffer();
@@ -234,7 +234,7 @@
openAncestors(newElements, monitor);
// validate existence
- IResource underlResource = getResource();
+ IResource underlResource = resource();
IStatus status = validateExistence(underlResource);
if (!status.isOK())
throw newJavaModelException(status);
@@ -436,6 +436,26 @@
return null;
}
+public IResource getResource() {
+ PackageFragmentRoot root = getPackageFragmentRoot();
+ if (root != null) {
+ if (root.isExternal())
+ return null;
+ if (root.isArchive())
+ return root.resource(root);
+ }
+ return resource(root);
+}
+
+public IResource resource() {
+ PackageFragmentRoot root = getPackageFragmentRoot();
+ if (root != null && root.isArchive())
+ return root.resource(root);
+ return resource(root);
+}
+
+protected abstract IResource resource(PackageFragmentRoot root);
+
/**
* Returns whether the corresponding resource or associated file exists
*/
Index: model/org/eclipse/jdt/internal/core/SourceMapper.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java,v
retrieving revision 1.131
diff -u -r1.131 SourceMapper.java
--- model/org/eclipse/jdt/internal/core/SourceMapper.java 21 Jan 2008 10:36:14 -0000 1.131
+++ model/org/eclipse/jdt/internal/core/SourceMapper.java 26 Feb 2008 09:54:59 -0000
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core;
-import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -78,14 +76,6 @@
public static boolean VERBOSE = false;
/**
- * Specifies the file name filter use to compute the root paths.
- */
- private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name);
- }
- };
- /**
* Specifies the location of the package fragment roots within
* the zip (empty specifies the default root). null
is
* not a valid root path.
@@ -401,7 +391,7 @@
manager.closeZipFile(zip); // handle null case
}
} else {
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), root.getPath(), true);
+ Object target = JavaModel.getTarget(root.getPath(), true);
if (target instanceof IResource) {
IResource resource = (IResource) target;
if (resource instanceof IContainer) {
@@ -419,19 +409,6 @@
// ignore
}
}
- } else if (target instanceof File) {
- File file = (File)target;
- if (file.isDirectory()) {
- File[] files = file.listFiles();
- for (int i = 0, max = files.length; i < max; i++) {
- File currentFile = files[i];
- if (currentFile.isDirectory()) {
- firstLevelPackageNames.add(currentFile.getName());
- } else if (Util.isClassFileName(currentFile.getName())) {
- containsADefaultPackage = true;
- }
- }
- }
}
}
@@ -467,16 +444,9 @@
manager.closeZipFile(zip); // handle null case
}
} else {
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.sourcePath, true);
- if (target instanceof IResource) {
- if (target instanceof IContainer) {
- computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
- }
- } else if (target instanceof File) {
- File file = (File)target;
- if (file.isDirectory()) {
- computeRootPath(file, firstLevelPackageNames, containsADefaultPackage, tempRoots);
- }
+ Object target = JavaModel.getTarget(this.sourcePath, true);
+ if (target instanceof IContainer) {
+ computeRootPath((IContainer)target, firstLevelPackageNames, containsADefaultPackage, tempRoots);
}
}
int size = tempRoots.size();
@@ -517,32 +487,6 @@
}
}
- private void computeRootPath(File directory, HashSet firstLevelPackageNames, boolean hasDefaultPackage, Set set) {
- File[] files = directory.listFiles();
- boolean hasSubDirectories = false;
- loop: for (int i = 0, max = files.length; i < max; i++) {
- File file = files[i];
- if (file.isDirectory()) {
- hasSubDirectories = true;
- if (firstLevelPackageNames.contains(file.getName())) {
- IPath fullPath = new Path(file.getParentFile().getPath());
- IPath rootPathEntry = fullPath.removeFirstSegments(this.sourcePath.segmentCount()).setDevice(null);
- set.add(rootPathEntry);
- break loop;
- } else {
- computeRootPath(file, firstLevelPackageNames, hasDefaultPackage, set);
- }
- } else if (i == max - 1 && !hasSubDirectories && hasDefaultPackage) {
- File parentDir = file.getParentFile();
- if (parentDir.list(FILENAME_FILTER).length != 0) {
- IPath fullPath = new Path(parentDir.getPath());
- IPath rootPathEntry = fullPath.removeFirstSegments(this.sourcePath.segmentCount()).setDevice(null);
- set.add(rootPathEntry);
- }
- }
- }
- }
-
private void computeRootPath(IContainer container, HashSet firstLevelPackageNames, boolean hasDefaultPackage, Set set) {
try {
IResource[] resources = container.members();
@@ -958,28 +902,14 @@
manager.closeZipFile(zip); // handle null case
}
} else {
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.sourcePath, true);
- if (target instanceof IResource) {
- if (target instanceof IContainer) {
- IResource res = ((IContainer)target).findMember(fullName);
- if (res instanceof IFile) {
- try {
- source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
- } catch (JavaModelException e) {
- // ignore
- }
- }
- }
- } else if (target instanceof File) {
- File file = (File)target;
- if (file.isDirectory()) {
- File sourceFile = new File(file, fullName);
- if (sourceFile.isFile()) {
- try {
- source = Util.getFileCharContent(sourceFile, this.encoding);
- } catch (IOException e) {
- // ignore
- }
+ Object target = JavaModel.getTarget(this.sourcePath, true);
+ if (target instanceof IContainer) {
+ IResource res = ((IContainer)target).findMember(fullName);
+ if (res instanceof IFile) {
+ try {
+ source = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray((IFile)res);
+ } catch (JavaModelException e) {
+ // ignore
}
}
}
Index: model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java,v
retrieving revision 1.28
diff -u -r1.28 CopyPackageFragmentRootOperation.java
--- model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java 27 Apr 2007 15:51:38 -0000 1.28
+++ model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java 26 Feb 2008 09:54:56 -0000
@@ -58,7 +58,7 @@
final IWorkspaceRoot workspaceRoot)
throws JavaModelException {
final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
- IResource rootResource = root.getResource();
+ IResource rootResource = ((JavaElement) root).resource();
if (root.getKind() == IPackageFragmentRoot.K_BINARY || exclusionPatterns == null) {
try {
IResource destRes;
@@ -212,12 +212,12 @@
if (!status.isOK()) {
return status;
}
- IPackageFragmentRoot root = (IPackageFragmentRoot)getElementToProcess();
+ PackageFragmentRoot root = (PackageFragmentRoot)getElementToProcess();
if (root == null || !root.exists()) {
return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
}
- IResource resource = root.getResource();
+ IResource resource = root.resource();
if (resource instanceof IFolder) {
if (resource.isLinked()) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
Index: model/org/eclipse/jdt/internal/core/LocalVariable.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LocalVariable.java,v
retrieving revision 1.23
diff -u -r1.23 LocalVariable.java
--- model/org/eclipse/jdt/internal/core/LocalVariable.java 22 Nov 2007 15:05:51 -0000 1.23
+++ model/org/eclipse/jdt/internal/core/LocalVariable.java 26 Feb 2008 09:54:59 -0000
@@ -251,8 +251,8 @@
return this.parent.getPath();
}
- public IResource getResource() {
- return this.parent.getResource();
+ public IResource resource() {
+ return this.parent.resource();
}
/**
Index: model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java,v
retrieving revision 1.6
diff -u -r1.6 ChangeClasspathOperation.java
--- model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java 17 Dec 2007 11:08:02 -0000 1.6
+++ model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java 26 Feb 2008 09:54:55 -0000
@@ -60,6 +60,9 @@
// since some clients rely on the project references when run inside an IWorkspaceRunnable
new ProjectReferenceChange(project, change.oldResolvedClasspath).updateProjectReferencesIfNecessary();
+ // and ensure that external folders are updated as well
+ new ExternalFolderChange(project, change.oldResolvedClasspath).updateExternalFoldersIfNecessary(null);
+
} else {
JavaElementDelta delta = new JavaElementDelta(getJavaModel());
int result = change.generateDelta(delta);
@@ -77,6 +80,10 @@
// ensure project references are updated on next build
state.addProjectReferenceChange(project, change.oldResolvedClasspath);
}
+ if ((result & ClasspathChange.HAS_LIBRARY_CHANGE) != 0) {
+ // ensure external folders are updated on next build
+ state.addExternalFolderChange(project, change.oldResolvedClasspath);
+ }
}
}
Index: model/org/eclipse/jdt/internal/core/CompilationUnit.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java,v
retrieving revision 1.244
diff -u -r1.244 CompilationUnit.java
--- model/org/eclipse/jdt/internal/core/CompilationUnit.java 21 Jan 2008 10:36:13 -0000 1.244
+++ model/org/eclipse/jdt/internal/core/CompilationUnit.java 26 Feb 2008 09:54:56 -0000
@@ -833,17 +833,12 @@
if (checkOwner && isPrimary()) return this;
return new CompilationUnit((PackageFragment)getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
}
-/**
- * @see IJavaElement#getResource()
+/*
+ * @see Openable#resource(PackageFragmentRoot)
*/
-public IResource getResource() {
- PackageFragmentRoot root = getPackageFragmentRoot();
+public IResource resource(PackageFragmentRoot root) {
if (root == null) return null; // working copy not in workspace
- if (root.isArchive()) {
- return root.getResource();
- } else {
- return ((IContainer) getParent().getResource()).getFile(new Path(getElementName()));
- }
+ return ((IContainer) ((Openable) this.parent).resource(root)).getFile(new Path(getElementName()));
}
/**
* @see ISourceReference#getSource()
Index: model/org/eclipse/jdt/internal/core/JavaProject.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v
retrieving revision 1.394
diff -u -r1.394 JavaProject.java
--- model/org/eclipse/jdt/internal/core/JavaProject.java 1 Feb 2008 17:09:09 -0000 1.394
+++ model/org/eclipse/jdt/internal/core/JavaProject.java 26 Feb 2008 09:54:59 -0000
@@ -503,7 +503,7 @@
if (projectPath.isPrefixOf(entryPath)){
if (checkExistency) {
- Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
+ Object target = JavaModel.getTarget(entryPath, checkExistency);
if (target == null) return;
if (target instanceof IFolder || target instanceof IProject){
@@ -521,16 +521,18 @@
if (referringEntry != null && !resolvedEntry.isExported()) return;
if (checkExistency) {
- Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
+ Object target = JavaModel.getTarget(entryPath, checkExistency);
if (target == null) return;
if (target instanceof IResource){
// internal target
- root = getPackageFragmentRoot((IResource) target);
- } else {
- // external target - only JARs allowed
+ root = getPackageFragmentRoot((IResource) target, entryPath);
+ } else if (target instanceof File) {
+ // external target
if (JavaModel.isFile(target) && (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))) {
root = new JarPackageFragmentRoot(entryPath, this);
+ } else if (((File) target).isDirectory()) {
+ root = new ExternalPackageFragmentRoot(entryPath, this);
}
}
} else {
@@ -672,10 +674,16 @@
IPath fullPath = resource.getFullPath();
IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null;
IClasspathEntry innerMostEntry = null;
+ ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager();
for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
IClasspathEntry entry = classpath[j];
IPath entryPath = entry.getPath();
+ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ IResource linkedFolder = foldersManager.getFolder(entryPath);
+ if (linkedFolder != null)
+ entryPath = linkedFolder.getFullPath();
+ }
if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath))
&& entryPath.isPrefixOf(fullPath)) {
innerMostEntry = entry;
@@ -1641,7 +1649,10 @@
* @see IJavaProject
*/
public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
-
+ return getPackageFragmentRoot(resource, null/*no entry path*/);
+ }
+
+ private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) {
switch (resource.getType()) {
case IResource.FILE:
if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resource.getName())) {
@@ -1650,6 +1661,8 @@
return null;
}
case IResource.FOLDER:
+ if (ExternalFoldersManager.isExternal(resource.getFullPath()))
+ return new ExternalPackageFragmentRoot(resource, entryPath, this);
return new PackageFragmentRoot(resource, this);
case IResource.PROJECT:
return new PackageFragmentRoot(resource, this);
@@ -1661,17 +1674,19 @@
/**
* @see IJavaProject
*/
- public IPackageFragmentRoot getPackageFragmentRoot(String jarPath) {
+ public IPackageFragmentRoot getPackageFragmentRoot(String libraryPath) {
- return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(jarPath)));
+ return getPackageFragmentRoot0(JavaProject.canonicalizedPath(new Path(libraryPath)));
}
/*
* no path canonicalization
*/
- public IPackageFragmentRoot getPackageFragmentRoot0(IPath jarPath) {
-
- return new JarPackageFragmentRoot(jarPath, this);
+ public IPackageFragmentRoot getPackageFragmentRoot0(IPath libraryPath) {
+ if (!org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(libraryPath.lastSegment()))
+ return new ExternalPackageFragmentRoot(libraryPath, this);
+ return new JarPackageFragmentRoot(libraryPath, this);
+
}
/**
@@ -1879,7 +1894,7 @@
/**
* @see IJavaElement
*/
- public IResource getResource() {
+ public IResource resource(PackageFragmentRoot root) {
return this.project;
}
Index: model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java,v
retrieving revision 1.38
diff -u -r1.38 PackageFragmentRootInfo.java
--- model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java 6 Nov 2006 14:13:45 -0000 1.38
+++ model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java 26 Feb 2008 09:54:59 -0000
@@ -54,6 +54,8 @@
* @exception JavaModelException The resource associated with this package fragment does not exist
*/
static Object[] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException {
+ if (ExternalFoldersManager.isExternal(folder.getFullPath()))
+ return NO_NON_JAVA_RESOURCES;
Object[] nonJavaResources = new IResource[5];
int nonJavaResourcesCounter = 0;
try {
Index: model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java,v
retrieving revision 1.50
diff -u -r1.50 ClassFileWorkingCopy.java
--- model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java 12 Dec 2006 17:13:59 -0000 1.50
+++ model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java 26 Feb 2008 09:54:55 -0000
@@ -14,7 +14,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IBuffer;
-import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
import org.eclipse.jdt.core.JavaModelException;
@@ -31,10 +30,10 @@
*/
public class ClassFileWorkingCopy extends CompilationUnit {
- public IClassFile classFile;
+ public ClassFile classFile;
-public ClassFileWorkingCopy(IClassFile classFile, WorkingCopyOwner owner) {
- super((PackageFragment) classFile.getParent(), ((BinaryType) ((ClassFile) classFile).getType()).getSourceFileName(null/*no info available*/), owner);
+public ClassFileWorkingCopy(ClassFile classFile, WorkingCopyOwner owner) {
+ super((PackageFragment) classFile.getParent(), ((BinaryType) classFile.getType()).getSourceFileName(null/*no info available*/), owner);
this.classFile = classFile;
}
@@ -70,8 +69,10 @@
return new ClassFileWorkingCopy(this.classFile, DefaultWorkingCopyOwner.PRIMARY);
}
-public IResource getResource() {
- return this.classFile.getResource();
+public IResource resource(PackageFragmentRoot root) {
+ if (root.isArchive())
+ return root.resource(root);
+ return this.classFile.resource(root);
}
/**
Index: model/org/eclipse/jdt/internal/core/JavaModel.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java,v
retrieving revision 1.91
diff -u -r1.91 JavaModel.java
--- model/org/eclipse/jdt/internal/core/JavaModel.java 21 Sep 2007 13:16:47 -0000 1.91
+++ model/org/eclipse/jdt/internal/core/JavaModel.java 26 Feb 2008 09:54:57 -0000
@@ -15,7 +15,6 @@
import java.util.HashSet;
import java.util.Map;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -235,7 +234,7 @@
/*
* @see IJavaElement
*/
-public IResource getResource() {
+public IResource resource(PackageFragmentRoot root) {
return ResourcesPlugin.getWorkspace().getRoot();
}
/**
@@ -313,46 +312,60 @@
* or null if unbound
* Internal items must be referred to using container relative paths.
*/
-public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
-
- if (path == null) return null;
-
- // lookup - inside the container
- if (path.getDevice() == null) { // container relative paths should not contain a device
- // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
- // (case of a workspace rooted at d:\ )
- IResource resource = container.findMember(path);
- if (resource != null){
- if (!checkResourceExistence ||resource.exists()) return resource;
- return null;
+public static Object getTarget(IPath path, boolean checkResourceExistence) {
+ Object target = getWorkspaceTarget(path); // Implicitly checks resource existence
+ if (target != null)
+ return target;
+ return getExternalTarget(path, checkResourceExistence);
+}
+public static Object getWorkspaceTarget(IPath path) {
+ if (path == null || path.getDevice() != null)
+ return null;
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace == null)
+ return null;
+ return workspace.getRoot().findMember(path);
+}
+public static Object getExternalTarget(IPath path, boolean checkResourceExistence) {
+ if (path == null)
+ return null;
+ ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
+ Object linkedFolder = externalFoldersManager.getFolder(path);
+ if (linkedFolder != null) {
+ if (checkResourceExistence) {
+ // check if external folder is present
+ File externalFile = new File(path.toOSString());
+ if (!externalFile.isDirectory()) {
+ return null;
+ }
}
+ return linkedFolder;
}
-
- // if path is relative, it cannot be an external path
- // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
- if (!path.isAbsolute()) return null;
-
- // lookup - outside the container
- return getTargetAsExternalFile(path, checkResourceExistence);
-}
-private synchronized static Object getTargetAsExternalFile(IPath path, boolean checkResourceExistence) {
File externalFile = new File(path.toOSString());
if (!checkResourceExistence) {
return externalFile;
- } else if (existingExternalFiles.contains(externalFile)) {
+ } else if (existingExternalFilesContains(externalFile)) {
return externalFile;
} else {
if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
}
- if (externalFile.exists()) {
+ if (externalFile.isFile()) { // isFile() checks for existence (it returns false if a directory)
// cache external file
- existingExternalFiles.add(externalFile);
+ existingExternalFilesAdd(externalFile);
return externalFile;
+ } else if (externalFile.isDirectory()) {
+ return externalFoldersManager.addFolder(path);
}
}
return null;
}
+private synchronized static void existingExternalFilesAdd(File externalFile) {
+ existingExternalFiles.add(externalFile);
+}
+private synchronized static boolean existingExternalFilesContains(File externalFile) {
+ return existingExternalFiles.contains(externalFile);
+}
/**
* Helper method - returns whether an object is afile (ie. which returns true to {@link java.io.File#isFile()}.
Index: model/org/eclipse/jdt/internal/core/PackageFragment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragment.java,v
retrieving revision 1.81
diff -u -r1.81 PackageFragment.java
--- model/org/eclipse/jdt/internal/core/PackageFragment.java 21 Sep 2007 13:16:47 -0000 1.81
+++ model/org/eclipse/jdt/internal/core/PackageFragment.java 26 Feb 2008 09:54:59 -0000
@@ -297,7 +297,7 @@
// We don't want to show non java resources of the default package (see PR #1G58NB8)
return JavaElementInfo.NO_NON_JAVA_RESOURCES;
} else {
- return ((PackageFragmentInfo) getElementInfo()).getNonJavaResources(getResource(), getPackageFragmentRoot());
+ return ((PackageFragmentInfo) getElementInfo()).getNonJavaResources(resource(), getPackageFragmentRoot());
}
}
/**
@@ -317,22 +317,17 @@
}
}
/**
- * @see IJavaElement#getResource()
+ * @see JavaElement#resource()
*/
-public IResource getResource() {
- PackageFragmentRoot root = this.getPackageFragmentRoot();
- if (root.isArchive()) {
- return root.getResource();
+public IResource resource(PackageFragmentRoot root) {
+ int length = this.names.length;
+ if (length == 0) {
+ return root.resource(root);
} else {
- int length = this.names.length;
- if (length == 0) {
- return root.getResource();
- } else {
- IPath path = new Path(this.names[0]);
- for (int i = 1; i < length; i++)
- path = path.append(this.names[i]);
- return ((IContainer)root.getResource()).getFolder(path);
- }
+ IPath path = new Path(this.names[0]);
+ for (int i = 1; i < length; i++)
+ path = path.append(this.names[i]);
+ return ((IContainer)root.resource(root)).getFolder(path);
}
}
/**
Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v
retrieving revision 1.312
diff -u -r1.312 DeltaProcessor.java
--- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 29 Jan 2008 18:02:22 -0000 1.312
+++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 26 Feb 2008 09:54:57 -0000
@@ -13,6 +13,7 @@
import java.io.File;
import java.util.*;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -112,7 +113,7 @@
if (resource != null) {
this.root = this.project.getPackageFragmentRoot(resource);
} else {
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.rootPath, false/*don't check existence*/);
+ Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/);
if (target instanceof IResource) {
this.root = this.project.getPackageFragmentRoot((IResource)target);
} else {
@@ -340,6 +341,8 @@
readRawClasspath(javaProject);
// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121569)
checkProjectReferenceChange(project, javaProject);
+ // and external folders as well
+ checkExternalFolderChange(project, javaProject);
}
this.state.rootsAreStale = true;
@@ -359,6 +362,8 @@
readRawClasspath(javaProject);
// ensure project references are updated
checkProjectReferenceChange(project, javaProject);
+ // and external folders as well
+ checkExternalFolderChange(project, javaProject);
}
} else {
try {
@@ -386,6 +391,8 @@
readRawClasspath(javaProject);
// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172666)
checkProjectReferenceChange(project, javaProject);
+ // and external folders as well
+ checkExternalFolderChange(project, javaProject);
} else {
// remove classpath cache so that initializeRoots() will not consider the project has a classpath
this.manager.removePerProjectInfo(javaProject);
@@ -471,6 +478,11 @@
}
}
+ private void checkExternalFolderChange(IProject project, JavaProject javaProject) {
+ ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
+ this.state.addExternalFolderChange(javaProject, change == null ? null : change.oldResolvedClasspath);
+ }
+
private void checkProjectReferenceChange(IProject project, JavaProject javaProject) {
ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
this.state.addProjectReferenceChange(javaProject, change == null ? null : change.oldResolvedClasspath);
@@ -487,14 +499,14 @@
}
}
private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
- IPath rootPath = (IPath)this.state.sourceAttachments.get(res.getFullPath());
+ IPath rootPath = (IPath)this.state.sourceAttachments.get(externalPath(res));
if (rootPath != null) {
RootInfo rootInfo = this.rootInfo(rootPath, delta.getKind());
if (rootInfo != null) {
IJavaProject projectOfRoot = rootInfo.project;
IPackageFragmentRoot root = null;
try {
- // close the root so that source attachement cache is flushed
+ // close the root so that source attachment cache is flushed
root = projectOfRoot.findPackageFragmentRoot(rootPath);
if (root != null) {
root.close();
@@ -610,7 +622,7 @@
if (rootInfo.project.contains(resource)) {
PackageFragmentRoot root = (PackageFragmentRoot) rootInfo.getPackageFragmentRoot(null);
// create package handle
- IPath pkgPath = path.removeFirstSegments(rootInfo.rootPath.segmentCount());
+ IPath pkgPath = path.removeFirstSegments(root.resource().getFullPath().segmentCount());
String[] pkgName = pkgPath.segments();
element = root.getPackageFragment(pkgName);
}
@@ -834,7 +846,7 @@
if (status == null){
// compute shared status
- Object targetLibrary = JavaModel.getTarget(wksRoot, entryPath, true);
+ Object targetLibrary = JavaModel.getTarget(entryPath, true);
if (targetLibrary == null){ // missing JAR
if (this.state.getExternalLibTimeStamps().remove(entryPath) != null){
@@ -1047,7 +1059,8 @@
}
// find the element type of the moved from element
- RootInfo movedFromInfo = this.enclosingRootInfo(movedFromPath, IResourceDelta.REMOVED);
+ IPath rootPath = externalPath(movedFromRes);
+ RootInfo movedFromInfo = this.enclosingRootInfo(rootPath, IResourceDelta.REMOVED);
int movedFromType =
this.elementType(
movedFromRes,
@@ -1133,7 +1146,8 @@
}
// find the element type of the moved from element
- RootInfo movedToInfo = this.enclosingRootInfo(movedToPath, IResourceDelta.ADDED);
+ IPath rootPath = externalPath(movedToRes);
+ RootInfo movedToInfo = this.enclosingRootInfo(rootPath, IResourceDelta.ADDED);
int movedToType =
this.elementType(
movedToRes,
@@ -1208,7 +1222,8 @@
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.PACKAGE_FRAGMENT:
if (rootInfo == null) {
- rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
+ IPath rootPath = externalPath(res);
+ rootInfo = this.enclosingRootInfo(rootPath, kind);
}
if (rootInfo == null) {
return NON_JAVA_RESOURCE;
@@ -1235,12 +1250,15 @@
return IJavaElement.COMPILATION_UNIT;
} else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
return IJavaElement.CLASS_FILE;
- } else if ((rootInfo = this.rootInfo(res.getFullPath(), kind)) != null
- && rootInfo.project.getProject().getFullPath().isPrefixOf(res.getFullPath()) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) {
- // case of proj=src=bin and resource is a jar file on the classpath
- return IJavaElement.PACKAGE_FRAGMENT_ROOT;
} else {
- return NON_JAVA_RESOURCE;
+ IPath rootPath = externalPath(res);
+ if ((rootInfo = this.rootInfo(rootPath, kind)) != null
+ && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) {
+ // case of proj=src=bin and resource is a jar file on the classpath
+ return IJavaElement.PACKAGE_FRAGMENT_ROOT;
+ } else {
+ return NON_JAVA_RESOURCE;
+ }
}
default:
@@ -1253,7 +1271,7 @@
public void flush() {
this.javaModelDeltas = new ArrayList();
}
-
+
private SourceElementParser getSourceElementParser(Openable element) {
if (this.sourceElementParserCache == null)
this.sourceElementParserCache = this.manager.indexManager.getSourceElementParser(element.getJavaProject(), null/*requestor will be set by indexer*/);
@@ -1271,6 +1289,14 @@
}
return null;
}
+
+ private IPath externalPath(IResource res) {
+ IPath resourcePath = res.getFullPath();
+ if (ExternalFoldersManager.isExternal(resourcePath))
+ return res.getLocation();
+ return resourcePath;
+ }
+
/*
* Fire Java Model delta, flushing them after the fact after post_change notification.
* If the firing mode has been turned off, this has no effect.
@@ -1391,7 +1417,8 @@
}
return true;
}
- });
+ },
+ IContainer.INCLUDE_HIDDEN);
} catch(FoundRelevantDeltaException e) {
//System.out.println("RELEVANT DELTA detected in: "+ (System.currentTimeMillis() - start));
return true;
@@ -1556,8 +1583,9 @@
*
ICompilationUnit#getElementAt
,
@@ -410,7 +414,7 @@
* @see org.eclipse.jdt.core.IJavaElement#getSchedulingRule()
*/
public ISchedulingRule getSchedulingRule() {
- IResource resource = getResource();
+ IResource resource = resource();
if (resource == null) {
class NoResourceSchedulingRule implements ISchedulingRule {
public IPath path;
Index: model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java,v
retrieving revision 1.126
diff -u -r1.126 PackageFragmentRoot.java
--- model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 27 Sep 2007 11:09:40 -0000 1.126
+++ model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 26 Feb 2008 09:54:59 -0000
@@ -62,7 +62,6 @@
monitor.beginTask(Messages.element_attachingSource, 2);
}
SourceMapper oldMapper= getSourceMapper();
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
boolean rootNeedsToBeClosed= false;
if (sourcePath == null) {
@@ -80,7 +79,7 @@
*/
} else {
/*
- // fire a delta to notify the UI about the source attachement.
+ // fire a delta to notify the UI about the source attachment.
JavaModelManager manager = (JavaModelManager) JavaModelManager.getJavaModelManager();
JavaModel model = (JavaModel) getJavaModel();
JavaElementDelta attachedSourceDelta = new JavaElementDelta(model);
@@ -101,7 +100,7 @@
}
}
// check if source path is valid
- Object target = JavaModel.getTarget(workspace.getRoot(), sourcePath, false);
+ Object target = JavaModel.getTarget(sourcePath, false);
if (target == null) {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, sourcePath));
}
@@ -153,7 +152,7 @@
*/
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
- return computeChildren(info);
+ return computeChildren(info, underlyingResource);
}
SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) {
@@ -181,13 +180,12 @@
*
* @exception JavaModelException The resource associated with this package fragment root does not exist
*/
-protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
+protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException {
// Note the children are not opened (so not added to newElements) for a regular package fragment root
- // Howver they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
+ // However they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren)
try {
// the underlying resource may be a folder or a project (in the case that the project folder
// is actually the package fragment root)
- IResource underlyingResource = getResource();
if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) {
ArrayList vChildren = new ArrayList(5);
IContainer rootFolder = (IContainer) underlyingResource;
@@ -324,7 +322,7 @@
if (!(o instanceof PackageFragmentRoot))
return false;
PackageFragmentRoot other = (PackageFragmentRoot) o;
- return getResource().equals(other.getResource()) &&
+ return resource().equals(other.resource()) &&
this.parent.equals(other.parent);
}
@@ -332,14 +330,13 @@
try {
IPath rootPath = this.getPath();
IClasspathEntry entry;
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
// try on enclosing project first
JavaProject parentProject = (JavaProject) getJavaProject();
try {
entry = parentProject.getClasspathEntryFor(rootPath);
if (entry != null){
- Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
+ Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
if (target instanceof IResource) {
if (target instanceof IFile) {
IFile file = (IFile) target;
@@ -374,7 +371,7 @@
try {
entry = jProject.getClasspathEntryFor(rootPath);
if (entry != null){
- Object target = JavaModel.getTarget(workspaceRoot, entry.getSourceAttachmentPath(), true);
+ Object target = JavaModel.getTarget(entry.getSourceAttachmentPath(), true);
if (target instanceof IResource) {
if (target instanceof IFile){
IFile file = (IFile) target;
@@ -386,12 +383,7 @@
}
} else if (target instanceof java.io.File){
java.io.File file = (java.io.File) target;
- if (file.isFile()) {
- if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
- return entry;
- }
- } else {
- // external directory
+ if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())){
return entry;
}
}
@@ -441,7 +433,7 @@
}
}
public String getElementName() {
- IResource res = getResource();
+ IResource res = resource();
if (res instanceof IFolder)
return ((IFolder) res).getName();
return ""; //$NON-NLS-1$
@@ -492,10 +484,10 @@
*/
protected void getHandleMemento(StringBuffer buff) {
IPath path;
- IResource underlyingResource = getResource();
+ IResource underlyingResource = resource();
if (underlyingResource != null) {
// internal jar or regular root
- if (getResource().getProject().equals(getJavaProject().getProject())) {
+ if (resource().getProject().equals(getJavaProject().getProject())) {
path = underlyingResource.getProjectRelativePath();
} else {
path = underlyingResource.getFullPath();
@@ -519,7 +511,7 @@
* Returns an array of non-java resources contained in the receiver.
*/
public Object[] getNonJavaResources() throws JavaModelException {
- return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), getResource(), this);
+ return ((PackageFragmentRootInfo) getElementInfo()).getNonJavaResources(getJavaProject(), resource(), this);
}
/**
@@ -556,9 +548,12 @@
* @see IJavaElement
*/
public IPath getPath() {
- return getResource().getFullPath();
+ return internalPath();
}
+public IPath internalPath() {
+ return resource().getFullPath();
+}
/*
* @see IPackageFragmentRoot
*/
@@ -580,7 +575,7 @@
/*
* @see IJavaElement
*/
-public IResource getResource() {
+public IResource resource(PackageFragmentRoot root) {
return (IResource)this.resource;
}
@@ -692,7 +687,7 @@
*/
public IResource getUnderlyingResource() throws JavaModelException {
if (!exists()) throw newNotPresentException();
- return getResource();
+ return resource();
}
/**
@@ -704,7 +699,7 @@
}
public int hashCode() {
- return getResource().hashCode();
+ return resource().hashCode();
}
/**
Index: model/org/eclipse/jdt/internal/core/DeletePackageFragmentRootOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeletePackageFragmentRootOperation.java,v
retrieving revision 1.17
diff -u -r1.17 DeletePackageFragmentRootOperation.java
--- model/org/eclipse/jdt/internal/core/DeletePackageFragmentRootOperation.java 27 Apr 2007 15:51:38 -0000 1.17
+++ model/org/eclipse/jdt/internal/core/DeletePackageFragmentRootOperation.java 26 Feb 2008 09:54:56 -0000
@@ -62,7 +62,7 @@
IClasspathEntry rootEntry)
throws JavaModelException {
final char[][] exclusionPatterns = ((ClasspathEntry)rootEntry).fullExclusionPatternChars();
- IResource rootResource = root.getResource();
+ IResource rootResource = ((JavaElement) root).resource();
if (rootEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE || exclusionPatterns == null) {
try {
rootResource.delete(this.updateResourceFlags, progressMonitor);
@@ -147,12 +147,12 @@
if (!status.isOK()) {
return status;
}
- IPackageFragmentRoot root = (IPackageFragmentRoot) this.getElementToProcess();
+ IJavaElement root = getElementToProcess();
if (root == null || !root.exists()) {
return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, root);
}
- IResource resource = root.getResource();
+ IResource resource = ((JavaElement) root).resource();
if (resource instanceof IFolder) {
if (resource.isLinked()) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_RESOURCE, root);
Index: model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java,v
retrieving revision 1.51
diff -u -r1.51 JavaProjectElementInfo.java
--- model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 1 Feb 2008 15:52:48 -0000 1.51
+++ model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 26 Feb 2008 09:54:59 -0000
@@ -248,7 +248,7 @@
try {
if (!root.isOpen()) {
PackageFragmentRootInfo info = root.isArchive() ? new JarPackageFragmentRootInfo() : new PackageFragmentRootInfo();
- ((PackageFragmentRoot) root).computeChildren(info);
+ ((PackageFragmentRoot) root).computeChildren(info, ((JavaElement) root).resource());
frags = info.children;
} else
frags = root.getChildren();
Index: model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java,v
retrieving revision 1.36
diff -u -r1.36 CreatePackageFragmentOperation.java
--- model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java 4 Jul 2007 14:11:12 -0000 1.36
+++ model/org/eclipse/jdt/internal/core/CreatePackageFragmentOperation.java 26 Feb 2008 09:54:56 -0000
@@ -74,7 +74,7 @@
JavaElementDelta delta = null;
PackageFragmentRoot root = (PackageFragmentRoot) getParentElement();
beginTask(Messages.operation_createPackageFragmentProgress, this.pkgName.length);
- IContainer parentFolder = (IContainer) root.getResource();
+ IContainer parentFolder = (IContainer) root.resource();
String[] sideEffectPackageName = CharOperation.NO_STRINGS;
ArrayList results = new ArrayList(this.pkgName.length);
char[][] inclusionPatterns = root.fullInclusionPatternChars();
@@ -114,7 +114,7 @@
protected ISchedulingRule getSchedulingRule() {
if (this.pkgName.length == 0)
return null; // no resource is going to be created
- IResource parentResource = getParentElement().getResource();
+ IResource parentResource = ((JavaElement) getParentElement()).resource();
IResource resource = ((IContainer) parentResource).getFolder(new Path(this.pkgName[0]));
return resource.getWorkspace().getRuleFactory().createRule(resource);
}
@@ -143,11 +143,11 @@
if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR)) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
}
- IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
+ IJavaElement root = getParentElement();
if (root.isReadOnly()) {
return new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, root);
}
- IContainer parentFolder = (IContainer) root.getResource();
+ IContainer parentFolder = (IContainer) ((JavaElement) root).resource();
int i;
for (i = 0; i < this.pkgName.length; i++) {
IResource subFolder = parentFolder.findMember(this.pkgName[i]);
Index: model/org/eclipse/jdt/internal/core/ClasspathEntry.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java,v
retrieving revision 1.98
diff -u -r1.98 ClasspathEntry.java
--- model/org/eclipse/jdt/internal/core/ClasspathEntry.java 15 Oct 2007 17:39:34 -0000 1.98
+++ model/org/eclipse/jdt/internal/core/ClasspathEntry.java 26 Feb 2008 09:54:56 -0000
@@ -233,8 +233,8 @@
classpathEntryName = manager.intern(getPath().segment(0));
} else {
classpathEntryType = AccessRestriction.LIBRARY;
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, false);
- if (target instanceof java.io.File) {
+ Object target = JavaModel.getWorkspaceTarget(path);
+ if (target == null) {
classpathEntryName = manager.intern(path.toOSString());
} else {
classpathEntryName = manager.intern(path.makeRelative().toString());
@@ -1624,7 +1624,7 @@
case IClasspathEntry.CPE_LIBRARY :
if (path.isAbsolute() && !path.isEmpty()) {
IPath sourceAttachment = entry.getSourceAttachmentPath();
- Object target = JavaModel.getTarget(workspaceRoot, path, true);
+ Object target = JavaModel.getTarget(path, true);
if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
long libraryJDK = Util.getJdkLevel(target);
@@ -1640,7 +1640,7 @@
if (checkSourceAttachment
&& sourceAttachment != null
&& !sourceAttachment.isEmpty()
- && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
+ && JavaModel.getTarget(sourceAttachment, true) == null){
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
}
} else {
@@ -1651,7 +1651,7 @@
if (checkSourceAttachment
&& sourceAttachment != null
&& !sourceAttachment.isEmpty()
- && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
+ && JavaModel.getTarget(sourceAttachment, true) == null){
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
}
}
@@ -1664,7 +1664,7 @@
} else if (checkSourceAttachment
&& sourceAttachment != null
&& !sourceAttachment.isEmpty()
- && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
+ && JavaModel.getTarget(sourceAttachment, true) == null){
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), projectName}));
}
} else {
@@ -1719,7 +1719,7 @@
}
if (path.isAbsolute() && !path.isEmpty()) {
IPath projectPath= project.getProject().getFullPath();
- if (!projectPath.isPrefixOf(path) || JavaModel.getTarget(workspaceRoot, path, true) == null){
+ if (!projectPath.isPrefixOf(path) || JavaModel.getTarget(path, true) == null){
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceFolder, new String[] {entryPathMsg, projectName}));
}
} else {
Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v
retrieving revision 1.384
diff -u -r1.384 JavaModelManager.java
--- model/org/eclipse/jdt/internal/core/JavaModelManager.java 11 Feb 2008 16:50:39 -0000 1.384
+++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 26 Feb 2008 09:54:58 -0000
@@ -407,6 +407,8 @@
/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
public ThreadLocal abortOnMissingSource = new ThreadLocal();
+ private ExternalFoldersManager externalFoldersManager = new ExternalFoldersManager();
+
/**
* Returns whether the given full path (for a package) conflicts with the output location
* of the given project.
@@ -899,11 +901,12 @@
* the package fragment the given resource is located in, or null
* if the given resource is not on the classpath of the given project.
*/
- public static IJavaElement determineIfOnClasspath(
- IResource resource,
- IJavaProject project) {
-
+ public static IJavaElement determineIfOnClasspath(IResource resource, IJavaProject project) {
IPath resourcePath = resource.getFullPath();
+ boolean isExternal = ExternalFoldersManager.isExternal(resourcePath);
+ if (isExternal)
+ resourcePath = resource.getLocation();
+
try {
JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) getJavaModelManager().getInfo(project);
ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache;
@@ -927,7 +930,10 @@
// allow creation of package fragment if it contains a .java file that is included
if (!Util.isExcluded(resource, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars())) {
// given we have a resource child of the root, it cannot be a JAR pkg root
- PackageFragmentRoot root =(PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
+ PackageFragmentRoot root =
+ isExternal ?
+ new ExternalPackageFragmentRoot(rootPath, (JavaProject) project) :
+ (PackageFragmentRoot) ((JavaProject) project).getFolderPackageFragmentRoot(rootPath);
if (root == null) return null;
IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());
@@ -1031,15 +1037,14 @@
public void rememberExternalLibTimestamps() {
IClasspathEntry[] classpath = this.resolvedClasspath;
if (classpath == null) return;
- IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
Map externalTimeStamps = JavaModelManager.getJavaModelManager().deltaState.getExternalLibTimeStamps();
for (int i = 0, length = classpath.length; i < length; i++) {
IClasspathEntry entry = classpath[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
if (externalTimeStamps.get(path) == null) {
- Object target = JavaModel.getTarget(wRoot, path, true);
- if (target instanceof java.io.File) {
+ Object target = JavaModel.getExternalTarget(path, true);
+ if (target instanceof File) {
long timestamp = DeltaProcessor.getTimeStamp((java.io.File)target);
externalTimeStamps.put(path, new Long(timestamp));
}
@@ -1643,6 +1648,10 @@
return this.elementsOutOfSynchWithBuffers;
}
+ public static ExternalFoldersManager getExternalManager() {
+ return MANAGER.externalFoldersManager;
+ }
+
public static IndexManager getIndexManager() {
return MANAGER.indexManager;
}
@@ -3653,6 +3662,9 @@
&& this.workspaceScope != null) {
manager.cleanUpIndexes();
}
+
+ // clean up external folders on full save
+ this.externalFoldersManager.cleanUp(null);
}
IProject savedProject = context.getProject();
@@ -3689,6 +3701,7 @@
// save external libs timestamps
this.deltaState.saveExternalLibTimeStamps();
+
}
/**
@@ -4073,8 +4086,8 @@
while (names.hasNext()) {
Map.Entry entry2 = (Map.Entry) names.next();
String typeName = (String) entry2.getKey();
- IType type = (IType) entry2.getValue();
- if (file.equals(type.getResource())) {
+ JavaElement type = (JavaElement) entry2.getValue();
+ if (file.equals(type.resource())) {
if (removedNames == null) removedNames = new String[namesSize];
namesSize--;
removedNames[removedNamesCount++] = typeName;
Index: model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java,v
retrieving revision 1.67
diff -u -r1.67 JarPackageFragmentRoot.java
--- model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 21 Sep 2007 13:16:47 -0000 1.67
+++ model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 26 Feb 2008 09:54:57 -0000
@@ -15,7 +15,6 @@
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.*;
@@ -67,7 +66,7 @@
* These are all of the directory zip entries, and any directories implied
* by the path of class files contained in the jar of this package fragment root.
*/
- protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException {
+ protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException {
HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
IJavaElement[] children;
ZipFile jar = null;
@@ -168,22 +167,19 @@
public PackageFragment getPackageFragment(String[] pkgName) {
return new JarPackageFragment(this, pkgName);
}
- /**
- * @see IPackageFragmentRoot
- */
- public IPath getPath() {
+ public IPath internalPath() {
if (isExternal()) {
return this.jarPath;
} else {
- return super.getPath();
+ return super.internalPath();
}
- }
- public IResource getResource() {
- if (this.resource == null) {
- this.resource = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.jarPath, false);
+ }
+ public IResource resource(PackageFragmentRoot root) {
+ if (this.resource == null && org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.jarPath.lastSegment())) {
+ this.resource = JavaModel.getTarget(this.jarPath, false);
}
if (this.resource instanceof IResource) {
- return super.getResource();
+ return super.resource(root);
} else {
// external jar
return null;
@@ -257,7 +253,7 @@
* @see IPackageFragmentRoot
*/
public boolean isExternal() {
- return getResource() == null;
+ return resource() == null;
}
/**
* Jars and jar entries are all read only
@@ -273,7 +269,6 @@
if (underlyingResource == null) {
return
JavaModel.getTarget(
- ResourcesPlugin.getWorkspace().getRoot(),
getPath(), // don't make the path relative as this is an external archive
true) != null;
} else {
Index: model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java,v
retrieving revision 1.105
diff -u -r1.105 CopyResourceElementsOperation.java
--- model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java 27 Apr 2007 15:51:38 -0000 1.105
+++ model/org/eclipse/jdt/internal/core/CopyResourceElementsOperation.java 26 Feb 2008 09:54:56 -0000
@@ -108,7 +108,7 @@
for (int i = 0; i < children.length; i++) {
IJavaElement child = children[i];
if (child.getElementType() == childOfInterest) {
- correctKindChildren.add(child.getResource());
+ correctKindChildren.add(((JavaElement) child).resource());
}
}
// Gather non-java resources
@@ -140,7 +140,7 @@
*/
private boolean createNeededPackageFragments(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder) throws JavaModelException {
boolean containsReadOnlyPackageFragment = false;
- IContainer parentFolder = (IContainer) root.getResource();
+ IContainer parentFolder = (IContainer) root.resource();
JavaElementDelta projectDelta = null;
String[] sideEffectPackageName = null;
char[][] inclusionPatterns = root.fullInclusionPatternChars();
@@ -368,12 +368,12 @@
private void processPackageFragmentResource(PackageFragment source, PackageFragmentRoot root, String newName) throws JavaModelException {
try {
String[] newFragName = (newName == null) ? source.names : Util.getTrimmedSimpleNames(newName);
- IPackageFragment newFrag = root.getPackageFragment(newFragName);
+ PackageFragment newFrag = root.getPackageFragment(newFragName);
IResource[] resources = collectResourcesOfInterest(source);
// if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458)
- boolean shouldMoveFolder = isMove() && !newFrag.getResource().exists(); // if new pkg fragment exists, it is an override
- IFolder srcFolder = (IFolder)source.getResource();
+ boolean shouldMoveFolder = isMove() && !newFrag.resource().exists(); // if new pkg fragment exists, it is an override
+ IFolder srcFolder = (IFolder)source.resource();
IPath destPath = newFrag.getPath();
if (shouldMoveFolder) {
// check if destination is not included in source
@@ -390,7 +390,7 @@
}
}
}
- boolean containsReadOnlySubPackageFragments = createNeededPackageFragments((IContainer) source.getParent().getResource(), root, newFragName, shouldMoveFolder);
+ boolean containsReadOnlySubPackageFragments = createNeededPackageFragments((IContainer) source.parent.resource(), root, newFragName, shouldMoveFolder);
boolean sourceIsReadOnly = Util.isReadOnly(srcFolder);
// Process resources
@@ -479,7 +479,7 @@
if (isMove()) {
// delete remaining files in this package (.class file in the case where Proj=src=bin)
// in case of a copy
- updateReadOnlyPackageFragmentsForMove((IContainer) source.getParent().getResource(), root, newFragName, sourceIsReadOnly);
+ updateReadOnlyPackageFragmentsForMove((IContainer) source.parent.resource(), root, newFragName, sourceIsReadOnly);
if (srcFolder.exists()) {
IResource[] remaining = srcFolder.members();
for (int i = 0, length = remaining.length; i < length; i++) {
@@ -498,9 +498,9 @@
IResource rootResource;
// check if source is included in destination
if (destPath.isPrefixOf(srcFolder.getFullPath())) {
- rootResource = newFrag.getResource();
+ rootResource = newFrag.resource();
} else {
- rootResource = source.getParent().getResource();
+ rootResource = source.parent.resource();
}
// delete recursively empty folders
@@ -508,7 +508,7 @@
}
} else if (containsReadOnlySubPackageFragments) {
// in case of a copy
- updateReadOnlyPackageFragmentsForCopy((IContainer) source.getParent().getResource(), root, newFragName);
+ updateReadOnlyPackageFragmentsForCopy((IContainer) source.parent.resource(), root, newFragName);
}
// workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=24505
if (isEmpty && isMove() && !(Util.isExcluded(source) || Util.isExcluded(newFrag))) {
@@ -592,8 +592,8 @@
}
}
- private void updateReadOnlyPackageFragmentsForCopy(IContainer sourceFolder, IPackageFragmentRoot root, String[] newFragName) {
- IContainer parentFolder = (IContainer) root.getResource();
+ private void updateReadOnlyPackageFragmentsForCopy(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName) {
+ IContainer parentFolder = (IContainer) root.resource();
for (int i = 0, length = newFragName.length; i null
if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
+ * Since 3.4, this path can also denote a path external to the workspace.
* and will be automatically converted to null
.
* @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
* or null
if this location should be automatically detected.
@@ -3872,7 +3884,8 @@
* @param path the absolute path of the binary archive
* @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
* or null
if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
- * and will be automatically converted to null
.
+ * and will be automatically converted to null
. Since 3.4, this path can also denote a path external
+ * to the workspace.
* @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
* or null
if this location should be automatically detected.
* @param isExported indicates whether this entry is contributed to dependent
@@ -3902,15 +3915,15 @@
* * A library entry is used to denote a prerequisite JAR or root folder containing binaries. * The target JAR can either be defined internally to the workspace (absolute path relative - * to the workspace root) or externally to the workspace (absolute path in the file system). - * The target root folder can only be defined internally to the workspace (absolute path relative - * to the workspace root). To use a binary folder external to the workspace, it must first be - * linked (see IFolder#createLink(...)). + * to the workspace root), or externally to the workspace (absolute path in the file system). + * The target root folder can also be defined internally to the workspace (absolute path relative + * to the workspace root), or - since 3.4 - externally to the workspace (absolute path in the file system). *
* e.g. Here are some examples of binary path usage
"c:\jdk1.2.2\jre\lib\rt.jar"
- reference to an external JAR on Windows "/Project/someLib.jar"
- reference to an internal JAR on Windows or Linux "/Project/classes/"
- reference to an internal binary folder on Windows or Linux "/home/usr/classes"
- reference to an external binary folder on Linux"/some/lib.jar"
is ambiguous.
* It can be a path to an external JAR (its file system path being "/some/lib.jar"
)
@@ -3943,7 +3956,8 @@
* @param path the absolute path of the binary archive
* @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
* or null
if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
- * and will be automatically converted to null
.
+ * and will be automatically converted to null
. Since 3.4, this path can also denote a path external
+ * to the workspace.
* @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
* or null
if this location should be automatically detected.
* @param accessRules the possibly empty list of access rules for this entry
Index: model/org/eclipse/jdt/core/ToolFactory.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java,v
retrieving revision 1.75
diff -u -r1.75 ToolFactory.java
--- model/org/eclipse/jdt/core/ToolFactory.java 28 May 2007 17:17:59 -0000 1.75
+++ model/org/eclipse/jdt/core/ToolFactory.java 26 Feb 2008 09:54:55 -0000
@@ -31,6 +31,7 @@
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
import org.eclipse.jdt.internal.compiler.util.Util;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
+import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.internal.core.util.ClassFileReader;
@@ -226,7 +227,7 @@
} else {
InputStream in = null;
try {
- in = ((IFile) classfile.getResource()).getContents();
+ in = ((IFile) ((JavaElement) classfile).resource()).getContents();
return createDefaultClassFileReader(in, decodingFlag);
} finally {
if (in != null)
Index: model/org/eclipse/jdt/core/IJavaElement.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaElement.java,v
retrieving revision 1.39
diff -u -r1.39 IJavaElement.java
--- model/org/eclipse/jdt/core/IJavaElement.java 24 Oct 2007 13:50:50 -0000 1.39
+++ model/org/eclipse/jdt/core/IJavaElement.java 26 Feb 2008 09:54:53 -0000
@@ -310,7 +310,7 @@
* Returns the innermost resource enclosing this element.
* If this element is included in an archive and this archive is not external,
* this is the underlying resource corresponding to the archive.
- * If this element is included in an external archive, null
+ * If this element is included in an external library, null
* is returned.
* This is a handle-only method.
*
Index: search/org/eclipse/jdt/internal/core/search/IndexSelector.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/IndexSelector.java,v
retrieving revision 1.38
diff -u -r1.38 IndexSelector.java
--- search/org/eclipse/jdt/internal/core/search/IndexSelector.java 28 Aug 2007 10:03:39 -0000 1.38
+++ search/org/eclipse/jdt/internal/core/search/IndexSelector.java 26 Feb 2008 09:55:01 -0000
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core.search;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
@@ -20,6 +21,7 @@
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
+import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
@@ -122,8 +124,13 @@
SimpleSet locations = new SimpleSet();
IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
if (focus == null) {
- for (int i = 0; i < projectsAndJars.length; i++)
- locations.add(manager.computeIndexLocation(projectsAndJars[i]));
+ for (int i = 0; i < projectsAndJars.length; i++) {
+ IPath path = projectsAndJars[i];
+ Object target = JavaModel.getTarget(path, false/*don't check existence*/);
+ if (target instanceof IFolder) // case of an external folder
+ path = ((IFolder) target).getFullPath();
+ locations.add(manager.computeIndexLocation(path));
+ }
} else {
try {
// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
@@ -131,7 +138,7 @@
JavaProject[] projectsCanSeeFocus = new JavaProject[length];
SimpleSet visitedProjects = new SimpleSet(length);
int projectIndex = 0;
- SimpleSet jarsToCheck = new SimpleSet(length);
+ SimpleSet externalLibsToCheck = new SimpleSet(length);
IClasspathEntry[] focusEntries = null;
if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns
JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
@@ -148,26 +155,28 @@
projectsCanSeeFocus[projectIndex++] = project;
}
} else {
- jarsToCheck.add(path);
+ externalLibsToCheck.add(path);
}
}
- for (int i = 0; i < projectIndex && jarsToCheck.elementSize > 0; i++) {
+ for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
for (int j = entries.length; --j >= 0;) {
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
- if (jarsToCheck.includes(path)) {
- locations.add(manager.computeIndexLocation(entry.getPath()));
- jarsToCheck.remove(path);
+ if (externalLibsToCheck.remove(path) != null) {
+ Object target = JavaModel.getTarget(path, false/*don't check existence*/);
+ if (target instanceof IFolder) // case of an external folder
+ path = ((IFolder) target).getFullPath();
+ locations.add(manager.computeIndexLocation(path));
}
}
}
}
// jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
- if (jarsToCheck.elementSize > 0) {
+ if (externalLibsToCheck.elementSize > 0) {
IJavaProject[] allProjects = model.getJavaProjects();
- for (int i = 0, l = allProjects.length; i < l && jarsToCheck.elementSize > 0; i++) {
+ for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
JavaProject project = (JavaProject) allProjects[i];
if (!visitedProjects.includes(project)) {
IClasspathEntry[] entries = project.getResolvedClasspath();
@@ -175,9 +184,11 @@
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
- if (jarsToCheck.includes(path)) {
- locations.add(manager.computeIndexLocation(entry.getPath()));
- jarsToCheck.remove(path);
+ if (externalLibsToCheck.remove(path) != null) {
+ Object target = JavaModel.getTarget(path, false/*don't check existence*/);
+ if (target instanceof IFolder) // case of an external folder
+ path = ((IFolder) target).getFullPath();
+ locations.add(manager.computeIndexLocation(path));
}
}
}
Index: search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java,v
retrieving revision 1.8
diff -u -r1.8 TypeNameMatchRequestorWrapper.java
--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 6 Mar 2007 02:38:51 -0000 1.8
+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 26 Feb 2008 09:55:02 -0000
@@ -153,10 +153,10 @@
|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
&& resourcePath.charAt(rootPathLength) == '/')) {
- IPackageFragmentRoot root = ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
+ PackageFragmentRoot root = (PackageFragmentRoot) ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
if (root == null) return null;
this.lastPkgFragmentRoot = root;
- this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
+ this.lastPkgFragmentRootPath = root.internalPath().toString();
this.packageHandles = new HashtableOfArrayToObject(5);
}
// create handle
Index: search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java,v
retrieving revision 1.65
diff -u -r1.65 JavaSearchScope.java
--- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 5 Feb 2008 15:35:14 -0000 1.65
+++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 26 Feb 2008 09:55:01 -0000
@@ -14,6 +14,7 @@
import java.util.HashSet;
import java.util.Map;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -36,6 +37,7 @@
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.PackageFragment;
+import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jdt.internal.core.util.Util;
/**
@@ -146,9 +148,12 @@
if ((includeMask & APPLICATION_LIBRARIES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
+ Object target = JavaModel.getTarget(path, false/*don't check existence*/);
+ if (target instanceof IFolder) // case of an external folder
+ path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
- addEnclosingProjectOrJar(path);
+ addEnclosingProjectOrJar(entry.getPath());
}
}
break;
@@ -168,9 +173,12 @@
}
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
+ Object target = JavaModel.getTarget(path, false/*don't check existence*/);
+ if (target instanceof IFolder) // case of an external folder
+ path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
- addEnclosingProjectOrJar(path);
+ addEnclosingProjectOrJar(entry.getPath());
}
break;
}
@@ -179,7 +187,7 @@
if ((includeMask & REFERENCED_PROJECTS) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
- add((JavaProject) model.getJavaProject(entry.getPath().lastSegment()), null, includeMask, visitedProjects, cpEntry);
+ add((JavaProject) model.getJavaProject(path.lastSegment()), null, includeMask, visitedProjects, cpEntry);
}
}
break;
@@ -202,6 +210,7 @@
public void add(IJavaElement element) throws JavaModelException {
IPath containerPath = null;
String containerPathToString = null;
+ PackageFragmentRoot root = null;
int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
switch (element.getElementType()) {
case IJavaElement.JAVA_MODEL:
@@ -211,11 +220,11 @@
add((JavaProject)element, null, includeMask, new HashSet(2), null);
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
- IPackageFragmentRoot root = (IPackageFragmentRoot)element;
- IPath rootPath = root.getPath();
+ root = (PackageFragmentRoot)element;
+ IPath rootPath = root.internalPath();
containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
- IResource rootResource = root.getResource();
+ IResource rootResource = root.resource();
String projectPath = root.getJavaProject().getPath().toString();
if (rootResource != null && rootResource.isAccessible()) {
String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
@@ -225,7 +234,7 @@
}
break;
case IJavaElement.PACKAGE_FRAGMENT:
- root = (IPackageFragmentRoot)element.getParent();
+ root = (PackageFragmentRoot)element.getParent();
projectPath = root.getJavaProject().getPath().toString();
if (root.isArchive()) {
String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
@@ -233,10 +242,10 @@
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, true/*package*/, null);
} else {
- IResource resource = element.getResource();
+ IResource resource = ((JavaElement) element).resource();
if (resource != null) {
if (resource.isAccessible()) {
- containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath();
+ containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
} else {
// for working copies, get resource container full path
containerPath = resource.getParent().getFullPath();
@@ -255,22 +264,22 @@
}
this.elements.add(element);
}
- root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
projectPath = root.getJavaProject().getPath().toString();
String relativePath;
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
containerPath = root.getParent().getPath();
- relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segmet*/);
+ relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/);
} else {
- containerPath = root.getPath();
+ containerPath = root.internalPath();
relativePath = getPath(element, true/*relative path*/).toString();
}
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
}
- if (containerPath != null)
- addEnclosingProjectOrJar(containerPath);
+ if (root != null)
+ addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}
/**
@@ -597,12 +606,12 @@
if (isJarFile) {
return project.getPackageFragmentRoot(this.containerPaths[index]);
}
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false);
+ Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index]+'/'+this.relativePaths[index]));
if (target instanceof IProject) {
return project.getPackageFragmentRoot((IProject) target);
}
if (target instanceof IResource) {
- IJavaElement element = JavaCore.create((IResource)target);
+ IJavaElement element = JavaModelManager.create((IResource) target, project);
return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
}
}
Index: search/org/eclipse/jdt/internal/core/search/HierarchyScope.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/HierarchyScope.java,v
retrieving revision 1.43
diff -u -r1.43 HierarchyScope.java
--- search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 27 Sep 2007 16:33:52 -0000 1.43
+++ search/org/eclipse/jdt/internal/core/search/HierarchyScope.java 26 Feb 2008 09:55:01 -0000
@@ -72,7 +72,7 @@
IPackageFragmentRoot root = (IPackageFragmentRoot)type.getPackageFragment().getParent();
if (root.isArchive()) {
IPath jarPath = root.getPath();
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), jarPath, true);
+ Object target = JavaModel.getTarget(jarPath, true);
String zipFileName;
if (target instanceof IFile) {
// internal jar
@@ -101,10 +101,9 @@
HashMap resources = new HashMap();
HashMap paths = new HashMap();
this.types = this.hierarchy.getAllTypes();
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
for (int i = 0; i < this.types.length; i++) {
IType type = this.types[i];
- IResource resource = type.getResource();
+ IResource resource = ((JavaElement) type).resource();
if (resource != null && resources.get(resource) == null) {
resources.put(resource, resource);
add(resource);
@@ -115,7 +114,7 @@
// type in a jar
JarPackageFragmentRoot jar = (JarPackageFragmentRoot) root;
IPath jarPath = jar.getPath();
- Object target = JavaModel.getTarget(workspaceRoot, jarPath, true);
+ Object target = JavaModel.getTarget(jarPath, true);
String zipFileName;
if (target instanceof IFile) {
// internal jar
Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v
retrieving revision 1.52
diff -u -r1.52 BasicSearchEngine.java
--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 15 Jan 2008 10:00:51 -0000 1.52
+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 26 Feb 2008 09:55:01 -0000
@@ -1140,7 +1140,7 @@
Util.verbose(" - java element: "+enclosingElement); //$NON-NLS-1$
}
IJavaSearchScope scope = createJavaSearchScope(new IJavaElement[] {enclosingElement});
- IResource resource = enclosingElement.getResource();
+ IResource resource = ((JavaElement) enclosingElement).resource();
if (enclosingElement instanceof IMember) {
IMember member = (IMember) enclosingElement;
ICompilationUnit cu = member.getCompilationUnit();
Index: model/org/eclipse/jdt/internal/core/util/Util.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v
retrieving revision 1.115
diff -u -r1.115 Util.java
--- model/org/eclipse/jdt/internal/core/util/Util.java 16 Jan 2008 11:52:53 -0000 1.115
+++ model/org/eclipse/jdt/internal/core/util/Util.java 26 Feb 2008 09:55:00 -0000
@@ -50,6 +50,7 @@
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.MemberValuePair;
+import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.MalformedTreeException;
@@ -1312,12 +1313,12 @@
return false;
case IJavaElement.PACKAGE_FRAGMENT:
- PackageFragmentRoot root = (PackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
- IResource resource = element.getResource();
+ PackageFragmentRoot root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ IResource resource = ((PackageFragment) element).resource();
return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars());
case IJavaElement.COMPILATION_UNIT:
- root = (PackageFragmentRoot)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
+ root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
resource = element.getResource();
if (resource == null)
return false;
Index: model/org/eclipse/jdt/internal/core/util/HandleFactory.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java,v
retrieving revision 1.43
diff -u -r1.43 HandleFactory.java
--- model/org/eclipse/jdt/internal/core/util/HandleFactory.java 10 Jan 2008 15:45:03 -0000 1.43
+++ model/org/eclipse/jdt/internal/core/util/HandleFactory.java 26 Feb 2008 09:55:00 -0000
@@ -33,18 +33,10 @@
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.internal.compiler.ast.*;
-import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.core.*;
-import org.eclipse.jdt.internal.core.JavaModel;
-import org.eclipse.jdt.internal.core.JavaModelManager;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jdt.internal.core.Openable;
-import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jdt.internal.core.util.Util;
/**
@@ -128,7 +120,7 @@
if (root == null)
return null; // match is outside classpath
this.lastPkgFragmentRoot = root;
- this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
+ this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.internalPath().toString();
this.packageHandles = new HashtableOfArrayToObject(5);
}
// create handle
@@ -252,7 +244,7 @@
IPath jarPath= new Path(jarPathString);
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), jarPath, false);
+ Object target = JavaModel.getTarget(jarPath, false);
if (target instanceof IFile) {
// internal jar: is it on the classpath of its project?
// e.g. org.eclipse.swt.win32/ws/win32/swt.jar
@@ -341,7 +333,7 @@
IPackageFragmentRoot[] roots= javaProject.getPackageFragmentRoots();
for (int j= 0, rootCount= roots.length; j < rootCount; j++) {
PackageFragmentRoot root= (PackageFragmentRoot)roots[j];
- if (root.getPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
+ if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
return root;
}
}
Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v
retrieving revision 1.309
diff -u -r1.309 MatchLocator.java
--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 30 Jan 2008 15:58:34 -0000 1.309
+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 26 Feb 2008 09:55:03 -0000
@@ -278,7 +278,7 @@
IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
try {
if (!root.isArchive())
- return Util.newClassFileReader(type.getResource());
+ return Util.newClassFileReader(((JavaElement) type).resource());
ZipFile zipFile = null;
try {
@@ -425,7 +425,7 @@
if (binaryType == null) {
ClassFile classFile = (ClassFile) type.getClassFile();
try {
- binaryType = getBinaryInfo(classFile, classFile.getResource());
+ binaryType = getBinaryInfo(classFile, classFile.resource());
} catch (CoreException e) {
if (e instanceof JavaModelException) {
throw (JavaModelException) e;
@@ -1186,7 +1186,7 @@
JavaProject javaProject = (JavaProject) openable.getJavaProject();
resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
if (resource == null)
- resource = javaProject.getProject(); // case of a file in an external jar
+ resource = javaProject.getProject(); // case of a file in an external jar or external folder
if (!javaProject.equals(previousJavaProject)) {
// locate matches in previous project
if (previousJavaProject != null) {
@@ -1559,7 +1559,7 @@
if (unit.isEmpty()) {
if (this.currentPossibleMatch.openable instanceof ClassFile) {
ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable;
- IBinaryType info = getBinaryInfo(classFile, this.currentPossibleMatch.resource);
+ IBinaryType info = getBinaryInfo(classFile, classFile.resource());
if (info != null) {
boolean mayBeGeneric = this.patternLocator.mayBeGeneric;
this.patternLocator.mayBeGeneric = false; // there's no longer generics in class files
Index: search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java,v
retrieving revision 1.25
diff -u -r1.25 JavaSearchNameEnvironment.java
--- search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java 29 Mar 2006 03:13:59 -0000 1.25
+++ search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java 26 Feb 2008 09:55:02 -0000
@@ -98,7 +98,7 @@
ZipFile zipFile = manager.getZipFile(path);
cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
} else {
- Object target = JavaModel.getTarget(workspaceRoot, path, false);
+ Object target = JavaModel.getTarget(path, true);
if (target == null) {
// target doesn't exist any longer
// just resize cpLocations
Index: model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java,v
retrieving revision 1.60
diff -u -r1.60 NameEnvironment.java
--- model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java 9 May 2007 14:21:18 -0000 1.60
+++ model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java 26 Feb 2008 09:55:00 -0000
@@ -96,7 +96,7 @@
nextEntry : for (int i = 0, l = classpathEntries.length; i < l; i++) {
ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
IPath path = entry.getPath();
- Object target = JavaModel.getTarget(root, path, true);
+ Object target = JavaModel.getTarget(path, true);
if (target == null) continue nextEntry;
switch(entry.getEntryKind()) {
@@ -128,7 +128,7 @@
nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
IClasspathEntry prereqEntry = prereqClasspathEntries[j];
if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- Object prereqTarget = JavaModel.getTarget(root, prereqEntry.getPath(), true);
+ Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true);
if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry;
IPath prereqOutputPath = prereqEntry.getOutputLocation() != null
? prereqEntry.getOutputLocation()
Index: model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java,v
retrieving revision 1.137
diff -u -r1.137 JavaBuilder.java
--- model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 17 Oct 2007 19:16:29 -0000 1.137
+++ model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 26 Feb 2008 09:54:59 -0000
@@ -429,6 +429,7 @@
if (javaProject == null || workspaceRoot == null) return new IProject[0];
ArrayList projects = new ArrayList();
+ ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
try {
IClasspathEntry[] entries = javaProject.getExpandedClasspath();
for (int i = 0, l = entries.length; i < l; i++) {
@@ -445,8 +446,13 @@
if (includeBinaryPrerequisites && path.segmentCount() > 1) {
// some binary resources on the class path can come from projects that are not included in the project references
IResource resource = workspaceRoot.findMember(path.segment(0));
- if (resource instanceof IProject)
+ if (resource instanceof IProject) {
p = (IProject) resource;
+ } else {
+ resource = externalFoldersManager.getFolder(path);
+ if (resource != null)
+ p = resource.getProject();
+ }
}
}
if (p != null && !projects.contains(p))
Index: search/org/eclipse/jdt/core/search/SearchParticipant.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchParticipant.java,v
retrieving revision 1.24
diff -u -r1.24 SearchParticipant.java
--- search/org/eclipse/jdt/core/search/SearchParticipant.java 28 Aug 2007 10:03:38 -0000 1.24
+++ search/org/eclipse/jdt/core/search/SearchParticipant.java 26 Feb 2008 09:55:00 -0000
@@ -11,8 +11,6 @@
package org.eclipse.jdt.core.search;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
@@ -196,8 +194,7 @@
*/
public final void scheduleDocumentIndexing(SearchDocument document, IPath indexLocation) {
IPath documentPath = new Path(document.getPath());
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- Object file = JavaModel.getTarget(root, documentPath, true);
+ Object file = JavaModel.getTarget(documentPath, true);
IPath containerPath = documentPath;
if (file instanceof IResource) {
containerPath = ((IResource)file).getProject().getFullPath();
Index: model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java,v
retrieving revision 1.82
diff -u -r1.82 HierarchyResolver.java
--- model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java 22 Feb 2008 12:35:09 -0000 1.82
+++ model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java 26 Feb 2008 09:55:00 -0000
@@ -697,7 +697,7 @@
if (classFile.getPackageFragmentRoot().isArchive()) {
binaryType = this.builder.createInfoFromClassFileInJar(classFile);
} else {
- IResource file = classFile.getResource();
+ IResource file = classFile.resource();
binaryType = this.builder.createInfoFromClassFile(classFile, file);
}
}
Index: codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java,v
retrieving revision 1.143
diff -u -r1.143 SelectionEngine.java
--- codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 22 Feb 2008 09:49:37 -0000 1.143
+++ codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 26 Feb 2008 09:54:53 -0000
@@ -1133,7 +1133,7 @@
}
} else { // binary type
ClassFile classFile = (ClassFile) context.getClassFile();
- ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo((IFile) classFile.getResource(), false/*don't fully initialize so as to keep constant pool (used below)*/);
+ ClassFileReader reader = (ClassFileReader) classFile.getBinaryTypeInfo((IFile) classFile.resource(), false/*don't fully initialize so as to keep constant pool (used below)*/);
CompilationResult result = new CompilationResult(reader.getFileName(), 1, 1, this.compilerOptions.maxProblemsPerUnit);
parsedUnit = new CompilationUnitDeclaration(this.parser.problemReporter(), result, 0);
HashSetOfCharArrayArray typeNames = new HashSetOfCharArrayArray();
Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java,v
retrieving revision 1.155
diff -u -r1.155 IndexManager.java
--- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 1 Mar 2007 18:38:55 -0000 1.155
+++ search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 26 Feb 2008 09:55:02 -0000
@@ -353,16 +353,12 @@
// requestingProject is no longer used to cancel jobs but leave it here just in case
if (JavaCore.getPlugin() == null) return;
- Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), path, true);
+ Object target = JavaModel.getTarget(path, true);
IndexRequest request = null;
if (target instanceof IFile) {
request = new AddJarFileToIndex((IFile) target, this);
} else if (target instanceof File) {
- if (((File) target).isFile()) {
- request = new AddJarFileToIndex(path, this);
- } else {
- return;
- }
+ request = new AddJarFileToIndex(path, this);
} else if (target instanceof IContainer) {
request = new IndexBinaryFolder((IContainer) target, this);
} else {
@@ -417,9 +413,7 @@
return Messages.process_name;
}
private void rebuildIndex(IPath indexLocation, IPath containerPath) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- if (workspace == null) return;
- Object target = JavaModel.getTarget(workspace.getRoot(), containerPath, true);
+ Object target = JavaModel.getTarget(containerPath, true);
if (target == null) return;
if (VERBOSE)
Index: model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
===================================================================
RCS file: model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
diff -N model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.core;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.util.Util;
+
+public class ExternalFoldersManager {
+ private static final boolean DEBUG = false;
+ private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$
+ private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$
+ private HashMap folders;
+ private int counter = 0;
+
+ {
+ this.folders = new HashMap();
+ IProject project = getExternalFoldersProject();
+ if (project.isAccessible()) {
+ try {
+ IResource[] members = project.members();
+ for (int i = 0, length = members.length; i < length; i++) {
+ IResource member = members[i];
+ if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
+ IPath externalFolderPath = member.getLocation();
+ this.folders.put(externalFolderPath, member);
+ }
+ }
+ } catch (CoreException e) {
+ Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public static boolean isExternal(IPath resourcePath) {
+ return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0));
+ }
+
+ public IFolder addFolder(IPath externalFolderPath) {
+ return addFolder(externalFolderPath, getExternalFoldersProject());
+ }
+
+ private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
+ Object existing = this.folders.get(externalFolderPath);
+ if (existing != null) {
+ return (IFolder) existing;
+ }
+ IFolder result;
+ do {
+ result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++);
+ } while (result.exists());
+ this.folders.put(externalFolderPath, result);
+ return result;
+ }
+
+ public IFolder createLinkFolder(IPath externalFolderPath, IProgressMonitor monitor) throws CoreException {
+ IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource
+ IFolder result = addFolder(externalFolderPath, externalFoldersProject);
+ if (!result.exists())
+ result.createLink(externalFolderPath, IResource.ALLOW_MISSING_LOCAL, monitor);
+ else
+ result.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ return result;
+ }
+
+ public synchronized void cleanUp(IProgressMonitor monitor) throws CoreException {
+ DeltaProcessingState state = JavaModelManager.getDeltaState();
+ HashMap roots = state.roots;
+ HashMap sourceAttachments = state.sourceAttachments;
+ if (roots == null && sourceAttachments == null)
+ return;
+ Iterator iterator = this.folders.keySet().iterator();
+ while (iterator.hasNext()) {
+ IPath path = (IPath) iterator.next();
+ if ((roots != null && !roots.containsKey(path))
+ && (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
+ IFolder folder = (IFolder) this.folders.get(path);
+ if (folder != null)
+ folder.delete(true, monitor);
+ }
+ }
+ IProject project = getExternalFoldersProject();
+ if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/)
+ project.delete(true, monitor);
+ }
+
+ public IProject getExternalFoldersProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(EXTERNAL_PROJECT_NAME);
+ }
+ private IProject createExternalFoldersProject(IProgressMonitor monitor) {
+ IProject project = getExternalFoldersProject();
+ if (!project.isAccessible()) {
+ try {
+ if (!project.exists()) {
+ IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
+ IPath stateLocation = JavaCore.getPlugin().getStateLocation();
+ desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME));
+ project.create(DEBUG ? null : desc, DEBUG ? IResource.NONE : IResource.HIDDEN, monitor);
+ }
+ try {
+ project.open(monitor);
+ } catch (CoreException e1) {
+ // .project or folder on disk have been deleted, recreate them
+ IPath stateLocation = DEBUG ? ResourcesPlugin.getWorkspace().getRoot().getLocation() : JavaCore.getPlugin().getStateLocation();
+ IPath projectPath = stateLocation.append(EXTERNAL_PROJECT_NAME);
+ projectPath.toFile().mkdirs();
+ FileOutputStream output = new FileOutputStream(projectPath.append(".project").toOSString()); //$NON-NLS-1$
+ try {
+ output.write((
+ "\n" + //$NON-NLS-1$
+ "NOTE: An external package fragment root never has an associated resource.
+ *
+ * @see org.eclipse.jdt.core.IPackageFragmentRoot
+ * @see org.eclipse.jdt.internal.core.PackageFragmentRootInfo
+ */
+public class ExternalPackageFragmentRoot extends PackageFragmentRoot {
+
+ /**
+ * The path to the external folder
+ * (an OS path)
+ */
+ protected final IPath externalPath;
+
+ /**
+ * Constructs a package fragment root which is the root of the Java package directory hierarchy
+ * based on an external folder that is not contained in a IJavaProject
and
+ * does not have an associated IResource
.
+ */
+ protected ExternalPackageFragmentRoot(IPath externalPath, JavaProject project) {
+ super(null, project);
+ this.externalPath = externalPath;
+ }
+
+ protected ExternalPackageFragmentRoot(IResource linkedFolder, IPath externalPath, JavaProject project) {
+ super(linkedFolder, project);
+ this.externalPath = externalPath == null ? linkedFolder.getLocation() : externalPath;
+ }
+
+ /**
+ * An external class folder is always K_BINARY.
+ */
+ protected int determineKind(IResource underlyingResource) {
+ return IPackageFragmentRoot.K_BINARY;
+ }
+ /**
+ * Returns true if this handle represents the same external folder
+ * as the given handle.
+ *
+ * @see Object#equals
+ */
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o instanceof ExternalPackageFragmentRoot) {
+ ExternalPackageFragmentRoot other= (ExternalPackageFragmentRoot) o;
+ return this.externalPath.equals(other.externalPath);
+ }
+ return false;
+ }
+ public String getElementName() {
+ return this.externalPath.lastSegment();
+ }
+ /**
+ * @see IPackageFragmentRoot
+ */
+ public int getKind() {
+ return IPackageFragmentRoot.K_BINARY;
+ }
+ /**
+ * @see IPackageFragmentRoot
+ */
+ public IPath getPath() {
+ return this.externalPath;
+ }
+
+ /**
+ * @see IJavaElement
+ */
+ public IResource getUnderlyingResource() throws JavaModelException {
+ return null;
+ }
+ public int hashCode() {
+ return this.externalPath.hashCode();
+ }
+ /**
+ * @see IPackageFragmentRoot
+ */
+ public boolean isExternal() {
+ return true;
+ }
+
+ public IResource resource(PackageFragmentRoot root) {
+ if (this.resource == null)
+ return (IResource) (this.resource = JavaModelManager.getExternalManager().getFolder(this.externalPath));
+ return super.resource(root);
+ }
+
+ protected void toStringAncestors(StringBuffer buffer) {
+ // don't show project as it is irrelevant for external folders.
+ }
+}
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java,v
retrieving revision 1.55
diff -u -r1.55 ClasspathInitializerTests.java
--- src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java 11 Oct 2007 11:32:42 -0000 1.55
+++ src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java 26 Feb 2008 09:55:06 -0000
@@ -890,6 +890,26 @@
}
}
+public void testContainerInitializer21() throws CoreException {
+ try {
+ createProject("P1");
+ createExternalFolder("externalLib");
+ ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", getExternalFolderPath("externalLib")}));
+ IJavaProject p2 = createJavaProject(
+ "P2",
+ new String[] {},
+ new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"},
+ "");
+ IPackageFragmentRoot root = p2.getPackageFragmentRoot(getExternalFolderPath("externalLib"));
+ assertTrue(getExternalFolderPath("externalLib") + " should exist", root.exists());
+ } finally {
+ stopDeltas();
+ deleteExternalFolder("externalLib");
+ deleteProject("P1");
+ deleteProject("P2");
+ }
+}
+
public void testVariableInitializer01() throws CoreException {
try {
createProject("P1");
Index: src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java,v
retrieving revision 1.33
diff -u -r1.33 ExternalJarDeltaTests.java
--- src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java 18 Dec 2007 16:32:55 -0000 1.33
+++ src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java 26 Feb 2008 09:55:07 -0000
@@ -44,9 +44,6 @@
// TESTS_NUMBERS = new int[] { 79860, 80918, 91078 };
// TESTS_RANGE = new int[] { 83304, -1 };
}
-private void touch(File f) {
- f.setLastModified(f.lastModified() + 10000);
-}
/*
* Ensures that passing an empty scope to refreshExternalArchives(..) doesn't throw a NPE
Index: src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java,v
retrieving revision 1.90
diff -u -r1.90 JavaProjectTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 17 Dec 2007 11:08:07 -0000 1.90
+++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 26 Feb 2008 09:55:08 -0000
@@ -55,6 +55,116 @@
super.tearDownSuite();
}
+/*
+ * Ensures that adding a library entry for an existing empty external library folder updates the model
+ */
+public void testAddExternalLibFolder1() throws CoreException {
+ try {
+ IJavaProject p = createJavaProject("P");
+ createExternalFolder("externalLib");
+ setClasspath(p, new IClasspathEntry[] {JavaCore.newLibraryEntry(new Path(getExternalFolderPath("externalLib")), null, null)});
+ assertElementDescendants(
+ "Unexpected project content",
+ "P\n" +
+ " "+ getExternalPath() + "externalLib\n" +
+ "