Search in sources :

Example 1 with DependencyConfig

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

the class PrintDepConfigsTask method printDepConfigs.

@TaskAction
public void printDepConfigs() {
    final Logger log = getProject().getLogger();
    log.info("-----------------------------------------------------------------------------------------------");
    log.lifecycle("Dependency Configurations:");
    log.lifecycle("--------------------------");
    log.lifecycle("Default Checkstyle version: " + depConfigs.getDefault().getCheckstyleBaseVersion());
    log.lifecycle("Active dependency configurations:");
    for (Map.Entry<String, DependencyConfig> entry : depConfigs.getAll().entrySet()) {
        DependencyConfig depConfig = entry.getValue();
        log.lifecycle("  - " + entry.getKey() + ": Checkstyle " + depConfig.getCheckstyleBaseVersion() + ", Java " + depConfig.getJavaLevel() + ", compatible: " + depConfig.getCompatibleCheckstyleVersions());
    }
    log.info("-----------------------------------------------------------------------------------------------");
    log.info("Full contents:");
    for (final Map.Entry<String, DependencyConfig> entry : depConfigs.getAll().entrySet()) {
        log.info("  - " + entry.getKey() + ":\t" + entry.getValue());
    }
    log.info("-----------------------------------------------------------------------------------------------");
}
Also used : Logger(org.gradle.api.logging.Logger) Map(java.util.Map) DependencyConfig(com.thomasjensen.checkstyle.addons.build.DependencyConfig) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with DependencyConfig

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

the class SiteCopyAllChecksConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull Copy pCopyTask, @Nullable DependencyConfig pUnused) {
    pCopyTask.setDescription("Copy list of all checks to site directory");
    pCopyTask.setGroup(SiteTask.SITE_GROUP);
    pCopyTask.setDestinationDir(new File(project.getBuildDir(), "site"));
    final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
    final String checksPackage = buildUtil.getBuildConfig().getChecksPackage().get();
    final File originalFile = new File(mainSourceSet.getResources().getSrcDirs().iterator().next(), "/" + checksPackage + "/all_checks.html");
    final Action<CopySpec> action = copySpec -> {
        copySpec.from(originalFile);
        copySpec.rename((String fileName) -> fileName.replace(originalFile.getName(), "index.html"));
        copySpec.filter(buildReplacements(project), ReplaceTokens.class);
    };
    pCopyTask.into("v" + project.getVersion() + "/checks", action);
    pCopyTask.into("latest/checks", action);
}
Also used : DependencyConfig(com.thomasjensen.checkstyle.addons.build.DependencyConfig) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Date(java.util.Date) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) CopySpec(org.gradle.api.file.CopySpec) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) Map(java.util.Map) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Copy(org.gradle.api.tasks.Copy) SourceSet(org.gradle.api.tasks.SourceSet) CopySpec(org.gradle.api.file.CopySpec) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) File(java.io.File)

Example 3 with DependencyConfig

use of com.thomasjensen.checkstyle.addons.build.DependencyConfig 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)

Example 4 with DependencyConfig

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

the class SiteCopyDownloadGuideConfigAction method configureTaskFor.

@Override
protected void configureTaskFor(@Nonnull Copy pCopyTask, @Nullable DependencyConfig pUnused) {
    pCopyTask.setDescription("Copy download guide frontmatter stub to site directory");
    pCopyTask.setGroup(SiteTask.SITE_GROUP);
    pCopyTask.setDestinationDir(new File(project.getBuildDir(), "site"));
    final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
    final File originalFile = new File(mainSourceSet.getResources().getSrcDirs().iterator().next(), "/download-guide.html");
    final Action<CopySpec> action = copySpec -> {
        copySpec.from(originalFile);
        copySpec.filter(SiteCopyAllChecksConfigAction.buildReplacements(project), ReplaceTokens.class);
    };
    pCopyTask.into("v" + project.getVersion(), action);
    pCopyTask.into("latest", action);
}
Also used : DependencyConfig(com.thomasjensen.checkstyle.addons.build.DependencyConfig) Action(org.gradle.api.Action) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) CopySpec(org.gradle.api.file.CopySpec) Nonnull(javax.annotation.Nonnull) File(java.io.File) Nullable(javax.annotation.Nullable) Copy(org.gradle.api.tasks.Copy) SourceSet(org.gradle.api.tasks.SourceSet) SourceSet(org.gradle.api.tasks.SourceSet) CopySpec(org.gradle.api.file.CopySpec) ReplaceTokens(org.apache.tools.ant.filters.ReplaceTokens) File(java.io.File)

Aggregations

DependencyConfig (com.thomasjensen.checkstyle.addons.build.DependencyConfig)4 File (java.io.File)3 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 ReplaceTokens (org.apache.tools.ant.filters.ReplaceTokens)3 SourceSet (org.gradle.api.tasks.SourceSet)3 BuildUtil (com.thomasjensen.checkstyle.addons.build.BuildUtil)2 HashMap (java.util.HashMap)2 Action (org.gradle.api.Action)2 Project (org.gradle.api.Project)2 CopySpec (org.gradle.api.file.CopySpec)2 Copy (org.gradle.api.tasks.Copy)2 BuildConfigExtension (com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)1 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)1 TaskCreator (com.thomasjensen.checkstyle.addons.build.TaskCreator)1 TaskNames (com.thomasjensen.checkstyle.addons.build.TaskNames)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Objects (java.util.Objects)1