public IProject createExternalFoldersProject(IProgressMonitor monitor) throws CoreException { IProject project = getExternalFoldersProject(); if (!project.isAccessible()) { if (!project.exists()) { createExternalFoldersProject(project, monitor); } openExternalFoldersProject(project, monitor); } return project; }
public IFolder addFolder(IPath externalFolderPath, boolean scheduleForCreation) { return addFolder(externalFolderPath, getExternalFoldersProject(), scheduleForCreation); }
public void updateExternalFoldersIfNecessary(boolean refreshIfExistAlready, IProgressMonitor monitor) throws JavaModelException { HashSet oldFolders = ExternalFoldersManager.getExternalFolders(this.oldResolvedClasspath); IClasspathEntry[] newResolvedClasspath = this.project.getResolvedClasspath(); HashSet newFolders = ExternalFoldersManager.getExternalFolders(newResolvedClasspath); if (newFolders == null) return; ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager(); Iterator iterator = newFolders.iterator(); while (iterator.hasNext()) { Object folderPath = iterator.next(); if (oldFolders == null || !oldFolders.remove(folderPath) || foldersManager.removePendingFolder(folderPath)) { try { foldersManager.createLinkFolder((IPath) folderPath, refreshIfExistAlready, monitor); } catch (CoreException e) { throw new JavaModelException(e); } } } // removal of linked folders is done during save } public String toString() {
public IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, IProgressMonitor monitor) throws CoreException { IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource return createLinkFolder(externalFolderPath, refreshIfExistAlready, externalFoldersProject, monitor); }
public void refreshReferences(IProject source, IProgressMonitor monitor) { IProject externalProject = getExternalFoldersProject(); if (source.equals(externalProject)) return; if (!JavaProject.hasJavaNature(source)) return; try { Set<IPath> externalFolders = getExternalFolders(((JavaProject) JavaCore.create(source)).getResolvedClasspath()); runRefreshJob(externalFolders); } catch (CoreException e) { Util.log(e, "Exception while refreshing external project"); //$NON-NLS-1$ } }
if (ExternalFoldersManager.isExternalFolderPath(entryPath) && externalFoldersManager.getFolder(entryPath) == null) { externalFoldersManager.addFolder(entryPath, true); externalFoldersManager.createPendingFolders(monitor);
public void cleanUp(IProgressMonitor monitor) throws CoreException { ArrayList toDelete = getFoldersToCleanUp(monitor); if (toDelete == null) return; for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); IFolder folder = (IFolder) entry.getValue(); folder.delete(true, monitor); IPath key = (IPath) entry.getKey(); this.folders.remove(key); } IProject project = getExternalFoldersProject(); if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/) project.delete(true, monitor); }
public IFolder removeFolder(IPath externalFolderPath) { return getFolders().remove(externalFolderPath); }
protected IStatus run(IProgressMonitor pm) { try { if (this.externalFolders == null) return Status.OK_STATUS; IPath externalPath = null; for (int index = 0; index < this.externalFolders.size(); index++ ) { if ((externalPath = (IPath)this.externalFolders.get(index)) != null) { IFolder folder = getFolder(externalPath); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321358 if (folder != null) folder.refreshLocal(IResource.DEPTH_INFINITE, pm); } // Set the processed ones to null instead of removing the element altogether, // so that they will not be considered as duplicates. // This will also avoid elements being shifted to the left every time an element // is removed. However, there is a risk of Collection size to be increased more often. this.externalFolders.setElementAt(null, index); } } catch (CoreException e) { return e.getStatus(); } return Status.OK_STATUS; } }
protected ISchedulingRule getSchedulingRule() { if (this.canChangeResources) { IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); return new MultiRule(new ISchedulingRule[] { // use project modification rule as this is needed to create the .classpath file if it doesn't exist yet, or to update project references ruleFactory.modifyRule(this.project.getProject()), // and external project modification rule in case the external folders are modified ruleFactory.modifyRule(JavaModelManager.getExternalManager().getExternalFoldersProject()) }); } return super.getSchedulingRule(); }
private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager, Map oldChainedEntriesMap, boolean addAsChainedEntry, Map knownDrives) { IPath resolvedPath; // If it's already been resolved, do not add to resolvedEntries if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) { result.rawReverseMap.put(resolvedPath, rawEntry); result.rootPathToResolvedEntries.put(resolvedPath, resolvedEntry); resolvedEntries.add(resolvedEntry); if (addAsChainedEntry) { IClasspathEntry chainedEntry = null; chainedEntry = (ClasspathEntry) oldChainedEntriesMap.get(resolvedPath); if (chainedEntry != null) { // This is required to keep the attributes if any added by the user in // the previous session such as source attachment path etc. copyFromOldChainedEntry((ClasspathEntry) resolvedEntry, (ClasspathEntry) chainedEntry); } } } if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) { externalFoldersManager.addFolder(resolvedPath, true/*scheduleForCreation*/); // no-op if not an external folder or if already registered } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336046 // The source attachment path could be external too and in which case, must be added. IPath sourcePath = resolvedEntry.getSourceAttachmentPath(); if (sourcePath != null && driveExists(sourcePath, knownDrives) && ExternalFoldersManager.isExternalFolderPath(sourcePath)) { externalFoldersManager.addFolder(sourcePath, true); } }
private IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, IProject externalFoldersProject, IProgressMonitor monitor) throws CoreException { IFolder result = addFolder(externalFolderPath, externalFoldersProject, false); if (!result.exists()) result.createLink(externalFolderPath, IResource.ALLOW_MISSING_LOCAL, monitor); else if (refreshIfExistAlready) result.refreshLocal(IResource.DEPTH_INFINITE, monitor); return result; }
this.externalFoldersManager.cleanUp(null);
public void refreshReferences(IProject source, IProgressMonitor monitor) { IProject externalProject = getExternalFoldersProject(); if (source.equals(externalProject)) return; if (!JavaProject.hasJavaNature(source)) return; try { Set<IPath> externalFolders = getExternalFolders(((JavaProject) JavaCore.create(source)).getResolvedClasspath()); runRefreshJob(externalFolders); } catch (CoreException e) { Util.log(e, "Exception while refreshing external project"); //$NON-NLS-1$ } }
if (ExternalFoldersManager.isExternalFolderPath(entryPath) && externalFoldersManager.getFolder(entryPath) == null) { externalFoldersManager.addFolder(entryPath, true); externalFoldersManager.createPendingFolders(monitor);
public IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, IProgressMonitor monitor) throws CoreException { IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource return createLinkFolder(externalFolderPath, refreshIfExistAlready, externalFoldersProject, monitor); }
public void cleanUp(IProgressMonitor monitor) throws CoreException { ArrayList toDelete = getFoldersToCleanUp(monitor); if (toDelete == null) return; for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); IFolder folder = (IFolder) entry.getValue(); folder.delete(true, monitor); IPath key = (IPath) entry.getKey(); this.folders.remove(key); } IProject project = getExternalFoldersProject(); if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/) project.delete(true, monitor); }
public IFolder getFolder(IPath externalFolderPath) { return (IFolder) getFolders().get(externalFolderPath); }
protected IStatus run(IProgressMonitor pm) { try { if (this.externalFolders == null) return Status.OK_STATUS; IPath externalPath = null; for (int index = 0; index < this.externalFolders.size(); index++ ) { if ((externalPath = (IPath)this.externalFolders.get(index)) != null) { IFolder folder = getFolder(externalPath); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321358 if (folder != null) folder.refreshLocal(IResource.DEPTH_INFINITE, pm); } // Set the processed ones to null instead of removing the element altogether, // so that they will not be considered as duplicates. // This will also avoid elements being shifted to the left every time an element // is removed. However, there is a risk of Collection size to be increased more often. this.externalFolders.setElementAt(null, index); } } catch (CoreException e) { return e.getStatus(); } return Status.OK_STATUS; } }
protected ISchedulingRule getSchedulingRule() { if (this.canChangeResources) { IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); return new MultiRule(new ISchedulingRule[] { // use project modification rule as this is needed to create the .classpath file if it doesn't exist yet, or to update project references ruleFactory.modifyRule(this.project.getProject()), // and external project modification rule in case the external folders are modified ruleFactory.modifyRule(JavaModelManager.getExternalManager().getExternalFoldersProject()) }); } return super.getSchedulingRule(); }