private FileTree getCompleteSourceTree() {
    FileTree javaccTaskSourceTree = getSource();
    FileTree javaTasksSourceTree = getJavaSourceTree();
    FileTree completeSourceTree = null;

    if (javaTasksSourceTree == null) {
      completeSourceTree = javaccTaskSourceTree;
    } else {
      completeSourceTree = javaccTaskSourceTree.plus(javaTasksSourceTree);
    }

    return excludeOutputDirectory(completeSourceTree);
  }
  private FileTree getJavaSourceTree() {
    FileTree javaSourceTree = null;
    TaskCollection<JavaCompile> javaCompileTasks =
        this.getProject().getTasks().withType(JavaCompile.class);

    for (JavaCompile task : javaCompileTasks) {
      if (javaSourceTree == null) {
        javaSourceTree = task.getSource();
      } else {
        javaSourceTree = javaSourceTree.plus(task.getSource());
      }
    }

    return excludeOutputDirectory(javaSourceTree);
  }
  private FileTree excludeOutputDirectory(FileTree sourceTree) {
    if (sourceTree == null) {
      return null;
    }

    Spec<File> outputDirectoryFilter =
        new Spec<File>() {

          @Override
          public boolean isSatisfiedBy(File file) {
            return file.getAbsolutePath().contains(getOutputDirectory().getAbsolutePath());
          }
        };

    sourceTree = sourceTree.minus(sourceTree.filter(outputDirectoryFilter)).getAsFileTree();
    return sourceTree;
  }
예제 #4
0
 public void execute(final CopySpecResolver specResolver) {
   FileTree source = specResolver.getSource();
   source.visit(new CopyFileVisitorImpl(specResolver, action, instantiator, fileSystem));
 }