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 Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTest.java    License: 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 #2
Source Project: transport   Author: linkedin   File: ShadedJarPackaging.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 #3
Source Project: Injector   Author: artyomd   File: VariantProcessor.java    License: 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 #4
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTest.java    License: 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 #5
Source Project: gradle-plugins   Author: freefair   File: JSassWarPlugin.java    License: MIT License 6 votes vote down vote up
@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 #6
Source Project: gradle-avro-plugin   Author: davidmc24   File: AvroPlugin.java    License: Apache License 2.0 6 votes vote down vote up
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 #7
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTest.java    License: 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 Project: curiostack   Author: curioswitch   File: TerraformPlugin.java    License: MIT License 6 votes vote down vote up
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 #9
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTest.java    License: 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 #10
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 #11
Source Project: gradle-plugins   Author: freefair   File: WarAttachClassesPlugin.java    License: MIT License 6 votes vote down vote up
@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 #12
Source Project: gradle-plugins   Author: freefair   File: JSassWebjarsPlugin.java    License: MIT License 6 votes vote down vote up
@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 #13
Source Project: gradle-plugins   Author: freefair   File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@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 #14
Source Project: dart   Author: f2prateek   File: TaskManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 #15
Source Project: gradle-plugins   Author: freefair   File: JSassJavaPlugin.java    License: MIT License 6 votes vote down vote up
@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 Project: transport   Author: linkedin   File: TransportPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 #17
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void CpdPlugin_shouldAddSourcesOfSubProjectsEvenIfAppliedOnlyOnParentProject(Project project, TaskProvider<Cpd> cpdCheck) {
    // When:
    Project subProject1 = ProjectBuilder.builder().withName("sub1").withParent(project).build();
    subProject1.getPlugins().apply(JavaPlugin.class);
    createProjectFiles(subProject1, "src/main/java/Clazz.java", "src/test/java/ClazzTest.java");

    Project subProject2 = ProjectBuilder.builder().withName("sub2").withParent(project).build();
    subProject2.getPlugins().apply(GroovyPlugin.class);
    createProjectFiles(subProject2, "src/main/groovy/Clazz.groovy", "src/main/resources/clazz.properties");

    subProject1.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"));
    });
    subProject2.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(subProject1.file("src/main/java/Clazz.java"));
    expected.add(subProject1.file("src/test/java/ClazzTest.java"));
    expected.add(subProject2.file("src/main/groovy/Clazz.groovy"));

    assertThat(cpdCheck.get().getSource()).containsExactlyInAnyOrderElementsOf(expected);

    assertThat(subProject1.getTasks().findByName("cpdCheck")).isNull();
    assertThat(subProject2.getTasks().findByName("cpdCheck")).isNull();
}
 
Example #18
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void CpdPlugin_shouldAllowConfigureToolDependenciesExplicitlyViaConfiguration(Project project, Configuration cpdConfiguration, TaskProvider<Cpd> cpdCheck) {
    // Given:
    project.getRepositories().mavenLocal();
    project.getRepositories().mavenCentral();

    // When:
    project.getDependencies().add("cpd", "net.sourceforge.pmd:pmd:5.0.2");

    // Then:
    assertThat(cpdCheck.get().getPmdClasspath()).isEqualTo(cpdConfiguration);
    assertThat(cpdConfiguration.resolve()).anyMatch(file -> file.getName().equals("pmd-5.0.2.jar"));
}
 
Example #19
Source Project: transport   Author: linkedin   File: DistributionPackaging.java    License: 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) {
  // Create a thin JAR to be included in the distribution
  final TaskProvider<Jar> platformThinJarTask = createThinJarTask(project, platformSourceSet, platform.getName());

  /*
    Include the thin JAR and all the runtime dependencies into the distribution for a given platform

    distributions {
      <platformName> {
        contents {
          from <platformThinJarTask>
          from project.configurations.<platformRuntimeClasspath>
        }
      }
    }
   */
  DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
  distributions.register(platform.getName(), distribution -> {
    distribution.setBaseName(project.getName());
    distribution.getContents()
        .from(platformThinJarTask)
        .from(getConfigurationForSourceSet(project, platformSourceSet, RUNTIME_CLASSPATH));
  });

  // Explicitly set classifiers for the created distributions or else leads to Maven packaging issues due to multiple
  // artifacts with the same classifier
  project.getTasks().named(platform.getName() + "DistTar", Tar.class, tar -> tar.setClassifier(platform.getName()));
  project.getTasks().named(platform.getName() + "DistZip", Zip.class, zip -> zip.setClassifier(platform.getName()));
  return ImmutableList.of(project.getTasks().named(platform.getName() + "DistTar", Tar.class),
      project.getTasks().named(platform.getName() + "DistZip", Zip.class));
}
 
Example #20
Source Project: transport   Author: linkedin   File: ShadedJarPackaging.java    License: 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 #21
Source Project: Injector   Author: artyomd   File: VariantProcessor.java    License: 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 #22
Source Project: playframework   Author: gradle   File: PlayPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private static void configureJavaScriptTasks(Project project) {
    TaskProvider<JavaScriptMinify> javaScriptMinifyTask = project.getTasks().named(PlayJavaScriptPlugin.JS_MINIFY_TASK_NAME, JavaScriptMinify.class);

    project.getTasks().named(ASSEMBLE_TASK_NAME, task -> task.dependsOn(javaScriptMinifyTask));

    project.getTasks().named(PlayApplicationPlugin.ASSETS_JAR_TASK_NAME, Jar.class, task -> {
        task.dependsOn(javaScriptMinifyTask);
        task.from(javaScriptMinifyTask.get().getDestinationDir(), copySpec -> copySpec.into("public"));
    });
}
 
Example #23
Source Project: playframework   Author: gradle   File: PlayDistributionPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPluginManager().apply(PlayApplicationPlugin.class);
    project.getPluginManager().apply(DistributionPlugin.class);

    TaskProvider<Task> stageLifecycleTask = createStageLifecycleTask(project);
    TaskProvider<Task> distLifecycleTask = createDistLifecycleTasks(project);

    DistributionContainer distributionContainer = (DistributionContainer) project.getExtensions().getByName("distributions");

    distributionContainer.all(distribution -> {
        createDistributionContentTasks(project, distribution);
        createDistributionZipTasks(project, distribution, stageLifecycleTask, distLifecycleTask);
    });
}
 
Example #24
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTextFileReportImplTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void CpdTextFileReportImpl_shouldHaveDefaultLineSeparatorAndTrimLeadingCommonSourceWhitespaces(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdTextFileReportImpl result = new CpdTextFileReportImpl("text", cpdCheck.get());

    // Then:
    assertThat(result.getLineSeparator()).isEqualTo(CpdTextFileReport.DEFAULT_LINE_SEPARATOR);
    assertThat(result.getTrimLeadingCommonSourceWhitespaces()).isEqualTo(CpdTextFileReport.DEFAULT_TRIM_LEADING_COMMON_SOURCE_WHITESPACE);
}
 
Example #25
Source Project: gradle-avro-plugin   Author: davidmc24   File: AvroPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private static void configureTasks(final Project project) {
    getSourceSets(project).configureEach(sourceSet -> {
        TaskProvider<GenerateAvroProtocolTask> protoTaskProvider = configureProtocolGenerationTask(project, sourceSet);
        TaskProvider<GenerateAvroJavaTask> javaTaskProvider = configureJavaGenerationTask(project, sourceSet, protoTaskProvider);
        configureTaskDependencies(project, sourceSet, javaTaskProvider);
    });
}
 
Example #26
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdCsvFileReportImplTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void CpdCsvFileReportImpl_shouldHaveDefaults(TaskProvider<Cpd> cpdCheck) {
    // When:
    CpdCsvFileReportImpl result = new CpdCsvFileReportImpl("csv", cpdCheck.get());

    // Then:
    assertThat(result.getSeparator()).isEqualTo(CpdCsvFileReport.DEFAULT_SEPARATOR);
    assertThat(result.isIncludeLineCount()).isEqualTo(CpdCsvFileReport.DEFAULT_INCLUDE_LINE_COUNT);
}
 
Example #27
Source Project: playframework   Author: gradle   File: PlayApplicationPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private TaskProvider<Jar> createAssetsJarTask(Project project) {
    TaskProvider<Jar> assetsJarTask = project.getTasks().register(ASSETS_JAR_TASK_NAME, Jar.class, jar -> {
        jar.setDescription("Assembles the assets jar for the application.");
        jar.setClassifier("assets");
        jar.from(project.file("public"), copySpec -> copySpec.into("public"));
    });

    project.getTasks().named(ASSEMBLE_TASK_NAME, assembleTask -> assembleTask.dependsOn(assetsJarTask));

    return assetsJarTask;
}
 
Example #28
Source Project: playframework   Author: gradle   File: PlayApplicationPlugin.java    License: Apache License 2.0 5 votes vote down vote up
private void registerOutgoingArtifact(Project project, TaskProvider<Jar> assetsJarTask) {
    Configuration runtimeElementsConfiguration = project.getConfigurations().getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME);
    PublishArtifact jarArtifact = new LazyPublishArtifact(assetsJarTask);
    ConfigurationPublications publications = runtimeElementsConfiguration.getOutgoing();
    publications.getArtifacts().add(jarArtifact);
    publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE);
}
 
Example #29
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdCsvFileReportImplTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void setSeparator_shouldThrowInvalidUserDataExceptionIfSeparatorIsSetToNull(TaskProvider<Cpd> cpdCheck) {
    // Given:
    CpdCsvFileReportImpl underTest = new CpdCsvFileReportImpl("csv", cpdCheck.get());

    // Expect:
    assertThatThrownBy(() -> underTest.setSeparator(null))
            .isInstanceOf(InvalidUserDataException.class)
            .hasMessage("CSV report 'separator' must not be null.");
}
 
Example #30
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdTest.java    License: 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");
}