use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class EPathUtil method collapse2EclipsePath.
static String collapse2EclipsePath(final String url, final ModuleRootModel model) {
final Project project = model.getModule().getProject();
final VirtualFile contentRoot = getContentRoot(model);
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
if (file != null) {
LOG.assertTrue(file.isValid());
if (file.getFileSystem() instanceof JarFileSystem) {
final VirtualFile jarFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (jarFile == null) {
LOG.error("Url: \'" + url + "\'; file: " + file);
return ProjectRootManagerImpl.extractLocalPath(url);
}
file = jarFile;
}
if (contentRoot != null && VfsUtilCore.isAncestor(contentRoot, file, false)) {
//inside current project
return VfsUtilCore.getRelativePath(file, contentRoot, '/');
} else {
//relative to other project
final String path = collapse2eclipseRelative2OtherModule(project, file);
if (path != null) {
return path;
}
}
//absolute path
return ProjectRootManagerImpl.extractLocalPath(url);
} else {
//try to avoid absolute path for deleted file
if (contentRoot != null) {
final String rootUrl = contentRoot.getUrl();
if (url.startsWith(rootUrl) && url.length() > rootUrl.length()) {
//without leading /
return url.substring(rootUrl.length() + 1);
}
}
final VirtualFile projectBaseDir = contentRoot != null ? contentRoot.getParent() : project.getBaseDir();
assert projectBaseDir != null;
final String projectUrl = projectBaseDir.getUrl();
if (url.startsWith(projectUrl)) {
//leading /
return url.substring(projectUrl.length());
}
final String path = VfsUtilCore.urlToPath(url);
final String projectPath = projectBaseDir.getPath();
if (path.startsWith(projectPath)) {
return ProjectRootManagerImpl.extractLocalPath(path.substring(projectPath.length()));
}
return ProjectRootManagerImpl.extractLocalPath(url);
}
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class EclipseUserLibrariesHelper method writeUserLibrary.
private static void writeUserLibrary(final Library library, final Element libElement) {
final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
for (VirtualFile file : files) {
Element archElement = new Element("archive");
if (file.getFileSystem() instanceof JarFileSystem) {
final VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (localFile != null) {
file = localFile;
}
}
archElement.setAttribute("path", file.getPath());
libElement.addContent(archElement);
}
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class FileTreeStructure method getParentElement.
@Nullable
public Object getParentElement(Object element) {
if (element instanceof FileElement) {
final FileElement fileElement = (FileElement) element;
final VirtualFile elementFile = getValidFile(fileElement);
if (elementFile != null && myRootElement.getFile() != null && myRootElement.getFile().equals(elementFile)) {
return null;
}
final VirtualFile parentElementFile = getValidFile(fileElement.getParent());
if (elementFile != null && parentElementFile != null) {
final VirtualFile parentFile = elementFile.getParent();
if (parentElementFile.equals(parentFile))
return fileElement.getParent();
}
VirtualFile file = fileElement.getFile();
if (file == null)
return null;
VirtualFile parent = file.getParent();
if (parent != null && parent.getFileSystem() instanceof JarFileSystem && parent.getParent() == null) {
// parent of jar contents should be local jar file
String localPath = parent.getPath().substring(0, parent.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
parent = LocalFileSystem.getInstance().findFileByPath(localPath);
}
if (parent != null && parent.isValid() && parent.equals(myRootElement.getFile())) {
return myRootElement;
}
if (parent == null) {
return myRootElement;
}
return new FileElement(parent, parent.getName());
}
return null;
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class AbstractModuleNode method contains.
@Override
public boolean contains(@NotNull VirtualFile file) {
Module module = getValue();
if (module == null || module.isDisposed())
return false;
if (file.getFileSystem() instanceof JarFileSystem) {
VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (local == null)
return false;
file = local;
}
for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
if (VfsUtilCore.isAncestor(root, file, false))
return true;
}
return false;
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class IdeaJdk method addSources.
private static void addSources(SdkModificator sdkModificator, final Sdk javaSdk) {
if (javaSdk != null) {
if (!addOrderEntries(OrderRootType.SOURCES, javaSdk, sdkModificator)) {
if (SystemInfo.isMac) {
Sdk[] jdks = ProjectJdkTable.getInstance().getAllJdks();
for (Sdk jdk : jdks) {
if (jdk.getSdkType() instanceof JavaSdk) {
addOrderEntries(OrderRootType.SOURCES, jdk, sdkModificator);
break;
}
}
} else {
String homePath = javaSdk.getHomePath();
if (homePath == null)
return;
final File jdkHome = new File(homePath).getParentFile();
@NonNls final String srcZip = "src.zip";
final File jarFile = new File(jdkHome, srcZip);
if (jarFile.exists()) {
JarFileSystem jarFileSystem = JarFileSystem.getInstance();
String path = jarFile.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
jarFileSystem.setNoCopyJarForPath(path);
sdkModificator.addRoot(jarFileSystem.findFileByPath(path), OrderRootType.SOURCES);
}
}
}
}
}
Aggregations