コード例 #1
0
 @Override
 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
     throws IOException {
   Path targetPath = toPath.resolve(fromPath.relativize(dir));
   if (!Files.exists(targetPath)) {
     targetPath.toFile().mkdirs();
     // Files.createDirectory(targetPath);
   }
   return FileVisitResult.CONTINUE;
 }
コード例 #2
0
  public void unpack(String artifact, File destination) {
    File archiveFile = getAsFile(artifact);

    if (archiveFile == null || !archiveFile.exists()) return;
    if (archiveFile.isDirectory()) {
      try {
        Files.walkFileTree(archiveFile.toPath(), new CopyDirVisitor(archiveFile, destination));
      } catch (Exception e) {
        OutputBouble.reportError(e);
      }

    } else if (archiveFile.getName().endsWith("jar")) {
      destination.mkdirs();
      try {
        java.util.jar.JarFile jar = new java.util.jar.JarFile(archiveFile);
        java.util.Enumeration jarEnum = jar.entries();
        while (jarEnum.hasMoreElements()) {
          java.util.jar.JarEntry file = (java.util.jar.JarEntry) jarEnum.nextElement();
          java.io.File f = new java.io.File(destination + java.io.File.separator + file.getName());
          if (file.isDirectory()) { // if its a directory, create it
            f.mkdir();
            continue;
          }
          java.io.InputStream is = jar.getInputStream(file); // get the input stream
          java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
          while (is.available() > 0) { // write contents of 'is' to 'fos'
            fos.write(is.read());
          }
          fos.close();
          is.close();
        }
        jar.close();
      } catch (Exception e) {

      }
    }
  }
コード例 #3
0
  public void downloadFlat(String artifact, String copyToDir) {
    OutputBouble bouble = OutputBouble.push();
    try {
      Artifact theArtifact = new DefaultArtifact(artifact);

      HashSet<Artifact> downloadThese = new HashSet<Artifact>();
      downloadThese.add(theArtifact);
      Stack<Artifact> downloadDependenciesOfThese = new Stack<Artifact>();
      downloadDependenciesOfThese.add(theArtifact);

      while (!downloadDependenciesOfThese.isEmpty()) {
        Artifact getDependenciesOfThis = downloadDependenciesOfThese.pop();
        List<Artifact> dependencies =
            dependencyManager.getDirectDependencies(getDependenciesOfThis);
        for (Artifact a : dependencies) {
          if (!downloadThese.contains(a)) {
            downloadThese.add(a);
            downloadDependenciesOfThese.add(a);
          }
        }
      }

      File destination = new File(copyToDir);
      destination.mkdirs();

      for (Artifact a : downloadThese) {
        File theFile = getAsFile(a);
        Files.copy(theFile.toPath(), new File(destination, theFile.getName()).toPath());
      }
    } catch (Exception e) {
      OutputBouble.reportError(e);
    } finally {
      bouble.pop();
      if (bouble.isError) bouble.writeToParent();
    }
  }
コード例 #4
0
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   Files.copy(file, toPath.resolve(fromPath.relativize(file)), copyOption);
   return FileVisitResult.CONTINUE;
 }