List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry ZipArchiveEntry
public ZipArchiveEntry(ZipArchiveEntry entry) throws ZipException
From source file:com.haulmont.cuba.core.app.FoldersServiceBean.java
protected ArchiveEntry newStoredEntry(String name, byte[] data) { ZipArchiveEntry zipEntry = new ZipArchiveEntry(name); zipEntry.setSize(data.length);//from w ww.j a v a2 s . c o m zipEntry.setCompressedSize(zipEntry.getSize()); CRC32 crc32 = new CRC32(); crc32.update(data); zipEntry.setCrc(crc32.getValue()); return zipEntry; }
From source file:com.naryx.tagfusion.expression.function.file.Zip.java
/** * Performing Zip() operation//from www . j a v a 2s . c o m * * @param session * @param zipfile * @param src * @param recurse * @param prefixx * @param compLvl * @param filter * @param overwrite * @param newpath * @throws cfmRunTimeException * @throws IOException */ protected void zipOperation(cfSession session, ZipArchiveOutputStream zipOut, File src, boolean recurse, String prefix, int compLvl, FilenameFilter filter, String newpath) throws cfmRunTimeException { if (src != null) { FileInputStream nextFileIn; ZipArchiveEntry nextEntry = null; byte[] buffer = new byte[4096]; int readBytes; zipOut.setLevel(compLvl); try { List<File> files = new ArrayList<File>(); int srcDirLen; if (src.isFile()) { String parentPath = src.getParent(); srcDirLen = parentPath.endsWith(File.separator) ? parentPath.length() : parentPath.length() + 1; files.add(src); } else { String parentPath = src.getAbsolutePath(); srcDirLen = parentPath.endsWith(File.separator) ? parentPath.length() : parentPath.length() + 1; getFiles(src, files, recurse, filter); } int noFiles = files.size(); File nextFile; boolean isDir; for (int i = 0; i < noFiles; i++) { nextFile = (File) files.get(i); isDir = nextFile.isDirectory(); if (noFiles == 1 && newpath != null) { // NEWPATH nextEntry = new ZipArchiveEntry(newpath.replace('\\', '/') + (isDir ? "/" : "")); } else { // PREFIX nextEntry = new ZipArchiveEntry( prefix + nextFile.getAbsolutePath().substring(srcDirLen).replace('\\', '/') + (isDir ? "/" : "")); } try { zipOut.putArchiveEntry(nextEntry); } catch (IOException e) { throwException(session, "Failed to add entry to zip file [" + nextEntry + "]. Reason: " + e.getMessage()); } if (!isDir) { nextEntry.setTime(nextFile.lastModified()); nextFileIn = new FileInputStream(nextFile); try { while (nextFileIn.available() > 0) { readBytes = nextFileIn.read(buffer); zipOut.write(buffer, 0, readBytes); } zipOut.flush(); } catch (IOException e) { throwException(session, "Failed to write entry [" + nextEntry + "] to zip file. Reason: " + e.getMessage()); } finally { // nextEntry close StreamUtil.closeStream(nextFileIn); } } zipOut.closeArchiveEntry(); } } catch (IOException ioe) { throwException(session, "Failed to create zip file: " + ioe.getMessage()); } } }
From source file:net.duckling.ddl.service.export.impl.ExportServiceImpl.java
private void writeCover(String path, ArchiveOutputStream out) { try {//from w w w .ja v a 2 s. com FileInputStream fis = new FileInputStream(epubPath + COVER); String entry = null != path ? path + "/cover.jpg" : "cover.jpg"; out.putArchiveEntry(new ZipArchiveEntry(entry)); IOUtils.copy(fis, out); fis.close(); out.closeArchiveEntry(); } catch (FileNotFoundException e) { LOG.error(COVER + ""); LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
From source file:com.jaeksoft.searchlib.crawler.web.spider.DownloadItem.java
public void writeToZip(ZipArchiveOutputStream zipOutput) throws IOException { if (contentInputStream == null) return;//from w ww .ja v a 2s . com String[] domainParts = StringUtils.split(uri.getHost(), '.'); StringBuilder path = new StringBuilder(); for (int i = domainParts.length - 1; i >= 0; i--) { path.append(domainParts[i]); path.append('/'); } String[] pathParts = StringUtils.split(uri.getPath(), '/'); for (int i = 0; i < pathParts.length - 1; i++) { if (StringUtils.isEmpty(pathParts[i])) continue; path.append(pathParts[i]); path.append('/'); } if (contentDispositionFilename != null) path.append(contentDispositionFilename); else { String lastPart = pathParts == null || pathParts.length == 0 ? null : pathParts[pathParts.length - 1]; if (StringUtils.isEmpty(lastPart)) path.append("index"); else path.append(lastPart); } if (uri.getPath().endsWith("/")) path.append("/_index"); String query = uri.getQuery(); String fragment = uri.getFragment(); if (!StringUtils.isEmpty(query) || !StringUtils.isEmpty(fragment)) { CRC32 crc32 = new CRC32(); if (!StringUtils.isEmpty(query)) crc32.update(query.getBytes()); if (!StringUtils.isEmpty(fragment)) crc32.update(fragment.getBytes()); path.append('.'); path.append(crc32.getValue()); } ZipArchiveEntry zipEntry = new ZipArchiveEntry(path.toString()); zipOutput.putArchiveEntry(zipEntry); BufferedInputStream bis = null; byte[] buffer = new byte[65536]; try { bis = new BufferedInputStream(contentInputStream); int l; while ((l = bis.read(buffer)) != -1) zipOutput.write(buffer, 0, l); zipOutput.closeArchiveEntry(); } finally { IOUtils.close(bis); } }
From source file:fr.itldev.koya.alfservice.KoyaContentService.java
private void addToZip(NodeRef node, ZipArchiveOutputStream out, String path) throws IOException { QName nodeQnameType = this.nodeService.getType(node); // Special case : links if (this.dictionaryService.isSubClass(nodeQnameType, ApplicationModel.TYPE_FILELINK)) { NodeRef linkDestinationNode = (NodeRef) nodeService.getProperty(node, ContentModel.PROP_LINK_DESTINATION); if (linkDestinationNode == null) { return; }//from www .j a va 2 s . co m // Duplicate entry: check if link is not in the same space of the // link destination if (nodeService.getPrimaryParent(node).getParentRef() .equals(nodeService.getPrimaryParent(linkDestinationNode).getParentRef())) { return; } nodeQnameType = this.nodeService.getType(linkDestinationNode); node = linkDestinationNode; } /** * TODO test name/title export result. */ String nodeName = (String) nodeService.getProperty(node, ContentModel.PROP_TITLE); nodeName = nodeName.replaceAll("([\\\"\\\\*\\\\\\>\\<\\?\\/\\:\\|]+)", "_"); // nodeName = noaccent ? unAccent(nodeName) : nodeName; if (this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_CONTENT)) { ContentReader reader = contentService.getReader(node, ContentModel.PROP_CONTENT); if (reader != null) { InputStream is = reader.getContentInputStream(); String filename = path.isEmpty() ? nodeName : path + '/' + nodeName; ZipArchiveEntry entry = new ZipArchiveEntry(filename); entry.setTime(((Date) nodeService.getProperty(node, ContentModel.PROP_MODIFIED)).getTime()); entry.setSize(reader.getSize()); out.putArchiveEntry(entry); try { byte buffer[] = new byte[8192]; while (true) { int nRead = is.read(buffer, 0, buffer.length); if (nRead <= 0) { break; } out.write(buffer, 0, nRead); } } catch (Exception exception) { logger.error(exception.getMessage(), exception); } finally { is.close(); out.closeArchiveEntry(); } } else { logger.warn("Could not read : " + nodeName + "content"); } } else if (this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_FOLDER) && !this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_SYSTEM_FOLDER)) { List<ChildAssociationRef> children = nodeService.getChildAssocs(node); if (children.isEmpty()) { String folderPath = path.isEmpty() ? nodeName + '/' : path + '/' + nodeName + '/'; out.putArchiveEntry(new ZipArchiveEntry(folderPath)); out.closeArchiveEntry(); } else { for (ChildAssociationRef childAssoc : children) { NodeRef childNodeRef = childAssoc.getChildRef(); addToZip(childNodeRef, out, path.isEmpty() ? nodeName : path + '/' + nodeName); } } } else { logger.info("Unmanaged type: " + nodeQnameType.getPrefixedQName(this.namespaceService) + ", filename: " + nodeName); } }
From source file:net.duckling.ddl.service.export.impl.ExportServiceImpl.java
private void writeOpf(String tname, List<String> allPages, ArchiveOutputStream out) { String pofTemplate = getTemplate(epubPath + AONE_OPF); StringBuilder sbItems = new StringBuilder(); StringBuilder sbItemrefs = new StringBuilder(); sbItems.append("<item id=\"css\" href=\"aone.css\" media-type=\"text/css\" />\n"); sbItems.append("<item id=\"cover\" href=\"cover.jpg\" media-type=\"image/jpeg\" />\n"); if (null != tname) { sbItems.append("<item id=\"index\" href=\"overview.html\" media-type=\"application/xhtml+xml\" />\n"); sbItemrefs.append("<itemref idref=\"index\" />\n"); }/*from w w w .j a v a2 s . c o m*/ Iterator<String> it = allPages.iterator(); while (it.hasNext()) { String str = it.next(); if (str.contains("/index.html")) { String tagname = getIDFromResPath(str); String path = str.substring(str.indexOf("/") + 1, str.length()); sbItems.append("<item id=\"" + tagname + "\" href=\"" + path + "\" media-type=\"application/xhtml+xml\" />\n"); sbItemrefs.append("<itemref idref=\"" + tagname + "\" />\n"); } else { String pid = getIDFromResPath(str); sbItems.append( "<item id=\"" + pid + "\" href=\"" + str + "\" media-type=\"application/xhtml+xml\" />\n"); sbItemrefs.append("<itemref idref=\"" + pid + "\" />\n"); } } sbItems.append("<item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\" />"); pofTemplate = pofTemplate.replace("ITEMS", sbItems.toString()); pofTemplate = pofTemplate.replace("ITEMREFS", sbItemrefs.toString()); InputStream in = new ByteArrayInputStream(pofTemplate.getBytes()); try { String entry = null != tname ? tname + "/aone.opf" : "aone.opf"; out.putArchiveEntry(new ZipArchiveEntry(entry)); IOUtils.copy(in, out); in.close(); out.closeArchiveEntry(); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
From source file:at.spardat.xma.xdelta.JarPatcher.java
/** * Entry to new name.//w w w .j a v a2s. co m * * @param source the source * @param name the name * @return the zip archive entry * @throws ZipException the zip exception */ private ZipArchiveEntry copyEntry(ZipArchiveEntry source) throws ZipException { ZipArchiveEntry ret = new ZipArchiveEntry(source.getName()); byte[] extra = source.getExtra(); if (extra != null) { ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ)); } else { ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true))); } ret.setInternalAttributes(source.getInternalAttributes()); ret.setExternalAttributes(source.getExternalAttributes()); ret.setExtraFields(source.getExtraFields(true)); return ret; }
From source file:big.BigZip.java
/** * Copies one file into the big archive * @param fileToCopy//from w w w . jav a 2 s .c o m * @return */ public boolean writeFile(final File fileToCopy) { // declare ByteArrayOutputStream outputZipStream = new ByteArrayOutputStream(); try { /* Create Archive Output Stream that attaches File Output Stream / and specifies type of compression */ ArchiveOutputStream logical_zip = new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, outputZipStream); /* Create Archieve entry - write header information*/ logical_zip.putArchiveEntry(new ZipArchiveEntry(fileToCopy.getName())); /* Copy input file */ IOUtils.copy(new FileInputStream(fileToCopy), logical_zip); logical_zip.closeArchiveEntry(); logical_zip.finish(); logical_zip.flush(); logical_zip.close(); // get the bytes final ByteArrayInputStream byteInput = new ByteArrayInputStream(outputZipStream.toByteArray()); byte[] buffer = new byte[8192]; int length, counter = 0; // add the magic number to this file block outputStream.write(magicSignature.getBytes()); // now copy the whole file into the BIG archive while ((length = byteInput.read(buffer)) > 0) { outputStream.write(buffer, 0, length); counter += length; } // if there is something else to be flushed, do it now outputStream.flush(); // calculate the base path final String resultingPath = fileToCopy.getAbsolutePath().replace(basePath, ""); // calculate the SHA1 signature final String output = utils.hashing.checksum.generateFileChecksum("SHA-1", fileToCopy); // write a new line in our index file writerFileIndex.write( "\n" + utils.files.getPrettyFileSize(currentPosition) + " " + output + " " + resultingPath); // increase the position counter currentPosition += counter + magicSignature.length(); } catch (Exception e) { System.err.println("BIG346 - Error copying file: " + fileToCopy.getAbsolutePath()); return false; } finally { } return true; }
From source file:net.duckling.ddl.service.export.impl.ExportServiceImpl.java
private void writeNcx(String tname, List<String> allPages, Map<String, String> id2Title, ArchiveOutputStream out) {/*ww w. j a va 2 s. c om*/ String ncxTemplate = getTemplate(epubPath + TOC_NCX); if (null != tname) { ncxTemplate = ncxTemplate.replace("DOCTITLE", "" + tname); ncxTemplate = ncxTemplate.replace("DOCAUTHOR", "" + tname); } StringBuilder sb = new StringBuilder(); int playOrder = 0; if (null != tname) { sb.append("<navPoint id=\"nv-catalog\" playOrder=\"" + (++playOrder) + "\">\n" + "<navLabel><text></text></navLabel>\n<content src=\"overview.html\"/>\n</navPoint>\n"); } int len = allPages.size(); for (int par = 0; par < len; par++) { String str = allPages.get(par); if (str.contains("/index.html")) { String tagName = getTagNameFromResPath(str); String path = str.substring(str.indexOf("/") + 1, str.length()); playOrder++; sb.append("<navPoint id=\"nv-" + playOrder + "\" playOrder=\"" + playOrder + "\">\n<navLabel><text>" + tagName + "</text></navLabel>\n<content src=\"" + path + "\"/>\n"); for (int child = par + 1; child < len; child++) { String item = allPages.get(child); if (item.contains("index")) { break; } String pageTitle = id2Title.get(item); playOrder++; sb.append("<navPoint id=\"nv-" + playOrder + "\" playOrder=\"" + playOrder + "\">\n<navLabel><text>" + pageTitle + "</text></navLabel>\n<content src=\"" + item + "\"/>\n</navPoint>\n"); } sb.append("</navPoint>\n"); } } ncxTemplate = ncxTemplate.replace("NAV_POINTS", sb.toString()); InputStream in = new ByteArrayInputStream(ncxTemplate.getBytes()); try { String entry = null != tname ? tname + "/toc.ncx" : "toc.ncx"; out.putArchiveEntry(new ZipArchiveEntry(entry)); IOUtils.copy(in, out); in.close(); out.closeArchiveEntry(); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
From source file:divconq.tool.release.Main.java
@Override public void run(Scanner scan, ApiSession api) { Path relpath = null;/*from w w w .j a v a 2 s . c o m*/ Path gitpath = null; Path wikigitpath = null; XElement fldset = Hub.instance.getConfig().selectFirst("CommandLine/Settings"); if (fldset != null) { relpath = Paths.get(fldset.getAttribute("ReleasePath")); gitpath = Paths.get(fldset.getAttribute("GitPath")); wikigitpath = Paths.get(fldset.getAttribute("WikiGitPath")); } boolean running = true; while (running) { try { System.out.println(); System.out.println("-----------------------------------------------"); System.out.println(" Release Builder Menu"); System.out.println("-----------------------------------------------"); System.out.println("0) Exit"); if (relpath != null) System.out.println("1) Build release package from Settings File"); System.out.println("2) Build custom release package [under construction]"); System.out.println("4) Pack the .jar files"); if (gitpath != null) System.out.println("5) Copy Source to GitHub folder"); System.out.println("6) Update AWWW"); String opt = scan.nextLine(); Long mopt = StringUtil.parseInt(opt); if (mopt == null) continue; switch (mopt.intValue()) { case 0: running = false; break; case 1: { ReleasesHelper releases = new ReleasesHelper(); if (!releases.init(relpath)) break; System.out.println("Select a release to build"); System.out.println("0) None"); List<String> rnames = releases.names(); for (int i = 0; i < rnames.size(); i++) System.out.println((i + 1) + ") " + rnames.get(i)); System.out.println("Option #: "); opt = scan.nextLine(); mopt = StringUtil.parseInt(opt); if ((mopt == null) || (mopt == 0)) break; XElement relchoice = releases.get(mopt.intValue() - 1); if (relchoice == null) { System.out.println("Invalid option"); break; } PackagesHelper availpackages = new PackagesHelper(); availpackages.init(); InstallHelper inst = new InstallHelper(); if (!inst.init(availpackages, relchoice)) break; XElement prindesc = availpackages.get(inst.prinpackage); XElement prininst = prindesc.find("Install"); if (prininst == null) { System.out.println("Principle package: " + inst.prinpackagenm + " cannot be released directly, it must be part of another package."); break; } String relvers = prindesc.getAttribute("Version"); System.out.println("Building release version " + relvers); if (prindesc.hasAttribute("LastVersion")) System.out.println("Previous release version " + prindesc.getAttribute("LastVersion")); String rname = relchoice.getAttribute("Name"); Path destpath = relpath.resolve(rname + "/" + rname + "-" + relvers + "-bin.zip"); if (Files.exists(destpath)) { System.out.println("Version " + relvers + " already exists, overwrite? (y/n): "); if (!scan.nextLine().toLowerCase().startsWith("y")) break; Files.delete(destpath); } System.out.println("Preparing zip files"); AtomicBoolean errored = new AtomicBoolean(); Path tempfolder = FileUtil.allocateTempFolder2(); ListStruct ignorepaths = new ListStruct(); Set<String> nolongerdepends = new HashSet<>(); Set<String> dependson = new HashSet<>(); // put all the release files into a temp folder inst.instpkgs.forEach(pname -> { availpackages.get(pname).selectAll("DependsOn").stream() .filter(doel -> !doel.hasAttribute("Option") || inst.relopts.contains(doel.getAttribute("Option"))) .forEach(doel -> { // copy all libraries we rely on doel.selectAll("Library").forEach(libel -> { dependson.add(libel.getAttribute("File")); Path src = Paths.get("./lib/" + libel.getAttribute("File")); Path dest = tempfolder.resolve("lib/" + libel.getAttribute("File")); try { Files.createDirectories(dest.getParent()); if (Files.notExists(dest)) Files.copy(src, dest, StandardCopyOption.COPY_ATTRIBUTES); } catch (Exception x) { errored.set(true); System.out.println("Unable to copy file: " + src); } }); // copy all files we rely on doel.selectAll("File").forEach(libel -> { Path src = Paths.get("./" + libel.getAttribute("Path")); Path dest = tempfolder.resolve(libel.getAttribute("Path")); try { Files.createDirectories(dest.getParent()); if (Files.notExists(dest)) Files.copy(src, dest, StandardCopyOption.COPY_ATTRIBUTES); } catch (Exception x) { errored.set(true); System.out.println("Unable to copy file: " + src); } }); // copy all folders we rely on doel.selectAll("Folder").forEach(libel -> { Path src = Paths.get("./" + libel.getAttribute("Path")); Path dest = tempfolder.resolve(libel.getAttribute("Path")); try { Files.createDirectories(dest.getParent()); } catch (Exception x) { errored.set(true); System.out.println("Unable to copy file: " + src); } OperationResult cres = FileUtil.copyFileTree(src, dest); if (cres.hasErrors()) errored.set(true); }); }); availpackages.get(pname).selectAll("IgnorePaths/Ignore") .forEach(doel -> ignorepaths.addItem(doel.getAttribute("Path"))); // NoLongerDependsOn functionally currently only applies to libraries availpackages.get(pname).selectAll("NoLongerDependsOn/Library") .forEach(doel -> nolongerdepends.add(doel.getAttribute("File"))); // copy the released packages folders Path src = Paths.get("./packages/" + pname); Path dest = tempfolder.resolve("packages/" + pname); try { Files.createDirectories(dest.getParent()); } catch (Exception x) { errored.set(true); System.out.println("Unable to copy file: " + src); } // we may wish to enhance filter to allow .JAR sometimes, but this is meant to prevent copying of packages/pname/lib/abc.lib.jar files OperationResult cres = FileUtil.copyFileTree(src, dest, path -> !path.toString().endsWith(".jar")); if (cres.hasErrors()) errored.set(true); // copy the released packages libraries Path libsrc = Paths.get("./packages/" + pname + "/lib"); Path libdest = tempfolder.resolve("lib"); if (Files.exists(libsrc)) { cres = FileUtil.copyFileTree(libsrc, libdest); if (cres.hasErrors()) errored.set(true); } }); if (errored.get()) { System.out.println("Error with assembling package"); break; } // copy the principle config Path csrc = Paths.get("./packages/" + inst.prinpackage + "/config"); Path cdest = tempfolder.resolve("config/" + inst.prinpackagenm); if (Files.exists(csrc)) { Files.createDirectories(cdest); OperationResult cres = FileUtil.copyFileTree(csrc, cdest); if (cres.hasErrors()) { System.out.println("Error with prepping config"); break; } } boolean configpassed = true; // copy packages with config = true for (XElement pkg : relchoice.selectAll("Package")) { if (!"true".equals(pkg.getAttribute("Config"))) break; String pname = pkg.getAttribute("Name"); int pspos = pname.lastIndexOf('/'); String pnm = (pspos != -1) ? pname.substring(pspos + 1) : pname; csrc = Paths.get("./packages/" + pname + "/config"); cdest = tempfolder.resolve("config/" + pnm); if (Files.exists(csrc)) { Files.createDirectories(cdest); OperationResult cres = FileUtil.copyFileTree(csrc, cdest); if (cres.hasErrors()) { System.out.println("Error with prepping extra config"); configpassed = false; break; } } } if (!configpassed) break; // also copy installer config if being used if (inst.includeinstaller) { csrc = Paths.get("./packages/dc/dcInstall/config"); cdest = tempfolder.resolve("config/dcInstall"); if (Files.exists(csrc)) { Files.createDirectories(cdest); OperationResult cres = FileUtil.copyFileTree(csrc, cdest); if (cres.hasErrors()) { System.out.println("Error with prepping install config"); break; } } } // write out the deployed file RecordStruct deployed = new RecordStruct(); deployed.setField("Version", relvers); deployed.setField("PackageFolder", relpath.resolve(rname)); deployed.setField("PackagePrefix", rname); OperationResult d1res = IOUtil.saveEntireFile(tempfolder.resolve("config/deployed.json"), deployed.toPrettyString()); if (d1res.hasErrors()) { System.out.println("Error with prepping deployed"); break; } RecordStruct deployment = new RecordStruct(); deployment.setField("Version", relvers); if (prindesc.hasAttribute("LastVersion")) deployment.setField("DependsOn", prindesc.getAttribute("LastVersion")); deployment.setField("UpdateMessage", "This update is complete, you may accept this update as runnable."); nolongerdepends.removeAll(dependson); ListStruct deletefiles = new ListStruct(); nolongerdepends.forEach(fname -> deletefiles.addItem("lib/" + fname)); deployment.setField("DeleteFiles", deletefiles); deployment.setField("IgnorePaths", ignorepaths); d1res = IOUtil.saveEntireFile(tempfolder.resolve("deployment.json"), deployment.toPrettyString()); if (d1res.hasErrors()) { System.out.println("Error with prepping deployment"); break; } // write env file d1res = IOUtil.saveEntireFile(tempfolder.resolve("env.bat"), "set mem=" + relchoice.getAttribute("Memory", "2048") + "\r\n" + "SET project=" + inst.prinpackagenm + "\r\n" + "SET service=" + relchoice.getAttribute("Service", inst.prinpackagenm) + "\r\n" + "SET servicename=" + relchoice.getAttribute("ServiceName", inst.prinpackagenm + " Service") + "\r\n"); if (d1res.hasErrors()) { System.out.println("Error with prepping env"); break; } System.out.println("Packing Release file."); Path relbin = relpath.resolve(rname + "/" + rname + "-" + relvers + "-bin.zip"); if (Files.notExists(relbin.getParent())) Files.createDirectories(relbin.getParent()); ZipArchiveOutputStream zipout = new ZipArchiveOutputStream(relbin.toFile()); try { Files.walkFileTree(tempfolder, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { ZipArchiveEntry entry = new ZipArchiveEntry( tempfolder.relativize(file).toString()); entry.setSize(Files.size(file)); zipout.putArchiveEntry(entry); zipout.write(Files.readAllBytes(file)); zipout.closeArchiveEntry(); return FileVisitResult.CONTINUE; } }); } catch (IOException x) { System.out.println("Error building zip: " + x); } zipout.close(); System.out.println("Release file written"); FileUtil.deleteDirectory(tempfolder); break; } // end case 1 case 3: { System.out.println("Note these utilities are only good from the main console,"); System.out.println("if you are using a remote connection then the encryption will"); System.out.println("not work as expected. [we do not have access the master keys]"); System.out.println(); Foreground.utilityMenu(scan); break; } case 4: { System.out.println("Packing jar library files."); String[] packlist = new String[] { "divconq.core", "divconq.interchange", "divconq.web", "divconq.tasks", "divconq.tasks.api", "ncc.uploader.api", "ncc.uploader.core", "ncc.workflow", "sd.core" }; String[] packnames = new String[] { "dcCore", "dcInterchange", "dcWeb", "dcTasks", "dcTasksApi", "nccUploaderApi", "nccUploader", "nccWorkflow", "sd/sdBackend" }; for (int i = 0; i < packlist.length; i++) { String lib = packlist[i]; String pname = packnames[i]; Path relbin = Paths.get("./ext/" + lib + ".jar"); Path srcbin = Paths.get("./" + lib + "/bin"); Path packbin = Paths.get("./packages/" + pname + "/lib/" + lib + ".jar"); if (Files.notExists(relbin.getParent())) Files.createDirectories(relbin.getParent()); Files.deleteIfExists(relbin); ZipArchiveOutputStream zipout = new ZipArchiveOutputStream(relbin.toFile()); try { Files.walkFileTree(srcbin, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { ZipArchiveEntry entry = new ZipArchiveEntry( srcbin.relativize(file).toString()); entry.setSize(Files.size(file)); zipout.putArchiveEntry(entry); zipout.write(Files.readAllBytes(file)); zipout.closeArchiveEntry(); return FileVisitResult.CONTINUE; } }); } catch (IOException x) { System.out.println("Error building zip: " + x); } zipout.close(); Files.copy(relbin, packbin, StandardCopyOption.REPLACE_EXISTING); } System.out.println("Done"); break; } case 5: { System.out.println("Copying Source Files"); System.out.println("Cleaning folders"); OperationResult or = FileUtil.deleteDirectory(gitpath.resolve("divconq.core/src/main/java")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("divconq.core/src/main/resources")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("divconq.interchange/src/main/java")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("divconq.tasks/src/main/java")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("divconq.tasks.api/src/main/java")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("divconq.web/src/main/java")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectory(gitpath.resolve("packages")); if (or.hasErrors()) { System.out.println("Error deleting files"); break; } or = FileUtil.deleteDirectoryContent(wikigitpath, ".git"); if (or.hasErrors()) { System.out.println("Error deleting wiki files"); break; } System.out.println("Copying folders"); System.out.println("Copy tree ./divconq.core/src"); or = FileUtil.copyFileTree(Paths.get("./divconq.core/src/divconq"), gitpath.resolve("divconq.core/src/main/java/divconq"), new Predicate<Path>() { @Override public boolean test(Path file) { return file.getFileName().toString().endsWith(".java"); } }); if (or.hasErrors()) { System.out.println("Error copying files"); break; } or = FileUtil.copyFileTree(Paths.get("./divconq.core/src/org"), gitpath.resolve("divconq.core/src/main/java/org"), new Predicate<Path>() { @Override public boolean test(Path file) { return file.getFileName().toString().endsWith(".java"); } }); if (or.hasErrors()) { System.out.println("Error copying files"); break; } or = FileUtil.copyFileTree(Paths.get("./divconq.core/src/localize"), gitpath.resolve("divconq.core/src/main/resources/localize"), new Predicate<Path>() { @Override public boolean test(Path file) { return file.getFileName().toString().endsWith(".xml"); } }); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./divconq.interchange/src"); or = FileUtil.copyFileTree(Paths.get("./divconq.interchange/src"), gitpath.resolve("divconq.interchange/src/main/java")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./divconq.tasks/src"); or = FileUtil.copyFileTree(Paths.get("./divconq.tasks/src"), gitpath.resolve("divconq.tasks/src/main/java")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./divconq.tasks.api/src"); or = FileUtil.copyFileTree(Paths.get("./divconq.tasks.api/src"), gitpath.resolve("divconq.tasks.api/src/main/java")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./divconq.web/src"); or = FileUtil.copyFileTree(Paths.get("./divconq.web/src"), gitpath.resolve("divconq.web/src/main/java")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcCore"); or = FileUtil.copyFileTree(Paths.get("./packages/dcCore"), gitpath.resolve("packages/dcCore")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcCorePublic"); or = FileUtil.copyFileTree(Paths.get("./packages/dcCorePublic"), gitpath.resolve("packages/dcCorePublic")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcInterchange"); or = FileUtil.copyFileTree(Paths.get("./packages/dcInterchange"), gitpath.resolve("packages/dcInterchange")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcTasks"); or = FileUtil.copyFileTree(Paths.get("./packages/dcTasks"), gitpath.resolve("packages/dcTasks")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcTasksApi"); or = FileUtil.copyFileTree(Paths.get("./packages/dcTasksApi"), gitpath.resolve("packages/dcTasksApi")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcTasksWeb"); or = FileUtil.copyFileTree(Paths.get("./packages/dcTasksWeb"), gitpath.resolve("packages/dcTasksWeb")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcTest"); or = FileUtil.copyFileTree(Paths.get("./packages/dcTest"), gitpath.resolve("packages/dcTest")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./packages/dcWeb"); or = FileUtil.copyFileTree(Paths.get("./packages/dcWeb"), gitpath.resolve("packages/dcWeb")); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copy tree ./divconq.wiki/public"); or = FileUtil.copyFileTree(Paths.get("./divconq.wiki/public"), wikigitpath); if (or.hasErrors()) { System.out.println("Error copying files"); break; } System.out.println("Copying files"); Files.copy(Paths.get("./README.md"), gitpath.resolve("README.md"), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); Files.copy(Paths.get("./RELEASE_NOTES.md"), gitpath.resolve("RELEASE_NOTES.md"), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); Files.copy(Paths.get("./NOTICE.txt"), gitpath.resolve("NOTICE.txt"), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); Files.copy(Paths.get("./LICENSE.txt"), gitpath.resolve("LICENSE.txt"), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); System.out.println("Done"); break; } case 6: { System.out.println("Are you sure you want to update AWWW Server? (y/n): "); if (!scan.nextLine().toLowerCase().startsWith("y")) break; ReleasesHelper releases = new ReleasesHelper(); if (!releases.init(relpath)) break; XElement relchoice = releases.get("AWWWServer"); if (relchoice == null) { System.out.println("Invalid option"); break; } PackagesHelper availpackages = new PackagesHelper(); availpackages.init(); InstallHelper inst = new InstallHelper(); if (!inst.init(availpackages, relchoice)) break; ServerHelper ssh = new ServerHelper(); if (!ssh.init(relchoice.find("SSH"))) break; ChannelSftp sftp = null; try { Channel channel = ssh.session().openChannel("sftp"); channel.connect(); sftp = (ChannelSftp) channel; // go to routines folder sftp.cd("/usr/local/bin/dc/AWWWServer"); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(".git")).findGitDir() // scan up the file system tree .build(); String lastsync = releases.getData("AWWWServer").getFieldAsString("LastCommitSync"); RevWalk rw = new RevWalk(repository); ObjectId head1 = repository.resolve(Constants.HEAD); RevCommit commit1 = rw.parseCommit(head1); releases.getData("AWWWServer").setField("LastCommitSync", head1.name()); ObjectId rev2 = repository.resolve(lastsync); RevCommit parent = rw.parseCommit(rev2); //RevCommit parent2 = rw.parseCommit(parent.getParent(0).getId()); DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); // list oldest first or change types are all wrong!! List<DiffEntry> diffs = df.scan(parent.getTree(), commit1.getTree()); for (DiffEntry diff : diffs) { String gnpath = diff.getNewPath(); String gopath = diff.getOldPath(); Path npath = Paths.get("./" + gnpath); Path opath = Paths.get("./" + gopath); if (diff.getChangeType() == ChangeType.DELETE) { if (inst.containsPathExtended(opath)) { System.out.println("- " + diff.getChangeType().name() + " - " + opath); try { sftp.rm(opath.toString()); System.out.println("deleted!!"); } catch (SftpException x) { System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println("Sftp Error: " + x); System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } else { System.out.println("/ " + diff.getChangeType().name() + " - " + gopath + " !!!!!!!!!!!!!!!!!!!!!!!!!"); } } else if ((diff.getChangeType() == ChangeType.ADD) || (diff.getChangeType() == ChangeType.MODIFY) || (diff.getChangeType() == ChangeType.COPY)) { if (inst.containsPathExtended(npath)) { System.out.println("+ " + diff.getChangeType().name() + " - " + npath); try { ssh.makeDirSftp(sftp, npath.getParent()); sftp.put(npath.toString(), npath.toString(), ChannelSftp.OVERWRITE); sftp.chmod(npath.endsWith(".sh") ? 484 : 420, npath.toString()); // 644 octal = 420 dec, 744 octal = 484 dec System.out.println("uploaded!!"); } catch (SftpException x) { System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println("Sftp Error: " + x); System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } else { System.out.println("> " + diff.getChangeType().name() + " - " + gnpath + " !!!!!!!!!!!!!!!!!!!!!!!!!"); } } else if (diff.getChangeType() == ChangeType.RENAME) { // remove the old if (inst.containsPathExtended(opath)) { System.out.println("- " + diff.getChangeType().name() + " - " + opath); try { sftp.rm(opath.toString()); System.out.println("deleted!!"); } catch (SftpException x) { System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println("Sftp Error: " + x); System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } else { System.out.println("/ " + diff.getChangeType().name() + " - " + gopath + " !!!!!!!!!!!!!!!!!!!!!!!!!"); } // add the new path if (inst.containsPathExtended(npath)) { System.out.println("+ " + diff.getChangeType().name() + " - " + npath); try { ssh.makeDirSftp(sftp, npath.getParent()); sftp.put(npath.toString(), npath.toString(), ChannelSftp.OVERWRITE); sftp.chmod(npath.endsWith(".sh") ? 484 : 420, npath.toString()); // 644 octal = 420 dec, 744 octal = 484 dec System.out.println("uploaded!!"); } catch (SftpException x) { System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); System.out.println("Sftp Error: " + x); System.out.println( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } else { System.out.println("> " + diff.getChangeType().name() + " - " + gnpath + " !!!!!!!!!!!!!!!!!!!!!!!!!"); } } else { System.out.println("??????????????????????????????????????????????????????????"); System.out.println(": " + diff.getChangeType().name() + " - " + gnpath + " ?????????????????????????"); System.out.println("??????????????????????????????????????????????????????????"); } } rw.dispose(); repository.close(); releases.saveData(); } catch (JSchException x) { System.out.println("Sftp Error: " + x); } finally { if (sftp.isConnected()) sftp.exit(); ssh.close(); } break; } case 7: { Path sfolder = Paths.get("/Work/Projects/awww-current/dairy-graze/poly"); Path dfolder = Paths.get("/Work/Projects/awww-current/dairy-graze/poly-js"); Files.list(sfolder).forEach(file -> { String fname = file.getFileName().toString(); if (!fname.endsWith(".xml")) return; FuncResult<XElement> lres = XmlReader.loadFile(file, false); if (lres.isEmptyResult()) { System.out.println("Unable to parse: " + file); return; } String zc = fname.substring(5, 8); String code = "zipsData['" + zc + "'] = "; XElement root = lres.getResult(); /* <polyline1 lng="-90.620897" lat="45.377447"/> <polyline1 lng="-90.619327" lat="45.3805"/> [-71.196845,41.67757],[-71.120168,41.496831],[-71.317338,41.474923],[-71.196845,41.67757] */ ListStruct center = new ListStruct(); ListStruct cords = new ListStruct(); ListStruct currentPoly = null; //String currentName = null; for (XElement child : root.selectAll("*")) { String cname = child.getName(); if (cname.startsWith("marker")) { // not always accurate if (center.isEmpty()) center.addItem(Struct.objectToDecimal(child.getAttribute("lng")), Struct.objectToDecimal(child.getAttribute("lat"))); currentPoly = new ListStruct(); cords.addItem(new ListStruct(currentPoly)); continue; } /* if (cname.startsWith("info")) { System.out.println("areas: " + child.getAttribute("areas")); continue; } */ if (!cname.startsWith("polyline")) continue; if (currentPoly == null) { //if (!cname.equals(currentName)) { //if (currentName == null) { // currentName = cname; // System.out.println("new poly: " + cname); currentPoly = new ListStruct(); cords.addItem(new ListStruct(currentPoly)); } currentPoly.addItem(new ListStruct(Struct.objectToDecimal(child.getAttribute("lng")), Struct.objectToDecimal(child.getAttribute("lat")))); } RecordStruct feat = new RecordStruct().withField("type", "Feature") .withField("id", "zip" + zc) .withField("properties", new RecordStruct().withField("name", "Prefix " + zc).withField("alias", zc)) .withField("geometry", new RecordStruct().withField("type", "MultiPolygon") .withField("coordinates", cords)); RecordStruct entry = new RecordStruct().withField("code", zc).withField("geo", feat) .withField("center", center); IOUtil.saveEntireFile2(dfolder.resolve("us-zips-" + zc + ".js"), code + entry.toPrettyString() + ";"); }); break; } } } catch (Exception x) { System.out.println("CLI error: " + x); } } }