Java Code Examples for org.zeroturnaround.zip.ZipUtil#pack()
The following examples show how to use
org.zeroturnaround.zip.ZipUtil#pack() .
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: MySQLDatabaseExport.java From olca-app with Mozilla Public License 2.0 | 6 votes |
@Override public void run() { try { IDatabase sourceDb = config.createInstance(); DerbyDatabase targetDb = createTemporaryDb(); DatabaseImport io = new DatabaseImport(sourceDb, targetDb); io.run(); sourceDb.close(); targetDb.close(); ZipUtil.pack(targetDb.getDatabaseDirectory(), zolcaFile); FileUtils.deleteDirectory(targetDb.getDatabaseDirectory()); success = true; } catch (Exception e) { success = false; log.error("failed export MySQL database as zolca-File", e); } }
Example 2
Source File: DbExportAction.java From olca-app with Mozilla Public License 2.0 | 6 votes |
private void realExport(IDatabaseConfiguration config, File zip, boolean active) { try { if (active) Database.close(); if (config instanceof DerbyConfiguration) { File folder = DatabaseDir.getRootFolder(config.getName()); ZipEntrySource[] toPack = collectFileSources(folder); ZipUtil.pack(toPack, zip); } else if (config instanceof MySQLConfiguration) { MySQLDatabaseExport export = new MySQLDatabaseExport((MySQLConfiguration) config, zip); export.run(); } } catch (Exception e) { log.error("Export failed " + zip, e); } }
Example 3
Source File: DefaultPackageWriter.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@Override public File write(Package pkg, File targetDirectory) { PackageMetadata packageMetadata = pkg.getMetadata(); File tmpDir = TempFileUtils.createTempDirectory("skipper" + packageMetadata.getName()).toFile(); File rootPackageDir = new File(tmpDir, String.format("%s-%s", packageMetadata.getName(), packageMetadata.getVersion())); rootPackageDir.mkdir(); writePackage(pkg, rootPackageDir); if (!pkg.getDependencies().isEmpty()) { File packagesDir = new File(rootPackageDir, "packages"); packagesDir.mkdir(); for (Package dependencyPkg : pkg.getDependencies()) { File packageDir = new File(packagesDir, dependencyPkg.getMetadata().getName()); packageDir.mkdir(); writePackage(dependencyPkg, packageDir); } } File targetZipFile = PackageFileUtils.calculatePackageZipFile(pkg.getMetadata(), targetDirectory); ZipUtil.pack(rootPackageDir, targetZipFile, true); FileSystemUtils.deleteRecursively(tmpDir); return targetZipFile; }
Example 4
Source File: MSDeployArtifactHandlerImpl.java From azure-gradle-plugins with MIT License | 6 votes |
private File createZipPackage() throws Exception { logInfo(""); logInfo(CREATE_ZIP_START); final String stageDirectoryPath = functionsTask.getDeploymentStageDirectory(); final File stageDirectory = new File(stageDirectoryPath); final File zipPackage = new File(stageDirectoryPath.concat(ZIP_EXT)); if (!stageDirectory.exists()) { String errorMessage = String.format(STAGE_DIR_NOT_FOUND, stageDirectoryPath); logError(STAGE_DIR_NOT_FOUND); throw new Exception(STAGE_DIR_NOT_FOUND); } ZipUtil.pack(stageDirectory, zipPackage); logDebug(REMOVE_LOCAL_SETTINGS); ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE); logInfo(CREATE_ZIP_DONE + stageDirectoryPath.concat(ZIP_EXT)); return zipPackage; }
Example 5
Source File: ArchiveService.java From difido-reports with Apache License 2.0 | 6 votes |
/** * Archive to ZIP the HTML reports folder of the specified execution. * * @param metadata * @return Path to temporary file contains the archived HTML reports or null * if problem occurred */ public java.nio.file.Path archiveReports(final ExecutionMetadata metadata) { final File source = getExecutionFolder(metadata); if (!source.exists()) { log.error("Report folder of execution " + metadata.getId() + " was not found"); return null; } File destination = null; try { destination = File.createTempFile("execution" + metadata.getId() + "_", ".zip"); } catch (IOException e) { log.error("Failed to create temp file", e); return null; } ZipUtil.pack(source, destination); log.debug("Temporary file with report of execution " + metadata.getId() + " was created in " + destination.getAbsolutePath()); final java.nio.file.Path destinationPath = destination.toPath(); return destinationPath; }
Example 6
Source File: ZipArtifactHandlerImpl.java From azure-gradle-plugins with MIT License | 5 votes |
protected File getZipFile() { final String stagingDirectoryPath = getDeploymentStagingDirectoryPath(); final File zipFile = new File(stagingDirectoryPath + ".zip"); final File stagingDirectory = new File(stagingDirectoryPath); ZipUtil.pack(stagingDirectory, zipFile); return zipFile; }
Example 7
Source File: UploadContentService.java From zest-writer with GNU General Public License v3.0 | 5 votes |
@Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { if (MainApp.getZdsutils().isAuthenticated() && result.isPresent()) { String targetId = result.get().getValue().getId(); String targetSlug = result.get().getValue().getSlug(); String pathDir = content.getFilePath (); updateMessage(Configuration.getBundle().getString("ui.task.zip.label")+" : "+targetSlug+" "+Configuration.getBundle().getString("ui.task.pending.label")+" ..."); ZipUtil.pack(new File(pathDir), new File(pathDir + ".zip")); updateMessage(Configuration.getBundle().getString("ui.task.import.label")+" : "+targetSlug+" "+Configuration.getBundle().getString("ui.task.pending.label")+" ..."); if(result.get().getValue().getType() == null) { if(!MainApp.getZdsutils().importNewContent(pathDir+ ".zip", result.get().getKey())) { throw new IOException(); } } else { if(!MainApp.getZdsutils().importContent(pathDir + ".zip", targetId, targetSlug, result.get().getKey())) { throw new IOException(); } } updateMessage(Configuration.getBundle().getString("ui.task.content.sync")+" ..."); try { MainApp.getZdsutils().getContentListOnline().clear(); MainApp.getZdsutils().initInfoOnlineContent("tutorial"); MainApp.getZdsutils().initInfoOnlineContent("article"); } catch (IOException e) { logger.error("Echec de téléchargement des metadonnés des contenus en ligne", e); } } return null; } }; }
Example 8
Source File: AbstractRunMojo.java From alfresco-sdk with Apache License 2.0 | 5 votes |
/** * Package customized war file and install it in local maven repo. * * @param warName the name of the custom war * @return the customized war file artifactId, to be used by the tomcat7 plugin * @throws MojoExecutionException when any problem appears packaging or installing the custom war */ protected String packageAndInstallCustomWar(String warName) throws MojoExecutionException { final String warArtifactId = "${project.artifactId}-" + warName; final String warSourceDir = getWarOutputDir(warName); // Package the customized war file // Note. don't use the maven-war-plugin here as it will package the module files twice, once from the // target/classes dir and once via the JAR String warPath = project.getBuild().getDirectory() + "/" + warName + ".war"; ZipUtil.pack(new File(warSourceDir), new File(warPath)); // Install the customized war file in the local maven repo executeMojo( plugin( groupId("org.apache.maven.plugins"), artifactId("maven-install-plugin"), version(MAVEN_INSTALL_PLUGIN_VERSION) ), goal("install-file"), configuration( element(name("file"), warPath), element(name("groupId"), "${project.groupId}"), element(name("artifactId"), warArtifactId), element(name("version"), "${project.version}"), element(name("packaging"), "war") // Don't forget, otherwise installed as .POM ) , execEnv ); return warArtifactId; }
Example 9
Source File: ConfigChecker.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
private void createBackup() { File pluginFolder = this.plugin.getDataFolder(); Logger logger = this.plugin.getLogger(); logger.info("Creating backup..."); try { File pluginsFolder = pluginFolder.getParentFile(); File backupFile = new File(pluginsFolder, "CombatLogX-backup-" + System.currentTimeMillis() + ".zip"); ZipUtil.pack(pluginFolder, backupFile); deleteFiles(pluginFolder); } catch(Exception ex) { logger.log(Level.SEVERE, "An error occurred while creating a backup:", ex); logger.info("Failed to create backup."); } }
Example 10
Source File: VFSZipperZIPTest.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testUnzipArchiveWithFileHierarchy() throws IOException { createFileHierarchy(temporaryPath); // Zips using third-party library that is tested and known to work as expected ZipUtil.pack(temporaryPath.toFile(), archivePath.toFile()); testUnzip(outputPath); }
Example 11
Source File: TestApiZds.java From zest-writer with GNU General Public License v3.0 | 4 votes |
@Test /** * This test allow to check relation between Zest Writer and Website * For run this test you need pass Jvm Args like -Dzw.username=USER -Dzw.password=PASSWORD * if no argument is supplied, the test will succeed anyway, * but the connection to the web site will not be tested */ public void testLogin() { assertEquals(config.getWorkspacePath(), TEST_DIR.getAbsolutePath()+File.separator+"workspace"); if(login != null && !login.equals("") && password != null && !password.equals("")) { ZdsHttp api = new ZdsHttp(config); try { assertTrue("Tentative d'authentification au site", api.login(login, password)); assertTrue("Vérification de l'authentification réussi", api.isAuthenticated()); api.initInfoOnlineContent("tutorial"); api.initInfoOnlineContent("article"); api.initGalleryId("1312", "tutoriel-test"); assertEquals(api.getGalleryId(), "3243"); api.downloaDraft("1312", "tutorial"); api.downloaDraft("1313", "article"); File offlineDir = new File(config.getWorkspaceFactory().getOfflineSaver().getBaseDirectory()); File onlineDir = new File(config.getWorkspaceFactory().getOnlineSaver().getBaseDirectory()); assertTrue(onlineDir.isDirectory()); assertTrue(onlineDir.list().length > 0); assertTrue(offlineDir.isDirectory()); assertTrue(offlineDir.list().length == 0); for(File on:onlineDir.listFiles()) api.unzipOnlineContent(on.getAbsolutePath()); assertTrue(offlineDir.list().length > 0); // import File zipfile = new File(offlineDir, "tutoriel-test.zip"); ZipUtil.pack(new File(offlineDir, "tutoriel-test"), zipfile); assertTrue(api.importContent(zipfile.getAbsolutePath(), "1312", "tutoriel-test", "Message d'import")); api.logout(); assertFalse(api.isAuthenticated()); } catch (IOException e) { fail(e.getMessage()); } } }
Example 12
Source File: Util.java From olca-app with Mozilla Public License 2.0 | 4 votes |
static void zip() { System.out.println(" Package databases ..."); ZipUtil.pack(F("build/empty"), F("dist/empty.zolca")); ZipUtil.pack(F("build/units"), F("dist/units.zolca")); ZipUtil.pack(F("build/flows"), F("dist/flows.zolca")); }
Example 13
Source File: ResourceFolder.java From selenium-grid-extensions with Apache License 2.0 | 4 votes |
private void mapFolderFromResources(URL dirURL, File destZip) throws URISyntaxException { File srcFolder = new File(dirURL.toURI()); ZipUtil.pack(srcFolder, destZip, pathKeeper()); }
Example 14
Source File: AirGapCreator.java From synopsys-detect with Apache License 2.0 | 4 votes |
public File createAirGapZip(DetectFilter inspectorFilter, File outputPath, String airGapSuffix, String gradleInspectorVersion) throws DetectUserFriendlyException { try { logger.info(""); logger.info(ReportConstants.RUN_SEPARATOR); logger.info(ReportConstants.RUN_SEPARATOR); logger.info("Detect is in Air Gap Creation mode."); logger.info("Detect will create an air gap of itself and then exit."); logger.info("The created air gap zip will not be cleaned up."); logger.info(String.format("Specify desired inspectors after -z argument in a comma separated list of ALL, NONE, %s", Arrays.stream(AirGapInspectors.values()).map(Enum::name).collect(Collectors.joining(", ")))); logger.info(ReportConstants.RUN_SEPARATOR); logger.info(ReportConstants.RUN_SEPARATOR); logger.info(""); File detectJar = airGapPathFinder.findDetectJar(); if (detectJar == null) { throw new DetectUserFriendlyException("To create an air gap zip, Detect must be run from a jar and be able to find that jar. Detect was unable to find it's own jar.", ExitCodeType.FAILURE_CONFIGURATION); } logger.info("The detect jar location: " + detectJar.getCanonicalPath()); logger.info("Creating zip at location: " + outputPath); String basename = FilenameUtils.removeExtension(detectJar.getName()); String airGapName = basename + "-air-gap"; if (StringUtils.isNotBlank(airGapSuffix)) { airGapName = airGapName + "-" + airGapSuffix.toLowerCase(); } File target = new File(outputPath, airGapName + ".zip"); File installFolder = new File(outputPath, basename); logger.info("Will build the zip in the following folder: " + installFolder.getCanonicalPath()); logger.info("Installing dependencies."); installAllAirGapDependencies(installFolder, inspectorFilter, gradleInspectorVersion); logger.info("Copying detect jar."); FileUtils.copyFile(detectJar, new File(installFolder, detectJar.getName())); logger.info("Zipping into: " + target.getCanonicalPath()); ZipUtil.pack(installFolder, target); logger.info("Cleaning up working directory: " + installFolder.getCanonicalPath()); FileUtils.deleteDirectory(installFolder); logger.info(ReportConstants.RUN_SEPARATOR); String result = target.getCanonicalPath(); logger.info("Successfully created air gap zip: " + result); logger.info(ReportConstants.RUN_SEPARATOR); eventSystem.publishEvent(Event.ResultProduced, new AirGapDetectResult(result)); return target; } catch (IOException e) { throw new DetectUserFriendlyException("Failed to create detect air gap zip.", e, ExitCodeType.FAILURE_UNKNOWN_ERROR); } }
Example 15
Source File: UploadImageService.java From zest-writer with GNU General Public License v3.0 | 4 votes |
@Override protected Task<String> createTask() { return new Task<String>() { @Override protected String call() throws Exception { if (MainApp.getZdsutils().isAuthenticated()) { MetadataContent find = getContentFromSlug(); if(find == null ) { updateMessage("Le contenu n'existe pas encore sur le site, tentative de création"); // send a new file content ZipUtil.pack(new File(content.getFilePath()), new File(content.getFilePath() + ".zip")); MainApp.getZdsutils().importNewContent(content.getFilePath() + ".zip", "Init content"); // refresh content list info MainApp.getZdsutils().getContentListOnline().clear(); MainApp.getZdsutils().initInfoOnlineContent("tutorial"); MainApp.getZdsutils().initInfoOnlineContent("article"); MainApp.getZdsutils().initInfoOnlineContent("opinion"); find = getContentFromSlug(); if(find == null) { throw new IOException(); } } String targetId = find.getId(); String targetSlug = find.getSlug(); if (MainApp.getZdsutils().getGalleryId() == null) { updateMessage(Configuration.getBundle().getString("ui.task.gallery.init")+" : "+targetSlug); MainApp.getZdsutils().initGalleryId(targetId, targetSlug); } updateMessage(Configuration.getBundle().getString("ui.task.gallery.send_image") + " " + imageFile.getAbsolutePath() + " " + Configuration.getBundle().getString("ui.task.gallery.to") + " " + MainApp.getZdsutils().getGalleryId()); return MainApp.getZdsutils().importImage(imageFile); } return null; } }; }
Example 16
Source File: GeneratorService.java From jhipster-online with Apache License 2.0 | 4 votes |
private void zipResult(File workingDir) { ZipUtil.pack(workingDir, new File(workingDir + ".zip")); }
Example 17
Source File: GitRepo.java From warnings-ng-plugin with MIT License | 4 votes |
/** * Zip bare repository, copy to Docker container using sftp, then unzip. The repo is now accessible over * "ssh://git@ip:port/home/git/gitRepo.git" * * @param host * IP of Docker container * @param port * SSH port of Docker container */ public void transferToDockerContainer(String host, int port) { try { Path zipPath = Files.createTempFile("git", "zip"); File zippedRepo = zipPath.toFile(); String zippedFilename = zipPath.getFileName().toString(); ZipUtil.pack(new File(dir.getPath()), zippedRepo); Properties props = new Properties(); props.put("StrictHostKeyChecking", "no"); JSch jSch = new JSch(); jSch.addIdentity(privateKey.getAbsolutePath()); Session session = jSch.getSession("git", host, port); session.setConfig(props); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); channel.cd("/home/git"); channel.put(new FileInputStream(zippedRepo), zippedFilename); ChannelExec channelExec = (ChannelExec) session.openChannel("exec"); InputStream in = channelExec.getInputStream(); channelExec.setCommand("unzip " + zippedFilename + " -d " + REPO_NAME); channelExec.connect(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; int index = 0; while ((line = reader.readLine()) != null) { System.out.println(++index + " : " + line); } channelExec.disconnect(); channel.disconnect(); session.disconnect(); // Files.delete(zipPath); } catch (IOException | JSchException | SftpException e) { throw new AssertionError("Can't transfer git repository to docker container", e); } }
Example 18
Source File: TestHelper.java From arthas with Apache License 2.0 | 3 votes |
public static void appendSpyJar(Instrumentation instrumentation) throws IOException { // find spy target/classes directory String file = TestHelper.class.getProtectionDomain().getCodeSource().getLocation().getFile(); File spyClassDir = new File(file, "../../../spy/target/classes").getAbsoluteFile(); File destJarFile = new File(file, "../../../spy/target/test-spy.jar").getAbsoluteFile(); ZipUtil.pack(spyClassDir, destJarFile); instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(destJarFile)); }