org.gradle.api.tasks.TaskProvider Java Examples
The following examples show how to use
org.gradle.api.tasks.TaskProvider.
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: CpdTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@Test void Cpd_shouldThrowInvalidUserDataExceptionIfTwoReportsAreEnabled(TaskProvider<Cpd> cpdCheck) { // Given: cpdCheck.configure(task -> task.reports(report -> { report.getCsv().setEnabled(false); report.getText().setEnabled(false); report.getVs().setEnabled(false); report.getXml().setEnabled(false); })); Cpd actual = cpdCheck.get(); // Expect: assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual))) .isInstanceOf(InvalidUserDataException.class) .hasMessage("Task 'cpdCheck' requires at least one enabled report."); }
Example #2
Source File: JSassJavaPlugin.java From gradle-plugins with MIT License | 6 votes |
@Override public void apply(Project project) { project.getPlugins().apply(JSassWebjarsPlugin.class); project.getPlugins().apply(JavaPlugin.class); File baseDestinationDir = new File(project.getBuildDir(), "jsass"); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { String taskName = sourceSet.getCompileTaskName("Sass"); TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> { sassCompile.setSource(sourceSet.getResources()); sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName())); sassCompile.setGroup(BasePlugin.BUILD_GROUP); sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set"); }); project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class) .configure(processResources -> processResources.from(sassCompileTaskProvider)); }); }
Example #3
Source File: CpdTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@Test void Cpd_shouldHaveCorrectTaskInputs(Project project, TaskProvider<Cpd> cpdCheck) { // Given: cpdCheck.configure(task -> { task.reports(report -> { report.getText().setDestination(project.file(project.getBuildDir() + "/cpdCheck.text")); report.getText().setEnabled(true); }); task.source(testFile(JAVA, "de/aaschmid/clazz/")); }); Cpd actual = cpdCheck.get(); // Expect: assertThat(actual.getInputs().getProperties()).hasSize(50); assertThat(actual.getInputs().getSourceFiles()).containsExactlyInAnyOrderElementsOf(testFilesRecurseIn(JAVA, "de/aaschmid/clazz")); }
Example #4
Source File: TaskManager.java From dart with Apache License 2.0 | 6 votes |
/** * A henson navigator is a class that helps a consumer to consume the navigation api that it * declares in its dependencies. The henson navigator will wrap the intent builders. Thus, a * henson navigator, is driven by consumption of intent builders, whereas the henson classes are * driven by the production of an intent builder. * * <p>This task is created per android variant: * * <ul> * <li>we scan the variant compile configuration for navigation api dependencies * <li>we generate a henson navigator class for this variant that wraps the intent builders * </ul> * * @param variant the variant for which to create a builder. * @param hensonNavigatorPackageName the package name in which we create the class. */ public TaskProvider<GenerateHensonNavigatorTask> createHensonNavigatorGenerationTask( BaseVariant variant, String hensonNavigatorPackageName, File destinationFolder) { TaskProvider<GenerateHensonNavigatorTask> generateHensonNavigatorTask = project .getTasks() .register( "generate" + capitalize(variant.getName()) + "HensonNavigator", GenerateHensonNavigatorTask.class, (Action<GenerateHensonNavigatorTask>) generateHensonNavigatorTask1 -> { generateHensonNavigatorTask1.hensonNavigatorPackageName = hensonNavigatorPackageName; generateHensonNavigatorTask1.destinationFolder = destinationFolder; generateHensonNavigatorTask1.variant = variant; generateHensonNavigatorTask1.logger = logger; generateHensonNavigatorTask1.project = project; generateHensonNavigatorTask1.hensonNavigatorGenerator = hensonNavigatorGenerator; }); return generateHensonNavigatorTask; }
Example #5
Source File: ShadedJarPackaging.java From transport with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates a {@link ShadeTask} which generates a shaded JAR containing all runtime dependencies of the platform's * {@link SourceSet} * * TODO: This code is borrowed from the Shade plugin. Call the functionality residing in the Shade plugin once it is * available */ private TaskProvider<ShadeTask> createShadeTask(Project project, Platform platform, SourceSet sourceSet, SourceSet mainSourceSet) { TaskProvider<ShadeTask> shadeTask = project.getTasks().register(sourceSet.getTaskName("shade", "Jar"), ShadeTask.class, task -> { task.setGroup(ShadowJavaPlugin.getSHADOW_GROUP()); task.setDescription("Create a combined JAR of " + platform.getName() + " output and runtime dependencies"); task.setClassifier(platform.getName()); task.getManifest() .inheritFrom(project.getTasks().named(mainSourceSet.getJarTaskName(), Jar.class).get().getManifest()); task.from(sourceSet.getOutput()); task.setConfigurations(ImmutableList.of(getConfigurationForSourceSet(project, sourceSet, RUNTIME_CLASSPATH))); task.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA"); }); // TODO: Figure out why this artifact is generated but not being published in Maven project.getArtifacts().add(ShadowBasePlugin.getCONFIGURATION_NAME(), shadeTask); return shadeTask; }
Example #6
Source File: VariantProcessor.java From Injector with Apache License 2.0 | 6 votes |
/** * merge manifests */ private void processManifest() { TaskProvider<InvokeManifestMerger> invokeManifestMergerTaskProvider = project.getTasks().register("merge" + variantName + "Manifest", InvokeManifestMerger.class); TaskProvider<ManifestProcessorTask> processManifestTaskTaskProvider = Iterables.get(variant.getOutputs(), 0).getProcessManifestProvider(); processManifestTaskTaskProvider.configure(manifestProcessorTask -> manifestProcessorTask.finalizedBy(invokeManifestMergerTaskProvider)); invokeManifestMergerTaskProvider.configure(manifestsMergeTask -> { manifestsMergeTask.setVariantName(variant.getName()); List<File> list = new ArrayList<>(); androidArchiveLibraries.forEach(resolvedArtifact -> list.add((resolvedArtifact).getManifest())); manifestsMergeTask.setSecondaryManifestFiles(list); manifestsMergeTask.setMainManifestFile(processManifestTaskTaskProvider.get().getAaptFriendlyManifestOutputFile()); manifestsMergeTask.setOutputFile(new File(processManifestTaskTaskProvider.get().getManifestOutputDirectory().get().getAsFile(), "AndroidManifest.xml")); manifestsMergeTask.dependsOn(processManifestTaskTaskProvider); }); }
Example #7
Source File: JSassWebjarsPlugin.java From gradle-plugins with MIT License | 6 votes |
@Override public void apply(Project project) { project.getPlugins().apply(JSassBasePlugin.class); Configuration webjars = project.getConfigurations().create("webjars"); project.getPlugins().withType(JavaPlugin.class, javaPlugin -> webjars.extendsFrom(project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)) ); TaskProvider<PrepareWebjars> prepareWebjarsTaskProvider = project.getTasks().register("prepareWebjars", PrepareWebjars.class, prepareWebjars -> { prepareWebjars.getWebjars().from(webjars); prepareWebjars.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("jsass/webjars")); }); project.getTasks().withType(SassCompile.class) .configureEach(sassCompile -> sassCompile.getIncludePaths().from(prepareWebjarsTaskProvider)); }
Example #8
Source File: WarAttachClassesPlugin.java From gradle-plugins with MIT License | 6 votes |
@Override public void apply(Project project) { project.getPlugins().apply(WarPlugin.class); WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention(); project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war -> war.getConvention().getPlugins().put("attachClasses", attachClassesConvention) ); project.afterEvaluate(p -> { if (attachClassesConvention.isAttachClasses()) { TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j -> j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier()) ); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar); } }); }
Example #9
Source File: CpdTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@Test void Cpd_shouldAllowConfigurationOfDefaultTaskProperties(Project project, TaskProvider<Cpd> cpdCheck) { // Given: Task dependantTask = project.getTasks().create("dependant"); // When: cpdCheck.configure(task -> { task.setDependsOn(singleton(dependantTask)); task.setDescription("Execute me!"); task.setEnabled(false); task.setExcludes(asList("*.kt", "*.txt")); task.setGroup("check"); }); // Then: Cpd actual = cpdCheck.get(); assertThat(actual.getDependsOn()).containsOnly(dependantTask); assertThat(actual.getDescription()).isEqualTo("Execute me!"); assertThat(actual.getEnabled()).isFalse(); assertThat(actual.getExcludes()).containsOnly("*.kt", "*.txt"); assertThat(actual.getGroup()).isEqualTo("check"); }
Example #10
Source File: JSassWarPlugin.java From gradle-plugins with MIT License | 6 votes |
@Override public void apply(Project project) { project.getPlugins().apply(JSassWebjarsPlugin.class); project.getPlugins().apply(WarPlugin.class); TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register("compileWebappSass", SassCompile.class, compileWebappSass -> { compileWebappSass.setGroup(BasePlugin.BUILD_GROUP); compileWebappSass.setDescription("Compile sass and scss files for the webapp"); WarPluginConvention warPluginConvention = project.getConvention().getPlugin(WarPluginConvention.class); compileWebappSass.source(warPluginConvention.getWebAppDir()); compileWebappSass.getDestinationDir().set(new File(project.getBuildDir(), "jsass/webapp")); }); project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class) .configure(war -> war.from(sassCompileTaskProvider)); }
Example #11
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@Test void CpdPlugin_shouldSetCpdCheckSourceEqualsToMainAndTestSourceSetsIfJavaPluginIsApplied(Project project, TaskProvider<Cpd> cpd) { // Given: String mainFile = "src/main/java/Clazz.java"; String testFile = "src/test/java/ClazzTest.java"; // When: project.getPlugins().apply(JavaPlugin.class); createProjectFiles(project, mainFile, "src/resources/java/message.properties", testFile); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME, sourceSet -> { sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/annotation")); sourceSet.getAllJava().srcDir(testFile(JAVA, "de/aaschmid/clazz")); sourceSet.getResources().srcDir(testFile(JAVA, "de/aaschmid/foo")); }); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME, sourceSet -> sourceSet.getJava().srcDir(testFile(JAVA, "de/aaschmid/test"))); // Then: List<File> expected = testFilesRecurseIn(JAVA, "de/aaschmid/annotation", "de/aaschmid/clazz", "de/aaschmid/test"); expected.add(project.file(mainFile)); expected.add(project.file(testFile)); assertThat(cpd.get().getSource()).containsExactlyInAnyOrderElementsOf(expected); }
Example #12
Source File: AvroPlugin.java From gradle-avro-plugin with Apache License 2.0 | 6 votes |
private static TaskProvider<GenerateAvroJavaTask> configureJavaGenerationTask(final Project project, final SourceSet sourceSet, TaskProvider<GenerateAvroProtocolTask> protoTaskProvider) { String taskName = sourceSet.getTaskName("generate", "avroJava"); TaskProvider<GenerateAvroJavaTask> javaTaskProvider = project.getTasks().register(taskName, GenerateAvroJavaTask.class, task -> { task.setDescription(String.format("Generates %s Avro Java source files from schema/protocol definition files.", sourceSet.getName())); task.setGroup(GROUP_SOURCE_GENERATION); task.source(getAvroSourceDir(project, sourceSet)); task.source(protoTaskProvider); task.include("**/*." + SCHEMA_EXTENSION, "**/*." + PROTOCOL_EXTENSION); task.getOutputDir().convention(getGeneratedOutputDir(project, sourceSet, JAVA_EXTENSION)); sourceSet.getJava().srcDir(task.getOutputDir()); JavaCompile compileJavaTask = project.getTasks().named(sourceSet.getCompileJavaTaskName(), JavaCompile.class).get(); task.getOutputCharacterEncoding().convention(project.provider(() -> Optional.ofNullable(compileJavaTask.getOptions().getEncoding()).orElse(Charset.defaultCharset().name()))); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), JavaCompile.class, compileJavaTask -> { compileJavaTask.source(javaTaskProvider); }); return javaTaskProvider; }
Example #13
Source File: CpdTest.java From gradle-cpd-plugin with Apache License 2.0 | 6 votes |
@Test void Cpd_shouldAllowConfigurationOfSourceTaskProperties(TaskProvider<Cpd> cpdCheck) { // Given: cpdCheck.configure(task -> { task.exclude("**/literal/*"); task.exclude("**/*z*.java"); task.include("**/*2.java"); task.source(testFile(JAVA, ".")); }); Cpd actual = cpdCheck.get(); // Expect: assertThat(actual.getExcludes()).containsOnly("**/literal/*", "**/*z*.java"); assertThat(actual.getIncludes()).containsOnly("**/*2.java"); assertThat(actual.getSource()).containsOnly(testFile(JAVA, "de/aaschmid/identifier/Identifier2.java")); }
Example #14
Source File: TerraformPlugin.java From curiostack with MIT License | 6 votes |
private static TaskProvider<TerraformOutputTask> createTerraformOutputTask( Project project, String taskName, String outputName, File outputFile) { return project .getTasks() .register( taskName, TerraformOutputTask.class, t -> { t.doFirst(unused -> project.mkdir(outputFile.getParent())); t.setArgs(ImmutableList.of("output", outputName)); t.dependsOn(project.getTasks().getByName("terraformInit")); t.setExecCustomizer( exec -> { exec.setIgnoreExitValue(true); try { exec.setStandardOutput(new FileOutputStream(outputFile)); } catch (FileNotFoundException e) { throw new UncheckedIOException("Could not open file.", e); } }); }); }
Example #15
Source File: JSassJavaPlugin.java From gradle-plugins with MIT License | 6 votes |
@Override public void apply(Project project) { project.getPlugins().apply(JSassWebjarsPlugin.class); project.getPlugins().apply(JavaPlugin.class); File baseDestinationDir = new File(project.getBuildDir(), "jsass"); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { String taskName = sourceSet.getCompileTaskName("Sass"); TaskProvider<SassCompile> sassCompileTaskProvider = project.getTasks().register(taskName, SassCompile.class, sassCompile -> { sassCompile.setSource(sourceSet.getResources()); sassCompile.getDestinationDir().set(new File(baseDestinationDir, sourceSet.getName())); sassCompile.setGroup(BasePlugin.BUILD_GROUP); sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set"); }); project.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class) .configure(processResources -> processResources.from(sassCompileTaskProvider)); }); }
Example #16
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@Test void CpdPlugin_shouldAllowConfigureCpdCheckTaskViaCpdExtension(Project project, CpdExtension cpd, TaskProvider<Cpd> cpdCheck) { // Given: cpd.setEncoding("UTF-8"); cpd.setIgnoreAnnotations(true); cpd.setIgnoreFailures(true); cpd.setIgnoreIdentifiers(true); cpd.setIgnoreLiterals(true); cpd.setLanguage("ruby"); cpd.setMinimumTokenCount(25); cpd.setReportsDir(project.file("cpd-reports")); cpd.setSkipDuplicateFiles(true); cpd.setSkipLexicalErrors(true); cpd.setSkipBlocks(false); cpd.setSkipBlocksPattern("<|>"); // When: Cpd task = cpdCheck.get(); // Then: assertThat(task.getEncoding()).isEqualTo("UTF-8"); assertThat(task.getIgnoreAnnotations()).isTrue(); assertThat(task.getIgnoreFailures()).isTrue(); assertThat(task.getIgnoreIdentifiers()).isTrue(); assertThat(task.getIgnoreLiterals()).isTrue(); assertThat(task.getLanguage()).isEqualTo("ruby"); assertThat(task.getMinimumTokenCount()).isEqualTo(25); assertThat(task.getReports().getCsv().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.csv")); assertThat(task.getReports().getText().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.text")); assertThat(task.getReports().getVs().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.vs")); assertThat(task.getReports().getXml().getDestination()).isEqualTo(project.file("cpd-reports/cpdCheck.xml")); assertThat(task.getSkipDuplicateFiles()).isTrue(); assertThat(task.getSkipLexicalErrors()).isTrue(); assertThat(task.getSkipBlocks()).isFalse(); assertThat(task.getSkipBlocksPattern()).isEqualTo("<|>"); }
Example #17
Source File: CMakeApplicationPlugin.java From native-samples with Apache License 2.0 | 5 votes |
public void apply(final Project project) { project.getPluginManager().apply("org.gradle.samples.wrapped-native-application"); /* * Create some tasks to drive the CMake build */ TaskContainer tasks = project.getTasks(); TaskProvider<CMake> cmakeDebug = tasks.register("cmakeDebug", CMake.class, task -> { task.setBuildType("Debug"); task.getIncludeDirs().from(project.getConfigurations().getByName("cppCompile")); task.getLinkFiles().from(project.getConfigurations().getByName("linkDebug")); task.getVariantDirectory().set(project.getLayout().getBuildDirectory().dir("debug")); task.getProjectDirectory().set(project.getLayout().getProjectDirectory()); }); TaskProvider<CMake> cmakeRelease = tasks.register("cmakeRelease", CMake.class, task -> { task.setBuildType("RelWithDebInfo"); task.getIncludeDirs().from(project.getConfigurations().getByName("cppCompile")); task.getLinkFiles().from(project.getConfigurations().getByName("linkRelease")); task.getVariantDirectory().set(project.getLayout().getBuildDirectory().dir("release")); task.getProjectDirectory().set(project.getLayout().getProjectDirectory()); }); TaskProvider<Make> assembleDebug = tasks.register("assembleDebug", Make.class, task -> { task.setGroup("Build"); task.setDescription("Builds the debug binaries"); task.generatedBy(cmakeDebug); task.binary(project.provider(() -> project.getName())); }); TaskProvider<Make> assembleRelease = tasks.register("assembleRelease", Make.class, task -> { task.setGroup("Build"); task.setDescription("Builds the release binaries"); task.generatedBy(cmakeRelease); task.binary(project.provider(() -> project.getName())); }); tasks.named("assemble", task -> task.dependsOn(assembleDebug)); }
Example #18
Source File: CpdTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@Test void Cpd_shouldThrowInvalidUserDataExceptionIfEncodingIsNull(TaskProvider<Cpd> cpdCheck) { // Given: cpdCheck.configure(task -> task.setEncoding(null)); Cpd actual = cpdCheck.get(); // Expect: assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual))) .isInstanceOf(InvalidUserDataException.class) .hasMessage("Task 'cpdCheck' requires 'encoding' but was: null."); }
Example #19
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@Test void CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfJavaPluginIsApplied(Project project, TaskProvider<Cpd> cpdCheck) { // When: project.getPlugins().apply(JavaBasePlugin.class); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().create("tmp", (SourceSet sourceSet) -> sourceSet.getJava().srcDir(testFile(JAVA, "."))); Task checkTask = project.getTasks().getByName("check"); // Then: assertThat((Set<Task>) checkTask.getTaskDependencies().getDependencies(checkTask)).contains(cpdCheck.get()); assertThat(cpdCheck.get().getSource()).containsExactlyInAnyOrderElementsOf(testFilesRecurseIn(JAVA, ".")); }
Example #20
Source File: CpdVsFileReportImplTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@Test void CpdVsFileReportImpl_shouldHaveNullAsDefaultEncoding(TaskProvider<Cpd> cpdCheck) { // When: CpdVsFileReportImpl result = new CpdVsFileReportImpl("vs", cpdCheck.get()); // Then: assertThat(result).isNotNull(); }
Example #21
Source File: CodeGeneratorPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { CodeGeneratorConfiguration codeGenerator = project.getExtensions().create("codeGenerator", CodeGeneratorConfiguration.class, project.getObjects()); Configuration codeGeneratorConfiguration = project.getConfigurations().create("codeGenerator"); JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class); for (SourceSet sourceSet : plugin.getSourceSets()) { String outputDir = project.getBuildDir() + "/generated-src/generator/" + sourceSet.getName(); File outputDirFile = new File(outputDir); project.getLogger().debug("Using output dir {}", outputDir); File inputDir = new File(project.getProjectDir() + "/src/code-generator/" + sourceSet.getName()); sourceSet.getJava().srcDir(inputDir); sourceSet.getJava().srcDir(outputDirFile); project.getLogger().debug("Using input dir {}", inputDir); String taskName = sourceSet.getTaskName("generate", "Code"); TaskProvider<GenerateCodeTask> generate = project.getTasks().register(taskName, GenerateCodeTask.class, s -> { s.setGroup("generate"); s.getOutputDir().set(outputDirFile); if(inputDir.isDirectory()) { s.getInputDir().set(inputDir); } s.getSourceSet().set(sourceSet.getName()); s.getCodeGeneratorClasspath().from(codeGeneratorConfiguration); s.getConfigurationValues().set(codeGenerator.getConfigurationValues()); s.dependsOn(codeGeneratorConfiguration); }); project.getTasks().named(sourceSet.getCompileJavaTaskName(), t -> t.dependsOn(generate)); } }
Example #22
Source File: Make.java From native-samples with Apache License 2.0 | 5 votes |
public void generatedBy(final TaskProvider<? extends Task> task) { variantDirectory.set(task.flatMap(it -> { if (it instanceof CMake) { return ((CMake) it).getVariantDirectory(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getMakeDirectory(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); outputDirectory.set(task.flatMap(it -> { if (it instanceof CMake) { return ((CMake) it).getVariantDirectory(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getPrefixDirectory(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); dependsOn(task); makeFiles.setFrom(task.map(it -> { if (it instanceof CMake) { return ((CMake) it).getCmakeFiles(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getOutputs().getFiles(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); }
Example #23
Source File: GeneratorPlugin.java From native-samples with Apache License 2.0 | 5 votes |
private void addTasksForSample(Sample sample, Project project) { String sampleNameCamelCase = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, sample.getName()); TaskProvider<SourceCopyTask> sourceCopyTask = project.getTasks().register(sampleNameCamelCase, SourceCopyTask.class, task -> { task.getSampleDir().set(sample.getSampleDir()); sample.getSourceActions().forEach( it -> it.execute(task)); }); }
Example #24
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource void CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied(Class<? extends Plugin> pluginClass, Project project, TaskProvider<Cpd> cpdCheck) { // When: project.getPlugins().apply(pluginClass); // Then: Task check = project.getTasks().getByName("check"); @SuppressWarnings("unchecked") Set<Task> dependencies = (Set<Task>) check.getTaskDependencies().getDependencies(check); assertThat(check.getDependsOn()).contains(cpdCheck); assertThat(dependencies).contains(cpdCheck.get()); }
Example #25
Source File: JdkDownloadPlugin.java From crate with Apache License 2.0 | 5 votes |
private static TaskProvider<?> createExtractTask( String taskName, Project rootProject, boolean isWindows, Provider<Directory> extractPath, Supplier<File> jdkBundle) { if (isWindows) { Action<CopySpec> removeRootDir = copy -> { // remove extra unnecessary directory levels copy.eachFile(details -> { Path newPathSegments = trimArchiveExtractPath(details.getRelativePath().getPathString()); String[] segments = StreamSupport.stream(newPathSegments.spliterator(), false) .map(Path::toString) .toArray(String[]::new); details.setRelativePath(new RelativePath(true, segments)); }); copy.setIncludeEmptyDirs(false); }; return rootProject.getTasks().register(taskName, Copy.class, copyTask -> { copyTask.doFirst(t -> rootProject.delete(extractPath)); copyTask.into(extractPath); Callable<FileTree> fileGetter = () -> rootProject.zipTree(jdkBundle.get()); copyTask.from(fileGetter, removeRootDir); }); } else { /* * Gradle TarFileTree does not resolve symlinks, so we have to manually * extract and preserve the symlinks. cf. https://github.com/gradle/gradle/issues/3982 * and https://discuss.gradle.org/t/tar-and-untar-losing-symbolic-links/2039 */ return rootProject.getTasks().register(taskName, SymbolicLinkPreservingUntarTask.class, task -> { task.getTarFile().fileProvider(rootProject.provider(jdkBundle::get)); task.getExtractPath().set(extractPath); task.setTransform(JdkDownloadPlugin::trimArchiveExtractPath); }); } }
Example #26
Source File: CMakeApplicationPlugin.java From native-samples with Apache License 2.0 | 5 votes |
public void apply(final Project project) { project.getPluginManager().apply("org.gradle.samples.wrapped-native-application"); /* * Create some tasks to drive the CMake build */ TaskContainer tasks = project.getTasks(); TaskProvider<CMake> cmakeDebug = tasks.register("cmakeDebug", CMake.class, task -> { task.setBuildType("Debug"); task.getIncludeDirs().from(project.getConfigurations().getByName("cppCompile")); task.getLinkFiles().from(project.getConfigurations().getByName("linkDebug")); task.getVariantDirectory().set(project.getLayout().getBuildDirectory().dir("debug")); task.getProjectDirectory().set(project.getLayout().getProjectDirectory()); }); TaskProvider<CMake> cmakeRelease = tasks.register("cmakeRelease", CMake.class, task -> { task.setBuildType("RelWithDebInfo"); task.getIncludeDirs().from(project.getConfigurations().getByName("cppCompile")); task.getLinkFiles().from(project.getConfigurations().getByName("linkRelease")); task.getVariantDirectory().set(project.getLayout().getBuildDirectory().dir("release")); task.getProjectDirectory().set(project.getLayout().getProjectDirectory()); }); TaskProvider<Make> assembleDebug = tasks.register("assembleDebug", Make.class, task -> { task.setGroup("Build"); task.setDescription("Builds the debug binaries"); task.generatedBy(cmakeDebug); task.binary(project.provider(() -> project.getName())); }); TaskProvider<Make> assembleRelease = tasks.register("assembleRelease", Make.class, task -> { task.setGroup("Build"); task.setDescription("Builds the release binaries"); task.generatedBy(cmakeRelease); task.binary(project.provider(() -> project.getName())); }); tasks.named("assemble", task -> task.dependsOn(assembleDebug)); }
Example #27
Source File: CpdPluginTest.java From gradle-cpd-plugin with Apache License 2.0 | 5 votes |
@Test void CpdPlugin_shouldAllowConfigureToolDependenciesExplicitlyViaToolVersionProperty(Project project, Configuration cpdConfiguration, CpdExtension cpd, TaskProvider<Cpd> cpdCheck) { // Given: project.getRepositories().mavenLocal(); project.getRepositories().mavenCentral(); // When: cpd.setToolVersion("5.2.1"); // Then: assertThat(cpdCheck.get().getPmdClasspath()).isEqualTo(cpdConfiguration); assertThat(cpdConfiguration.resolve()).anyMatch(file -> file.getName().equals("pmd-core-5.2.1.jar")); }
Example #28
Source File: MavenPluginPlugin.java From gradle-plugins with MIT License | 5 votes |
@Override public void apply(Project project) { project.getPlugins().apply(JavaPlugin.class); MavenPublishJavaPlugin mavenPublishJavaPlugin = project.getPlugins().apply(MavenPublishJavaPlugin.class); // https://github.com/gradle/gradle/issues/10555#issue-492150084 if (project.getGradle().getGradleVersion().matches("5\\.6(\\.[12])?")) { mavenPublishJavaPlugin.getPublication().getPom().withXml(xmlProvider -> xmlProvider.asNode().appendNode("packaging", "maven-plugin") ); } else { mavenPublishJavaPlugin.getPublication().getPom().setPackaging("maven-plugin"); } TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks().named("generatePomFileForMavenJavaPublication", GenerateMavenPom.class); TaskProvider<DescriptorGeneratorTask> descriptorGeneratorTaskProvider = project.getTasks().register("generateMavenPluginDescriptor", DescriptorGeneratorTask.class, generateMavenPluginDescriptor -> { generateMavenPluginDescriptor.dependsOn(generateMavenPom); generateMavenPluginDescriptor.getPomFile().set(generateMavenPom.get().getDestination()); generateMavenPluginDescriptor.getOutputDirectory().set( project.getLayout().getBuildDirectory().dir("maven-plugin") ); SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main"); generateMavenPluginDescriptor.getSourceDirectories().from(main.getAllJava().getSourceDirectories()); JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName(main.getCompileJavaTaskName()); generateMavenPluginDescriptor.getClassesDirectories().from(javaCompile); generateMavenPluginDescriptor.getEncoding().convention(javaCompile.getOptions().getEncoding()); }); project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources.class) .configure(processResources -> processResources.from(descriptorGeneratorTaskProvider)); }
Example #29
Source File: TransportPlugin.java From transport with BSD 2-Clause "Simplified" License | 5 votes |
/** * Configures SourceSets, dependencies and tasks related to each Transport UDF platform */ private void configurePlatform(Project project, Platform platform, SourceSet mainSourceSet, SourceSet testSourceSet, File baseOutputDir) { SourceSet sourceSet = configureSourceSet(project, platform, mainSourceSet, baseOutputDir); configureGenerateWrappersTask(project, platform, mainSourceSet, sourceSet); List<TaskProvider<? extends Task>> packagingTasks = configurePackagingTasks(project, platform, sourceSet, mainSourceSet); // Add Transport tasks to build task dependencies project.getTasks().named(LifecycleBasePlugin.BUILD_TASK_NAME).configure(task -> task.dependsOn(packagingTasks)); TaskProvider<Test> testTask = configureTestTask(project, platform, mainSourceSet, testSourceSet); project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(task -> task.dependsOn(testTask)); }
Example #30
Source File: Make.java From native-samples with Apache License 2.0 | 5 votes |
public void generatedBy(final TaskProvider<? extends Task> task) { variantDirectory.set(task.flatMap(it -> { if (it instanceof CMake) { return ((CMake) it).getVariantDirectory(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getMakeDirectory(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); outputDirectory.set(task.flatMap(it -> { if (it instanceof CMake) { return ((CMake) it).getVariantDirectory(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getPrefixDirectory(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); dependsOn(task); makeFiles.setFrom(task.map(it -> { if (it instanceof CMake) { return ((CMake) it).getCmakeFiles(); } else if (it instanceof ConfigureTask) { return ((ConfigureTask) it).getOutputs().getFiles(); } else { throw new IllegalArgumentException("Make task cannot extract build information from \'" + it.getClass().getName() + "\' task"); } })); }