private Node node(String path) { return dest.join(path); } }
public T join(String... names) { return join(Arrays.asList(names)); }
private List<? extends Node> list(Node<?> node, List<Object[]> includes) throws IOException { Node child; if (includes.size() == 1 && includes.get(0)[0] instanceof String) { child = node.join((String) includes.get(0)[0]); if (child.exists()) { return Collections.singletonList(child); } else { return Collections.emptyList(); } } else { return node.list(); } }
private Node archiveDirectory(Node node) throws MkdirException { return node.getParent().join("archive", FMT.format(LocalDateTime.now())).mkdirsOpt(); } }
/** * Throws an exception if this is not a link. */ public T resolveLink() throws ReadLinkException { String path; path = readLink(); if (path.startsWith(Filesystem.SEPARATOR_STRING)) { return getRoot().node(path.substring(1), null); } else { return (T) getParent().join(path); } }
/** @return kind of a path, with . and .. where appropriate. */ public String getRelative(Node base) { String startfilepath; String destpath; String common; StringBuilder result; int len; int ups; int i; if (base.equals(this)) { return "."; } startfilepath = base.join("foo").getPath(); destpath = getPath(); common = Strings.getCommon(startfilepath, destpath); common = common.substring(0, common.lastIndexOf(Filesystem.SEPARATOR_CHAR) + 1); // ok for idx == -1 len = common.length(); startfilepath = startfilepath.substring(len); destpath = destpath.substring(len); result = new StringBuilder(); ups = Strings.count(startfilepath, Filesystem.SEPARATOR_STRING); for (i = 0; i < ups; i++) { result.append("..").append(Filesystem.SEPARATOR_STRING); } result.append(destpath); return result.toString(); }
public void moveInto(Node directory) throws ExistsException, NodeNotFoundException, MoveException { directory.checkDirectory(); move(directory.join(getName())); }
/** @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 void copyInto(Node directory) throws ExistsException, NodeNotFoundException, CopyException { directory.checkDirectory(); copy(directory.join(getName())); }
private FileNode docroot(World world, MavenProject project) throws IOException { FileNode directory; List<FileNode> result; Filter filter; directory = world.file(project.getBasedir()); filter = directory.getWorld().filter(); filter.include("target/*/WEB-INF"); filter.predicate((node, b) -> node.isDirectory() && (node.join("lib").isDirectory() || node.join("classes").isDirectory())); filter.exclude("target/test-classes/**/*"); result = directory.find(filter); switch (result.size()) { case 0: throw new IOException("No web application found. Did you build the project?"); case 1: return result.get(0).getParent(); default: throw new FileNotFoundException("web.xml ambiguous: " + result); } } }
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 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(); }
break; node = data.join(getPath(entry)); if ("".equals(node.getPath())) { continue;
public ClassDef lookup(String name) throws IOException { ClassDef result; Node file; String path; ClassDef def; def = defs.get(name); if (def != null) { return def; } if (parent != null) { result = parent.lookup(name); if (result != null) { return result; } } path = ClassRef.classToResName(name); for (Node dir : lazy) { file = dir.join(path); if (file.isFile()) { def = Input.load(file); add(def); return def; } } return null; }
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(); } }