org.gradle.api.tasks.TaskCollection Java Examples

The following examples show how to use org.gradle.api.tasks.TaskCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompileJjtreeTask.java    From javaccPlugin with MIT License 6 votes vote down vote up
@TaskAction
public void run() {
    TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class);
    CompilerInputOutputConfiguration inputOutputDirectories
        = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks);
    JjtreeProgramInvoker jjtreeInvoker = new JjtreeProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory());
    ProgramArguments arguments = new ProgramArguments();
    arguments.addAll(getArguments());
    SourceFileCompiler compiler = new JavaccSourceFileCompiler(jjtreeInvoker, arguments, inputOutputDirectories, getLogger());

    compiler.createTempOutputDirectory();
    compiler.compileSourceFilesToTempOutputDirectory();
    compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory();
    compiler.copyNonJavaccFilesToOutputDirectory();
    compiler.cleanTempOutputDirectory();
}
 
Example #2
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 6 votes vote down vote up
@Test
public void compileJavaccDoesNotDependOnCompileJJTreeWhenInputDirectoryEmpty() {
    applyJavaPluginToProject();
    applyJavaccPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();

    final File inputDirectory = new File(getClass().getResource("/empty").getFile());
    CompileJjtreeTask compileJjtreeTask = (CompileJjtreeTask) project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE);
    compileJjtreeTask.setInputDirectory(inputDirectory);

    action.execute(project);

    TaskCollection<CompileJavaccTask> compileJavaccTasks = project.getTasks().withType(CompileJavaccTask.class);
    for (CompileJavaccTask task : compileJavaccTasks) {
        Set<Object> dependencies = task.getDependsOn();
        assertFalse(dependencies.contains(project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE)));
    }
}
 
Example #3
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 6 votes vote down vote up
@Test
public void compileJavaccDependOnCompileJJTreeWhenInputDirectoryNotEmpty() {
    applyJavaPluginToProject();
    applyJavaccPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();

    final File inputDirectory = new File(getClass().getResource("/jjtree/input").getFile());
    CompileJjtreeTask compileJjtreeTask = (CompileJjtreeTask) project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE);
    compileJjtreeTask.setInputDirectory(inputDirectory);

    action.execute(project);

    TaskCollection<CompileJavaccTask> compileJavaccTasks = project.getTasks().withType(CompileJavaccTask.class);
    for (CompileJavaccTask task : compileJavaccTasks) {
        Set<Object> dependencies = task.getDependsOn();
        assertTrue(dependencies.contains(project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE)));
    }
}
 
Example #4
Source File: CompileJavaccTask.java    From javaccPlugin with MIT License 6 votes vote down vote up
@TaskAction
public void run() {
    TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class);
    CompilerInputOutputConfiguration inputOutputDirectories
        = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks);
    JavaccProgramInvoker javaccInvoker = new JavaccProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory());
    ProgramArguments arguments = new ProgramArguments();
    arguments.addAll(getArguments());
    SourceFileCompiler compiler = new JavaccSourceFileCompiler(javaccInvoker, arguments, inputOutputDirectories, getLogger());

    compiler.createTempOutputDirectory();
    compiler.compileSourceFilesToTempOutputDirectory();
    compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory();
    compiler.copyNonJavaccFilesToOutputDirectory();
    compiler.cleanTempOutputDirectory();
}
 
Example #5
Source File: TransformManager.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static List<TransformTask> findTransformTaskByTransformType(VariantContext appVariantContext, Class<?>
    transformClass) {
    List<TransformTask> transformTasksList = Lists.newArrayList();
    VariantConfiguration config = appVariantContext.getVariantConfiguration();
    TaskCollection<TransformTask> transformTasks = appVariantContext.getProject().getTasks().withType(
        TransformTask.class);
    SortedMap<String, TransformTask> transformTaskSortedMap = transformTasks.getAsMap();
    String variantName = config.getFullName();
    for (String taskName : transformTaskSortedMap.keySet()) {
        TransformTask transformTask = transformTaskSortedMap.get(taskName);
        if (variantName == transformTask.getVariantName()) {
            if (transformTask.getTransform().getClass() == transformClass) {
                transformTasksList.add(transformTask);
            }
        }
    }
    return transformTasksList;
}
 
Example #6
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 6 votes vote down vote up
@Test
public void generatedJavaFilesFromCompileJavaccAreAddedToMainJavaSourceSet() {
    applyJavaccPluginToProject();
    applyJavaPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();
    final File outputDirectory = new File(getClass().getResource("/javacc/testgenerated").getFile());
    CompileJavaccTask compileJavaccTask = (CompileJavaccTask) project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE);
    compileJavaccTask.setOutputDirectory(outputDirectory);

    action.execute(project);

    TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class);
    for (JavaCompile task : javaCompilationTasks) {
        assertTrue(task.getSource().contains(new File(outputDirectory, "someSourceFile.txt")));
    }
}
 
Example #7
Source File: ThorntailUtils.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order:
 * <p>
 * 1. Custom-JAR-Task defined in ThorntailExtension 'archiveTask'
 * 2. WAR-Task
 * 3. JAR-Task
 */
public static Jar getArchiveTask(Project project) {

    TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class);
    Jar customArchiveTask = project.getExtensions().getByType(ThorntailExtension.class).getArchiveTask();

    if (customArchiveTask != null) {
        return existingArchiveTasks.getByName(customArchiveTask.getName());

    } else if (existingArchiveTasks.findByName(WarPlugin.WAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(WarPlugin.WAR_TASK_NAME);

    } else if (existingArchiveTasks.findByName(JavaPlugin.JAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(JavaPlugin.JAR_TASK_NAME);
    }

    throw new GradleException("Unable to detect Archive-Task: project contains neither 'war' nor 'jar', " +
            "nor is custom Archive-Task specified in the \"thorntail\" extension.");
}
 
Example #8
Source File: MinikubePluginTest.java    From minikube-build-tools-for-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMinikubeExtensionSetProperties() {
  Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
  project.getPluginManager().apply(MinikubePlugin.class);
  MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube");
  ex.setMinikube("/custom/minikube/path");

  TaskContainer t = project.getTasks();
  TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class);

  Assert.assertEquals(3, tc.size());

  tc.forEach(
      minikubeTask -> {
        Assert.assertEquals(minikubeTask.getMinikube(), "/custom/minikube/path");
      });
}
 
Example #9
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 5 votes vote down vote up
@Test
public void compileJavaDependsOnCompileJavaccAfterExecutionWhenJavaPluginApplied() {
    applyJavaccPluginToProject();
    applyJavaPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();

    action.execute(project);

    TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class);
    for (JavaCompile task : javaCompilationTasks) {
        Set<Object> dependencies = task.getDependsOn();
        assertTrue(dependencies.contains(project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE)));
    }
}
 
Example #10
Source File: CompileJjdocTask.java    From javaccPlugin with MIT License 5 votes vote down vote up
@TaskAction
public void run() {
    TaskCollection<JavaCompile> javaCompileTasks = this.getProject().getTasks().withType(JavaCompile.class);
    CompilerInputOutputConfiguration inputOutputDirectories
        = new JavaccCompilerInputOutputConfiguration(getInputDirectory(), getOutputDirectory(), getSource(), javaCompileTasks);
    JjdocProgramInvoker jjdocInvoker = new JjdocProgramInvoker(getProject(), getClasspath(), inputOutputDirectories.getTempOutputDirectory());
    ProgramArguments arguments = new ProgramArguments();
    arguments.addAll(getArguments());
    SourceFileCompiler compiler = new JavaccSourceFileCompiler(jjdocInvoker, arguments, inputOutputDirectories, getLogger());

    compiler.createTempOutputDirectory();
    compiler.compileSourceFilesToTempOutputDirectory();
    compiler.copyCompiledFilesFromTempOutputDirectoryToOutputDirectory();
    compiler.cleanTempOutputDirectory();
}
 
Example #11
Source File: JavaccCompilerInputOutputConfiguration.java    From javaccPlugin with MIT License 5 votes vote down vote up
public JavaccCompilerInputOutputConfiguration(File inputDirectory, File outputDirectory, FileTree source, TaskCollection<JavaCompile> javaCompileTasks) {
    this.inputDirectory = inputDirectory;
    this.outputDirectory = outputDirectory;
    this.source = source;
    this.javaCompileTasks = new HashSet<JavaCompile>();

    if (!CollectionUtils.isEmpty(javaCompileTasks)) {
        this.javaCompileTasks.addAll(javaCompileTasks);
    }
}
 
Example #12
Source File: MinikubePluginTest.java    From minikube-build-tools-for-java with Apache License 2.0 5 votes vote down vote up
private void AssertMinikubeTaskConfig(
    TaskCollection<MinikubeTask> tc, String taskName, String taskCommand) {
  MinikubeTask minikubeTask = tc.getByName(taskName);
  Assert.assertEquals(minikubeTask.getMinikube(), "minikube");
  Assert.assertEquals(minikubeTask.getCommand(), taskCommand);
  Assert.assertArrayEquals(minikubeTask.getFlags(), new String[] {});
}
 
Example #13
Source File: MinikubePluginTest.java    From minikube-build-tools-for-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultMinikubeTasks() {
  Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
  project.getPluginManager().apply(MinikubePlugin.class);
  ((ProjectInternal) project).evaluate();

  TaskContainer t = project.getTasks();
  TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class);

  Assert.assertEquals(3, tc.size());

  AssertMinikubeTaskConfig(tc, "minikubeStart", "start");
  AssertMinikubeTaskConfig(tc, "minikubeStop", "stop");
  AssertMinikubeTaskConfig(tc, "minikubeDelete", "delete");
}
 
Example #14
Source File: MtlTransformInjector.java    From atlas with Apache License 2.0 5 votes vote down vote up
private TransformTask findTransformTask(Class transformClazz) {

        TaskCollection<TransformTask> androidTasks = project.getTasks().withType(TransformTask.class);

        for (TransformTask transformTask : androidTasks) {
            if (transformTask.getTransform().getClass().equals(transformClazz)) {

                if (appVariantContext.getVariantData().getName().equals(transformTask.getVariantName())) {
                    return transformTask;
                }
            }
        }

        return null;
    }
 
Example #15
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 5 votes vote down vote up
@Test
public void compileJavaDoesNotDependOnCompileJavaccWhenJavaccPluginNotApplied() {
    applyJavaPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();

    action.execute(project);

    TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class);
    for (JavaCompile task : javaCompilationTasks) {
        Set<Object> dependencies = task.getDependsOn();
        assertFalse(dependencies.contains(project.getTasks().findByName(CompileJavaccTask.TASK_NAME_VALUE)));
    }
}
 
Example #16
Source File: JavaToJavaccDependencyActionTest.java    From javaccPlugin with MIT License 5 votes vote down vote up
@Test
public void compileJavaDoesNotDependOnCompileJJTreeWhenJavaccPluginNotApplied() {
    applyJavaPluginToProject();
    JavaToJavaccDependencyAction action = new JavaToJavaccDependencyAction();

    action.execute(project);

    TaskCollection<JavaCompile> javaCompilationTasks = project.getTasks().withType(JavaCompile.class);
    for (JavaCompile task : javaCompilationTasks) {
        Set<Object> dependencies = task.getDependsOn();
        assertFalse(dependencies.contains(project.getTasks().findByName(CompileJjtreeTask.TASK_NAME_VALUE)));
    }
}
 
Example #17
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Closure spec) {
    return matching(Specs.<T>convertClosureToSpec(spec));
}
 
Example #18
Source File: JavaToJavaccDependencyAction.java    From javaccPlugin with MIT License 4 votes vote down vote up
private void addJavaccDependencyToJavaCompileTask(TaskCollection<JavaCompile> javaCompilationTasks, CompileJavaccTask compileJavaccTask) {
    for (JavaCompile task : javaCompilationTasks) {
        task.dependsOn(compileJavaccTask);
        task.source(compileJavaccTask.getOutputDirectory());
    }
}
 
Example #19
Source File: JavaccCompilerInputOutputConfigurationTest.java    From javaccPlugin with MIT License 4 votes vote down vote up
public JavaccConfigurationBuilder withJavaCompileTasks(TaskCollection<JavaCompile> javaCompileTasks) {
    this.javaCompileTasks = javaCompileTasks;

    return this;
}
 
Example #20
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Closure spec) {
    return matching(Specs.<T>convertClosureToSpec(spec));
}
 
Example #21
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Spec<? super T> spec) {
    return filtered(createFilter(spec));
}
 
Example #22
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public <S extends T> TaskCollection<S> withType(Class<S> type) {
    return filtered(createFilter(type));
}
 
Example #23
Source File: DefaultTaskCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public <S extends T> TaskCollection<S> withType(Class<S> type) {
    return filtered(createFilter(type));
}
 
Example #24
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Spec<? super T> spec) {
    return filtered(createFilter(spec));
}
 
Example #25
Source File: DefaultTaskCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public <S extends T> TaskCollection<S> withType(Class<S> type) {
    return filtered(createFilter(type));
}
 
Example #26
Source File: GeneratorPlugin.java    From native-samples with Apache License 2.0 4 votes vote down vote up
public void apply(Project project) {
    TaskCollection<SampleGeneratorTask> generatorTasks = project.getTasks().withType(SampleGeneratorTask.class);
    TaskCollection<GitRepoTask> repoTasks = project.getTasks().withType(GitRepoTask.class);

    // Add project extension
    SamplesExtension extension = project.getExtensions().create("samples", SamplesExtension.class, project);

    // Add a task to generate the list of samples
    TaskProvider<SamplesManifestTask> manifestTask = project.getTasks().register("samplesManifest", SamplesManifestTask.class, task -> {
        task.getManifest().set(project.file("samples-list.txt"));
        task.getSampleDirs().set(project.provider(() -> {
            return generatorTasks.stream().map(generator -> {
                return generator.getSampleDir().get().getAsFile().getAbsolutePath();
            }).collect(Collectors.toList());
        }));
        task.getRepoDirs().set(project.provider(() -> {
            return repoTasks.stream().map(generator -> {
                return generator.getSampleDir().get().getAsFile().getAbsolutePath();
            }).collect(Collectors.toList());
        }));
    });

    // Add a task to clean the samples
    project.getTasks().register("cleanSamples", CleanSamplesTask.class, task -> {
        // Need the location without the task dependency as we want to clean whatever was generated last time, not whatever will be generated next time
        task.getManifest().set(project.provider(() -> {
            return manifestTask.get().getManifest().get();
        }));
    });

    // Apply conventions to the generator tasks
    generatorTasks.configureEach( task -> {
        task.getTemplatesDir().set(project.file("src/templates"));
    });

    // Add a lifecycle task to generate the source files for the samples
    TaskProvider<Task> generateSource = project.getTasks().register("generateSource", task -> {
        task.dependsOn(generatorTasks);
        task.dependsOn(manifestTask);
        task.setGroup("source generation");
        task.setDescription("generate the source files for all samples");
    });

    extension.getExternalRepos().all(it -> {
        addTasksForRepo(it, generateSource, project);
    });

    extension.getSamples().all(it -> {
        addTasksForSample(it, project);
    });


    // Add a lifecycle task to generate the repositories
    project.getTasks().register("generateRepos", task -> {
        task.dependsOn(repoTasks);
        task.setGroup("source generation");
        task.setDescription("generate the Git repositories for all samples");
    });
}
 
Example #27
Source File: InjectTransformManager.java    From atlas with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the list of all transformtasks
 *
 * @return
 */
private SortedMap<String, TransformTask> getTransformTasks() {
    TaskCollection<TransformTask> transformTasks = project.getTasks()
            .withType(TransformTask.class);
    return transformTasks.getAsMap();
}
 
Example #28
Source File: DefaultTaskCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Closure spec) {
    return matching(Specs.<T>convertClosureToSpec(spec));
}
 
Example #29
Source File: DefaultTaskCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public TaskCollection<T> matching(Spec<? super T> spec) {
    return filtered(createFilter(spec));
}
 
Example #30
Source File: DefaultTaskCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public <S extends T> TaskCollection<S> withType(Class<S> type) {
    return filtered(createFilter(type));
}