source = "";
}
//we have to work on this one to resolve to full files, as what is stored is the position
//relative to the project location
List<String> strings = StringUtils.splitAndRemoveEmptyTrimmed(source, '|');
FastStringBuffer buf = new FastStringBuffer();
IWorkspaceRoot root = null;
ResourcesPlugin resourcesPlugin = ResourcesPlugin.getPlugin();
for (String currentPath : strings) {
if (currentPath.trim().length() > 0) {
IPath p = new Path(currentPath);
if (resourcesPlugin == null) {
//in tests
buf.append(currentPath);
buf.append("|");
continue;
}
if (root == null) {
root = ResourcesPlugin.getWorkspace().getRoot();
}
if (p.segmentCount() < 1) {
Log.log("Found no segment in: " + currentPath + " for: " + project);
continue; //No segment? Really weird!
}
//try to get relative to the workspace
IContainer container = null;
IResource r = null;
try {
r = root.findMember(p);
} catch (Exception e) {
Log.log(e);
}
if (!(r instanceof IContainer) && !(r instanceof IFile)) {
//If we didn't find the file, let's try to sync things, as this can happen if the workspace
//is still not properly synchronized.
String firstSegment = p.segment(0);
IResource firstSegmentResource = root.findMember(firstSegment);
if (!(firstSegmentResource instanceof IContainer) && !(firstSegmentResource instanceof IFile)) {
//we cannot even get the 1st part... let's do sync
long currentTimeMillis = System.currentTimeMillis();
if (doFullSynchAt == -1 || currentTimeMillis > doFullSynchAt) {
doFullSynchAt = currentTimeMillis + (60 * 2 * 1000); //do a full synch at most once every 2 minutes
try {
root.refreshLocal(p.segmentCount() + 1, null);
} catch (CoreException e) {
//ignore
}
}
} else {
Long doSynchAt = directMembersChecked.get(firstSegment);
long currentTimeMillis = System.currentTimeMillis();
if (doSynchAt == null || currentTimeMillis > doFullSynchAt) {
directMembersChecked.put(firstSegment, currentTimeMillis + (60 * 2 * 1000));
//OK, we can get to the 1st segment, so, let's do a refresh just from that point on, not in the whole workspace...
try {
firstSegmentResource.refreshLocal(p.segmentCount(), null);
} catch (CoreException e) {
//ignore
}
}
}
//Now, try to get it knowing that it's properly synched (it may still not be there, but at least we tried it)
try {
r = root.findMember(p);
} catch (Exception e) {
Log.log(e);
}
}
if (r instanceof IContainer) {
container = (IContainer) r;
buf.append(FileUtils.getFileAbsolutePath(container.getLocation().toFile()));
buf.append("|");
} else if (r instanceof IFile) { //zip/jar/egg file
String extension = r.getFileExtension();
if (extension == null || FileTypesPreferencesPage.isValidZipFile("." + extension) == false) {
Log.log("Error: the path " + currentPath + " is a file but is not a recognized zip file.");
} else {
buf.append(FileUtils.getFileAbsolutePath(r.getLocation().toFile()));
buf.append("|");
}
} else {
//We're now always making sure that it's all synchronized, so, if we got here, it really doesn't exist (let's warn about it)
//Not in workspace?... maybe it was removed, so, let the user know about it (and still add it to the pythonpath as is)
Log.log(IStatus.WARNING, "Unable to find the path " + currentPath + " in the project were it's \n"
+ "added as a source folder for pydev (project: " + project.getName() + ") member:" + r,
null);
//No good: try to get it relative to the project
String curr = currentPath;
IPath path = new Path(curr.trim());
if (project.getFullPath().isPrefixOf(path)) {
path = path.removeFirstSegments(1);
if (FileTypesPreferencesPage.isValidZipFile(curr)) {
r = project.getFile(path);
} else {
//get it relative to the project
r = project.getFolder(path);
}
if (r != null) {
buf.append(FileUtils.getFileAbsolutePath(r.getLocation().toFile()));
buf.append("|");
continue; //Don't go on to append it relative to the workspace root.
}
}
//Nothing worked: force it to be relative to the workspace.
IPath rootLocation = root.getRawLocation();
//Note that this'll be cached for later use.
buf.append(FileUtils.getFileAbsolutePath(rootLocation.append(currentPath.trim()).toFile()));
buf.append("|");
}
}
}
if (external == null) {
external = "";
}
return buf.append("|").append(external).append("|").append(contributed).toString();
}