com.intellij.util.io.ZipUtil Java Examples
The following examples show how to use
com.intellij.util.io.ZipUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginDownloader.java From consulo with Apache License 2.0 | 6 votes |
public static void install(final File fromFile, final String pluginName, boolean deleteFromFile) throws IOException { // add command to unzip file to the plugins path String unzipPath; if (ZipUtil.isZipContainsFolder(fromFile)) { unzipPath = ContainerPathManager.get().getInstallPluginsPath(); } else { unzipPath = ContainerPathManager.get().getInstallPluginsPath() + File.separator + pluginName; } StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(fromFile, new File(unzipPath)); StartupActionScriptManager.addActionCommand(unzip); // add command to remove temp plugin file if (deleteFromFile) { StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand(fromFile); StartupActionScriptManager.addActionCommand(deleteTemp); } }
Example #2
Source File: StartupActionScriptManager.java From consulo with Apache License 2.0 | 6 votes |
@Override public void execute(final Logger logger) throws IOException { if (!mySource.exists()) { logger.error("Source file " + mySource.getAbsolutePath() + " does not exist for action " + this); } else if (!canCreateFile(myDestination)) { JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), MessageFormat .format("<html>Cannot unzip {0}<br>to<br>{1}<br>Please, check your access rights on folder <br>{2}", mySource.getAbsolutePath(), myDestination.getAbsolutePath(), myDestination), "Installing Plugin", JOptionPane.ERROR_MESSAGE); } else { try { ZipUtil.extract(mySource, myDestination, myFilenameFilter); } catch (Exception ex) { logger.error(ex); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), MessageFormat .format("<html>Failed to extract ZIP file {0}<br>to<br>{1}<br>You may need to re-download the plugin you tried to install.", mySource.getAbsolutePath(), myDestination.getAbsolutePath()), "Installing Plugin", JOptionPane.ERROR_MESSAGE); } } }
Example #3
Source File: InstalledPluginsManagerMain.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static PluginDescriptor loadDescriptionFromJar(final File file) throws IOException { PluginDescriptor descriptor = null; if (file.getName().endsWith(".zip")) { final File outputDir = FileUtil.createTempDirectory("plugin", ""); try { ZipUtil.extract(file, outputDir, null); final File[] files = outputDir.listFiles(); if (files != null && files.length == 1) { descriptor = PluginsLoader.loadPluginDescriptor(files[0]); } } finally { FileUtil.delete(outputDir); } } return descriptor; }
Example #4
Source File: UnzipNewModuleBuilderProcessor.java From consulo with Apache License 2.0 | 6 votes |
protected void unzip(@Nonnull ModifiableRootModel model) { InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(myPath); if (resourceAsStream == null) { LOG.error("Resource by path '" + myPath + "' not found"); return; } try { File tempFile = FileUtil.createTempFile("template", "zip"); FileUtil.writeToFile(tempFile, FileUtil.loadBytes(resourceAsStream)); final VirtualFile moduleDir = model.getModule().getModuleDir(); File outputDir = VfsUtil.virtualToIoFile(moduleDir); ZipUtil.extract(tempFile, outputDir, null); } catch (IOException e) { LOG.error(e); } }
Example #5
Source File: MuleSdkSelectionDialog.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private void downloadVersionWithProgress(String version, String destinationDir) { Messages.showInfoMessage(contentPane, "Download Is Going to Take Some Time. Good time for a coffee.", "Mule Distribution Download"); final Optional<MuleUrl> first = MuleUrl.getVERSIONS().stream().filter((url) -> url.getName().equals(version)).findFirst(); final MuleUrl muleUrl = first.get(); try { final ProgressManager instance = ProgressManager.getInstance(); final File distro = instance.runProcessWithProgressSynchronously(() -> { final URL artifactUrl = new URL(muleUrl.getUrl()); final File sourceFile = FileUtil.createTempFile("mule" + version, ".zip"); if (download(instance.getProgressIndicator(), artifactUrl, sourceFile, version)) { final File destDir = new File(destinationDir); destDir.mkdirs(); ZipUtil.extract(sourceFile, destDir, null); try (ZipFile zipFile = new ZipFile(sourceFile)) { String rootName = zipFile.entries().nextElement().getName(); return new File(destDir, rootName); } } else { return null; } }, "Downloading Mule Distribution " + muleUrl.getName(), true, null); if (distro != null) { final MuleSdk muleSdk = new MuleSdk(distro.getAbsolutePath()); MuleSdkManagerImpl.getInstance().addSdk(muleSdk); myTableModel.addRow(muleSdk); final int rowIndex = myTableModel.getRowCount() - 1; myInputsTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex); onOK(); } } catch (Exception e) { Messages.showErrorDialog("An error occurred while trying to download " + version + ".\n" + e.getMessage(), "Mule SDK Download Error"); } }
Example #6
Source File: UnpackedAars.java From intellij with Apache License 2.0 | 5 votes |
private void copyLocally(FileOperationProvider ops, AarAndJar aarAndJar) { String cacheKey = cacheKeyForAar(aarAndJar.aar); File aarDir = aarDirForKey(cacheKey); try { if (ops.exists(aarDir)) { ops.deleteRecursively(aarDir, true); } ops.mkdirs(aarDir); // TODO(brendandouglas): decompress via ZipInputStream so we don't require a local file File toCopy = getOrCreateLocalFile(aarAndJar.aar); ZipUtil.extract( toCopy, aarDir, // Skip jars. The merged jar will be synchronized by JarTraits. (dir, name) -> !name.endsWith(".jar")); createStampFile(ops, aarDir, aarAndJar.aar); // copy merged jar if (aarAndJar.jar != null) { try (InputStream stream = aarAndJar.jar.getInputStream()) { Path destination = Paths.get(jarFileForKey(cacheKey).getPath()); ops.mkdirs(destination.getParent().toFile()); Files.copy(stream, destination, StandardCopyOption.REPLACE_EXISTING); } } } catch (IOException e) { logger.warn(String.format("Failed to extract AAR %s to %s", aarAndJar.aar, aarDir), e); } }
Example #7
Source File: ShopwareInstallerProjectGenerator.java From idea-php-shopware-plugin with MIT License | 5 votes |
@Override public void generateProject(@NotNull final Project project, final @NotNull VirtualFile baseDir, final @NotNull ShopwareInstallerSettings settings, @NotNull Module module) { String downloadPath = settings.getVersion().getUrl(); String toDir = baseDir.getPath(); VirtualFile zipFile = PhpConfigurationUtil.downloadFile(project, null, toDir, downloadPath, "shopware.zip"); if (zipFile == null) { showErrorNotification(project, "Cannot download Shopware.zip file"); return; } // Convert files File zip = VfsUtil.virtualToIoFile(zipFile); File base = VfsUtil.virtualToIoFile(baseDir); Task.Backgroundable task = new Task.Backgroundable(project, "Extracting", true) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { try { // unzip file ZipUtil.extract(zip, base, null); // Delete TMP File FileUtil.delete(zip); // Activate Plugin IdeHelper.enablePluginAndConfigure(project); } catch (IOException e) { showErrorNotification(project, "There is a error occurred"); } } }; ProgressManager.getInstance().run(task); }
Example #8
Source File: PlatformTestUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void assertJarFilesEqual(File file1, File file2) throws IOException { final File tempDirectory1; final File tempDirectory2; final JarFile jarFile1 = new JarFile(file1); try { final JarFile jarFile2 = new JarFile(file2); try { tempDirectory1 = PlatformTestCase.createTempDir("tmp1"); tempDirectory2 = PlatformTestCase.createTempDir("tmp2"); ZipUtil.extract(jarFile1, tempDirectory1, null); ZipUtil.extract(jarFile2, tempDirectory2, null); } finally { jarFile2.close(); } } finally { jarFile1.close(); } final VirtualFile dirAfter = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory1); assertNotNull(tempDirectory1.toString(), dirAfter); final VirtualFile dirBefore = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory2); assertNotNull(tempDirectory2.toString(), dirBefore); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { dirAfter.refresh(false, true); dirBefore.refresh(false, true); } }); assertDirectoriesEqual(dirAfter, dirBefore); }
Example #9
Source File: ExportSettingsAction.java From consulo with Apache License 2.0 | 5 votes |
private static void exportInstalledPlugins(File saveFile, ZipOutputStream output, HashSet<String> writtenItemRelativePaths) throws IOException { final Set<String> oldPlugins = new LinkedHashSet<>(); for (PluginDescriptor descriptor : consulo.container.plugin.PluginManager.getPlugins()) { if (!PluginIds.isPlatformPlugin(descriptor.getPluginId()) && descriptor.isEnabled()) { oldPlugins.add(descriptor.getPluginId().getIdString()); } } if (!oldPlugins.isEmpty()) { final File tempFile = File.createTempFile("installed", "plugins"); tempFile.deleteOnExit(); Files.write(tempFile.toPath(), oldPlugins, StandardCharsets.UTF_8); ZipUtil.addDirToZipRecursively(output, saveFile, tempFile, "/" + PluginManager.INSTALLED_TXT, null, writtenItemRelativePaths); } }
Example #10
Source File: MemoryDumpHelper.java From consulo with Apache License 2.0 | 5 votes |
public static synchronized void captureMemoryDumpZipped(@Nonnull String zipPath) throws Exception { File tempFile = FileUtil.createTempFile("heapDump.", ".hprof"); FileUtil.delete(tempFile); captureMemoryDump(tempFile.getPath()); ZipUtil.compressFile(tempFile, new File(zipPath)); FileUtil.delete(tempFile); }