use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class JarSonarqubeConfigAction method configureTaskFor.
@Override
protected void configureTaskFor(@Nonnull ShadowJar pJarTask, @Nullable DependencyConfig pDepConfig) {
Objects.requireNonNull(pDepConfig, "required dependency config not present");
pJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
pJarTask.setDescription("Assembles the SonarQube plugin for dependency configuration '" + pDepConfig.getName() + "'");
final BuildConfigExtension buildConfig = buildUtil.getBuildConfig();
final TaskContainer tasks = project.getTasks();
// Inputs for up-to-date checking
final TaskInputs inputs = pJarTask.getInputs();
inputs.property(BuildUtil.GROUP_ID, project.getGroup());
inputs.property(BuildUtil.VERSION, project.getVersion());
inputs.property("name", buildConfig.getLongName());
inputs.property("description", project.getDescription());
inputs.property("authorName", buildConfig.getAuthorName());
inputs.property("sqPluginKey", buildConfig.getSqPluginKey());
inputs.property("sqPackage", buildConfig.getSqPackage());
inputs.property("gitHash", buildConfig.getGitHash());
inputs.property("orgUrl", buildConfig.getOrgUrl());
inputs.property("issueTrackerUrl", buildConfig.getIssueTrackerUrl());
inputs.property("website", buildConfig.getWebsite());
// archive name
pJarTask.getArchiveFileName().set("sonar-" + inputs.getProperties().get("sqPluginKey") + "-" + inputs.getProperties().get(BuildUtil.VERSION) + (pDepConfig.isDefaultConfig() ? "" : ("-csp" + pDepConfig.getSonarQubeMinCsPluginVersion())) + ".jar");
// Task Dependencies
final TaskProvider<Task> sqClassesTaskProvider = buildUtil.getTaskProvider(TaskNames.sonarqubeClasses, Task.class, pDepConfig);
pJarTask.dependsOn(sqClassesTaskProvider);
final VersionFileTask versionTask = (VersionFileTask) tasks.getByName(VersionFileTask.TASK_NAME);
pJarTask.dependsOn(versionTask);
final JavaCompile compileMainTask = buildUtil.getTask(TaskNames.compileJava, JavaCompile.class, pDepConfig);
final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
final Copy resourcesMainTask = (Copy) tasks.getByName(mainSourceSet.getProcessResourcesTaskName());
pJarTask.dependsOn(compileMainTask, resourcesMainTask);
// Add dependencies as shadowed packages (in cooperation with jarSonarqubeRelocate task)
final Configuration shadowCfg = new ClasspathBuilder(project).buildMainRuntimeConfiguration(pDepConfig, false);
pJarTask.getConfigurations().add(shadowCfg);
// Configuration of JAR file contents
pJarTask.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
pJarTask.into("META-INF", copySpec -> copySpec.from("LICENSE"));
final JavaCompile compileSqTask = buildUtil.getTask(TaskNames.compileSonarqubeJava, JavaCompile.class, pDepConfig);
pJarTask.from(compileSqTask.getDestinationDirectory());
pJarTask.from(compileMainTask.getDestinationDirectory());
pJarTask.from(resourcesMainTask.getDestinationDir(), copySpec -> {
copySpec.include("checkstyle_packages.xml");
copySpec.include("**/messages*.properties");
copySpec.include("**/*.json");
});
pJarTask.into(inputs.getProperties().get("sqPackage"), copySpec -> copySpec.from(versionTask.getVersionFile()));
// Manifest
setManifestAttributes(pJarTask, pDepConfig);
}
use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class JarEclipseConfigAction method getPublishedDependencyLibs.
/**
* Scan the dependencies of the specified configurations and return a list of File objects for each dependency.
* Resolves the configurations if they are still unresolved.
*
* @param pTask the calling task
* @param pDepConfig the current dependency configuration
* @return list of files
*/
@Nonnull
private Set<File> getPublishedDependencyLibs(@Nonnull final Task pTask, @Nonnull final DependencyConfig pDepConfig) {
Set<File> result = new HashSet<>();
Configuration cfg = new ClasspathBuilder(pTask.getProject()).buildMainRuntimeConfiguration(pDepConfig);
for (ResolvedDependency dep : cfg.getResolvedConfiguration().getFirstLevelModuleDependencies()) {
if (!isCheckstyle(dep)) {
for (ResolvedArtifact artifact : dep.getAllModuleArtifacts()) {
result.add(artifact.getFile());
}
}
}
return result;
}
use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder 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.ClasspathBuilder 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);
}
}
use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class FatJarConfigAction method configureTaskFor.
@Override
protected void configureTaskFor(@Nonnull ShadowJar pFatJarTask, @Nullable DependencyConfig pDepConfig) {
Objects.requireNonNull(pDepConfig, "required dependency config not present");
pFatJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
pFatJarTask.getArchiveClassifier().set("all");
// set appendix for archive name
final String appendix = pDepConfig.getName();
if (!pDepConfig.isDefaultConfig()) {
pFatJarTask.getArchiveAppendix().set(appendix);
}
// dependency on the corresponding (thin) Jar task
final Jar thinJarTask = buildUtil.getTask(TaskNames.jar, Jar.class, pDepConfig);
pFatJarTask.dependsOn(thinJarTask);
pFatJarTask.setDescription("Create a combined JAR of project and runtime dependencies of '" + SourceSet.MAIN_SOURCE_SET_NAME + "' for dependency configuration '" + pDepConfig.getName() + "'");
buildUtil.inheritManifest(pFatJarTask, pDepConfig);
pFatJarTask.from(thinJarTask.getArchiveFile());
Configuration cfg = new ClasspathBuilder(project).buildMainRuntimeConfiguration(pDepConfig);
pFatJarTask.setConfigurations(Collections.singletonList(cfg));
pFatJarTask.exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "META-INF/maven/**/*", "pom.xml");
final Set<String> deps = getNonCheckstyleDeps(cfg);
if (deps.size() > 0) {
// append all licenses found in dependent Jars into one
pFatJarTask.append("META-INF/LICENSE");
pFatJarTask.dependencies((final DependencyFilter pDependencyFilter) -> {
for (String dep : deps) {
pDependencyFilter.include(pDependencyFilter.dependency(dep));
}
});
}
}
Aggregations