@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())); }
@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()))); }
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; }
@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())); }