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));
}
}
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);
}
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);
}
}
Aggregations