Search in sources :

Example 1 with JBZipEntry

use of com.intellij.util.io.zip.JBZipEntry in project intellij-community by JetBrains.

the class WorkingContextManager method pack.

private synchronized void pack(int max, int delta, String zipPostfix) {
    JBZipFile archive = null;
    try {
        archive = getTasksArchive(zipPostfix);
        List<JBZipEntry> entries = archive.getEntries();
        if (entries.size() > max + delta) {
            JBZipEntry[] array = entries.toArray(new JBZipEntry[entries.size()]);
            Arrays.sort(array, ENTRY_COMPARATOR);
            for (int i = array.length - 1; i >= max; i--) {
                archive.eraseEntry(array[i]);
            }
        }
    } catch (IOException e) {
        LOG.error(e);
    } finally {
        closeArchive(archive);
    }
}
Also used : JBZipFile(com.intellij.util.io.zip.JBZipFile) IOException(java.io.IOException) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 2 with JBZipEntry

use of com.intellij.util.io.zip.JBZipEntry in project intellij-community by JetBrains.

the class WorkingContextManager method removeContext.

private void removeContext(String name, String postfix) {
    JBZipFile archive = null;
    try {
        archive = getTasksArchive(postfix);
        JBZipEntry entry = archive.getEntry(name);
        if (entry != null) {
            archive.eraseEntry(entry);
        }
    } catch (IOException e) {
        LOG.error(e);
    } finally {
        closeArchive(archive);
    }
}
Also used : JBZipFile(com.intellij.util.io.zip.JBZipFile) IOException(java.io.IOException) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 3 with JBZipEntry

use of com.intellij.util.io.zip.JBZipEntry in project intellij-community by JetBrains.

the class WorkingContextManager method getContextHistory.

private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
    JBZipFile archive = null;
    try {
        archive = getTasksArchive(zipPostfix);
        List<JBZipEntry> entries = archive.getEntries();
        return ContainerUtil.mapNotNull(entries, (NullableFunction<JBZipEntry, ContextInfo>) entry -> entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null);
    } catch (IOException e) {
        LOG.error(e);
        return Collections.emptyList();
    } finally {
        closeArchive(archive);
    }
}
Also used : Arrays(java.util.Arrays) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) PathManager(com.intellij.openapi.application.PathManager) NonNls(org.jetbrains.annotations.NonNls) XMLOutputter(org.jdom.output.XMLOutputter) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBZipFile(com.intellij.util.io.zip.JBZipFile) JBZipEntry(com.intellij.util.io.zip.JBZipEntry) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Notifications(com.intellij.notification.Notifications) Extensions(com.intellij.openapi.extensions.Extensions) StringUtil(com.intellij.openapi.util.text.StringUtil) NullableFunction(com.intellij.util.NullableFunction) IOException(java.io.IOException) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) Task(com.intellij.tasks.Task) TestOnly(org.jetbrains.annotations.TestOnly) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) JdomKt(com.intellij.util.JdomKt) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Element(org.jdom.Element) Collections(java.util.Collections) JBZipFile(com.intellij.util.io.zip.JBZipFile) IOException(java.io.IOException) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 4 with JBZipEntry

use of com.intellij.util.io.zip.JBZipEntry in project intellij-community by JetBrains.

the class PackageFileWorker method packFile.

private void packFile(String archivePath, String pathInArchive, List<CompositePackagingElement<?>> parents) throws IOException {
    final File archiveFile = new File(archivePath);
    if (parents.isEmpty()) {
        LOG.debug("  adding to archive " + archivePath);
        JBZipFile file = getOrCreateZipFile(archiveFile);
        try {
            final String fullPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, myRelativeOutputPath));
            final JBZipEntry entry = file.getOrCreateEntry(fullPathInArchive);
            entry.setData(FileUtil.loadFileBytes(myFile));
        } finally {
            file.close();
        }
        return;
    }
    final CompositePackagingElement<?> element = parents.get(0);
    final String nextPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, element.getName()));
    final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
    if (element instanceof ArchivePackagingElement) {
        JBZipFile zipFile = getOrCreateZipFile(archiveFile);
        try {
            final JBZipEntry entry = zipFile.getOrCreateEntry(nextPathInArchive);
            LOG.debug("  extracting to temp file: " + nextPathInArchive + " from " + archivePath);
            final File tempFile = FileUtil.createTempFile("packageFile" + FileUtil.sanitizeFileName(nextPathInArchive), FileUtilRt.getExtension(PathUtil.getFileName(nextPathInArchive)));
            if (entry.getSize() != -1) {
                FileUtil.writeToFile(tempFile, entry.getData());
            }
            packFile(FileUtil.toSystemIndependentName(tempFile.getAbsolutePath()), "", parentsTrail);
            entry.setData(FileUtil.loadFileBytes(tempFile));
            FileUtil.delete(tempFile);
        } finally {
            zipFile.close();
        }
    } else {
        packFile(archivePath, nextPathInArchive, parentsTrail);
    }
}
Also used : CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) JBZipFile(com.intellij.util.io.zip.JBZipFile) ArchivePackagingElement(com.intellij.packaging.impl.elements.ArchivePackagingElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 5 with JBZipEntry

use of com.intellij.util.io.zip.JBZipEntry in project intellij-community by JetBrains.

the class ReorderJarsTest method testPluginXml.

@Test
public void testPluginXml() throws Exception {
    String path = getTestDataPath() + "/ide/plugins/reorderJars";
    ReorderJarsMain.main(new String[] { path + "/zkmOrder.txt", path, myTempDirectory.getPath() });
    File[] files = myTempDirectory.listFiles();
    assertNotNull(files);
    File file = files[0];
    assertEquals("zkm.jar", file.getName());
    JBZipFile zipFile = new JBZipFile(file);
    try {
        List<JBZipEntry> entries = zipFile.getEntries();
        System.out.println(entries);
        assertEquals(JarMemoryLoader.SIZE_ENTRY, entries.get(0).getName());
        assertEquals("META-INF/plugin.xml", entries.get(1).getName());
    } finally {
        zipFile.close();
    }
}
Also used : JBZipFile(com.intellij.util.io.zip.JBZipFile) JBZipFile(com.intellij.util.io.zip.JBZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) JBZipEntry(com.intellij.util.io.zip.JBZipEntry) Test(org.junit.Test)

Aggregations

JBZipEntry (com.intellij.util.io.zip.JBZipEntry)8 JBZipFile (com.intellij.util.io.zip.JBZipFile)8 IOException (java.io.IOException)5 File (java.io.File)4 InvalidDataException (com.intellij.openapi.util.InvalidDataException)2 WriteExternalException (com.intellij.openapi.util.WriteExternalException)2 ZipFile (java.util.zip.ZipFile)2 Element (org.jdom.Element)2 XMLOutputter (org.jdom.output.XMLOutputter)2 Test (org.junit.Test)2 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 PathManager (com.intellij.openapi.application.PathManager)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Extensions (com.intellij.openapi.extensions.Extensions)1 Project (com.intellij.openapi.project.Project)1 FileUtil (com.intellij.openapi.util.io.FileUtil)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1