Example #1
0
 private void processCopy(Node operation) {
   List<Node> fromNode = getChildNodes(operation, "from");
   List<Node> toNode = getChildNodes(operation, "to");
   if (fromNode.isEmpty() || toNode.isEmpty()) {
     return;
   }
   String path = fromNode.get(0).getTextContent();
   String fromPath = (new File(path).isAbsolute()) ? path : absolutePath(path);
   String toPath = absolutePath(toNode.get(0).getTextContent());
   Boolean copyContents = fromPath.endsWith(File.separator + "*");
   File from = new File((copyContents) ? fromPath.substring(0, fromPath.length() - 2) : fromPath);
   File to = new File(toPath);
   if (!from.exists()) {
     Utils.onError(new Error.FileNotFound(from.getPath()));
     return;
   }
   try {
     if (copyContents) {
       FileUtils.forceMkdir(to);
       FileUtils.copyDirectory(from, to);
     } else if (from.isDirectory()) {
       FileUtils.forceMkdir(to);
       FileUtils.copyDirectoryToDirectory(from, to);
     } else {
       if (to.isDirectory()) {
         FileUtils.forceMkdir(to);
         FileUtils.copyFileToDirectory(from, to);
       } else {
         File toDir = new File(Utils.getParentDir(to));
         FileUtils.forceMkdir(toDir);
         FileUtils.copyFile(from, to);
       }
     }
   } catch (IOException ex) {
     Utils.onError(new Error.FileCopy(from.getPath(), to.getPath()));
   }
 }
Example #2
0
 public void apply(String path, String[] scripts)
     throws ParserConfigurationException, TransformerConfigurationException {
   File target = new File(path);
   if (target.isDirectory()) {
     String callerDir = this.targetDir;
     this.targetDir = path;
     for (String script : scripts) call(script);
     this.targetDir = callerDir;
   } else {
     String tmpDir = inflate(path);
     if (tmpDir == null) return;
     apply(tmpDir, scripts);
     deflate(tmpDir, path);
   }
 }
Example #3
0
 public void apply(String path, NodeList[] operations)
     throws ParserConfigurationException, TransformerConfigurationException {
   File target = new File(path);
   if (target.isDirectory()) {
     String callerDir = this.targetDir;
     this.targetDir = path;
     for (NodeList ops : operations) {
       for (int i = 0; i < ops.getLength(); i++) call(ops.item(i));
     }
     this.targetDir = callerDir;
   } else {
     String tmpDir = inflate(path);
     if (tmpDir == null) return;
     apply(tmpDir, operations);
     deflate(tmpDir, path);
   }
 }
Example #4
0
 private void processDelete(Node operation) {
   String path = absolutePath(operation.getTextContent());
   File target = new File(path);
   if (!target.exists()) {
     Utils.onError(new Error.FileNotFound(target.getPath()));
     return;
   }
   try {
     if (target.isDirectory()) {
       FileUtils.deleteDirectory(target);
     } else {
       FileUtils.forceDelete(target);
     }
   } catch (IOException ex) {
     Utils.onError(new Error.FileDelete(target.getPath()));
   }
 }