org.gradle.api.plugins.JavaPlugin Java Examples

The following examples show how to use org.gradle.api.plugins.JavaPlugin. 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: SourcesJarPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #2
Source File: AspectJPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #3
Source File: JigsawPlugin.java    From gradle-java-modules with Apache License 2.0 7 votes vote down vote up
private void configureCompileTestJavaTask(final Project project) {
    final JavaCompile compileTestJava = (JavaCompile) project.getTasks()
            .findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    compileTestJava.getInputs().property("moduleName", module.geName());
    compileTestJava.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(compileTestJava.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("junit");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath());
            compileTestJava.getOptions().setCompilerArgs(args);
            compileTestJava.setClasspath(project.files());
        }
    });
}
 
Example #4
Source File: LombokPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;

    lombokBasePlugin = project.getPlugins().apply(LombokBasePlugin.class);
    lombokBasePlugin.getLombokExtension().getConfig().put("config.stopBubbling", "true");

    generateLombokConfig = project.getTasks().register("generateLombokConfig", GenerateLombokConfig.class, genConfig -> {
        genConfig.getProperties().convention(lombokBasePlugin.getLombokExtension().getConfig());
        genConfig.setGroup("lombok");
    });

    project.getTasks().withType(Delombok.class).configureEach(this::configureDelombokDefaults);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> configureJavaPluginDefaults());

}
 
Example #5
Source File: JSassJavaPlugin.java    From gradle-plugins with 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 #6
Source File: MergeClassesTask.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
public void configureMergeClassesAfterEvaluate() {
    if (!mergeClassesHelper().isMergeRequired()) {
        return;
    }

    var mergeClasses = mergeClassesHelper().createMergeClassesTask();

    mergeClassesHelper().allCompileTaskStream().forEach(task -> {
        mergeClasses.from(task.getDestinationDir());
        mergeClasses.dependsOn(task);
    });
    mergeClasses.into(helper().getMergedDir());

    Stream.of(ApplicationPlugin.TASK_RUN_NAME, JavaPlugin.TEST_TASK_NAME)
            .map(helper()::findTask)
            .flatMap(Optional::stream)
            .forEach(task -> task.dependsOn(mergeClasses));
}
 
Example #7
Source File: CompileModuleInfoTask.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
/**
 * Preconfigures a separate task that is meant to compile {@code module-info.java} separately.
 * Final (modular) configuration is performed later by {@link CompileJavaTaskMutator}.
 */
private JavaCompile preconfigureCompileModuleInfoJava(JavaCompile compileJava) {
    var compileModuleInfoJava = helper().compileJavaTask(CompileModuleOptions.COMPILE_MODULE_INFO_TASK_NAME);

    compileModuleInfoJava.setClasspath(project.files()); // empty
    compileModuleInfoJava.setSource(pathToModuleInfoJava());
    compileModuleInfoJava.getOptions().setSourcepath(project.files(pathToModuleInfoJava().getParent()));

    compileModuleInfoJava.setDestinationDir(helper().getModuleInfoDir());

    // we need all the compiled classes before compiling module-info.java
    compileModuleInfoJava.dependsOn(compileJava);

    // make "classes" trigger module-info.java compilation
    helper().task(JavaPlugin.CLASSES_TASK_NAME).dependsOn(compileModuleInfoJava);

    return compileModuleInfoJava;
}
 
Example #8
Source File: QuarkusDev.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void addSelfWithLocalDeps(Project project, DevModeContext context, Set<String> visited,
        Set<AppArtifactKey> addedDeps, boolean root) {
    if (!visited.add(project.getPath())) {
        return;
    }
    final Configuration compileCp = project.getConfigurations().findByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
    if (compileCp != null) {
        compileCp.getIncoming().getDependencies().forEach(d -> {
            if (d instanceof ProjectDependency) {
                addSelfWithLocalDeps(((ProjectDependency) d).getDependencyProject(), context, visited, addedDeps, false);
            }
        });
    }

    addLocalProject(project, context, addedDeps, root);
}
 
Example #9
Source File: WarAttachClassesPlugin.java    From gradle-plugins with 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 #10
Source File: CpdPluginTest.java    From gradle-cpd-plugin with 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 File: JSassWebjarsPlugin.java    From gradle-plugins with 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 #12
Source File: AbstractGeneratorTask.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Nonnull
private List<ComponentDependency> getRuntimeDependencies() {
    return getProject().getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
            .getResolvedConfiguration()
            .getResolvedArtifacts()
            .stream()
            .map(resolvedDependency -> {
                ComponentDependency componentDependency = new ComponentDependency();

                componentDependency.setArtifactId(resolvedDependency.getModuleVersion().getId().getName());
                componentDependency.setGroupId(resolvedDependency.getModuleVersion().getId().getGroup());
                componentDependency.setVersion(resolvedDependency.getModuleVersion().getId().getVersion());
                componentDependency.setType(resolvedDependency.getType());

                return componentDependency;
            })
            .collect(Collectors.toList());
}
 
Example #13
Source File: JSassJavaPlugin.java    From gradle-plugins with 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 File: AppEngineStandardExtensionTest.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private Project setUpTestProject(String buildFileName) throws IOException {
  Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle");
  InputStream buildFileContent =
      getClass()
          .getClassLoader()
          .getResourceAsStream(
              "projects/AppEnginePluginTest/Extension/" + buildFileName + ".gradle");
  Files.copy(buildFileContent, buildFile);

  Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF");
  Files.createDirectories(webInf);
  File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
  Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

  Project p = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build();
  p.getPluginManager().apply(JavaPlugin.class);
  p.getPluginManager().apply(WarPlugin.class);
  p.getPluginManager().apply(AppEngineStandardPlugin.class);
  ((ProjectInternal) p).evaluate();

  return p;
}
 
Example #15
Source File: CodeServerBuilder.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Collection<File> listProjectDepsSrcDirs(Project project) {
	ConfigurationContainer configs = project.getConfigurations();
	Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
	DependencySet depSet = compileConf.getAllDependencies();

	List<File> result = Lists.newArrayList();
	for (Dependency dep : depSet) {
		if (dep instanceof ProjectDependency) {
			Project projectDependency = ((ProjectDependency) dep).getDependencyProject();
			if (projectDependency.getPlugins().hasPlugin(PwtLibPlugin.class)) {
				JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class);
				SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);

				result.addAll(mainSourceSet.getAllSource().getSrcDirs());
			}
		}
	}
	return result;
}
 
Example #16
Source File: SourcesJarPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #17
Source File: MultiModuleTestProject.java    From app-gradle-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Build and evaluate multi-module project.
 *
 * @return root project
 */
public Project build() throws IOException {
  Project rootProject = ProjectBuilder.builder().withProjectDir(projectRoot).build();
  for (String module : modules) {
    Project p = ProjectBuilder.builder().withName(module).withParent(rootProject).build();

    // Create an appengine-web.xml for each module
    Path webInf = p.getProjectDir().toPath().resolve("src/main/webapp/WEB-INF");
    Files.createDirectories(webInf);
    File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile();
    Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8));

    p.getPluginManager().apply(JavaPlugin.class);
    p.getPluginManager().apply(WarPlugin.class);
    p.getPluginManager().apply(AppEngineStandardPlugin.class);

    DeployExtension deploy =
        p.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy();
    deploy.setProjectId("project");
    deploy.setVersion("version");
  }
  ((ProjectInternal) rootProject).evaluate();
  return rootProject;
}
 
Example #18
Source File: ThorntailUtils.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order:
 * <p>
 * 1. Custom-JAR-Task defined in ThorntailExtension 'archiveTask'
 * 2. WAR-Task
 * 3. JAR-Task
 */
public static Jar getArchiveTask(Project project) {

    TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class);
    Jar customArchiveTask = project.getExtensions().getByType(ThorntailExtension.class).getArchiveTask();

    if (customArchiveTask != null) {
        return existingArchiveTasks.getByName(customArchiveTask.getName());

    } else if (existingArchiveTasks.findByName(WarPlugin.WAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(WarPlugin.WAR_TASK_NAME);

    } else if (existingArchiveTasks.findByName(JavaPlugin.JAR_TASK_NAME) != null) {
        return existingArchiveTasks.getByName(JavaPlugin.JAR_TASK_NAME);
    }

    throw new GradleException("Unable to detect Archive-Task: project contains neither 'war' nor 'jar', " +
            "nor is custom Archive-Task specified in the \"thorntail\" extension.");
}
 
Example #19
Source File: CuriostackRootPlugin.java    From curiostack with MIT License 6 votes vote down vote up
private static void addStandardJavaTestDependencies(Project project) {
  DependencyHandler dependencies = project.getDependencies();

  dependencies.add(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, "com.google.code.findbugs:jsr305");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME,
      "org.curioswitch.curiostack:curio-testing-framework");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.assertj:assertj-core");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.awaitility:awaitility");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "junit:junit");
  dependencies.add(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.mockito:mockito-core");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.mockito:mockito-junit-jupiter");
  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "info.solidsoft.mockito:mockito-java8");

  dependencies.add(
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, "org.junit.jupiter:junit-jupiter-api");
  dependencies.add(
      JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.jupiter:junit-jupiter-engine");
  dependencies.add(
      JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.vintage:junit-vintage-engine");
}
 
Example #20
Source File: JavadocJarPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        project.getLogger().warn("io.freefair.javadoc-jar is deprecated. Use java.withJavadocJar() instead");

        javadocJar = project.getTasks().register("javadocJar", Jar.class, javadocJar -> {
            javadocJar.from(project.getTasks().named(JavaPlugin.JAVADOC_TASK_NAME));
            javadocJar.getArchiveClassifier().set("javadoc");
            javadocJar.setDescription("Assembles a jar archive containing the javadocs.");
            javadocJar.setGroup(BasePlugin.BUILD_GROUP);
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, javadocJar);
    });

    project.getPlugins().withType(AggregateJavadocPlugin.class, aggregateJavadocPlugin -> {
        aggregateJavadocJar = project.getTasks().register("aggregateJavadocJar", Jar.class, aggregateJavadocJar -> {
            aggregateJavadocJar.from(aggregateJavadocPlugin.getAggregateJavadoc());
            aggregateJavadocJar.getArchiveClassifier().set("javadoc");
            aggregateJavadocJar.setGroup(BasePlugin.BUILD_GROUP);
        });

        project.getPlugins().apply(BasePlugin.class);
        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, aggregateJavadocJar);

        project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
            aggregateJavadocJar.configure(aggregateJavadocJar -> {

                aggregateJavadocJar.getArchiveClassifier().convention("aggregateJavadoc");
                aggregateJavadocJar.getDestinationDirectory().set(new File(
                        project.getConvention().getPlugin(JavaPluginConvention.class).getDocsDir(),
                        "aggregateJavadoc"
                ));
            });
        });

    });
}
 
Example #21
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 #22
Source File: ClasspathScanPluginTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
void apply_afterJava() {
	this.project.getPlugins().apply(JavaPlugin.class);
	this.project.getPlugins().apply(ClasspathScanPlugin.class);

	checkForGeneratedTasks();
}
 
Example #23
Source File: SimpleCodeGenerationTest.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Test
public void applyAfterJava() {
    project.getPlugins().apply(JavaPlugin.class);
    project.getPlugins().apply(CodeGeneratorPlugin.class);

    TaskContainer tasks = project.getTasks();
    assertThat(tasks.parallelStream().anyMatch(t -> t.getName().equals("generateCode")), is(equalTo(true)));
}
 
Example #24
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 #25
Source File: ClojureCommonPlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(ClojureBasePlugin.class);
  project.getPlugins().apply(JavaPlugin.class);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  configureDev(project, sourceSets);
  configureDependencyConstraints(project);

  configureDevSource(sourceSets, SourceSet::getResources);
}
 
Example #26
Source File: ClientNativeBase.java    From client-gradle-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Inject
public ClientNativeBase(Project project) {
    this.project = project;
    project.getPluginManager().withPlugin("java", e ->
            dependsOn(project.getTasks().findByName(JavaPlugin.CLASSES_TASK_NAME),
                      project.getTasks().findByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME)));
}
 
Example #27
Source File: EarPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureWithNoJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention) {
    project.getTasks().withType(Ear.class, new Action<Ear>() {
        public void execute(final Ear task) {
            task.from(new Callable<FileCollection>() {
                public FileCollection call() throws Exception {
                    if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
                        return null;
                    } else {
                        return project.fileTree(earPluginConvention.getAppDirName());
                    }
                }
            });
        }
    });
}
 
Example #28
Source File: CpdPluginTest.java    From gradle-cpd-plugin with 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 #29
Source File: JigsawPlugin.java    From gradle-java-modules with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    LOGGER.debug("Applying JigsawPlugin to " + project.getName());
    project.getPlugins().apply(JavaPlugin.class);
    project.getExtensions().create(EXTENSION_NAME, JavaModule.class);

    configureJavaTasks(project);
}
 
Example #30
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())));
            }
        });
    });


}