Java 类org.gradle.api.tasks.SourceTask 实例源码

项目:javaccPlugin    文件:JavaccCompilerInputOutputConfigurationTest.java   
@Test
public void getCompleteSourceTreeReturnsSourceAndJavaSourceWhenProjectHasJavaCompileTasks() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    testFolder.newFolder("inputJava");
    File javaFile = addTaskWithSourceFile(project, "compileJava", "inputJava/MyClass.java", JavaCompile.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class))
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, containsInAnyOrder(javaccFile.getCanonicalFile(), javaFile.getCanonicalFile()));
}
项目:javaccPlugin    文件:JavaccCompilerInputOutputConfigurationTest.java   
@Test
public void getCompleteSourceTreeExcludesOutputFolder() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class))
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, contains(javaccFile.getCanonicalFile()));
    assertThat(completeSourceTree, not(contains(outputFile.getCanonicalFile())));
}
项目:javaccPlugin    文件:JavaccCompilerInputOutputConfigurationTest.java   
private File addTaskWithSourceFile(Project project, String taskName, String sourceFileName, Class<? extends SourceTask> taskType) throws IOException {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(Task.TASK_TYPE, taskType);

    SourceTask compileJava = (SourceTask) project.task(options, taskName);
    File javaFile = testFolder.newFile(sourceFileName);
    compileJava.source(javaFile.getCanonicalFile());

    return javaFile;
}
项目:javaccPlugin    文件:JavaccCompilerInputOutputConfigurationTest.java   
@Test
public void getCompleteSourceTreeReturnsSourceWhenNoJavaCompileTask() throws IOException {
    Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build();
    File javaccFile = addTaskWithSourceFile(project, "compileJavacc", "input/TestClass.jj", CompileJavaccTask.class);
    CompilerInputOutputConfiguration configuration = builder
        .withInputDirectory(inputDirectory)
        .withOutputDirectory(outputDirectory)
        .withSource(((SourceTask) project.getTasks().getByName("compileJavacc")).getSource())
        .build();

    FileTree completeSourceTree = configuration.getCompleteSourceTree();

    assertThat(completeSourceTree, contains(javaccFile.getCanonicalFile()));
}