public T mkdirOpt() throws MkdirException { try { if (!isDirectory()) { mkdir(); // fail here if it's a file! } } catch (ExistsException e) { throw new MkdirException(this, e); } return (T) this; }
public T checkDirectory() throws ExistsException, DirectoryNotFoundException { if (isDirectory()) { return (T) this; } if (exists()) { throw new DirectoryNotFoundException(this, "directory not found - this is a file"); } else { throw new DirectoryNotFoundException(this); } }
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); } } }
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(); }
public T mkdirsOpt() throws MkdirException { T parent; try { if (!isDirectory()) { parent = getParent(); if (parent != null) { parent.mkdirsOpt(); } mkdir(); // fail here if it's a file! } } catch (ExistsException e) { throw new MkdirException(this, e); } return (T)this; }
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; }
/** * 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); } }
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));