use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class GradleInstallationManager method getClassRoots.
/**
* Allows to ask for the classpath roots of the classes that are additionally provided by the gradle integration (e.g. gradle class
* files, bundled groovy-all jar etc).
*
* @param project target project to use for gradle home retrieval
* @return classpath roots of the classes that are additionally provided by the gradle integration (if any);
* <code>null</code> otherwise
*/
@Nullable
public List<VirtualFile> getClassRoots(@Nullable Project project) {
List<File> files = getClassRoots(project, null);
if (files == null)
return null;
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
return ContainerUtil.mapNotNull(files, file -> {
final VirtualFile virtualFile = localFileSystem.refreshAndFindFileByIoFile(file);
return virtualFile != null ? jarFileSystem.getJarRootForLocalFile(virtualFile) : null;
});
}
use of com.intellij.openapi.vfs.JarFileSystem in project android by JetBrains.
the class AndroidRootUtil method fillExternalLibrariesAndModules.
private static void fillExternalLibrariesAndModules(@NotNull final Module module, @NotNull final Set<VirtualFile> outputDirs, @NotNull final Set<Module> visited, @Nullable final Set<VirtualFile> libraries, final boolean exportedLibrariesOnly, final boolean recursive) {
if (!visited.add(module)) {
return;
}
ApplicationManager.getApplication().runReadAction(() -> {
ModuleRootManager manager = ModuleRootManager.getInstance(module);
for (OrderEntry entry : manager.getOrderEntries()) {
if (!(entry instanceof ExportableOrderEntry) || ((ExportableOrderEntry) entry).getScope() != DependencyScope.COMPILE) {
continue;
}
if (libraries != null && entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
Library library = libraryOrderEntry.getLibrary();
if (library != null && (!exportedLibrariesOnly || libraryOrderEntry.isExported())) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
if (!file.exists()) {
continue;
}
if (file.getFileType() instanceof ArchiveFileType) {
if (file.getFileSystem() instanceof JarFileSystem) {
VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (localFile != null) {
libraries.add(localFile);
}
} else {
libraries.add(file);
}
} else if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) {
collectClassFilesAndJars(file, libraries, new HashSet<>());
}
}
}
} else if (entry instanceof ModuleOrderEntry) {
Module depModule = ((ModuleOrderEntry) entry).getModule();
if (depModule == null) {
continue;
}
AndroidFacet facet = AndroidFacet.getInstance(depModule);
boolean libraryProject = facet != null && facet.isLibraryProject();
CompilerModuleExtension extension = CompilerModuleExtension.getInstance(depModule);
if (extension != null) {
VirtualFile classDir = extension.getCompilerOutputPath();
if (libraryProject) {
VirtualFile tmpArtifactsDir = AndroidDexCompiler.getOutputDirectoryForDex(depModule);
if (tmpArtifactsDir != null) {
VirtualFile packedClassesJar = tmpArtifactsDir.findChild(CLASSES_JAR_FILE_NAME);
if (packedClassesJar != null) {
outputDirs.add(packedClassesJar);
}
}
} else // do not support android-app->android-app compile dependencies
if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
outputDirs.add(classDir);
}
}
if (recursive) {
fillExternalLibrariesAndModules(depModule, outputDirs, visited, libraries, !libraryProject || exportedLibrariesOnly, true);
}
}
}
});
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-plugins by JetBrains.
the class FlexSwcFoldersRootDetector method collectRoots.
private static void collectRoots(VirtualFile file, final List<VirtualFile> result, final ProgressIndicator progressIndicator) {
if (!file.isDirectory() || file.getFileSystem() instanceof JarFileSystem)
return;
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile child) {
progressIndicator.checkCanceled();
if (child.isDirectory()) {
progressIndicator.setText2(child.getPresentableUrl());
} else if ("swc".equalsIgnoreCase(child.getExtension()) || "ane".equalsIgnoreCase(child.getExtension())) {
final VirtualFile dir = child.getParent();
result.add(dir);
return skipTo(dir);
}
return CONTINUE;
}
});
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getStringValue.
/**
* Returns the plain String value for the given constant.
*
* @param context Current context.
* @param strutsModel StrutsModel.
* @param name Name of constant.
* @return {@code null} if no value could be resolved.
*/
@Nullable
private static String getStringValue(@NotNull final PsiFile context, @NotNull final StrutsModel strutsModel, @NotNull @NonNls final String name) {
final Project project = context.getProject();
final Module module = ModuleUtilCore.findModuleForPsiElement(context);
assert module != null : context;
// collect all properties with matching key
final List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(project, name);
String value = null;
// 1. default.properties from struts2-core.jar
final IProperty strutsDefaultProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && virtualFile.getFileSystem() instanceof JarFileSystem && StringUtil.endsWith(virtualFile.getPath(), STRUTS_DEFAULT_PROPERTIES) && ModuleUtilCore.moduleContainsFile(module, virtualFile, true);
});
if (strutsDefaultProperty != null) {
value = strutsDefaultProperty.getValue();
}
// 2. <constant> from StrutsModel
final Condition<Constant> constantNameCondition = constant -> Comparing.equal(constant.getName().getStringValue(), name);
final List<DomFileElement<StrutsRoot>> domFileElements = new ArrayList<>();
collectStrutsXmls(domFileElements, strutsModel, "struts-default.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts-plugin.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts.xml", false);
for (final DomFileElement<StrutsRoot> domFileElement : domFileElements) {
final Constant constant = ContainerUtil.find(domFileElement.getRootElement().getConstants(), constantNameCondition);
final String strutsXmlValue = constant != null ? constant.getValue().getStringValue() : null;
if (strutsXmlValue != null) {
value = strutsXmlValue;
}
}
// 3. struts.properties in current module
final IProperty strutsProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && Comparing.equal(virtualFile.getName(), STRUTS_PROPERTIES_FILENAME) && ModuleUtilCore.moduleContainsFile(module, virtualFile, false);
});
if (strutsProperty != null) {
value = strutsProperty.getValue();
}
// 4. web.xml
final WebFacet webFacet = WebUtil.getWebFacet(context);
if (webFacet == null) {
// should not happen in real projects..
return value;
}
final WebApp webApp = webFacet.getRoot();
if (webApp == null) {
// no web.xml
return value;
}
final Filter filter = ContainerUtil.find(webApp.getFilters(), WEB_XML_STRUTS_FILTER_CONDITION);
if (filter != null) {
final ParamValue initParam = ContainerUtil.find(filter.getInitParams(), (Condition<ParamValue>) paramValue -> Comparing.equal(paramValue.getParamName().getStringValue(), name));
if (initParam != null) {
value = initParam.getParamValue().getStringValue();
}
}
return value;
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class ModuleHighlightUtil method getModuleDescriptor.
@Nullable
static PsiJavaModule getModuleDescriptor(@NotNull PsiFileSystemItem fsItem) {
VirtualFile file = fsItem.getVirtualFile();
if (file == null)
return null;
Project project = fsItem.getProject();
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
if (index.isInLibraryClasses(file)) {
VirtualFile classRoot = index.getClassRootForFile(file);
if (classRoot != null) {
VirtualFile descriptorFile = classRoot.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE);
if (descriptorFile == null) {
descriptorFile = classRoot.findFileByRelativePath("META-INF/versions/9/" + PsiJavaModule.MODULE_INFO_CLS_FILE);
}
if (descriptorFile != null) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(descriptorFile);
if (psiFile instanceof PsiJavaFile) {
return ((PsiJavaFile) psiFile).getModuleDeclaration();
}
} else if (classRoot.getFileSystem() instanceof JarFileSystem && "jar".equalsIgnoreCase(classRoot.getExtension())) {
return LightJavaModule.getModule(PsiManager.getInstance(project), classRoot);
}
}
return null;
} else {
return getModuleDescriptor(index.getModuleForFile(file));
}
}
Aggregations