@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"); }); }
public static List<TransformTask> findTransformTaskByTransformType(AppVariantContext 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; }
/** * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order: * * 1. Custom-JAR-Task defined in SwarmExtension 'archiveTask' * 2. WAR-Task * 3. JAR-Task */ private Jar getArchiveTask(Project project) { TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class); Jar customArchiveTask = project.getExtensions().getByType(SwarmExtension.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); } return null; }
private List<String> buildCompilerArgs(JavaPluginConvention javaPluginConvention) { TaskCollection<JavaCompile> javaCompilers = getProject().getTasks().withType(JavaCompile.class); CompileOptions firstCompilerOptions = javaCompilers.isEmpty() ? null : javaCompilers.iterator().next().getOptions(); List<String> args = new ArrayList<>(Arrays.asList("-source", javaPluginConvention.getSourceCompatibility().toString(), "-target", javaPluginConvention.getTargetCompatibility().toString(), "-encoding", getDefaultOrCompilerEncoding(firstCompilerOptions))); if (firstCompilerOptions != null) { FileCollection bootClasspath = firstCompilerOptions.getBootstrapClasspath(); if (bootClasspath != null) { args.add("-bootclasspath"); args.add(bootClasspath.getAsPath()); } } return args; }
@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(); }
@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(); }
@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"))); } }
@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))); } }
@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))); } }
/** * Adds execution data generated by the given tasks to the list of those used during coverage analysis. Only tasks with a {@link JacocoTaskExtension} will be included; all others will be ignored. * * @param tasks one or more tasks to add */ public void executionData(TaskCollection tasks) { tasks.all(new Action<Task>() { @Override public void execute(Task task) { executionData(task); } }); }
/** * Adds execution data generated by the given tasks to the list of those merged. Only tasks with a {@link JacocoTaskExtension} will be included; all others will be ignored. * * @param tasks one or more tasks to merge */ public void executionData(TaskCollection tasks) { tasks.all(new Action<Task>() { @Override public void execute(Task task) { executionData(task); } }); }
/** * Applies Jacoco to all of the given tasks. * * @param tasks the tasks to apply Jacoco to */ public <T extends Task & JavaForkOptions> void applyTo(TaskCollection tasks) { tasks.withType(JavaForkOptions.class, new Action<JavaForkOptions>() { @Override public void execute(JavaForkOptions task) { applyTo(Cast.<T>uncheckedCast(task)); } }); }
public RealizableTaskCollection(Class<T> type, TaskCollection<T> delegate, MutableModelNode modelNode) { assert !(delegate instanceof RealizableTaskCollection) : "Attempt to wrap already realizable task collection in realizable wrapper: " + delegate; this.delegate = delegate; this.type = type; this.modelNode = modelNode; }
@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"); }
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[] {}); }
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; }
@Before public void setUp() { project = mock(Project.class); when(project.getSubprojects()).thenReturn(Collections.<Project>emptySet()); when(project.getRootProject()).thenReturn(project); final TaskContainer tasks = mock(TaskContainer.class); final TaskCollection emptyTaskCollection = mock(TaskCollection.class); when(emptyTaskCollection.iterator()).thenReturn(Iterators.emptyIterator()); when(emptyTaskCollection.toArray()).thenReturn(EMPTY_ARRAY); when(tasks.withType(any(Class.class))).thenReturn(emptyTaskCollection); when(project.getTasks()).thenReturn(tasks); }
@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(); }
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); } }
@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))); } }
@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))); } }
@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))); } }
@Override public void apply(final Project project) { project.apply(Collections.singletonMap("plugin", ErrorProneBasePlugin.class)); final ErrorProneToolChain toolChain = ErrorProneToolChain.create(project); final Action<JavaCompile> action = task -> task.setToolChain(toolChain); final TaskCollection<JavaCompile> javaCompileTasks = project.getTasks().withType(JavaCompile.class); javaCompileTasks.all(action); javaCompileTasks.whenTaskAdded(action); }
@Override public <S extends Task> TaskCollection<S> withType(Class<S> type) { return new RealizableTaskCollection<S>(type, super.withType(type), modelNode); }
private <S extends T> RealizableTaskCollection<S> realizable(Class<S> type, TaskCollection<S> collection) { return new RealizableTaskCollection<S>(type, collection, modelNode); }
@Override public TaskCollection<T> matching(Spec<? super T> spec) { return realizable(type, delegate.matching(spec)); }
@Override public TaskCollection<T> matching(Closure closure) { return realizable(type, delegate.matching(closure)); }
@Override public <S extends T> TaskCollection<S> withType(Class<S> type) { return realizable(type, delegate.withType(type)); }
@Override public <S extends T> TaskCollection<S> withType(Class<S> type) { return filtered(createFilter(type)); }
@Override public TaskCollection<T> matching(Spec<? super T> spec) { return filtered(createFilter(spec)); }
@Override public TaskCollection<T> matching(Closure spec) { return matching(Specs.<T>convertClosureToSpec(spec)); }
/** * Gets the list of all transformtasks * * @return */ private SortedMap<String, TransformTask> getTransformTasks() { TaskCollection<TransformTask> transformTasks = project.getTasks() .withType(TransformTask.class); return transformTasks.getAsMap(); }
private void addJavaccDependencyToJavaCompileTask(TaskCollection<JavaCompile> javaCompilationTasks, CompileJavaccTask compileJavaccTask) { for (JavaCompile task : javaCompilationTasks) { task.dependsOn(compileJavaccTask); task.source(compileJavaccTask.getOutputDirectory()); } }
public JavaccConfigurationBuilder withJavaCompileTasks(TaskCollection<JavaCompile> javaCompileTasks) { this.javaCompileTasks = javaCompileTasks; return this; }