Skip to content

Commit

Permalink
fix exception from buildpath changes on windows, bug 401623
Browse files Browse the repository at this point in the history
  • Loading branch information
panchenko committed Mar 26, 2013
1 parent 15af04a commit 2dae687
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Expand Up @@ -229,4 +229,19 @@ public static IFileHandle getFile(IModelElement element,
} }
} }


/**
* Answers if the specified full path belongs to the local environment.
*/
public static boolean isLocalEnvironment(IPath fullPath) {
final String device = fullPath.getDevice();
if (device != null) {
final int pos = device.indexOf(SEPARATOR);
if (pos >= 0) {
return LocalEnvironment.ENVIRONMENT_ID.equals(device.substring(
0, pos));
}
}
return false;
}

} }
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.dltk.internal.core; package org.eclipse.dltk.internal.core;


import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;


import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
Expand All @@ -35,25 +34,23 @@ public ExternalFolderChange(ScriptProject project,
*/ */
public void updateExternalFoldersIfNecessary(boolean refreshIfExistAlready, public void updateExternalFoldersIfNecessary(boolean refreshIfExistAlready,
IProgressMonitor monitor) throws ModelException { IProgressMonitor monitor) throws ModelException {
HashSet oldFolders = ExternalFoldersManager HashSet<IPath> oldFolders = ExternalFoldersManager
.getExternalFolders(this.oldResolvedBuildpath); .getExternalFolders(this.oldResolvedBuildpath);
IBuildpathEntry[] newResolvedBuildpath = this.project IBuildpathEntry[] newResolvedBuildpath = this.project
.getResolvedBuildpath(); .getResolvedBuildpath();
HashSet newFolders = ExternalFoldersManager HashSet<IPath> newFolders = ExternalFoldersManager
.getExternalFolders(newResolvedBuildpath); .getExternalFolders(newResolvedBuildpath);
if (newFolders == null) if (newFolders == null)
return; return;
ExternalFoldersManager foldersManager = ModelManager ExternalFoldersManager foldersManager = ModelManager
.getExternalManager(); .getExternalManager();
Iterator iterator = newFolders.iterator(); for (IPath folderPath : newFolders) {
while (iterator.hasNext()) {
Object folderPath = iterator.next();
if (oldFolders == null || !oldFolders.remove(folderPath)) { if (oldFolders == null || !oldFolders.remove(folderPath)) {
try { try {
foldersManager.createLinkFolder((IPath) folderPath, foldersManager.createLinkFolder(folderPath,
refreshIfExistAlready, monitor); refreshIfExistAlready, monitor);
} catch (CoreException e) { } catch (CoreException e) {
throw new ModelException(e); ModelException.propagate(e);
} }
} }
} }
Expand Down
Expand Up @@ -28,9 +28,11 @@
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.dltk.annotations.Nullable;
import org.eclipse.dltk.core.DLTKCore; import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.IBuildpathEntry; import org.eclipse.dltk.core.IBuildpathEntry;
import org.eclipse.dltk.core.IScriptProjectFilenames; import org.eclipse.dltk.core.IScriptProjectFilenames;
import org.eclipse.dltk.core.environment.EnvironmentPathUtils;
import org.eclipse.dltk.internal.core.util.Util; import org.eclipse.dltk.internal.core.util.Util;


public class ExternalFoldersManager { public class ExternalFoldersManager {
Expand All @@ -43,18 +45,23 @@ public class ExternalFoldersManager {
* Returns a set of external path to external folders referred to on the * Returns a set of external path to external folders referred to on the
* given buildpath. Returns null if none. * given buildpath. Returns null if none.
*/ */
public static HashSet getExternalFolders(IBuildpathEntry[] buildpath) { @Nullable
public static HashSet<IPath> getExternalFolders(IBuildpathEntry[] buildpath) {
if (buildpath == null) if (buildpath == null)
return null; return null;
HashSet folders = null; HashSet<IPath> folders = null;
for (int i = 0; i < buildpath.length; i++) { for (int i = 0; i < buildpath.length; i++) {
IBuildpathEntry entry = buildpath[i]; IBuildpathEntry entry = buildpath[i];
if (entry.getEntryKind() == IBuildpathEntry.BPE_LIBRARY) { if (entry.getEntryKind() == IBuildpathEntry.BPE_LIBRARY) {
IPath entryPath = entry.getPath(); IPath entryPath = entry.getPath();
if (isExternalFolderPath(entryPath)) { if (EnvironmentPathUtils.isLocalEnvironment(entryPath)) {
if (folders == null) final IPath local = EnvironmentPathUtils
folders = new HashSet(); .getLocalPath(entryPath);
folders.add(entryPath); if (isExternalFolderPath(local)) {
if (folders == null)
folders = new HashSet<IPath>();
folders.add(local);
}
} }
} }
} }
Expand Down
Expand Up @@ -942,11 +942,11 @@ public ResolvedBuildpath resolveBuildpath(IBuildpathEntry[] rawClasspath,
ExternalFoldersManager externalFoldersManager = ModelManager ExternalFoldersManager externalFoldersManager = ModelManager
.getExternalManager(); .getExternalManager();
ResolvedBuildpath result = new ResolvedBuildpath(); ResolvedBuildpath result = new ResolvedBuildpath();
Map knownDrives = new HashMap(); Map<String, Boolean> knownDrives = new HashMap<String, Boolean>();


Map referencedEntriesMap = new HashMap(); Map referencedEntriesMap = new HashMap();
List<IPath> rawLibrariesPath = new ArrayList<IPath>(); List<IPath> rawLibrariesPath = new ArrayList<IPath>();
LinkedHashSet resolvedEntries = new LinkedHashSet(); LinkedHashSet<IBuildpathEntry> resolvedEntries = new LinkedHashSet<IBuildpathEntry>();


if (resolveChainedLibraries) { if (resolveChainedLibraries) {
for (int index = 0; index < rawClasspath.length; index++) { for (int index = 0; index < rawClasspath.length; index++) {
Expand Down Expand Up @@ -1125,9 +1125,10 @@ public ResolvedBuildpath resolveBuildpath(IBuildpathEntry[] rawClasspath,


private void addToResult(IBuildpathEntry rawEntry, private void addToResult(IBuildpathEntry rawEntry,
IBuildpathEntry resolvedEntry, ResolvedBuildpath result, IBuildpathEntry resolvedEntry, ResolvedBuildpath result,
LinkedHashSet resolvedEntries, LinkedHashSet<IBuildpathEntry> resolvedEntries,
ExternalFoldersManager externalFoldersManager, ExternalFoldersManager externalFoldersManager,
Map oldChainedEntriesMap, boolean addAsChainedEntry, Map knownDrives) { Map oldChainedEntriesMap, boolean addAsChainedEntry,
Map<String, Boolean> knownDrives) {


IPath resolvedPath; IPath resolvedPath;
// If it's already been resolved, do not add to resolvedEntries // If it's already been resolved, do not add to resolvedEntries
Expand Down Expand Up @@ -1192,11 +1193,12 @@ private void copyFromOldChainedEntry(BuildpathEntry resolvedEntry,
* File#exists() takes lot of time for an unmapped drive. Hence, cache the * File#exists() takes lot of time for an unmapped drive. Hence, cache the
* info. https://bugs.eclipse.org/bugs/show_bug.cgi?id=338649 * info. https://bugs.eclipse.org/bugs/show_bug.cgi?id=338649
*/ */
private boolean driveExists(IPath sourcePath, Map knownDrives) { private boolean driveExists(IPath sourcePath,
Map<String, Boolean> knownDrives) {
String drive = sourcePath.getDevice(); String drive = sourcePath.getDevice();
if (drive == null) if (drive == null)
return true; return true;
Boolean good = (Boolean) knownDrives.get(drive); Boolean good = knownDrives.get(drive);
if (good == null) { if (good == null) {
if (new File(drive).exists()) { if (new File(drive).exists()) {
knownDrives.put(drive, Boolean.TRUE); knownDrives.put(drive, Boolean.TRUE);
Expand Down

0 comments on commit 2dae687

Please sign in to comment.