private static File jarModulesOutput( @NotNull Set<Module> modules, @Nullable Manifest manifest, final @Nullable String pluginXmlPath) throws IOException { File jarFile = FileUtil.createTempFile(TEMP_PREFIX, JAR_EXTENSION); jarFile.deleteOnExit(); ZipOutputStream jarPlugin = null; try { BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(jarFile)); jarPlugin = manifest != null ? new JarOutputStream(out, manifest) : new JarOutputStream(out); final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); final Set<String> writtenItemRelativePaths = new HashSet<String>(); for (Module module : modules) { final VirtualFile compilerOutputPath = CompilerModuleExtension.getInstance(module).getCompilerOutputPath(); if (compilerOutputPath == null) continue; // pre-condition: output dirs for all modules are up-to-date ZipUtil.addDirToZipRecursively( jarPlugin, jarFile, new File(compilerOutputPath.getPath()), "", createFilter(progressIndicator, FileTypeManager.getInstance()), writtenItemRelativePaths); } if (pluginXmlPath != null) { ZipUtil.addFileToZip( jarPlugin, new File(pluginXmlPath), "/META-INF/plugin.xml", writtenItemRelativePaths, createFilter(progressIndicator, null)); } } finally { if (jarPlugin != null) jarPlugin.close(); } return jarFile; }
private static void makeAndAddLibraryJar( final VirtualFile virtualFile, final File zipFile, final String pluginName, final ZipOutputStream zos, final Set<String> usedJarNames, final ProgressIndicator progressIndicator, final String preferredName) throws IOException { File libraryJar = FileUtil.createTempFile(TEMP_PREFIX, JAR_EXTENSION); libraryJar.deleteOnExit(); ZipOutputStream jar = null; try { jar = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(libraryJar))); ZipUtil.addFileOrDirRecursively( jar, libraryJar, VfsUtilCore.virtualToIoFile(virtualFile), "", createFilter(progressIndicator, FileTypeManager.getInstance()), null); } finally { if (jar != null) jar.close(); } final String jarName = getLibraryJarName( virtualFile.getName() + JAR_EXTENSION, usedJarNames, preferredName == null ? null : preferredName + JAR_EXTENSION); ZipUtil.addFileOrDirRecursively( zos, zipFile, libraryJar, getZipPath(pluginName, jarName), createFilter(progressIndicator, null), null); }