X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java index 6ed2fdb..f860394 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java @@ -52,7 +52,6 @@ import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; @@ -88,7 +87,7 @@ public class JavaModelManager implements ISaveParticipant { * Unique handle onto the JavaModel */ final JavaModel javaModel = new JavaModel(); - +// public IndexManager indexManager = new IndexManager(); /** * Classpath variables pool */ @@ -96,13 +95,13 @@ public class JavaModelManager implements ISaveParticipant { public static HashMap PreviousSessionVariables = new HashMap(5); public static HashSet OptionNames = new HashSet(20); public final static String CP_VARIABLE_PREFERENCES_PREFIX = PHPeclipsePlugin.PLUGIN_ID+".classpathVariable."; //$NON-NLS-1$ -// public final static String CP_CONTAINER_PREFERENCES_PREFIX = PHPCore.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$ + public final static String CP_CONTAINER_PREFERENCES_PREFIX = PHPeclipsePlugin.PLUGIN_ID+".classpathContainer."; //$NON-NLS-1$ public final static String CP_ENTRY_IGNORE = "####"; //$NON-NLS-1$ /** * Classpath containers pool */ - public static HashMap Containers = new HashMap(5); + public static HashMap containers = new HashMap(5); public static HashMap PreviousSessionContainers = new HashMap(5); /** @@ -432,8 +431,8 @@ public class JavaModelManager implements ISaveParticipant { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue; IPath rootPath = entry.getPath(); if (rootPath.equals(resourcePath)) { - return project.getPackageFragmentRoot(resource); - } else if (rootPath.isPrefixOf(resourcePath) && !Util.isExcluded(resource, ((ClasspathEntry)entry).fullExclusionPatternChars())) { + return project.getPackageFragmentRoot(resource); + } else if (rootPath.isPrefixOf(resourcePath) && !Util.isExcluded(resource, null, ((ClasspathEntry)entry).fullExclusionPatternChars())) { // given we have a resource child of the root, it cannot be a JAR pkg root IPackageFragmentRoot root = ((JavaProject) project).getFolderPackageFragmentRoot(rootPath); if (root == null) return null; @@ -541,24 +540,85 @@ public class JavaModelManager implements ISaveParticipant { /** * A weak set of the known scopes. */ - protected WeakHashMap scopes = new WeakHashMap(); - + protected WeakHashMap searchScopes = new WeakHashMap(); + +// public static class PerProjectInfo { +// public IProject project; +// public Object savedState; +// public boolean triedRead; +// public IClasspathEntry[] classpath; +// public IClasspathEntry[] lastResolvedClasspath; +// public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries +// public IPath outputLocation; +// public Preferences preferences; +// public PerProjectInfo(IProject project) { +// +// this.triedRead = false; +// this.savedState = null; +// this.project = project; +// } +// } + public static class PerProjectInfo { + public IProject project; public Object savedState; public boolean triedRead; - public IClasspathEntry[] classpath; - public IClasspathEntry[] lastResolvedClasspath; + public IClasspathEntry[] rawClasspath; + public IClasspathEntry[] resolvedClasspath; public Map resolvedPathToRawEntries; // reverse map from resolved path to raw entries public IPath outputLocation; public Preferences preferences; + public PerProjectInfo(IProject project) { this.triedRead = false; this.savedState = null; this.project = project; } + + // updating raw classpath need to flush obsoleted cached information about resolved entries + public synchronized void updateClasspathInformation(IClasspathEntry[] newRawClasspath) { + + this.rawClasspath = newRawClasspath; + this.resolvedClasspath = null; + this.resolvedPathToRawEntries = null; + } + public String toString() { + StringBuffer buffer = new StringBuffer(); + buffer.append("Info for "); //$NON-NLS-1$ + buffer.append(this.project.getFullPath()); + buffer.append("\nRaw classpath:\n"); //$NON-NLS-1$ + if (this.rawClasspath == null) { + buffer.append(" \n"); //$NON-NLS-1$ + } else { + for (int i = 0, length = this.rawClasspath.length; i < length; i++) { + buffer.append(" "); //$NON-NLS-1$ + buffer.append(this.rawClasspath[i]); + buffer.append('\n'); + } + } + buffer.append("Resolved classpath:\n"); //$NON-NLS-1$ + IClasspathEntry[] resolvedCP = this.resolvedClasspath; + if (resolvedCP == null) { + buffer.append(" \n"); //$NON-NLS-1$ + } else { + for (int i = 0, length = resolvedCP.length; i < length; i++) { + buffer.append(" "); //$NON-NLS-1$ + buffer.append(resolvedCP[i]); + buffer.append('\n'); + } + } + buffer.append("Output location:\n "); //$NON-NLS-1$ + if (this.outputLocation == null) { + buffer.append(""); //$NON-NLS-1$ + } else { + buffer.append(this.outputLocation); + } + return buffer.toString(); + } } + public static class PerWorkingCopyInfo implements IProblemRequestor { int useCount = 0; IProblemRequestor problemRequestor; @@ -979,6 +1039,9 @@ public class JavaModelManager implements ISaveParticipant { return this.elementsOutOfSynchWithBuffers; } +// public IndexManager getIndexManager() { +// return this.indexManager; +// } /** * Returns the IJavaElement represented by the * String memento. @@ -1582,9 +1645,14 @@ public class JavaModelManager implements ISaveParticipant { } } -// PROTECTED VOID REMOVEINFO(IJAVAELEMENT ELEMENT) { -// THIS.CACHE.REMOVEINFO(ELEMENT); -// } + /** + * Remembers the given scope in a weak set + * (so no need to remove it: it will be removed by the garbage collector) + */ +// public void rememberScope(AbstractSearchScope scope) { +// // NB: The value has to be null so as to not create a strong reference on the scope +// this.searchScopes.put(scope, null); +// } /* * Removes all cached info for the given element (including all children) * from the cache. @@ -1689,11 +1757,55 @@ public class JavaModelManager implements ISaveParticipant { System.out.println(Util.bind("build.saveStateComplete", String.valueOf(t))); //$NON-NLS-1$ } } - + private synchronized Map containerClone(IJavaProject project) { + Map originalProjectContainers = (Map)this.containers.get(project); + if (originalProjectContainers == null) return null; + Map projectContainers = new HashMap(originalProjectContainers.size()); + projectContainers.putAll(originalProjectContainers); + return projectContainers; + } /** * @see ISaveParticipant */ public void saving(ISaveContext context) throws CoreException { + + // save container values on snapshot/full save + Preferences preferences = JavaCore.getPlugin().getPluginPreferences(); + IJavaProject[] projects = getJavaModel().getJavaProjects(); + for (int i = 0, length = projects.length; i < length; i++) { + IJavaProject project = projects[i]; + // clone while iterating (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59638) + Map projectContainers = containerClone(project); + if (projectContainers == null) continue; + for (Iterator keys = projectContainers.keySet().iterator(); keys.hasNext();) { + IPath containerPath = (IPath) keys.next(); +// IClasspathContainer container = (IClasspathContainer) projectContainers.get(containerPath); + String containerKey = CP_CONTAINER_PREFERENCES_PREFIX+project.getElementName() +"|"+containerPath;//$NON-NLS-1$ + String containerString = CP_ENTRY_IGNORE; +// try { +// if (container != null) { +// containerString = ((JavaProject)project).encodeClasspath(container.getClasspathEntries(), null, false); +// } +// } catch(JavaModelException e){ +// // could not encode entry: leave it as CP_ENTRY_IGNORE +// } + preferences.setDefault(containerKey, CP_ENTRY_IGNORE); // use this default to get rid of removed ones + preferences.setValue(containerKey, containerString); + } + } + JavaCore.getPlugin().savePluginPreferences(); + +// if (context.getKind() == ISaveContext.FULL_SAVE) { +// // will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658) +// context.needDelta(); +// +// // clean up indexes on workspace full save +// // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=52347) +// IndexManager manager = this.indexManager; +// if (manager != null) { +// manager.cleanUpIndexes(); +// } +// } IProject savedProject = context.getProject(); if (savedProject != null) { @@ -1720,6 +1832,36 @@ public class JavaModelManager implements ISaveParticipant { throw new CoreException(new MultiStatus(JavaCore.PLUGIN_ID, IStatus.ERROR, stats, Util.bind("build.cannotSaveStates"), null)); //$NON-NLS-1$ } } + /** + * @see ISaveParticipant + */ +// public void saving(ISaveContext context) throws CoreException { +// +// IProject savedProject = context.getProject(); +// if (savedProject != null) { +// if (!JavaProject.hasJavaNature(savedProject)) return; // ignore +// PerProjectInfo info = getPerProjectInfo(savedProject, true /* create info */); +// saveState(info, context); +// return; +// } +// +// ArrayList vStats= null; // lazy initialized +// for (Iterator iter = perProjectInfo.values().iterator(); iter.hasNext();) { +// try { +// PerProjectInfo info = (PerProjectInfo) iter.next(); +// saveState(info, context); +// } catch (CoreException e) { +// if (vStats == null) +// vStats= new ArrayList(); +// vStats.add(e.getStatus()); +// } +// } +// if (vStats != null) { +// IStatus[] stats= new IStatus[vStats.size()]; +// vStats.toArray(stats); +// throw new CoreException(new MultiStatus(JavaCore.PLUGIN_ID, IStatus.ERROR, stats, Util.bind("build.cannotSaveStates"), null)); //$NON-NLS-1$ +// } +// } /** * Record the order in which to build the java projects (batch build). This order is based @@ -1903,4 +2045,29 @@ public class JavaModelManager implements ISaveParticipant { return result; } } + + /* + * A HashSet that contains the IJavaProject whose classpath is being resolved. + */ + private ThreadLocal classpathsBeingResolved = new ThreadLocal(); + + private HashSet getClasspathBeingResolved() { + HashSet result = (HashSet) this.classpathsBeingResolved.get(); + if (result == null) { + result = new HashSet(); + this.classpathsBeingResolved.set(result); + } + return result; + } + public boolean isClasspathBeingResolved(IJavaProject project) { + return getClasspathBeingResolved().contains(project); + } + + public void setClasspathBeingResolved(IJavaProject project, boolean classpathIsResolved) { + if (classpathIsResolved) { + getClasspathBeingResolved().add(project); + } else { + getClasspathBeingResolved().remove(project); + } + } }