Search in sources :

Example 1 with JavaLevelUtil

use of com.thomasjensen.checkstyle.addons.build.JavaLevelUtil in project checkstyle-addons by checkstyle-addons.

the class JavadocConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull Javadoc pJavadocTask, @Nullable DependencyConfig pDepConfig) {
    Objects.requireNonNull(pDepConfig, "required dependency config not present");
    final JavaVersion javaLevel = pDepConfig.getJavaLevel();
    pJavadocTask.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
    pJavadocTask.setDescription("Generate Javadoc API documentation for dependency configuration '" + pDepConfig.getName() + "' (Java level: " + javaLevel + ")");
    pJavadocTask.dependsOn(buildUtil.getTaskProvider(TaskNames.compileJava, JavaCompile.class, pDepConfig), buildUtil.getTaskProvider(TaskNames.compileSonarqubeJava, JavaCompile.class, pDepConfig));
    final JavaPluginExtension javaExt = project.getExtensions().getByType(JavaPluginExtension.class);
    pJavadocTask.setDestinationDir(new File(javaExt.getDocsDir().getAsFile().get(), pJavadocTask.getName()));
    configureJavadocTask(pJavadocTask, pDepConfig);
    final JavaLevelUtil javaLevelUtil = new JavaLevelUtil(project);
    if (javaLevelUtil.isOlderSupportedJava(javaLevel)) {
        pJavadocTask.setExecutable(javaLevelUtil.getJavadocExecutable(javaLevel));
    }
}
Also used : JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) JavaVersion(org.gradle.api.JavaVersion) JavaLevelUtil(com.thomasjensen.checkstyle.addons.build.JavaLevelUtil) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 2 with JavaLevelUtil

use of com.thomasjensen.checkstyle.addons.build.JavaLevelUtil in project checkstyle-addons by checkstyle-addons.

the class TestTaskConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull Test pTestTask, @Nullable DependencyConfig pDepConfig) {
    Objects.requireNonNull(pDepConfig, "required dependency config not present");
    final String csVersion = getCsVersion();
    final String baseCsVersion = pDepConfig.getCheckstyleBaseVersion();
    final TaskContainer tasks = project.getTasks();
    final JavaVersion javaLevel = pDepConfig.getJavaLevel();
    pTestTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
    // Only produce JUnit XMLs for the default test task in order to minimize noise.
    pTestTask.getReports().getJunitXml().getRequired().set(Boolean.FALSE);
    if (baseCsVersion.equals(csVersion)) {
        pTestTask.setDescription("Run the unit tests using dependency configuration '" + pDepConfig.getName() + "' (Checkstyle " + baseCsVersion + ", Java level: " + javaLevel + ")");
    } else {
        pTestTask.setDescription("Run the unit tests compiled for Checkstyle " + baseCsVersion + " against a Checkstyle " + csVersion + " runtime (Java level: " + javaLevel + ")");
    }
    final SourceSet testSourceSet = buildUtil.getSourceSet(SourceSet.TEST_SOURCE_SET_NAME);
    final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
    final SourceSet sqSourceSet = buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME);
    pTestTask.dependsOn(buildUtil.getTaskProvider(TaskNames.compileTestJava, Task.class, pDepConfig), tasks.named(testSourceSet.getProcessResourcesTaskName()), buildUtil.getTaskProvider(TaskNames.compileJava, Task.class, pDepConfig), tasks.named(mainSourceSet.getProcessResourcesTaskName()), buildUtil.getTaskProvider(TaskNames.compileSonarqubeJava, Task.class, pDepConfig), tasks.named(sqSourceSet.getProcessResourcesTaskName()));
    new com.thomasjensen.checkstyle.addons.build.TestConfigAction().execute(pTestTask);
    final TaskProvider<JavaCompile> compileTaskProvider = buildUtil.getTaskProvider(TaskNames.compileTestJava, JavaCompile.class, pDepConfig);
    Provider<Directory> destDir = compileTaskProvider.flatMap(AbstractCompile::getDestinationDirectory);
    pTestTask.setTestClassesDirs(project.files(destDir));
    final JavaPluginExtension javaExt = project.getExtensions().getByType(JavaPluginExtension.class);
    pTestTask.getReports().getHtml().getOutputLocation().fileValue(new File(javaExt.getTestReportDir().getAsFile().get(), pTestTask.getName()));
    final JacocoTaskExtension jacoco = (JacocoTaskExtension) pTestTask.getExtensions().getByName(JacocoPluginExtension.TASK_EXTENSION_NAME);
    jacoco.setEnabled(false);
    pTestTask.setClasspath(new ClasspathBuilder(project).buildTestExecutionClasspath(pDepConfig, csVersion));
    final JavaLevelUtil javaLevelUtil = new JavaLevelUtil(project);
    if (javaLevelUtil.isOlderSupportedJava(javaLevel)) {
        pTestTask.setExecutable(javaLevelUtil.getJvmExecutable(javaLevel));
    }
    // Make the Checkstyle version available to the test cases via a system property.
    pTestTask.systemProperty(CSVERSION_SYSPROP_NAME, csVersion);
}
Also used : Task(org.gradle.api.Task) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) JavaVersion(org.gradle.api.JavaVersion) JacocoTaskExtension(org.gradle.testing.jacoco.plugins.JacocoTaskExtension) JavaLevelUtil(com.thomasjensen.checkstyle.addons.build.JavaLevelUtil) SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) AbstractCompile(org.gradle.api.tasks.compile.AbstractCompile) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File) Directory(org.gradle.api.file.Directory)

Example 3 with JavaLevelUtil

use of com.thomasjensen.checkstyle.addons.build.JavaLevelUtil in project checkstyle-addons by checkstyle-addons.

the class CompileConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull JavaCompile pCompileTask, @Nullable DependencyConfig pDepConfig) {
    Objects.requireNonNull(pDepConfig, "required dependency config not present");
    final SourceSet sourceSetToCompile = getSourceSetToCompile();
    final JavaVersion javaLevel = pDepConfig.getJavaLevel();
    pCompileTask.setGroup(BasePlugin.BUILD_GROUP);
    pCompileTask.setDescription("Compile sources from '" + sourceSetToCompile.getName() + "' source set using dependency configuration '" + pDepConfig.getName() + "' (Java level: " + javaLevel + ")");
    // Additional Task Input: the dependency configuration file
    pCompileTask.getInputs().file(pDepConfig.getConfigFile());
    final CompileOptions options = pCompileTask.getOptions();
    options.setEncoding(StandardCharsets.UTF_8.toString());
    // show deprecation warnings in compiler output
    options.setDeprecation(true);
    final JavaLevelUtil javaLevelUtil = new JavaLevelUtil(project);
    if (javaLevelUtil.isOlderSupportedJava(javaLevel)) {
        options.setFork(true);
        options.getForkOptions().setExecutable(javaLevelUtil.getCompilerExecutable(javaLevel));
    }
    final File destDir = calculateDestDirFromSourceSet(sourceSetToCompile, pDepConfig.getName());
    pCompileTask.setSource(sourceSetToCompile.getAllJava());
    pCompileTask.getDestinationDirectory().set(destDir);
    pCompileTask.setSourceCompatibility(javaLevel.toString());
    pCompileTask.setTargetCompatibility(javaLevel.toString());
    FileCollection cp = new ClasspathBuilder(project).buildCompileClasspath(pDepConfig, sourceSetToCompile.getName());
    pCompileTask.setClasspath(cp);
    if (isTest(sourceSetToCompile)) {
        TaskProvider<Task> mainCompile = buildUtil.getTaskProvider(TaskNames.compileJava, Task.class, pDepConfig);
        TaskProvider<Task> sonarqubeCompile = buildUtil.getTaskProvider(TaskNames.compileSonarqubeJava, Task.class, pDepConfig);
        pCompileTask.dependsOn(mainCompile, sonarqubeCompile);
    }
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) CompileOptions(org.gradle.api.tasks.compile.CompileOptions) JavaVersion(org.gradle.api.JavaVersion) JavaLevelUtil(com.thomasjensen.checkstyle.addons.build.JavaLevelUtil) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Aggregations

JavaLevelUtil (com.thomasjensen.checkstyle.addons.build.JavaLevelUtil)3 File (java.io.File)3 JavaVersion (org.gradle.api.JavaVersion)3 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)2 Task (org.gradle.api.Task)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 SourceSet (org.gradle.api.tasks.SourceSet)2 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)2 Directory (org.gradle.api.file.Directory)1 FileCollection (org.gradle.api.file.FileCollection)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 AbstractCompile (org.gradle.api.tasks.compile.AbstractCompile)1 CompileOptions (org.gradle.api.tasks.compile.CompileOptions)1 JacocoTaskExtension (org.gradle.testing.jacoco.plugins.JacocoTaskExtension)1