z.setProject(prj); z.setTaskType("zip"); classesJar.getParentFile().mkdirs();
@RequestMapping("/starter.zip") @ResponseBody public ResponseEntity<byte[]> springZip(BasicProjectRequest basicRequest) throws IOException { ProjectRequest request = (ProjectRequest) basicRequest; File dir = this.projectGenerator.generateProjectStructure(request); File download = this.projectGenerator.createDistributionFile(dir, ".zip"); String wrapperScript = getWrapperScript(request); new File(dir, wrapperScript).setExecutable(true); Zip zip = new Zip(); zip.setProject(new Project()); zip.setDefaultexcludes(false); ZipFileSet set = new ZipFileSet(); set.setDir(dir); set.setFileMode("755"); set.setIncludes(wrapperScript); set.setDefaultexcludes(false); zip.addFileset(set); set = new ZipFileSet(); set.setDir(dir); set.setIncludes("**,"); set.setExcludes(wrapperScript); set.setDefaultexcludes(false); zip.addFileset(set); zip.setDestFile(download.getCanonicalFile()); zip.execute(); return upload(download, dir, generateFileName(request, "zip"), "application/zip"); }
zip.setDestFile(new File(this.workdirectory.getAbsolutePath() + FILE_SEPARATOR + JONAS_ROOT_ZIP_FILE)); zip.setUpdate(true); zip.setProject(p); try { zip.execute(); zip.setDestFile(new File(this.workdirectory.getAbsolutePath() + FILE_SEPARATOR + JONAS_BASE_ZIP_FILE)); zip.setUpdate(true); zip.setProject(p); try { zip.execute();
/** * Copies a jar file from the master to slave. */ private void copyJar(PrintStream log, FilePath dst, Class<?> representative, String seedName) throws IOException, InterruptedException { // in normal execution environment, the master should be loading 'representative' from this jar, so // in that way we can find it. File jar = Which.jarFile(representative); if(jar.isDirectory()) { // but during the development and unit test environment, we may be picking the class up from the classes dir Zip zip = new Zip(); zip.setBasedir(jar); File t = File.createTempFile(seedName, "jar"); t.delete(); zip.setDestFile(t); zip.setProject(new Project()); zip.execute(); jar = t; } new FilePath(jar).copyTo(dst.child(seedName +".jar")); log.println("Copied "+seedName+".jar"); } }
Project p = new Project(); p.init(); Zip zip = new Zip(); zip.setProject(p); zip.setDestFile(zipFile); // a java.io.File for the zip you want to create zip.setBasedir(new File("D:\\reports")); zip.setIncludes("january/**"); zip.perform();
zip.setProject(project);
/** * Zip jonas-starter folder to jonas-starter.jar. */ public void zipStarter() { Project p = new Project(); Zip zip = new Zip(); zip.setBasedir(getStarterDefaultLocation()); zip.setDestFile(new File(this.starterJarFileLocation.getAbsolutePath(), this.starterJarFileName)); zip.setUpdate(true); zip.setProject(p); try { zip.execute(); setStarterDefaultLocation(new File(this.starterJarFileLocation.getAbsolutePath(), this.starterJarFileName)); renameStarterJarFile(); this.output.write(this.starterJarFileName + " successfully created !"); this.output.write("Location: " + this.starterDefaultLocation); } catch (Exception e) { this.output.write("Error in packaging jonas-starter : " + e.getMessage()); } }
/** * Copies a jar file from the master to slave. */ static FilePath copyJar(PrintStream log, FilePath dst, Class<?> representative, String seedName) throws IOException, InterruptedException { // in normal execution environment, the master should be loading 'representative' from this jar, so // in that way we can find it. File jar = Which.jarFile(representative); FilePath copiedJar = dst.child(seedName + ".jar"); if (jar.isDirectory()) { // but during the development and unit test environment, we may be picking the class up from the classes dir Zip zip = new Zip(); zip.setBasedir(jar); File t = File.createTempFile(seedName, "jar"); t.delete(); zip.setDestFile(t); zip.setProject(new Project()); zip.execute(); jar = t; } else if (copiedJar.exists() && copiedJar.digest().equals(Util.getDigestOf(jar))) { log.println(seedName + ".jar already up to date"); return copiedJar; } // Theoretically could be a race condition on a multi-executor Windows slave; symptom would be an IOException during the build. // Could perhaps be solved by synchronizing on dst.getChannel() or similar. new FilePath(jar).copyTo(copiedJar); log.println("Copied " + seedName + ".jar"); return copiedJar; }
Project p = new Project(); p.init(); Zip zip = new Zip(); zip.setProject(p); zip.setDestFile(new File(outputDir, "out.zip")); FileSet fs = new FileSet(); fs.setProject(p); fs.setDirectory(targetDir); zip.addFileset(fs); zip.perform();
/** * 执行压缩操作 * @param srcPathName 需要被压缩的文件/文件夹 * @param dest 生成的zip包的位置 */ public static void doZipCompress(String srcPathName, String dest) { File srcdir = new File(srcPathName); if (!srcdir.exists()){ throw new GlobalException(1 , srcPathName + "不存在" , null); } File zipFile = new File(dest); Project prj = new Project(); Zip zip = new Zip(); zip.setProject(prj); zip.setDestFile(zipFile); FileSet fileSet = new FileSet(); fileSet.setProject(prj); fileSet.setDir(srcdir); //排除哪些文件或文件夹 fileSet.setExcludes(".DS_Store"); zip.addFileset(fileSet); zip.execute(); }
rezip.setProject(new Project()); ZipFileSet z = new ZipFileSet(); z.setSrc(war);
zip.setDestFile(new File(this.workdirectory, JONAS_ROOT_ZIP_FILE)); zip.setUpdate(true); zip.setProject(project); try { zip.execute(); zip.setDestFile(new File(this.workdirectory, JONAS_BASE_ZIP_FILE)); zip.setUpdate(true); zip.setProject(project); try { zip.execute();
z.setProject(prj); z.setTaskType("zip"); classesJar.getParentFile().mkdirs();
/** 获取压缩任务对象 */ @Override protected Task getTask() { Project project = new Project(); Zip zip = new Zip(); FileSet src = getSourceFileSet(); src.setProject(project); zip.setProject(project); zip.setDestFile(getTargetFile()); zip.addFileset(src); if(encoding != null) zip.setEncoding(encoding); if(comment != null) zip.setComment(comment); return zip; }
task.setUpdate(true); task.setProject(p); task.init(); target.addTask(task);