org.gradle.language.base.plugins.LifecycleBasePlugin Java Examples

The following examples show how to use org.gradle.language.base.plugins.LifecycleBasePlugin. 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: CpdPlugin.java    From gradle-cpd-plugin with Apache License 2.0 6 votes vote down vote up
private void logWarningIfCheckTaskOnTaskGraph(Project project, TaskExecutionGraph graph) {
    if (logger.isWarnEnabled()) {
        Optional<Task> lastCheckTask = graph.getAllTasks().stream().sorted(reverseOrder())
                .filter(t -> t.getName().endsWith(LifecycleBasePlugin.CHECK_TASK_NAME)).findFirst();
        if (lastCheckTask.isPresent()) { // it is possible to just execute a task before "check", e.g. "compileJava"
            Task task = lastCheckTask.get();
            String message = "\n" +
                    "WARNING: Due to the absence of '" + LifecycleBasePlugin.class.getSimpleName() +
                    "' on " + project + " the task ':" + TASK_NAME_CPD_CHECK +
                    "' could not be added to task graph. Therefore CPD will not be executed. To prevent this, manually add a task dependency of ':" +
                    TASK_NAME_CPD_CHECK + "' to a '" + LifecycleBasePlugin.CHECK_TASK_NAME +
                    "' task of a subproject.\n" +
                    "1) Directly to " + task.getProject() + ":\n" +
                    "    " + task.getName() + ".dependsOn(':" + TASK_NAME_CPD_CHECK + "')\n" +
                    "2) Indirectly, e.g. via " + project + ":\n" +
                    "    project('" + task.getProject().getPath() + "') {\n" +
                    "        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject\n" +
                    "            " + task.getName() + ".dependsOn(" + TASK_NAME_CPD_CHECK + ")\n" +
                    "        }\n" +
                    "    }\n";
            logger.warn(message);
        }
    }
}
 
Example #2
Source File: BasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void apply(Project project) {
    project.getPlugins().apply(LifecycleBasePlugin.class);

    BasePluginConvention convention = new BasePluginConvention(project);
    project.getConvention().getPlugins().put("base", convention);

    configureBuildConfigurationRule(project);
    configureUploadRules(project);
    configureUploadArchivesTask();
    configureArchiveDefaults(project, convention);
    configureConfigurations(project);
    configureAssemble(project);
}
 
Example #3
Source File: TransportPlugin.java    From transport with 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 #4
Source File: BasePlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void apply(Project project) {
    project.getPluginManager().apply(LifecycleBasePlugin.class);

    BasePluginConvention convention = new BasePluginConvention(project);
    project.getConvention().getPlugins().put("base", convention);

    configureBuildConfigurationRule(project);
    configureUploadRules(project);
    configureUploadArchivesTask();
    configureArchiveDefaults(project, convention);
    configureConfigurations(project);
    configureAssemble((ProjectInternal) project);
}
 
Example #5
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void createBinaryLifecycleTask(SourceSet sourceSet, Project target) {
    sourceSet.compiledBy(sourceSet.getClassesTaskName());

    Task binaryLifecycleTask = target.task(sourceSet.getClassesTaskName());
    binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
    binaryLifecycleTask.setDescription("Assembles " + sourceSet.getOutput() + ".");
    binaryLifecycleTask.dependsOn(sourceSet.getOutput().getDirs());
    binaryLifecycleTask.dependsOn(sourceSet.getCompileJavaTaskName());
    binaryLifecycleTask.dependsOn(sourceSet.getProcessResourcesTaskName());
}
 
Example #6
Source File: AggregateJacocoReportPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JacocoPlugin.class);

    project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {

        reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));

        project.allprojects(subproject -> {
            subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
                SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                reportTask.sourceSets(main);
            });

            subproject.getTasks()
                    .withType(Test.class)
                    .forEach(reportTask::executionData);
        });

        JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
        reportTask.getReports().getHtml().setEnabled(true);
        reportTask.getReports().all(report -> {
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
            }
            else {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
            }
        });
    });


}
 
Example #7
Source File: AggregateJacocoReportPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JacocoPlugin.class);

    project.getTasks().register("aggregateJacocoReport", JacocoReport.class, reportTask -> {

        reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        reportTask.setDescription(String.format("Generates aggregated code coverage report for the %s project.", project.getPath()));

        project.allprojects(subproject -> {
            subproject.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
                SourceSetContainer sourceSets = subproject.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                reportTask.sourceSets(main);
            });

            subproject.getTasks()
                    .withType(Test.class)
                    .forEach(reportTask::executionData);
        });

        JacocoPluginExtension reportingExtension = project.getExtensions().getByType(JacocoPluginExtension.class);
        reportTask.getReports().getHtml().setEnabled(true);
        reportTask.getReports().all(report -> {
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + report.getName())));
            }
            else {
                report.setDestination(project.provider(() -> new File(reportingExtension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName())));
            }
        });
    });


}
 
Example #8
Source File: BasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void apply(Project project) {
    project.getPlugins().apply(LifecycleBasePlugin.class);

    BasePluginConvention convention = new BasePluginConvention(project);
    project.getConvention().getPlugins().put("base", convention);

    configureBuildConfigurationRule(project);
    configureUploadRules(project);
    configureUploadArchivesTask();
    configureArchiveDefaults(project, convention);
    configureConfigurations(project);
    configureAssemble(project);
}
 
Example #9
Source File: CpdPlugin.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
private void createTask(Project project) {
    TaskProvider<Cpd> taskProvider = project.getTasks().register(TASK_NAME_CPD_CHECK, Cpd.class, task -> {
        task.setDescription("Run CPD analysis for all sources");
        project.getAllprojects().forEach(p ->
                p.getPlugins().withType(JavaBasePlugin.class, plugin ->
                        p.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet ->
                                sourceSet.getAllJava().getSrcDirs().forEach(task::source)
                        )
                )
        );
    });

    project.getPlugins().withType(LifecycleBasePlugin.class, plugin ->
            project.getTasks().findByName(LifecycleBasePlugin.CHECK_TASK_NAME).dependsOn(taskProvider));
}
 
Example #10
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
static Stream<Class<? extends Plugin>> CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied() {
    return Stream.of(
            LifecycleBasePlugin.class,
            BasePlugin.class,
            LanguageBasePlugin.class,
            JavaBasePlugin.class,

            JavaPlugin.class,
            GroovyPlugin.class,
            CppPlugin.class
        );
}
 
Example #11
Source File: LegacyJavaComponentPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createBinaryLifecycleTask(ClassDirectoryBinarySpecInternal binary, Project target) {
    Task binaryLifecycleTask = target.task(binary.getNamingScheme().getLifecycleTaskName());
    binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
    binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
    binary.setBuildTask(binaryLifecycleTask);
}
 
Example #12
Source File: TransportPlugin.java    From transport with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates and configures a task to run tests written using the Unified Testing Framework against a given platform
 */
private TaskProvider<Test> configureTestTask(Project project, Platform platform, SourceSet mainSourceSet,
    SourceSet testSourceSet) {

  /*
    Configures the classpath configuration to run platform-specific tests. E.g. For the Presto platform,

    configurations {
      prestoTestClasspath {
        extendsFrom testImplementation
      }
    }

    dependencies {
      prestoTestClasspath sourceSets.main.output, sourceSets.test.output
      prestoTestClasspath 'com.linkedin.transport:transportable-udfs-test-presto'
    }
   */
  Configuration testClasspath = project.getConfigurations()
      .create(platform.getName() + "TestClasspath",
          config -> config.extendsFrom(getConfigurationForSourceSet(project, testSourceSet, IMPLEMENTATION)));
  addDependencyToConfiguration(project, testClasspath, mainSourceSet.getOutput());
  addDependencyToConfiguration(project, testClasspath, testSourceSet.getOutput());
  platform.getDefaultTestDependencyConfigurations()
      .forEach(dependencyConfiguration -> addDependencyToConfiguration(project, testClasspath,
          dependencyConfiguration.getDependencyString()));

  /*
    Creates the test task for a given platform. E.g. For the Presto platform,

    task prestoTest(type: Test, dependsOn: test) {
      group 'Verification'
      description 'Runs the Presto tests.'
      testClassesDirs = sourceSets.test.output.classesDirs
      classpath = configurations.prestoTestClasspath
      useTestNG()
    }
  */

  return project.getTasks().register(testTaskName(platform), Test.class, task -> {
    task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
    task.setDescription("Runs Transport UDF tests on " + platform.getName());
    task.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs());
    task.setClasspath(testClasspath);
    task.useTestNG();
    task.mustRunAfter(project.getTasks().named("test"));
  });
}
 
Example #13
Source File: StaticSitePlugin.java    From curiostack with MIT License 4 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(NodePlugin.class);

  var config = StaticSiteExtension.create(project);

  var mergeSite =
      project
          .getTasks()
          .register(
              "mergeSite",
              Copy.class,
              t -> {
                t.from("src");
                t.into("build/site");

                for (SiteProject site : config.getSites().get()) {
                  site.getProject()
                      .getPlugins()
                      .withType(
                          LifecycleBasePlugin.class,
                          unused ->
                              t.dependsOn(
                                  site.getProject()
                                      .getTasks()
                                      .named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)));
                  t.from(site.getBuildDir(), copy -> copy.into(site.getOutputSubDir()));
                }
              });

  var assemble = project.getTasks().named("assemble");
  assemble.configure(t -> t.dependsOn(mergeSite));

  var yarn = project.getRootProject().getTasks().named("yarn");

  var deployAlpha =
      project
          .getTasks()
          .register(
              "deployAlpha",
              GcloudTask.class,
              t -> {
                t.dependsOn(assemble);
                // TODO(choko): Remove this major hack - the command line has two --project flags
                // and we're just lucky the later is used.
                t.args(
                    config
                        .getAppEngineProject()
                        .map(
                            appEngineProject ->
                                ImmutableList.of(
                                    "app", "deploy", "--project=" + appEngineProject)));
              });

  var deployProd =
      project
          .getTasks()
          .register(
              "deployProd",
              NodeTask.class,
              t -> {
                t.dependsOn(yarn, assemble);
                t.args(
                    config
                        .getFirebaseProject()
                        .map(
                            firebaseProject ->
                                ImmutableList.of(
                                    "run", "firebase", "--project", firebaseProject, "deploy")));
              });

  project
      .getTasks()
      .register(
          "preview",
          NodeTask.class,
          t -> {
            t.dependsOn(yarn, assemble);
            t.args("run", "superstatic", "--port=8080");
          });

  CurioGenericCiPlugin.addToReleaseBuild(project, deployProd);

  project.afterEvaluate(
      unused -> {
        if (config.getAutoDeployAlpha().get()) {
          CurioGenericCiPlugin.addToMasterBuild(project, deployAlpha);
        }
      });
}
 
Example #14
Source File: LegacyJavaComponentPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createBinaryLifecycleTask(ClassDirectoryBinarySpecInternal binary, Project target) {
    Task binaryLifecycleTask = target.task(binary.getNamingScheme().getLifecycleTaskName());
    binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
    binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
    binary.setBuildTask(binaryLifecycleTask);
}