Search in sources :

Example 6 with ClasspathBuilder

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

the class GeneratePomConfigAction method buildDependencies4Pom.

private void buildDependencies4Pom(@Nonnull final Node pParentNode, @Nonnull final DependencyConfig pDepConfig) {
    final Configuration cfg = new ClasspathBuilder(project).buildMainRuntimeConfiguration(pDepConfig);
    for (Dependency d : cfg.getAllDependencies()) {
        if (!(d instanceof ExternalDependency)) {
            throw new GradleException("Incompatible dependency: " + d);
        }
        final ExternalDependency jar = (ExternalDependency) d;
        final Iterator<DependencyArtifact> artifactIterator = jar.getArtifacts().iterator();
        final DependencyArtifact artifcat = artifactIterator.hasNext() ? artifactIterator.next() : null;
        final String depClassifier = artifcat != null ? artifcat.getClassifier() : null;
        final Node n = pParentNode.appendNode("dependency");
        n.appendNode(BuildUtil.GROUP_ID, jar.getGroup());
        n.appendNode(BuildUtil.ARTIFACT_ID, jar.getName());
        n.appendNode(BuildUtil.VERSION, jar.getVersion());
        if (depClassifier != null) {
            n.appendNode("classifier", depClassifier);
        }
        n.appendNode("scope", "compile");
    }
}
Also used : ExternalDependency(org.gradle.api.artifacts.ExternalDependency) Configuration(org.gradle.api.artifacts.Configuration) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) DependencyArtifact(org.gradle.api.artifacts.DependencyArtifact) GradleException(org.gradle.api.GradleException) Node(groovy.util.Node) ExternalDependency(org.gradle.api.artifacts.ExternalDependency) Dependency(org.gradle.api.artifacts.Dependency)

Example 7 with ClasspathBuilder

use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder 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 8 with ClasspathBuilder

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

the class JavadocConfigAction method configureJavadocTask.

/**
 * These configurations are also applied to the standard 'javadoc' task, plus they are applied to ours.
 *
 * @param pJavadocTask the task to configure
 * @param pDepConfig dependency config
 */
public void configureJavadocTask(@Nonnull Javadoc pJavadocTask, @Nonnull final DependencyConfig pDepConfig) {
    // can't use fields here
    final Project project = pJavadocTask.getProject();
    final BuildUtil buildUtil = new BuildUtil(project);
    final StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) pJavadocTask.getOptions();
    options.setEncoding(StandardCharsets.UTF_8.toString());
    options.setDocEncoding(StandardCharsets.UTF_8.toString());
    options.setCharSet(StandardCharsets.UTF_8.toString());
    options.setAuthor(false);
    options.setUse(true);
    options.setNoDeprecated(true);
    options.setSplitIndex(false);
    options.setLinks(pDepConfig.getJavadocLinks());
    options.setHeader(buildUtil.getBuildConfig().getLongName().get());
    options.setWindowTitle(buildUtil.getBuildConfig().getLongName().get());
    pJavadocTask.setTitle(buildUtil.getBuildConfig().getLongName().get() + " v" + project.getVersion());
    pJavadocTask.setSource(buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME).getAllJava().plus(buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME).getAllJava()));
    pJavadocTask.setClasspath(new ClasspathBuilder(project).buildJavadocClasspath(pDepConfig));
    // javadoc does not inherit the proxy settings (https://issues.gradle.org/browse/GRADLE-1228)
    if (System.getProperty("http.proxyHost") != null) {
        options.jFlags("-DproxyHost=" + System.getProperty("http.proxyHost"), "-DproxyPort=" + System.getProperty("http.proxyPort"), "-DproxyUser=" + System.getProperty("http.proxyUser"), "-DproxyPassword=" + System.getProperty("http.proxyPassword"));
    }
}
Also used : Project(org.gradle.api.Project) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions)

Aggregations

ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)8 File (java.io.File)4 Task (org.gradle.api.Task)4 Configuration (org.gradle.api.artifacts.Configuration)4 SourceSet (org.gradle.api.tasks.SourceSet)4 TaskContainer (org.gradle.api.tasks.TaskContainer)3 BuildConfigExtension (com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)2 BuildUtil (com.thomasjensen.checkstyle.addons.build.BuildUtil)2 JavaLevelUtil (com.thomasjensen.checkstyle.addons.build.JavaLevelUtil)2 Nonnull (javax.annotation.Nonnull)2 JavaVersion (org.gradle.api.JavaVersion)2 Project (org.gradle.api.Project)2 Jar (org.gradle.api.tasks.bundling.Jar)2 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)2 DependencyFilter (com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter)1 ShadowJar (com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar)1 DependencyConfig (com.thomasjensen.checkstyle.addons.build.DependencyConfig)1 TaskCreator (com.thomasjensen.checkstyle.addons.build.TaskCreator)1 TaskNames (com.thomasjensen.checkstyle.addons.build.TaskNames)1 Node (groovy.util.Node)1