Search in sources :

Example 6 with BuildConfigExtension

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);
}
Also used : DependencyConfig(com.thomasjensen.checkstyle.addons.build.DependencyConfig) TaskCreator(com.thomasjensen.checkstyle.addons.build.TaskCreator) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) Attributes(org.gradle.api.java.archives.Attributes) Jar(org.gradle.api.tasks.bundling.Jar) Jvm(org.gradle.internal.jvm.Jvm) Project(org.gradle.api.Project) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) TaskNames(com.thomasjensen.checkstyle.addons.build.TaskNames) HashMap(java.util.HashMap) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) Objects(java.util.Objects) GenerateMavenPom(org.gradle.api.publish.maven.tasks.GenerateMavenPom) Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) Map(java.util.Map) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) Manifest(org.gradle.api.java.archives.Manifest) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) GradleVersion(org.gradle.util.GradleVersion) Task(org.gradle.api.Task) HashMap(java.util.HashMap) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) GenerateMavenPom(org.gradle.api.publish.maven.tasks.GenerateMavenPom) File(java.io.File)

Aggregations

BuildConfigExtension (com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)6 BuildUtil (com.thomasjensen.checkstyle.addons.build.BuildUtil)3 Task (org.gradle.api.Task)3 Attributes (org.gradle.api.java.archives.Attributes)3 SourceSet (org.gradle.api.tasks.SourceSet)3 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)2 File (java.io.File)2 HashMap (java.util.HashMap)2 Manifest (org.gradle.api.java.archives.Manifest)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 TaskInputs (org.gradle.api.tasks.TaskInputs)2 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)2 DependencyConfig (com.thomasjensen.checkstyle.addons.build.DependencyConfig)1 TaskCreator (com.thomasjensen.checkstyle.addons.build.TaskCreator)1 TaskNames (com.thomasjensen.checkstyle.addons.build.TaskNames)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Nonnull (javax.annotation.Nonnull)1