Java Code Examples for org.gradle.api.tasks.TaskProvider#configure()

The following examples show how to use org.gradle.api.tasks.TaskProvider#configure() . 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: VariantProcessor.java    From Injector with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@Test
void Cpd_shouldHaveCorrectTaskOutputs(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> {
        task.reports(report -> {
            report.getCsv().setDestination(project.file(project.getBuildDir() + "/cpd.csv"));
            report.getCsv().setEnabled(false);
            report.getText().setDestination(project.file("cpdCheck.txt"));
            report.getText().setEnabled(true);
            report.getVs().setDestination(project.file("cpd.vs"));
        });
        task.source(testFile(JAVA, "."));
    });
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThat(actual.getOutputs().getFiles()).containsExactlyInAnyOrder(
            project.file(project.getBuildDir() + "/cpd.csv"),
            project.file("cpdCheck.txt"),
            project.file("cpd.vs"),
            project.file(project.getBuildDir() + "/reports/cpd/cpdCheck.xml")
    );
}
 
Example 4
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: GeneratorPlugin.java    From native-samples with Apache License 2.0 6 votes vote down vote up
private void addTasksForRepo(ExternalRepo repo, TaskProvider<Task> generateSource, Project project) {
    TaskProvider<SyncExternalRepoTask> syncTask = project.getTasks().register("sync" + StringUtils.capitalize(repo.getName()), SyncExternalRepoTask.class, task -> {
        task.getRepoUrl().set(repo.getRepoUrl());
        task.getCheckoutDirectory().set(project.file("repos/" + repo.getName()));
    });
    TaskProvider<SourceCopyTask> setupTask = project.getTasks().register("copy" + StringUtils.capitalize(repo.getName()), SourceCopyTask.class, task -> {
        task.dependsOn(syncTask);
        task.getSampleDir().set(syncTask.get().getCheckoutDirectory());
        task.doFirst(task1 -> {
            repo.getSourceActions().forEach(it -> {
                it.execute(task);
            });
        });
    });
    TaskProvider<UpdateRepoTask> updateTask = project.getTasks().register("update" + StringUtils.capitalize(repo.getName()), UpdateRepoTask.class, task -> {
        task.dependsOn(setupTask);
        task.getSampleDir().set(syncTask.get().getCheckoutDirectory());
        repo.getRepoActions().forEach(it -> {
            task.change(it);
        });
    });
    generateSource.configure(task -> {
        task.dependsOn(updateTask);
    });
}
 
Example 6
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource
void getXmlRendererEncoding(String taskEncoding, String reportEncoding, String expected, TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.setEncoding(taskEncoding));

    CpdXmlFileReportImpl report = new CpdXmlFileReportImpl("xml", cpdCheck.get());
    report.setEncoding(reportEncoding);

    // Expect:
    assertThat(cpdCheck.get().getXmlRendererEncoding(report)).isEqualTo(expected);
}
 
Example 9
Source File: ShadedJarPackaging.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public List<TaskProvider<? extends Task>> configurePackagingTasks(Project project, Platform platform,
    SourceSet platformSourceSet, SourceSet mainSourceSet) {
  TaskProvider<ShadeTask> shadeTask = createShadeTask(project, platform, platformSourceSet, mainSourceSet);
  shadeTask.configure(task -> {
    if (_excludedDependencies != null) {
      task.setExcludedDependencies(ImmutableSet.copyOf(_excludedDependencies));
    }
    if (_classesToNotShade != null) {
      task.setDoNotShade(_classesToNotShade);
    }
  });
  return ImmutableList.of(shadeTask);
}
 
Example 10
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldThrowInvalidUserDataExceptionIfMinimumTokenCountIsMinusOne(TaskProvider<Cpd> cpdCheck) {
    // Given:
    cpdCheck.configure(task -> task.setMinimumTokenCount(-1));
    Cpd actual = cpdCheck.get();

    // Expect:
    assertThatThrownBy(() -> actual.getActions().forEach(a -> a.execute(actual)))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessageMatching("Task 'cpdCheck' requires 'minimumTokenCount' to be greater than zero.");
}
 
Example 11
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldAllowConfigurationOfCpdTaskReportProperties(Project project, TaskProvider<Cpd> cpdCheck) {
    // When:
    cpdCheck.configure(task -> task.reports(reports -> {
        reports.getCsv().setDestination(project.file(project.getBuildDir() + "/cpdCheck.csv"));
        reports.getCsv().setEnabled(true);
        reports.getCsv().setSeparator(';');
        reports.getCsv().setIncludeLineCount(false);

        reports.getText().setDestination(project.file(project.getBuildDir() + "/cpdCheck.text"));
        reports.getText().setEnabled(true);
        reports.getText().setLineSeparator("-_-");
        reports.getText().setTrimLeadingCommonSourceWhitespaces(true);

        reports.getVs().setDestination(project.file("cpdCheck.vs"));
        reports.getVs().setEnabled(true);

        reports.getXml().setDestination(project.file(project.getBuildDir() + "/reports/cpdCheck.xml"));
        reports.getXml().setEnabled(false);
        reports.getXml().setEncoding("UTF-16");
    }));

    // Then:
    CpdReports actual = cpdCheck.get().getReports();
    assertThat(actual.getCsv().getDestination()).isEqualTo(project.file("build/cpdCheck.csv"));
    assertThat(actual.getCsv().isEnabled()).isTrue();
    assertThat(actual.getCsv().getSeparator()).isEqualTo(';');
    assertThat(actual.getCsv().isIncludeLineCount()).isFalse();
    assertThat(actual.getText().getDestination()).isEqualTo(project.file("build/cpdCheck.text"));
    assertThat(actual.getText().isEnabled()).isTrue();
    assertThat(actual.getText().getLineSeparator()).isEqualTo("-_-");
    assertThat(actual.getText().getTrimLeadingCommonSourceWhitespaces()).isTrue();
    assertThat(actual.getVs().getDestination()).isEqualTo(project.file("cpdCheck.vs"));
    assertThat(actual.getVs().isEnabled()).isTrue();
    assertThat(actual.getXml().getDestination()).isEqualTo(project.file("build/reports/cpdCheck.xml"));
    assertThat(actual.getXml().isEnabled()).isFalse();
    assertThat(actual.getXml().getEncoding()).isEqualTo("UTF-16");
}
 
Example 13
Source File: CpdTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void Cpd_shouldAllowConfigurationOfCpdTaskProperties(Project project, TaskProvider<Cpd> cpdCheck) {
    // Given:
    List<File> expectedPmdClasspath = createProjectFiles(project, "libs/pmd-classpath/");

    // When:
    cpdCheck.configure(task -> {
        task.setDescription("Execute me!");
        task.setGroup("check");

        task.setEncoding("ISO-8859-1");
        task.setIgnoreAnnotations(true);
        task.setIgnoreFailures(true);
        task.setIgnoreIdentifiers(true);
        task.setIgnoreLiterals(true);
        task.setLanguage("cpp");
        task.setMinimumTokenCount(10);
        task.setPmdClasspath(project.files(expectedPmdClasspath));
        task.setSkipDuplicateFiles(true);
        task.setSkipLexicalErrors(true);
        task.setSkipBlocks(false);
        task.setSkipBlocksPattern("<template|>");
    });

    // Then:
    Cpd actual = cpdCheck.get();
    assertThat(actual.getEncoding()).isEqualTo("ISO-8859-1");
    assertThat(actual.getIgnoreAnnotations()).isTrue();
    assertThat(actual.getIgnoreFailures()).isTrue();
    assertThat(actual.getIgnoreIdentifiers()).isTrue();
    assertThat(actual.getIgnoreLiterals()).isTrue();
    assertThat(actual.getLanguage()).isEqualTo("cpp");
    assertThat(actual.getMinimumTokenCount()).isEqualTo(10);
    assertThat(actual.getPmdClasspath()).containsExactlyInAnyOrderElementsOf(expectedPmdClasspath);
    assertThat(actual.getSkipDuplicateFiles()).isTrue();
    assertThat(actual.getSkipLexicalErrors()).isTrue();
    assertThat(actual.getSkipBlocks()).isFalse();
    assertThat(actual.getSkipBlocksPattern()).isEqualTo("<template|>");
}
 
Example 14
Source File: ProtobufPlugin.java    From curiostack with MIT License 5 votes vote down vote up
private static void configureExtractIncludeTask(
    TaskProvider<ExtractProtosTask> task, SourceSet sourceSet, Project project) {
  task.configure(
      t ->
          t.getFiles()
              .from(
                  project
                      .getConfigurations()
                      // NOTE: Must be runtime, not compile, classpath since proto files are
                      // resources and not part of Java compilation.
                      .getByName(sourceSet.getRuntimeClasspathConfigurationName())));
}
 
Example 15
Source File: PlayDistributionPlugin.java    From playframework with Apache License 2.0 5 votes vote down vote up
private void createDistributionZipTasks(Project project, Distribution distribution, TaskProvider<Task> stageLifecycleTask, TaskProvider<Task> distLifecycleTask) {
    final String capitalizedDistName = capitalizeDistributionName(distribution.getName());
    final String stageTaskName = "stage" + capitalizedDistName + "Dist";
    final File stageDir = new File(project.getBuildDir(), "stage");
    final String baseName = (distribution.getBaseName() != null && "".equals(distribution.getBaseName())) ? distribution.getBaseName() : distribution.getName();

    TaskProvider<Sync> stageSyncTask = project.getTasks().register(stageTaskName, Sync.class, sync -> {
        sync.setDescription("Copies the '" + distribution.getName() + "' distribution to a staging directory.");
        sync.setDestinationDir(stageDir);

        sync.into(baseName, copySpec -> copySpec.with(distribution.getContents()));
    });

    stageLifecycleTask.configure(task -> task.dependsOn(stageSyncTask));

    final String distributionZipTaskName = "create" + capitalizedDistName + "ZipDist";
    TaskProvider<Zip> distZipTask = project.getTasks().register(distributionZipTaskName, Zip.class, zip -> {
        zip.setDescription("Packages the '" + distribution.getName() + "' distribution as a zip file.");
        zip.setBaseName(baseName);
        zip.setDestinationDir(new File(project.getBuildDir(), "distributions"));
        zip.from(stageSyncTask);
    });

    final String distributionTarTaskName = "create" + capitalizedDistName + "TarDist";
    TaskProvider<Tar> distTarTask = project.getTasks().register(distributionTarTaskName, Tar.class, tar -> {
        tar.setDescription("Packages the '" + distribution.getName() + "' distribution as a tar file.");
        tar.setBaseName(baseName);
        tar.setDestinationDir(new File(project.getBuildDir(), "distributions"));
        tar.from(stageSyncTask);
    });

    distLifecycleTask.configure(task -> {
        task.dependsOn(distZipTask);
        task.dependsOn(distTarTask);
    });
}
 
Example 16
Source File: VariantProcessor.java    From Injector with Apache License 2.0 5 votes vote down vote up
private void createDexTask(InjectorExtension extension) {
	TaskProvider<CreateInjectDexes> taskProvider = project.getTasks().register("createInject" + variantName + "Dexes",
			CreateInjectDexes.class, extension, projectPackageName, variantName, project.getBuildDir().getAbsolutePath(),
			androidArchiveLibraries, jarFiles, variant.getMergedFlavor().getMinSdkVersion().getApiLevel(),
			sourceCompatibilityVersion, targetCompatibilityVersion);

	taskProvider.configure(createInjectDexes -> {
		TaskProvider<?> extractAARsTask = project.getTasks().named(InjectorPlugin.EXTRACT_AARS_TASK_NAME);
		TaskProvider<?> assembleTask = project.getTasks().named("assemble" + variantName);
		TaskProvider<?> rGenerationTask = project.getTasks().named("generate" + variantName + "RFile");
		createInjectDexes.dependsOn(extractAARsTask);
		createInjectDexes.dependsOn(rGenerationTask);
		createInjectDexes.dependsOn(assembleTask);
	});
}
 
Example 17
Source File: ProtobufPlugin.java    From curiostack with MIT License 4 votes vote down vote up
private static SourceSetTasks configureSourceSet(
    String sourceSetName, Project project, ProtobufExtension extension) {
  NamedDomainObjectProvider<SourceDirectorySet> sources =
      extension.getSources().register(sourceSetName);

  Configuration protobufConfiguration =
      project
          .getConfigurations()
          .create(
              SourceSetUtils.getConfigName(sourceSetName, "protobuf"),
              c -> {
                c.setVisible(false);
                c.setTransitive(true);
                c.setExtendsFrom(ImmutableList.of());
              });
  TaskProvider<ExtractProtosTask> extract =
      project
          .getTasks()
          .register(
              "extract" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto",
              ExtractProtosTask.class,
              t -> {
                t.getFiles().from(protobufConfiguration);
                t.setDestDir(project.file("build/extracted-protos/" + sourceSetName));
              });

  TaskProvider<ExtractProtosTask> extractInclude =
      project
          .getTasks()
          .register(
              "extractInclude" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto",
              ExtractProtosTask.class,
              t -> t.setDestDir(project.file("build/extracted-include-protos/" + sourceSetName)));

  TaskProvider<GenerateProtoTask> generateProto =
      project
          .getTasks()
          .register(
              "generate" + SourceSetUtils.getTaskSuffix(sourceSetName) + "Proto",
              GenerateProtoTask.class,
              sourceSetName,
              extension);

  // To ensure languages are added in order, we have to make sure this is hooked up eagerly.
  var languages = project.getObjects().listProperty(LanguageSettings.class).empty();
  extension.getLanguages().all(languages::add);

  generateProto.configure(
      t -> {
        t.dependsOn(extract, extractInclude);

        t.getSources().source(sources.get()).srcDir(extract.get().getDestDir());

        t.include(extractInclude.get().getDestDir());
        t.setLanguages(languages);
      });
  return ImmutableSourceSetTasks.builder()
      .extractProtos(extract)
      .extractIncludeProtos(extractInclude)
      .generateProto(generateProto)
      .build();
}
 
Example 18
Source File: PlayApplicationPlugin.java    From playframework with Apache License 2.0 4 votes vote down vote up
private void configureRunTask(TaskProvider<PlayRun> playRun, PlayConfiguration filteredRuntime) {
    playRun.configure(task -> {
        task.getRuntimeClasspath().from(filteredRuntime.getNonChangingArtifacts());
        task.getChangingClasspath().from(filteredRuntime.getChangingArtifacts());
    });
}
 
Example 19
Source File: InjectorPlugin.java    From Injector with Apache License 2.0 4 votes vote down vote up
private void createExtractAARsTask() {
	TaskProvider<ExtractAarTask> extractAarTaskTaskProvider = project.getTasks().register(EXTRACT_AARS_TASK_NAME, ExtractAarTask.class);
	extractAarTaskTaskProvider.configure(extractAarTask -> extractAarTask.setAndroidArchiveLibraries(aars));
}