Search in sources :

Example 26 with Library

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

the class ModuleProjectStructureElement method getUsagesInElement.

@Override
public List<ProjectStructureElementUsage> getUsagesInElement() {
    final List<ProjectStructureElementUsage> usages = new ArrayList<>();
    final ModuleEditor moduleEditor = myContext.getModulesConfigurator().getModuleEditor(myModule);
    if (moduleEditor != null) {
        for (OrderEntry entry : moduleEditor.getOrderEntries()) {
            if (entry instanceof ModuleOrderEntry) {
                ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) entry;
                final Module module = moduleOrderEntry.getModule();
                if (module != null) {
                    usages.add(new UsageInModuleClasspath(myContext, this, new ModuleProjectStructureElement(myContext, module), moduleOrderEntry.getScope()));
                }
            } else if (entry instanceof LibraryOrderEntry) {
                LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
                final Library library = libraryOrderEntry.getLibrary();
                if (library != null) {
                    usages.add(new UsageInModuleClasspath(myContext, this, new LibraryProjectStructureElement(myContext, library), libraryOrderEntry.getScope()));
                }
            } else if (entry instanceof JdkOrderEntry) {
                final Sdk jdk = ((JdkOrderEntry) entry).getJdk();
                if (jdk != null) {
                    usages.add(new UsageInModuleClasspath(myContext, this, new SdkProjectStructureElement(myContext, jdk), null));
                }
            }
        }
    }
    return usages;
}
Also used : ArrayList(java.util.ArrayList) ModuleEditor(com.intellij.openapi.roots.ui.configuration.ModuleEditor) Library(com.intellij.openapi.roots.libraries.Library) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 27 with Library

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

the class ClsGenericsHighlightingTest method commitLibraryModel.

protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) {
    LibraryTable libraryTable = model.getModuleLibraryTable();
    Library library = libraryTable.createLibrary("test");
    Library.ModifiableModel libraryModel = library.getModifiableModel();
    for (String annotationsDir : libraryPath) {
        String path = testDataPath + "/libs/" + annotationsDir;
        VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
        assertNotNull(libJarLocal);
        VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
        assertNotNull(jarRoot);
        libraryModel.addRoot(jarRoot, jarRoot.getName().contains("-sources") ? OrderRootType.SOURCES : OrderRootType.CLASSES);
    }
    libraryModel.commit();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 28 with Library

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

the class PrepareToDeployAction method doPrepare.

public static boolean doPrepare(final Module module, final List<String> errorMessages, final List<String> successMessages) {
    final String pluginName = module.getName();
    final String defaultPath = new File(module.getModuleFilePath()).getParent() + File.separator + pluginName;
    final HashSet<Module> modules = new HashSet<>();
    PluginBuildUtil.getDependencies(module, modules);
    modules.add(module);
    final Set<Library> libs = new HashSet<>();
    for (Module dep : modules) {
        PluginBuildUtil.getLibraries(dep, libs);
    }
    final Map<Module, String> jpsModules = collectJpsPluginModules(module);
    modules.removeAll(jpsModules.keySet());
    final boolean isZip = !libs.isEmpty() || !jpsModules.isEmpty();
    final String oldPath = defaultPath + (isZip ? JAR_EXTENSION : ZIP_EXTENSION);
    final File oldFile = new File(oldPath);
    if (oldFile.exists()) {
        if (Messages.showYesNoDialog(module.getProject(), DevKitBundle.message("suggest.to.delete", oldPath), DevKitBundle.message("info.message"), Messages.getInformationIcon()) == Messages.YES) {
            FileUtil.delete(oldFile);
        }
    }
    final String dstPath = defaultPath + (isZip ? ZIP_EXTENSION : JAR_EXTENSION);
    final File dstFile = new File(dstPath);
    return clearReadOnly(module.getProject(), dstFile) && ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        if (progressIndicator != null) {
            progressIndicator.setText(DevKitBundle.message("prepare.for.deployment.common"));
            progressIndicator.setIndeterminate(true);
        }
        try {
            File jarFile = preparePluginsJar(module, modules);
            if (isZip) {
                processLibrariesAndJpsPlugins(jarFile, dstFile, pluginName, libs, jpsModules, progressIndicator);
            } else {
                FileUtil.copy(jarFile, dstFile);
            }
            LocalFileSystem.getInstance().refreshIoFiles(Collections.singleton(dstFile), true, false, null);
            successMessages.add(DevKitBundle.message("saved.message", isZip ? 1 : 2, pluginName, dstPath));
        } catch (final IOException e) {
            errorMessages.add(e.getMessage() + "\n(" + dstPath + ")");
        }
    }, DevKitBundle.message("prepare.for.deployment", pluginName), true, module.getProject());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile)

Example 29 with Library

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

the class PrepareToDeployAction method processLibrariesAndJpsPlugins.

private static void processLibrariesAndJpsPlugins(final File jarFile, final File zipFile, final String pluginName, final Set<Library> libs, Map<Module, String> jpsModules, final ProgressIndicator progressIndicator) throws IOException {
    if (FileUtil.ensureCanCreateFile(zipFile)) {
        ZipOutputStream zos = null;
        try {
            zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
            addStructure(pluginName, zos);
            addStructure(pluginName + "/" + MIDDLE_LIB_DIR, zos);
            final String entryName = pluginName + JAR_EXTENSION;
            ZipUtil.addFileToZip(zos, jarFile, getZipPath(pluginName, entryName), new HashSet<>(), createFilter(progressIndicator, FileTypeManager.getInstance()));
            for (Map.Entry<Module, String> entry : jpsModules.entrySet()) {
                File jpsPluginJar = jarModulesOutput(Collections.singleton(entry.getKey()), null, null);
                ZipUtil.addFileToZip(zos, jpsPluginJar, getZipPath(pluginName, entry.getValue()), null, null);
            }
            Set<String> usedJarNames = new HashSet<>();
            usedJarNames.add(entryName);
            Set<VirtualFile> jarredVirtualFiles = new HashSet<>();
            for (Library library : libs) {
                final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
                for (VirtualFile virtualFile : files) {
                    if (jarredVirtualFiles.add(virtualFile)) {
                        if (virtualFile.getFileSystem() instanceof JarFileSystem) {
                            addLibraryJar(virtualFile, zipFile, pluginName, zos, usedJarNames, progressIndicator);
                        } else {
                            makeAndAddLibraryJar(virtualFile, zipFile, pluginName, zos, usedJarNames, progressIndicator, library.getName());
                        }
                    }
                }
            }
        } finally {
            if (zos != null)
                zos.close();
        }
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile)

Example 30 with Library

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

the class ChunkBuildPluginExtension method process.

public void process(Project project, ModuleChunk chunk, GenerationOptions genOptions, CompositeGenerator generator) {
    final Module[] modules = chunk.getModules();
    if (isPlugins(modules)) {
        final BuildTargetsFactory factory = BuildTargetsFactory.getInstance();
        final Module module = modules[0];
        PluginBuildConfiguration buildProperties = PluginBuildConfiguration.getInstance(module);
        final Set<Library> libs = new HashSet<>();
        PluginBuildUtil.getLibraries(module, libs);
        @NonNls String jarPath = chunk.getBaseDir().getPath() + "/" + chunk.getName();
        if (libs.isEmpty()) {
            jarPath += ".jar";
        } else {
            jarPath += ".zip";
        }
        generator.add(new Property(PluginBuildProperties.getJarPathProperty(chunk.getName()), GenerationUtils.toRelativePath(jarPath, chunk, genOptions)), 1);
        generator.add(factory.createComment(DevKitBundle.message("ant.build.jar.comment", chunk.getName())), 1);
        generator.add(new BuildJarTarget(chunk, genOptions, buildProperties));
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PluginBuildConfiguration(org.jetbrains.idea.devkit.build.PluginBuildConfiguration) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Property(com.intellij.compiler.ant.taskdefs.Property) HashSet(java.util.HashSet)

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