Extracted getSdkRootVirtualFile()

This commit is contained in:
Andrey Vlasovskikh
2014-03-05 15:13:28 +04:00
parent 6baec9712b
commit 90bd285851
@@ -659,9 +659,9 @@ public class PythonSdkType extends SdkType {
}
public static void addSdkRoot(SdkModificator sdkModificator, String path) {
VirtualFile child = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (child != null) {
addSdkRoot(sdkModificator, child);
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (file != null) {
addSdkRoot(sdkModificator, file);
}
else {
LOG.info("Bogus sys.path entry " + path);
@@ -669,19 +669,26 @@ public class PythonSdkType extends SdkType {
}
private static void addSdkRoot(@NotNull SdkModificator sdkModificator, @NotNull VirtualFile child) {
@NonNls String suffix = child.getExtension();
if (suffix != null) suffix = suffix.toLowerCase(); // Why on earth empty suffix is null and not ""?
VirtualFile toAdd = child;
if ((!child.isDirectory()) && ("zip".equals(suffix) || "egg".equals(suffix))) {
// NOTE: Files marked as library sources are not considered part of project source. Since the directory of the project the
// user is working on is included in PYTHONPATH with many configurations (e.g. virtualenv), we must not mark SDK paths as
// library sources, only as classes.
sdkModificator.addRoot(getSdkRootVirtualFile(child), OrderRootType.CLASSES);
}
@NotNull
public static VirtualFile getSdkRootVirtualFile(@NotNull VirtualFile path) {
String suffix = path.getExtension();
if (suffix != null) {
suffix = suffix.toLowerCase(); // Why on earth empty suffix is null and not ""?
}
if ((!path.isDirectory()) && ("zip".equals(suffix) || "egg".equals(suffix))) {
// a .zip / .egg file must have its root extracted first
toAdd = JarFileSystem.getInstance().getJarRootForLocalFile(child);
}
if (toAdd != null) {
// NOTE: Files marked as library sources are not considered part of project source. Since the directory of the project the
// user is working on is included in PYTHONPATH with many configurations (e.g. virtualenv), we must not mark SDK paths as
// library sources, only as classes.
sdkModificator.addRoot(toAdd, OrderRootType.CLASSES);
final VirtualFile jar = JarFileSystem.getInstance().getJarRootForLocalFile(path);
if (jar != null) {
return jar;
}
}
return path;
}
public static String getSkeletonsPath(String basePath, String sdkHome) {