public static StageConfiguration load(Gson gson, Node file) throws IOException { try (Reader reader = file.newReader()) { return gson.fromJson(reader, StageConfiguration.class); } }
/** * Returns a String representation suitable for messages. * * CAUTION: don't use to convert to a string, use instead. */ @Override public String toString() { Node working; working = getWorld().getWorking(); if (working == null || !getRoot().equals(working.getRoot())) { return getUri().toString(); } else { if (hasAncestor(working)) { return getRelative(working); } else { return Filesystem.SEPARATOR_STRING + getPath(); } } }
public T deleteFileOpt() throws IOException { if (exists()) { deleteFile(); } return (T) this; }
public T deleteTreeOpt() throws IOException { if (exists()) { deleteTree(); } return (T) this; }
public T deleteDirectoryOpt() throws IOException { if (exists()) { deleteDirectory(); } return (T) this; }
boolean isDir; name = src.node.getName(); dest = null; try { childVariablesList = new ArrayList<>(); name = splitContext(name, parentVariables, childVariablesList); isDir = src.node.isDirectory(); for (Map<String, String> childVariables : childVariablesList) { dest = destParent.join(path == null ? name : path.apply(name, childVariables)); if (isDir) { dest.mkdirsOpt(); } else { dest.getParent().mkdirsOpt(); if (content == null || binary.matches(src.node.getRelative(sourcedir))) { src.node.copyFile(dest); } else { dest.writeString(content.apply(src.node.readString(), childVariables)); dest.setPermissions(src.node.getPermissions()); } catch (Exception e) { if (dest == null) { dest = destParent.join(name);
Node node; buffer = file.getWorld().getBuffer(); try (ZipInputStream zip = new ZipInputStream(file.newInputStream())) { while (true) { entry = zip.getNextEntry(); break; node = data.join(getPath(entry)); if ("".equals(node.getPath())) { continue; node.mkdirsOpt(); } else if (isManifest(node)) { mergeManifest(new Manifest(zip)); zip.closeEntry(); } else { node.getParent().mkdirsOpt(); buffer.copy(zip, node); zip.closeEntry();
out.closeEntry(); content = (List) data.find("**/*"); files = new ArrayList<>(); if (isManifest(node)) { throw new ArchiveException("manifest file not allowed"); } else if (node.isFile()) { files.add(node); } else { out.putNextEntry(new ZipEntry(Strings.removeLeft(node.getPath() + "/", pathRoot))); out.closeEntry(); try (InputStream in = file.newInputStream()) { out.putNextEntry(new ZipEntry(Strings.removeLeft(file.getPath(), pathRoot))); file.getWorld().getBuffer().copy(in, out); out.closeEntry();
private void rotateLogs(Stage stage) throws IOException { Node archived; for (Node logfile : stage.getBackstage().find("**/*.log")) { archived = archiveDirectory(logfile).join(logfile.getName() + ".gz"); console.verbose.println(String.format("rotating %s to %s", logfile.getRelative(stage.getBackstage()), archived.getRelative(stage.getBackstage()))); logfile.gzip(archived); logfile.deleteFile(); } }
/** @param passphrase null to try to load passphrase from ~/.ssh/passphrase file */ public void addDefaultIdentity(String passphrase) throws IOException, JSchException { Node dir; Node file; Node key; dir = getWorld().getHome().join(".ssh"); file = dir.join("passphrase"); if (passphrase == null && file.exists()) { passphrase = file.readString().trim(); } key = dir.join("id_dsa"); if (!key.exists()) { key = dir.join("id_rsa"); if (!key.exists()) { key = dir.join("identity"); } } if (!key.isFile()) { throw new IOException("private key not found: " + key); } addIdentity(key, passphrase); }
public static NodeReader create(Node node) throws FileNotFoundException, NewInputStreamException { try { return new NodeReader(node, node.newInputStream(), node.getWorld().getSettings().encoding); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
public void gunzip(Node dest) throws IOException { try (InputStream rawIn = newInputStream(); InputStream in = new GZIPInputStream(rawIn); OutputStream out = dest.newOutputStream()) { getWorld().getBuffer().copy(in, out); } }
public void moveInto(Node directory) throws ExistsException, NodeNotFoundException, MoveException { directory.checkDirectory(); move(directory.join(getName())); }
public void copyInto(Node directory) throws ExistsException, NodeNotFoundException, CopyException { directory.checkDirectory(); copy(directory.join(getName())); }
public String directory(Node leftdir, Node rightdir, List<String> paths) throws IOException { StringBuilder result; Node left; Node right; result = new StringBuilder(); leftdir.checkDirectory(); rightdir.checkDirectory(); for (String path : paths) { left = leftdir.join(path); right = rightdir.join(path); if (left.isDirectory()) { if (right.isDirectory()) { // ok } else if (right.isFile()) { throw new IOException("TODO"); } else { if (brief) { header('A', path, result); } else { // TODO } } } else if (right.isDirectory()) { header("A", path, result); } else { file(left, right, path, result); } } return result.toString(); }
private Node call(String name, Node src, Node destParent, Map<String, String> context) throws ReflectionException, IOException { String fileName; String methodName; Method m; Node dest; fileName = name.substring(1); methodName = normalize(fileName); m = calls.get(methodName); if (m == null) { throw new ReflectionException("unknown call: " + methodName + " (defined: " + calls.keySet() + ")"); } dest = destParent.join(fileName); if (src.isDirectory()) { dest.mkdirsOpt(); doInvoke(m, dest, context); } else { dest.writeString((String) doInvoke(m, context)); } return dest; }
public NodeWriter newAppender() throws IOException { return newWriter(true); }
/** * Copies this to dest. Overwrites existing file and adds to existing directories. * * @throws NodeNotFoundException if this does not exist */ public void copy(Node dest) throws NodeNotFoundException, CopyException { try { if (isDirectory()) { dest.mkdirOpt(); copyDirectory(dest); } else { copyFile(dest); } } catch (FileNotFoundException | CopyException e) { throw e; } catch (IOException e) { throw new CopyException(this, dest, e); } }