use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class InternalTestDiscoveryListener method zipOutput.
private static void zipOutput(String tracesDirectory) {
final File[] files = new File(tracesDirectory).listFiles();
if (files == null) {
System.out.println("No traces found.");
return;
}
System.out.println("Preparing zip.");
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(tracesDirectory + File.separator + "out.zip"))) {
for (File file : files) {
ZipUtil.addFileToZip(zipOutputStream, file, "/" + file.getName(), null, null);
}
System.out.println("Zip prepared.");
for (File file : files) {
FileUtil.delete(file);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class ZipUtil method update.
/*
* update an existing jar file. Adds/replace files specified in relpathToFile map
*/
public static void update(InputStream in, OutputStream out, Map<String, File> relpathToFile) throws IOException {
ZipInputStream zis = new ZipInputStream(in);
ZipOutputStream zos = new ZipOutputStream(out);
try {
// put the old entries first, replace if necessary
ZipEntry e;
while ((e = zis.getNextEntry()) != null) {
String name = e.getName();
if (!relpathToFile.containsKey(name)) {
// copy the old stuff
// do our own compression
ZipEntry e2 = new ZipEntry(name);
e2.setMethod(e.getMethod());
e2.setTime(e.getTime());
e2.setComment(e.getComment());
e2.setExtra(e.getExtra());
if (e.getMethod() == ZipEntry.STORED) {
e2.setSize(e.getSize());
e2.setCrc(e.getCrc());
}
zos.putNextEntry(e2);
FileUtil.copy(zis, zos);
} else {
// replace with the new files
final File file = relpathToFile.get(name);
//addFile(file, name, zos);
relpathToFile.remove(name);
addFileToZip(zos, file, name, null, null);
}
}
// add the remaining new files
for (final String path : relpathToFile.keySet()) {
File file = relpathToFile.get(path);
addFileToZip(zos, file, path, null, null);
}
} finally {
zis.close();
zos.close();
}
}
use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class PrepareToDeployAction method processLibrariesAndJpsPlugins.
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<>(), 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<>();
usedJarNames.add(entryName);
Set<VirtualFile> jarredVirtualFiles = new HashSet<>();
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();
}
}
}
use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class PrepareToDeployAction method makeAndAddLibraryJar.
private static void makeAndAddLibraryJar(final VirtualFile virtualFile, final File zipFile, final String pluginName, final ZipOutputStream zos, final Set<String> usedJarNames, final ProgressIndicator progressIndicator, final String preferredName) throws IOException {
File libraryJar = FileUtil.createTempFile(TEMP_PREFIX, JAR_EXTENSION);
libraryJar.deleteOnExit();
ZipOutputStream jar = null;
try {
jar = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(libraryJar)));
ZipUtil.addFileOrDirRecursively(jar, libraryJar, VfsUtilCore.virtualToIoFile(virtualFile), "", createFilter(progressIndicator, FileTypeManager.getInstance()), null);
} finally {
if (jar != null)
jar.close();
}
final String jarName = getLibraryJarName(virtualFile.getName() + JAR_EXTENSION, usedJarNames, preferredName == null ? null : preferredName + JAR_EXTENSION);
ZipUtil.addFileOrDirRecursively(zos, zipFile, libraryJar, getZipPath(pluginName, jarName), createFilter(progressIndicator, null), null);
}
use of java.util.zip.ZipOutputStream in project intellij-community by JetBrains.
the class IoTestUtil method createTestJar.
@NotNull
public static File createTestJar(@NotNull File jarFile, @NotNull File root) {
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile))) {
FileUtil.visitFiles(root, file -> {
if (file.isFile()) {
String path = FileUtil.toSystemIndependentName(ObjectUtils.assertNotNull(FileUtil.getRelativePath(root, file)));
try {
stream.putNextEntry(new ZipEntry(path));
try (InputStream is = new FileInputStream(file)) {
FileUtil.copy(is, stream);
}
stream.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return true;
});
return jarFile;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations