Search in sources :

Example 1 with BuildConfigExtension

use of com.thomasjensen.checkstyle.addons.build.BuildConfigExtension 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);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskInputs(org.gradle.api.tasks.TaskInputs) Configuration(org.gradle.api.artifacts.Configuration) Copy(org.gradle.api.tasks.Copy) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) JavaCompile(org.gradle.api.tasks.compile.JavaCompile)

Example 2 with BuildConfigExtension

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

the class JarConfigAction method mfAttrStd.

/**
 * Build a little map with standard manifest attributes.
 *
 * @param pProject Gradle project
 * @return the map
 */
public static Map<String, String> mfAttrStd(final Project pProject) {
    final BuildConfigExtension buildConfig = new BuildUtil(pProject).getBuildConfig();
    Map<String, String> result = new HashMap<>();
    result.put("Manifest-Version", "1.0");
    result.put("Website", buildConfig.getWebsite().get());
    result.put("Created-By", GradleVersion.current().toString());
    result.put("Built-By", System.getProperty("user.name"));
    result.put("Build-Jdk", Jvm.current().toString());
    return result;
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) HashMap(java.util.HashMap) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)

Example 3 with BuildConfigExtension

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

the class JarEclipseConfigAction 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 String baseCsVersion = pDepConfig.getCheckstyleBaseVersion();
    final String myJavaLevel = pDepConfig.getJavaLevel().toString();
    pJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
    pJarTask.setDescription("Assembles the Eclipse-CS plugin for dependency configuration '" + pDepConfig.getName() + "'");
    // adjust archive name
    String appendix = "eclipse";
    if (!pDepConfig.isDefaultConfig()) {
        appendix = pDepConfig.getName() + '-' + appendix;
    }
    pJarTask.getArchiveAppendix().set(appendix);
    // Dependency on 'classes' task (compile and resources)
    pJarTask.dependsOn(buildUtil.getTaskProvider(TaskNames.mainClasses, Task.class, pDepConfig));
    // 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("authorName", buildConfig.getAuthorName());
    // Configuration of JAR file contents
    pJarTask.into("META-INF", copySpec -> copySpec.from("LICENSE"));
    final JavaCompile compileTask = buildUtil.getTask(TaskNames.compileJava, JavaCompile.class, pDepConfig);
    pJarTask.from(compileTask.getDestinationDirectory());
    final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
    pJarTask.from(Objects.requireNonNull(mainSourceSet.getOutput().getResourcesDir()), copySpec -> {
        copySpec.exclude("**/*.html", "**/*.md");
        copySpec.rename(filename -> filename.replace("eclipsecs-plugin.xml", "plugin.xml"));
        copySpec.filter(versionReplacement(project.getVersion().toString()), ReplaceTokens.class);
    });
    final Set<File> pubLibs = getPublishedDependencyLibs(pJarTask, pDepConfig);
    pJarTask.into("lib", copySpec -> copySpec.from(pubLibs));
    final Attributes attrs = pJarTask.getManifest().getAttributes();
    attrs.clear();
    attrs.put("Bundle-ManifestVersion", "2");
    attrs.put("Bundle-Name", inputs.getProperties().get("name") + " Eclipse-CS Extension (based on Checkstyle " + baseCsVersion + ")");
    attrs.put("Bundle-SymbolicName", inputs.getProperties().get(BuildUtil.GROUP_ID) + ";singleton:=true");
    attrs.put("Bundle-Version", eclipsifyVersion(inputs.getProperties().get(BuildUtil.VERSION).toString()));
    attrs.put("Require-Bundle", "net.sf.eclipsecs.checkstyle," + "net.sf.eclipsecs.core," + "net.sf.eclipsecs.ui");
    attrs.put("Bundle-RequiredExecutionEnvironment", "JavaSE-" + myJavaLevel);
    attrs.put("Eclipse-LazyStart", "true");
    attrs.put("Bundle-Vendor", inputs.getProperties().get("authorName"));
    attrs.put("Import-Package", "org.eclipse.core.resources," + "org.eclipse.jdt.core.dom," + "org.eclipse.jface.resource," + "org.eclipse.jface.text," + "org.eclipse.swt.graphics," + "org.eclipse.ui");
    attrs.putAll(JarConfigAction.mfAttrStd(project));
    if (!pubLibs.isEmpty()) {
        attrs.put("Bundle-ClassPath", ".," + flattenPrefixLibs("lib/", pubLibs, ','));
    }
    buildUtil.addBuildTimestampDeferred(pJarTask);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) TaskInputs(org.gradle.api.tasks.TaskInputs) Attributes(org.gradle.api.java.archives.Attributes) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 4 with BuildConfigExtension

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

the class VersionFileTask method writeVersionFile.

@TaskAction
public void writeVersionFile() {
    final BuildConfigExtension buildConfig = new BuildUtil(getProject()).getBuildConfig();
    List<String> lines = new ArrayList<>();
    lines.add("# " + buildConfig.getLongName().get() + " version information");
    lines.add("# " + buildConfig.getBuildTimestamp().get());
    lines.add("version=" + getProject().getVersion());
    try {
        Files.write(getVersionFile().get().toPath(), lines, StandardCharsets.US_ASCII);
    } catch (IOException e) {
        throw new GradleException("Failed to create file: " + getVersionFile().get().getAbsolutePath(), e);
    }
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) IOException(java.io.IOException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with BuildConfigExtension

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

the class JarConfigAction method configureManifest.

private void configureManifest(@Nonnull Jar pJarTask, @Nonnull DependencyConfig pDepConfig, @Nonnull final String pAppendix) {
    final BuildConfigExtension buildConfig = buildUtil.getBuildConfig();
    String effectiveName = project.getName();
    if (!pDepConfig.isDefaultConfig()) {
        effectiveName += '-' + pAppendix;
    }
    Manifest manifest = pJarTask.getManifest();
    final Attributes attrs = manifest.getAttributes();
    attrs.clear();
    attrs.put("Specification-Title", effectiveName);
    attrs.put("Specification-Vendor", buildConfig.getAuthorName().get());
    attrs.put("Specification-Vendor-Id", "com.thomasjensen");
    attrs.put("Specification-Version", project.getVersion());
    attrs.put("Implementation-Title", effectiveName);
    attrs.put("Implementation-Vendor", buildConfig.getAuthorName().get());
    attrs.put("Implementation-Vendor-Id", "com.thomasjensen");
    attrs.put("Implementation-Version", project.getVersion());
    attrs.put("Implementation-Build", buildConfig.getGitHash().get());
    attrs.put("Checkstyle-Version", pDepConfig.getCheckstyleBaseVersion());
    attrs.putAll(mfAttrStd(project));
    buildUtil.addBuildTimestampDeferred(pJarTask);
}
Also used : Attributes(org.gradle.api.java.archives.Attributes) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) Manifest(org.gradle.api.java.archives.Manifest)

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