Search in sources :

Example 16 with Library

use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.

the class JarFromModulesTemplate method addLibraries.

private void addLibraries(Set<Library> libraries, ArtifactRootElement<?> root, CompositePackagingElement<?> archive, List<String> classpath) {
    PackagingElementFactory factory = PackagingElementFactory.getInstance();
    for (Library library : libraries) {
        if (LibraryPackagingElement.getKindForLibrary(library).containsDirectoriesWithClasses()) {
            for (VirtualFile classesRoot : library.getFiles(OrderRootType.CLASSES)) {
                if (classesRoot.isInLocalFileSystem()) {
                    archive.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(classesRoot.getPath(), "/"));
                } else {
                    final PackagingElement<?> child = factory.createFileCopyWithParentDirectories(PathUtil.getLocalFile(classesRoot).getPath(), "/");
                    root.addOrFindChild(child);
                    classpath.addAll(ManifestFileUtil.getClasspathForElements(Collections.singletonList(child), myContext, PlainArtifactType.getInstance()));
                }
            }
        } else {
            final List<? extends PackagingElement<?>> children = factory.createLibraryElements(library);
            classpath.addAll(ManifestFileUtil.getClasspathForElements(children, myContext, PlainArtifactType.getInstance()));
            root.addOrFindChildren(children);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Library(com.intellij.openapi.roots.libraries.Library)

Example 17 with Library

use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.

the class LibraryElementType method chooseAndCreate.

@NotNull
public List<? extends LibraryPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
    final List<Library> selected = context.chooseLibraries(ProjectBundle.message("dialog.title.packaging.choose.library"));
    final List<LibraryPackagingElement> elements = new ArrayList<>();
    for (Library library : selected) {
        elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName(), null));
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with Library

use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.

the class LibraryPackagingElement method getSubstitution.

public List<? extends PackagingElement<?>> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) {
    final Library library = findLibrary(context);
    if (library != null) {
        final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
        final List<PackagingElement<?>> elements = new ArrayList<>();
        for (VirtualFile file : files) {
            String localPath = PathUtil.getLocalPath(file);
            if (localPath != null) {
                final String path = FileUtil.toSystemIndependentName(localPath);
                elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
            }
        }
        return elements;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) ComplexPackagingElement(com.intellij.packaging.elements.ComplexPackagingElement) Library(com.intellij.openapi.roots.libraries.Library)

Example 19 with Library

use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.

the class LibraryDefinitionsGeneratorFactory method create.

/**
   * Create a generator for the specified libary type. It generates a list of library definitions.
   *
   * @param libraryTable a library table to examine
   * @param baseDir      base directory for ant build script
   * @param comment      a comment to use for the library
   * @return the created generator or null if there is a nothing to generate
   */
@Nullable
public Generator create(LibraryTable libraryTable, File baseDir, final String comment) {
    final Library[] libraries = libraryTable.getLibraries();
    if (libraries.length == 0) {
        return null;
    }
    final CompositeGenerator gen = new CompositeGenerator();
    gen.add(new Comment(comment), 1);
    // sort libraries to ensure stable order of them.
    TreeMap<String, Library> sortedLibs = new TreeMap<>();
    for (final Library library : libraries) {
        final String libraryName = library.getName();
        if (!myUsedLibraries.contains(libraryName)) {
            continue;
        }
        sortedLibs.put(BuildProperties.getLibraryPathId(libraryName), library);
    }
    for (final Library library : sortedLibs.values()) {
        final String libraryName = library.getName();
        final Path libraryPath = new Path(BuildProperties.getLibraryPathId(libraryName));
        genLibraryContent(myProject, myGenOptions, library, baseDir, libraryPath);
        gen.add(libraryPath, 1);
    }
    return gen.getGeneratorCount() > 0 ? gen : null;
}
Also used : Path(com.intellij.compiler.ant.taskdefs.Path) Library(com.intellij.openapi.roots.libraries.Library) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with Library

use of com.intellij.openapi.roots.libraries.Library in project azure-tools-for-java by Microsoft.

the class SparkLibraryOptionsPanel method calculateSuitableLibraries.

private List<Library> calculateSuitableLibraries() {
    ArrayList suitableLibraries = new ArrayList();
    Library[] libraries = this.librariesContainer.getAllLibraries();
    for (int i = 0; i < libraries.length; ++i) {
        Library library = libraries[i];
        PersistentLibraryKind type = ((LibraryEx) library).getKind();
        if (type != null && type instanceof SparkLibraryKind) {
            suitableLibraries.add(library);
        }
    }
    return suitableLibraries;
}
Also used : PersistentLibraryKind(com.intellij.openapi.roots.libraries.PersistentLibraryKind) ArrayList(java.util.ArrayList) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)266 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Module (com.intellij.openapi.module.Module)43 NotNull (org.jetbrains.annotations.NotNull)32 File (java.io.File)31 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)28 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)27 Project (com.intellij.openapi.project.Project)25 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)25 Nullable (org.jetbrains.annotations.Nullable)25 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)19 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)12 THashSet (gnu.trove.THashSet)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 Result (com.intellij.openapi.application.Result)7 Logger (com.intellij.openapi.diagnostic.Logger)7