Java Code Examples for com.intellij.util.io.ZipUtil#extract()

The following examples show how to use com.intellij.util.io.ZipUtil#extract() . 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: StartupActionScriptManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: InstalledPluginsManagerMain.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: UnzipNewModuleBuilderProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 4
Source File: UnpackedAars.java    From intellij with Apache License 2.0 5 votes vote down vote up
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 5
Source File: ShopwareInstallerProjectGenerator.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@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 6
Source File: PlatformTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
}