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;
}
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();
}
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());
}
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();
}
}
}
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));
}
}
Aggregations