use of com.thomasjensen.checkstyle.addons.build.BuildConfigExtension in project checkstyle-addons by checkstyle-addons.
the class JarConfigAction method configureTaskFor.
@Override
protected void configureTaskFor(@Nonnull Jar pJarTask, @Nullable DependencyConfig pDepConfig) {
Objects.requireNonNull(pDepConfig, "required dependency config not present");
final BuildConfigExtension buildConfig = buildUtil.getBuildConfig();
final TaskContainer tasks = project.getTasks();
pJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
pJarTask.setDescription("Assembles a jar archive containing the '" + SourceSet.MAIN_SOURCE_SET_NAME + "' classes for dependency configuration '" + pDepConfig.getName() + "'");
// set appendix for archive name
final String appendix = pDepConfig.getName();
if (!pDepConfig.isDefaultConfig()) {
pJarTask.getArchiveAppendix().set(appendix);
}
// Dependency on pom.properties generating task
pJarTask.dependsOn(tasks.named(TaskNames.generatePomProperties.getName(pDepConfig)));
// Task Input: pom.properties file
final File pomPropsUsed = ((GeneratePomPropsTask) tasks.getByName(TaskNames.generatePomProperties.getName(pDepConfig))).getPluginPomProps();
pJarTask.getInputs().file(pomPropsUsed);
// Dependency on pom.xml generating task
final GenerateMavenPom generatePomTask = buildUtil.getTask(TaskNames.generatePomFileForCheckstyleAddonsPublication, GenerateMavenPom.class, pDepConfig);
pJarTask.dependsOn(generatePomTask);
// Dependency on 'classes' task (compile and resources)
pJarTask.dependsOn(buildUtil.getTaskProvider(TaskNames.mainClasses, Task.class, pDepConfig));
// Configuration of JAR file contents
pJarTask.from(generatePomTask.getDestination(), copySpec -> copySpec.rename(filename -> filename.replace("pom-default.xml", "pom.xml")));
final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
pJarTask.from(new ClasspathBuilder(project).getClassesDirs(mainSourceSet, pDepConfig));
pJarTask.from(mainSourceSet.getOutput().getResourcesDir());
pJarTask.exclude("download-guide.html", "**/*.md", "**/checks/all_checks.html", "eclipsecs-plugin.xml", "**/checkstyle-metadata.*");
pJarTask.into("META-INF", copySpec -> copySpec.from("LICENSE"));
// add generated pom.xml and pom.properties to archive, setting build timestamp in the process
pJarTask.into("META-INF/maven/" + project.getGroup() + "/" + project.getName(), copySpec -> {
copySpec.from(generatePomTask.getDestination());
copySpec.rename(filename -> filename.replace("pom-default.xml", "pom.xml"));
copySpec.from(pomPropsUsed);
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("buildTimestamp", buildConfig.getBuildTimestamp().get().toString());
Map<String, Object> propsMap = new HashMap<>();
propsMap.put("tokens", placeHolders);
copySpec.filter(propsMap, ReplaceTokens.class);
});
// Manifest
configureManifest(pJarTask, pDepConfig, appendix);
}
Aggregations