Java Code Examples for com.intellij.openapi.roots.libraries.Library#getFiles()
The following examples show how to use
com.intellij.openapi.roots.libraries.Library#getFiles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
/** * Creates a URLClassLoader for a given library or libraries * * @param libraries the library or libraries * @return the classloader */ public @Nullable URLClassLoader newURLClassLoaderForLibrary(Library... libraries) throws MalformedURLException { List<URL> urls = new ArrayList<>(); for (Library library : libraries) { if (library != null) { VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); if (files.length == 1) { VirtualFile vf = files[0]; if (vf.getName().toLowerCase().endsWith(".jar")) { String path = vf.getPath(); if (path.endsWith("!/")) { path = path.substring(0, path.length() - 2); } URL url = new URL("file:" + path); urls.add(url); } } } } if (urls.isEmpty()) { return null; } URL[] array = urls.toArray(new URL[urls.size()]); return new URLClassLoader(array); }
Example 2
Source File: AarLibrary.java From intellij with Apache License 2.0 | 6 votes |
/** Get path to res folder according to CLASSES root of modifiable model */ @Nullable public PathString getResFolder(Project project) { Library aarLibrary = ProjectLibraryTable.getInstance(project) .getLibraryByName(this.key.getIntelliJLibraryName()); if (aarLibrary != null) { VirtualFile[] files = aarLibrary.getFiles(OrderRootType.CLASSES); for (VirtualFile file : files) { if (file.isDirectory() && SdkConstants.FD_RES.equals(file.getName())) { return new PathString(file.getPath()); } } } return null; }
Example 3
Source File: BlazeSourceJarNavigationPolicy.java From intellij with Apache License 2.0 | 6 votes |
@Nullable private VirtualFile getSourceJarRoot( Project project, BlazeProjectData blazeProjectData, PsiJavaFile clsFile) { Library library = findLibrary(project, clsFile); if (library == null || library.getFiles(OrderRootType.SOURCES).length != 0) { // If the library already has sources attached, no need to hunt for them. return null; } BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library); if (blazeLibrary == null) { return null; } // TODO: If there are multiple source jars, search for one containing this PsiJavaFile. for (ArtifactLocation jar : blazeLibrary.libraryArtifact.getSourceJars()) { VirtualFile root = getSourceJarRoot(project, blazeProjectData.getArtifactLocationDecoder(), jar); if (root != null) { return root; } } return null; }
Example 4
Source File: PackagingElementFactoryImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<? extends PackagingElement<?>> createLibraryElements(@Nonnull Library library) { final LibraryTable table = library.getTable(); final String libraryName = library.getName(); if (table != null) { return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null)); } if (libraryName != null) { final Module module = ((LibraryImpl)library).getModule(); if (module != null) { return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName())); } } final List<PackagingElement<?>> elements = new ArrayList<>(); for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) { final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)); elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path)); } return elements; }
Example 5
Source File: OrderEntryUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void addLibraryToRoots(@Nonnull Module module, @Nonnull Library library) { final ModuleRootManager manager = ModuleRootManager.getInstance(module); final ModifiableRootModel rootModel = manager.getModifiableModel(); if (library.getTable() == null) { final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary(); final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel(); for (OrderRootType orderRootType : OrderRootType.getAllTypes()) { VirtualFile[] files = library.getFiles(orderRootType); for (VirtualFile jarFile : files) { libraryModel.addRoot(jarFile, orderRootType); } } libraryModel.commit(); } else { rootModel.addLibraryEntry(library); } rootModel.commit(); }
Example 6
Source File: GradleToolDelegate.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private void processLibrary(Library library, ModuleRootManager manager, Set<String> deploymentIds) { VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); if (files.length == 1) { File file = new File(files[0].getCanonicalPath().substring(0, files[0].getCanonicalPath().length() - 2)); String deploymentIdStr = ToolDelegate.getDeploymentJarId(file); if (deploymentIdStr != null && !isDependency(manager, deploymentIdStr)) { deploymentIds.add(deploymentIdStr); } } }
Example 7
Source File: QuarkusModuleUtil.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
public static boolean isQuarkusExtensionWithDeploymentArtifact(Library library) { boolean result = false; VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); for(int i=0; !result && i < files.length;++i) { if (files[i].isDirectory()) { result = ToolDelegate.getDeploymentJarId(VfsUtilCore.virtualToIoFile(files[i])) != null; } } return result; }
Example 8
Source File: LibrariesAction.java From intellij-sdk-docs with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(@NotNull AnActionEvent event) { Project project = event.getProject(); if (project == null) return; Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); if (element instanceof PsiClass) { PsiFile psiFile = ((PsiClass) element).getContainingFile(); if (psiFile == null) return; VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) return; final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); StringBuilder jars = new StringBuilder(); for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { if (orderEntry instanceof LibraryOrderEntry) { final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry; final Library library = libraryEntry.getLibrary(); if (library == null) continue; VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); if (files.length == 0) continue; for (VirtualFile jar : files) { jars.append(jar.getName()).append(", "); } } } String fileAndLibs; if (jars.length() > 0) { fileAndLibs = virtualFile.getName() + ": " + jars.toString(); } else { fileAndLibs = "None"; } Messages.showInfoMessage("Libraries for file: " + fileAndLibs, "Libraries Info"); } }
Example 9
Source File: HaxeLibrary.java From intellij-haxe with Apache License 2.0 | 5 votes |
/** * Test whether this library is effectively the same as a Library appearing * in IDEA's library tables. * * @param lib - Library to test. * @return true if this library uses the same sources as the IDEA library; false otherwise. */ public boolean matchesIdeaLib(Library lib) { if (null == lib) { return false; } HaxeClasspath cp = getClasspathEntries(); VirtualFile[] sources = lib.getFiles(OrderRootType.SOURCES); for (VirtualFile file : sources) { if (!cp.containsUrl(file.getUrl())) { return false; } } return cp.size() == sources.length; }
Example 10
Source File: LibraryPackagingElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public List<? extends PackagingElement<?>> getSubstitution(@Nonnull PackagingElementResolvingContext context, @Nonnull ArtifactType artifactType) { final Library library = findLibrary(context); if (library != null) { final VirtualFile[] files = library.getFiles(BinariesOrderRootType.getInstance()); final List<PackagingElement<?>> elements = new ArrayList<PackagingElement<?>>(); for (VirtualFile file : files) { final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file)); elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path)); } return elements; } return null; }
Example 11
Source File: LibraryPackagingElement.java From consulo with Apache License 2.0 | 5 votes |
public static PackagingElementOutputKind getKindForLibrary(final Library library) { boolean containsDirectories = false; boolean containsJars = false; for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) { if (file.isInLocalFileSystem()) { containsDirectories = true; } else { containsJars = true; } } return new PackagingElementOutputKind(containsDirectories, containsJars); }
Example 12
Source File: LibraryElementPresentation.java From consulo with Apache License 2.0 | 5 votes |
public static String getLibraryItemText(final @Nonnull Library library, final boolean includeTableName) { String name = library.getName(); VirtualFile[] files = library.getFiles(BinariesOrderRootType.getInstance()); if (name != null) { return name + (includeTableName ? getLibraryTableComment(library) : ""); } else if (files.length > 0) { return files[0].getName() + (includeTableName ? getLibraryTableComment(library) : ""); } else { return ProjectBundle.message("library.empty.item"); } }
Example 13
Source File: StructureConfigurableContext.java From consulo with Apache License 2.0 | 5 votes |
public VirtualFile[] getLibraryFiles(Library library, final OrderRootType type) { final LibraryTable table = library.getTable(); if (table != null) { final LibraryTable.ModifiableModel modifiableModel = getModifiableLibraryTable(table); if (modifiableModel instanceof LibrariesModifiableModel) { final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel; if (librariesModel.hasLibraryEditor(library)) { return librariesModel.getLibraryEditor(library).getFiles(type); } } } return library.getFiles(type); }
Example 14
Source File: LibraryScope.java From consulo with Apache License 2.0 | 4 votes |
public LibraryScope(Project project, Library library) { super(project, library.getFiles(BinariesOrderRootType.getInstance()), library.getFiles(SourcesOrderRootType.getInstance())); myLibrary = library; }
Example 15
Source File: LibrariesContainerFactory.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public VirtualFile[] getLibraryFiles(@Nonnull final Library library, @Nonnull final OrderRootType rootType) { return library.getFiles(rootType); }