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<String>(),
           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<String>();
       usedJarNames.add(entryName);
       Set<VirtualFile> jarredVirtualFiles = new HashSet<VirtualFile>();
       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();
     }
   }
 }
 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;
 }