// TODO: needs to be generalized someday for other profiles private static boolean isValidFilename(final String filename) { if (filename.contains("/") || filename.contains("\\") || filename.contains(":")) { return false; } final File tempFile = new File(FileUtil.getTempDirectory() + File.separator + filename); return FileUtil.ensureCanCreateFile(tempFile); }
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(); } } }
public static void savePluginsList(Collection<String> ids, boolean append, File plugins) throws IOException { if (!plugins.isFile()) { FileUtil.ensureCanCreateFile(plugins); } PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(plugins, append))); try { for (String id : ids) { printWriter.println(id); } printWriter.flush(); } finally { printWriter.close(); } }
@SuppressWarnings("UseOfSystemOutOrSystemErr") private static synchronized void printOrder(Loader loader, String url, Resource resource) { if (!ourDumpOrder) return; if (!ourOrderedUrls.add(url)) return; String home = FileUtil.toSystemIndependentName(PathManager.getHomePath()); try { ourOrderSize += resource.getContentLength(); } catch (IOException e) { e.printStackTrace(System.out); } if (ourOrder == null) { final File orderFile = new File(PathManager.getBinPath() + File.separator + "order.txt"); try { if (!FileUtil.ensureCanCreateFile(orderFile)) return; ourOrder = new PrintStream(new FileOutputStream(orderFile, true)); ShutDownTracker.getInstance() .registerShutdownTask( new Runnable() { public void run() { ourOrder.close(); System.out.println(ourOrderSize); } }); } catch (IOException e) { return; } } if (ourOrder != null) { String jarURL = FileUtil.toSystemIndependentName(loader.getBaseURL().getFile()); jarURL = StringUtil.trimStart(jarURL, "file:/"); if (jarURL.startsWith(home)) { jarURL = jarURL.replaceFirst(home, ""); jarURL = StringUtil.trimEnd(jarURL, "!/"); ourOrder.println(url + ":" + jarURL); } } }