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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations