diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index a57cb432..ae752a3c 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -16,4 +16,4 @@ jobs: distribution: 'temurin' java-version: 17 - uses: gradle/actions/setup-gradle@v5 - - run: "./gradlew :test" + - run: "./gradlew :qualityCheck :test" diff --git a/.gitignore b/.gitignore index 3316d645..0beadf34 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ build .kotlin/ +# Ignore IntelliJ IDEA config directory +.idea/ + # Used by takari-plugin-testing library used in MavenEndToEndFuncTest # unfortunately this path is hard coded here https://github.com/takari/takari-plugin-testing-project/blob/04312cdd308b284ed8dfa9655174abc2efcbfe20/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/junit/MavenVersionResolver.java#L97 # and can therefore not be changed to be inside the build directory. diff --git a/build.gradle.kts b/build.gradle.kts index 490859c1..a8fecc49 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,29 +1,7 @@ -plugins { - id("groovy") - id("java-gradle-plugin") - id("java-test-fixtures") - id("jvm-test-suite") - id("org.asciidoctor.jvm.convert") version "4.0.5" - id("org.gradlex.internal.plugin-publish-conventions") version "0.6" -} +plugins { id("java-test-fixtures") } -group = "org.gradlex" version = "1.0.3" -java { - toolchain.languageVersion = JavaLanguageVersion.of(17) -} - -tasks.compileJava { - options.release = 8 - options.compilerArgs.add("-Werror") -} - -tasks.javadoc { - // Enable all JavaDoc checks, but the one requiring JavaDoc everywhere - (options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-Xwerror") -} - dependencies { api(platform(libs.mavenPluginTools.bom)) { because("the version for other dependencies in api would be missing otherwise") @@ -33,33 +11,26 @@ dependencies { implementation(libs.mavenPluginTools.java) implementation(libs.mavenPluginTools.generators) - api(libs.mavenPlugin.annotations) { - because("MavenMojo references types from this artifact") - } + api(libs.mavenPlugin.annotations) { because("MavenMojo references types from this artifact") } implementation(libs.mavenPlugin.api) - implementation(libs.sisu.injectPlexus) { - because("it is needed to implement the plexus logging adapter") - } - implementation(libs.plexus.velocity) { - because("it is needed to generate the help mojo") - } + implementation(libs.sisu.injectPlexus) { because("it is needed to implement the plexus logging adapter") } + implementation(libs.plexus.velocity) { because("it is needed to generate the help mojo") } constraints { - implementation(libs.qdox) { - because("we need the fix for https://github.com/paul-hammant/qdox/issues/43") - } + implementation(libs.qdox) { because("we need the fix for https://github.com/paul-hammant/qdox/issues/43") } } testFixturesImplementation(libs.junit4) testFixturesImplementation(libs.commonsLang) } -pluginPublishConventions { - id("${project.group}.${project.name}") - implementationClass("org.gradlex.maven.plugin.development.MavenPluginDevelopmentPlugin") - displayName("Maven Plugin Development Gradle Plugin") - description("Gradle plugin for developing Apache Maven plugins.") - tags("gradlex", "maven", "mojo", "maven plugin") +publishingConventions { + pluginPortal("${project.group}.${project.name}") { + implementationClass("org.gradlex.maven.plugin.development.MavenPluginDevelopmentPlugin") + displayName("Maven Plugin Development Gradle Plugin") + description("Gradle plugin for developing Apache Maven plugins.") + tags("gradlex", "maven", "mojo", "maven plugin") + } gitHub("https://github.com/gradlex-org/maven-plugin-development") website("https://gradlex.org/maven-plugin-development") developer { @@ -69,71 +40,18 @@ pluginPublishConventions { } } -// Required to write localRepository property to src/test/resources/test.properties for takari-plugin-testing used in MavenEndToEndFuncTest -tasks.processTestResources { - expand("localRepository" to project.layout.buildDirectory.dir("mavenLocal").get().asFile) -} +// Required to write localRepository property to src/test/resources/test.properties for takari-plugin-testing used in +// MavenEndToEndFuncTest +tasks.processTestResources { expand("localRepository" to project.layout.buildDirectory.dir("mavenLocal").get().asFile) } -testing.suites.named("test") { - useSpock() - dependencies { - implementation(libs.spock.core) - implementation(libs.spock.junit4) - implementation(libs.takariPluginTesting) - implementation(project.dependencies.testFixtures(project)) - runtimeOnly(libs.junitVintageEngine) - } - targets.all { - testTask.configure { - maxParallelForks = 4 - } - } -} - -testing.suites.register("testSamples") { - useJUnit() - dependencies { - implementation(gradleTestKit()) - implementation(libs.exemplar.sampleCheck) - } - targets.all { - testTask.configure { - inputs.dir("src/docs/snippets") - .withPathSensitivity(PathSensitivity.RELATIVE) - .withPropertyName("snippets") - } - } -} +// === the following custom configuration should be removed once tests are migrated to Java +apply(plugin = "groovy") -tasks { - test { - useJUnitPlatform() - } - jar { - from(rootProject.file("LICENSE.txt")) { - into("META-INF") - } - } - asciidoctor { - notCompatibleWithConfigurationCache("See https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/564") - inputs.dir("src/docs/snippets") - .withPathSensitivity(PathSensitivity.RELATIVE) - .withPropertyName("snippets") - outputOptions { - separateOutputDirs = false - } - - attributes(mapOf( - "docinfodir" to "src/docs/asciidoc", - "docinfo" to "shared", - "source-highlighter" to "prettify", - "tabsize" to "4", - "toc" to "left", - "icons" to "font", - "sectanchors" to true, - "idprefix" to "", - "idseparator" to "-", - "snippets-path" to "$projectDir/src/docs/snippets" - )) - } -} +dependencies { + testImplementation(libs.spock.core) + testImplementation(libs.spock.junit4) + testImplementation(libs.takariPluginTesting) + testImplementation(project.dependencies.testFixtures(project)) + testRuntimeOnly(libs.junitVintageEngine) +} // +// ==================================================================================== diff --git a/gradle.properties b/gradle.properties index d39edd1a..6f78d3f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,2 @@ org.gradle.caching=true org.gradle.configuration-cache=true -org.gradle.parallel=true diff --git a/gradle/checkstyle/checkstyle.xml b/gradle/checkstyle/checkstyle.xml deleted file mode 100644 index e7521b07..00000000 --- a/gradle/checkstyle/checkstyle.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/gradle/checkstyle/header.txt b/gradle/checkstyle/header.txt deleted file mode 100644 index 4fe8a001..00000000 --- a/gradle/checkstyle/header.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ \ No newline at end of file diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 00000000..20fe5710 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1 @@ +toolchainVersion=17 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6b9d876b..715d583a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,4 +18,3 @@ junit4 = { module = "junit:junit", version = "4.13.2" } junitVintageEngine = { module = "org.junit.vintage:junit-vintage-engine", version = "6.0.0" } takariPluginTesting = { module = "io.takari.maven.plugins:takari-plugin-integration-testing", version = "3.1.1" } commonsLang = { module = "org.apache.commons:commons-lang3", version = "3.19.0" } -exemplar-sampleCheck = { module = "org.gradle.exemplar:samples-check", version = "1.0.3" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 4ff9400c..b731ecf2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,37 +1,5 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -plugins { - id("com.gradle.develocity") version "4.2.2" - id("com.gradle.common-custom-user-data-gradle-plugin") version "2.4.0" -} - -dependencyResolutionManagement { - repositories { - mavenCentral() - } -} +plugins { id("org.gradlex.internal-build-conventions") version "0.8" } rootProject.name = "maven-plugin-development" includeBuild("sample/gradle-producer-build") - -develocity { - buildScan { - termsOfUseUrl = "https://gradle.com/terms-of-service" - termsOfUseAgree = "yes" - publishing.onlyIf { !System.getenv("CI").isNullOrEmpty() } - } -} diff --git a/src/docs/snippets/dependencies/dependencies.sample.conf b/src/docs/snippets/dependencies/dependencies.sample.conf index 91bbbba6..590334b1 100644 --- a/src/docs/snippets/dependencies/dependencies.sample.conf +++ b/src/docs/snippets/dependencies/dependencies.sample.conf @@ -1,9 +1,2 @@ -commands: [{ - execution-subdirectory: groovy - executable: gradle - args: tasks -},{ - execution-subdirectory: kotlin - executable: gradle - args: tasks -}] +executable: gradlew +args: tasks diff --git a/src/docs/snippets/help-mojo/help-mojo.sample.conf b/src/docs/snippets/help-mojo/help-mojo.sample.conf index 91bbbba6..590334b1 100644 --- a/src/docs/snippets/help-mojo/help-mojo.sample.conf +++ b/src/docs/snippets/help-mojo/help-mojo.sample.conf @@ -1,9 +1,2 @@ -commands: [{ - execution-subdirectory: groovy - executable: gradle - args: tasks -},{ - execution-subdirectory: kotlin - executable: gradle - args: tasks -}] +executable: gradlew +args: tasks diff --git a/src/main/java/org/gradlex/maven/plugin/development/FileUtils.java b/src/main/java/org/gradlex/maven/plugin/development/FileUtils.java index eb7166c6..cf435346 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/FileUtils.java +++ b/src/main/java/org/gradlex/maven/plugin/development/FileUtils.java @@ -1,19 +1,4 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development; import java.io.File; @@ -32,6 +17,5 @@ static Optional getExtension(File file) { return Optional.of(fileNameSegments[fileNameSegments.length - 1]); } - private FileUtils() { - } + private FileUtils() {} } diff --git a/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentExtension.java b/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentExtension.java index 2e535f82..3342a1e1 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentExtension.java +++ b/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentExtension.java @@ -1,19 +1,4 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development; import org.gradle.api.artifacts.Configuration; @@ -23,19 +8,19 @@ public interface MavenPluginDevelopmentExtension { String NAME = "mavenPlugin"; - Property getGroupId(); + Property getGroupId(); - Property getArtifactId(); + Property getArtifactId(); - Property getVersion(); + Property getVersion(); - Property getName(); + Property getName(); - Property getDescription(); + Property getDescription(); - Property getGoalPrefix(); + Property getGoalPrefix(); - Property getHelpMojoPackage(); + Property getHelpMojoPackage(); /** * The set of dependencies to add to the plugin descriptor. diff --git a/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentPlugin.java b/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentPlugin.java index 406bc681..15ded0c1 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentPlugin.java +++ b/src/main/java/org/gradlex/maven/plugin/development/MavenPluginDevelopmentPlugin.java @@ -1,21 +1,12 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collector; +import java.util.stream.Collectors; import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -47,13 +38,6 @@ import org.gradlex.maven.plugin.development.task.MavenPluginDescriptor; import org.gradlex.maven.plugin.development.task.UpstreamProjectDescriptor; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collector; -import java.util.stream.Collectors; - public class MavenPluginDevelopmentPlugin implements Plugin { public static final String TASK_GROUP_NAME = "Maven Plugin Development"; @@ -76,47 +60,55 @@ public void apply(Project project) { project.getPluginManager().apply(JavaPlugin.class); - Provider pluginOutputDirectory = project.getLayout().getBuildDirectory().dir("mavenPlugin"); + Provider pluginOutputDirectory = + project.getLayout().getBuildDirectory().dir("mavenPlugin"); Provider descriptorDir = pluginOutputDirectory.map(it -> it.dir("descriptor")); Provider helpMojoDir = pluginOutputDirectory.map(it -> it.dir("helpMojo")); - MavenPluginDevelopmentExtension extension = project.getExtensions().create(MavenPluginDevelopmentExtension.NAME, MavenPluginDevelopmentExtension.class); - extension.getGroupId().convention(project.provider(() -> project.getGroup().toString())); + MavenPluginDevelopmentExtension extension = project.getExtensions() + .create(MavenPluginDevelopmentExtension.NAME, MavenPluginDevelopmentExtension.class); + extension.getGroupId().convention(project.provider(() -> project.getGroup() + .toString())); extension.getArtifactId().convention(project.provider(project::getName)); - extension.getVersion().convention(project.provider(() -> project.getVersion().toString())); + extension.getVersion().convention(project.provider(() -> project.getVersion() + .toString())); extension.getName().convention(project.provider(project::getName)); extension.getDescription().convention(project.provider(project::getDescription)); extension.getDependencies().convention(project.getConfigurations().getByName("runtimeClasspath")); - TaskProvider generateHelpMojoTask = project.getTasks().register("generateMavenPluginHelpMojoSources", GenerateHelpMojoSourcesTask.class, task -> { - task.setGroup(TASK_GROUP_NAME); - task.setDescription("Generates a Maven help mojo that documents the usage of the Maven plugin"); - - // capture helpMojoPackage property here for configuration cache compatibility - Property helpMojoPkg = extension.getHelpMojoPackage(); - task.onlyIf(t -> helpMojoPkg.isPresent()); - - task.getHelpMojoPackage().convention(extension.getHelpMojoPackage()); - task.getOutputDirectory().convention(helpMojoDir); - task.getHelpPropertiesFile().convention(pluginOutputDirectory.map(it -> it.file("maven-plugin-help.properties"))); - task.getPluginDescriptor().convention(project.provider(() -> mavenPluginDescriptorOf(extension))); - task.getRuntimeDependencies().convention(collectRuntimeDependencies(project, extension)); - }); - - SourceSet main = project.getExtensions().getByType(SourceSetContainer.class).getByName("main"); - TaskProvider generateTask = project.getTasks().register("generateMavenPluginDescriptor", GenerateMavenPluginDescriptorTask.class, task -> { - task.setGroup(TASK_GROUP_NAME); - task.setDescription("Generates the Maven plugin descriptor file"); - - task.getClassesDirs().from(main.getJava().getClassesDirectory()); - task.getSourcesDirs().from(main.getJava().getSourceDirectories()); - task.getUpstreamProjects().convention(project.provider(() -> extractUpstreamProjects(project))); - task.getOutputDirectory().convention(descriptorDir); - task.getPluginDescriptor().convention(project.provider(() -> mavenPluginDescriptorOf(extension))); - task.getRuntimeDependencies().convention(collectRuntimeDependencies(project, extension)); - - task.dependsOn(main.getOutput(), generateHelpMojoTask); - }); + TaskProvider generateHelpMojoTask = project.getTasks() + .register("generateMavenPluginHelpMojoSources", GenerateHelpMojoSourcesTask.class, task -> { + task.setGroup(TASK_GROUP_NAME); + task.setDescription("Generates a Maven help mojo that documents the usage of the Maven plugin"); + + // capture helpMojoPackage property here for configuration cache compatibility + Property helpMojoPkg = extension.getHelpMojoPackage(); + task.onlyIf(t -> helpMojoPkg.isPresent()); + + task.getHelpMojoPackage().convention(extension.getHelpMojoPackage()); + task.getOutputDirectory().convention(helpMojoDir); + task.getHelpPropertiesFile() + .convention(pluginOutputDirectory.map(it -> it.file("maven-plugin-help.properties"))); + task.getPluginDescriptor().convention(project.provider(() -> mavenPluginDescriptorOf(extension))); + task.getRuntimeDependencies().convention(collectRuntimeDependencies(project, extension)); + }); + + SourceSet main = + project.getExtensions().getByType(SourceSetContainer.class).getByName("main"); + TaskProvider generateTask = project.getTasks() + .register("generateMavenPluginDescriptor", GenerateMavenPluginDescriptorTask.class, task -> { + task.setGroup(TASK_GROUP_NAME); + task.setDescription("Generates the Maven plugin descriptor file"); + + task.getClassesDirs().from(main.getJava().getClassesDirectory()); + task.getSourcesDirs().from(main.getJava().getSourceDirectories()); + task.getUpstreamProjects().convention(project.provider(() -> extractUpstreamProjects(project))); + task.getOutputDirectory().convention(descriptorDir); + task.getPluginDescriptor().convention(project.provider(() -> mavenPluginDescriptorOf(extension))); + task.getRuntimeDependencies().convention(collectRuntimeDependencies(project, extension)); + + task.dependsOn(main.getOutput(), generateHelpMojoTask); + }); project.afterEvaluate(p -> { Jar jarTask = (Jar) p.getTasks().findByName(main.getJarTaskName()); @@ -127,30 +119,35 @@ public void apply(Project project) { private static MavenPluginDescriptor mavenPluginDescriptorOf(MavenPluginDevelopmentExtension extension) { return new MavenPluginDescriptor( - GAV.of(extension.getGroupId().get(), extension.getArtifactId().get(), extension.getVersion().get()), + GAV.of( + extension.getGroupId().get(), + extension.getArtifactId().get(), + extension.getVersion().get()), extension.getName().get(), extension.getDescription().getOrElse(""), - extension.getGoalPrefix().getOrNull() - ); + extension.getGoalPrefix().getOrNull()); } private List extractUpstreamProjects(Project project) { - Configuration compileClasspath = project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); - // It's not possible to access group, and version of project dependencies, see https://github.com/gradle/gradle/issues/31973 + Configuration compileClasspath = + project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); + // It's not possible to access group, and version of project dependencies, see + // https://github.com/gradle/gradle/issues/31973 String group = project.getGroup().toString(); String version = project.getVersion().toString(); - Map classDirectoriesByGAV = getDependencyProjectClassesDirectoriesMappedByGav(compileClasspath, group, version); - Map sourcesDirectoriesByGAV = getDependencyProjectSourceDirectoriesMappedByGav(project, compileClasspath, group, version); + Map classDirectoriesByGAV = + getDependencyProjectClassesDirectoriesMappedByGav(compileClasspath, group, version); + Map sourcesDirectoriesByGAV = + getDependencyProjectSourceDirectoriesMappedByGav(project, compileClasspath, group, version); return classDirectoriesByGAV.entrySet().stream() .collect(associateClassesDirectoriesToSourcesDirectories(sourcesDirectoriesByGAV)); } - private Map getDependencyProjectClassesDirectoriesMappedByGav(Configuration compileClasspath, String group, String version) { - return compileClasspath.getIncoming() - .artifactView(projects()) - .getArtifacts().getArtifacts().stream() + private Map getDependencyProjectClassesDirectoriesMappedByGav( + Configuration compileClasspath, String group, String version) { + return compileClasspath.getIncoming().artifactView(projects()).getArtifacts().getArtifacts().stream() .collect(collectToDirectoriesMappedByGav(group, version)); } @@ -160,21 +157,26 @@ private static Action projects() { }; } - private Collector> collectToDirectoriesMappedByGav(String group, String version) { + private Collector> collectToDirectoriesMappedByGav( + String group, String version) { return Collectors.toMap( a -> { - ProjectComponentIdentifier m = (ProjectComponentIdentifier) a.getId().getComponentIdentifier(); + ProjectComponentIdentifier m = + (ProjectComponentIdentifier) a.getId().getComponentIdentifier(); return GAV.of(group, m.getProjectName(), version); }, artifact -> project.getObjects().fileCollection().from(artifact.getFile()), - FileCollection::plus - ); + FileCollection::plus); } - private Map getDependencyProjectSourceDirectoriesMappedByGav(Project project, Configuration compileClasspath, String group, String version) { - return compileClasspath.getIncoming() + private Map getDependencyProjectSourceDirectoriesMappedByGav( + Project project, Configuration compileClasspath, String group, String version) { + return compileClasspath + .getIncoming() .artifactView(projectSources(project.getObjects())) - .getArtifacts().getArtifacts().stream() + .getArtifacts() + .getArtifacts() + .stream() .collect(collectToDirectoriesMappedByGav(group, version)); } @@ -186,7 +188,6 @@ private static Action projectSources(ObjectFacto }; } - private static Spec projectDependencies() { return ci -> ci instanceof ProjectComponentIdentifier; } @@ -197,43 +198,57 @@ private static Spec projectDependencies() { */ private static Action sourceAttributes(ObjectFactory objectFactory) { return attributes -> { - attributes.attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.class, Category.VERIFICATION)); - attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objectFactory.named(VerificationType.class, VerificationType.MAIN_SOURCES)); + attributes.attribute( + Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.class, Category.VERIFICATION)); + attributes.attribute( + VerificationType.VERIFICATION_TYPE_ATTRIBUTE, + objectFactory.named(VerificationType.class, VerificationType.MAIN_SOURCES)); }; } - private static Collector, ArrayList, ArrayList> associateClassesDirectoriesToSourcesDirectories(Map sourcesDirectoriesByGav) { - return Collector.of(ArrayList::new, (acc, e) -> { - acc.add(new UpstreamProjectDescriptor( - e.getKey(), - e.getValue(), - sourcesDirectoriesByGav.get(e.getKey()) - )); - }, (l, r) -> { - l.addAll(r); - return l; - }, Collector.Characteristics.UNORDERED); + private static Collector< + Map.Entry, + ArrayList, + ArrayList> + associateClassesDirectoriesToSourcesDirectories(Map sourcesDirectoriesByGav) { + return Collector.of( + ArrayList::new, + (acc, e) -> { + acc.add(new UpstreamProjectDescriptor( + e.getKey(), e.getValue(), sourcesDirectoriesByGav.get(e.getKey()))); + }, + (l, r) -> { + l.addAll(r); + return l; + }, + Collector.Characteristics.UNORDERED); } - private static Provider> collectRuntimeDependencies(Project project, MavenPluginDevelopmentExtension extension) { - return extension.getDependencies().map(c -> - c.getIncoming().getArtifacts().getArtifacts().stream() - .map(toDependencyDescriptor(project.getGroup().toString(), project.getVersion().toString())).collect(Collectors.toList()) - ); + private static Provider> collectRuntimeDependencies( + Project project, MavenPluginDevelopmentExtension extension) { + return extension.getDependencies().map(c -> c.getIncoming().getArtifacts().getArtifacts().stream() + .map(toDependencyDescriptor( + project.getGroup().toString(), project.getVersion().toString())) + .collect(Collectors.toList())); } - private static Function toDependencyDescriptor(String group, String version) { + private static Function toDependencyDescriptor( + String group, String version) { return artifact -> { ComponentIdentifier id = artifact.getId().getComponentIdentifier(); GAV gav = null; if (id instanceof ModuleComponentIdentifier) { ModuleComponentIdentifier externalDependencyIdentifier = (ModuleComponentIdentifier) id; - gav = GAV.of(externalDependencyIdentifier.getGroup(), externalDependencyIdentifier.getModule(), externalDependencyIdentifier.getVersion()); + gav = GAV.of( + externalDependencyIdentifier.getGroup(), + externalDependencyIdentifier.getModule(), + externalDependencyIdentifier.getVersion()); } else { ProjectComponentIdentifier projectDependencyIdentifier = (ProjectComponentIdentifier) id; gav = GAV.of(group, projectDependencyIdentifier.getProjectName(), version); } - return new DependencyDescriptor(gav, FileUtils.getExtension(artifact.getFile()).orElse(null)); + return new DependencyDescriptor( + gav, FileUtils.getExtension(artifact.getFile()).orElse(null)); }; } } diff --git a/src/main/java/org/gradlex/maven/plugin/development/internal/MavenLoggerAdapter.java b/src/main/java/org/gradlex/maven/plugin/development/internal/MavenLoggerAdapter.java index ce1a336b..b467cf31 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/internal/MavenLoggerAdapter.java +++ b/src/main/java/org/gradlex/maven/plugin/development/internal/MavenLoggerAdapter.java @@ -1,24 +1,10 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.internal; import org.gradle.api.logging.Logger; -public final class MavenLoggerAdapter implements org.codehaus.plexus.logging.Logger, org.apache.maven.plugin.logging.Log { +public final class MavenLoggerAdapter + implements org.codehaus.plexus.logging.Logger, org.apache.maven.plugin.logging.Log { private final Logger delegate; diff --git a/src/main/java/org/gradlex/maven/plugin/development/internal/MavenServiceFactory.java b/src/main/java/org/gradlex/maven/plugin/development/internal/MavenServiceFactory.java index d2e3830f..036bae3c 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/internal/MavenServiceFactory.java +++ b/src/main/java/org/gradlex/maven/plugin/development/internal/MavenServiceFactory.java @@ -1,21 +1,10 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.internal; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.annotations.JavaAnnotationsMojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocBlockTagsToXhtmlConverter; @@ -25,11 +14,6 @@ import org.apache.maven.tools.plugin.scanner.DefaultMojoScanner; import org.apache.maven.tools.plugin.scanner.MojoScanner; -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - public final class MavenServiceFactory { public static MojoScanner createMojoScanner(MavenLoggerAdapter loggerAdapter) { @@ -51,12 +35,15 @@ private static MojoDescriptorExtractor annotationExtractor(MavenLoggerAdapter lo setField(extractor, "mojoAnnotationsScanner", annotationsScanner); - // TODO this needs a map of tag converts, see the org.apache.maven.tools.plugin.extractor.annotations.converter.tag + // TODO this needs a map of tag converts, see the + // org.apache.maven.tools.plugin.extractor.annotations.converter.tag // in org.apache.maven.plugin-tools:maven-plugin-tools-annotations - JavadocInlineTagsToXhtmlConverter javadocInlineTagsToHtmlConverter = new JavadocInlineTagsToXhtmlConverter(Collections.emptyMap()); + JavadocInlineTagsToXhtmlConverter javadocInlineTagsToHtmlConverter = + new JavadocInlineTagsToXhtmlConverter(Collections.emptyMap()); setField(extractor, "javadocInlineTagsToHtmlConverter", javadocInlineTagsToHtmlConverter); - JavadocBlockTagsToXhtmlConverter javadocBlockTagsToHtmlConverter = new JavadocBlockTagsToXhtmlConverter(javadocInlineTagsToHtmlConverter, Collections.emptyMap()); + JavadocBlockTagsToXhtmlConverter javadocBlockTagsToHtmlConverter = + new JavadocBlockTagsToXhtmlConverter(javadocInlineTagsToHtmlConverter, Collections.emptyMap()); setField(extractor, "javadocBlockTagsToHtmlConverter", javadocBlockTagsToHtmlConverter); return extractor; diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/AbstractMavenPluginDevelopmentTask.java b/src/main/java/org/gradlex/maven/plugin/development/task/AbstractMavenPluginDevelopmentTask.java index 703ebbd1..71c69ec9 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/AbstractMavenPluginDevelopmentTask.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/AbstractMavenPluginDevelopmentTask.java @@ -1,21 +1,8 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; +import java.util.stream.Collectors; +import javax.inject.Inject; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; @@ -26,9 +13,6 @@ import org.gradle.api.provider.Property; import org.gradle.api.tasks.Nested; -import javax.inject.Inject; -import java.util.stream.Collectors; - public abstract class AbstractMavenPluginDevelopmentTask extends DefaultTask { @Nested @@ -50,18 +34,18 @@ protected PluginDescriptor createPluginDescriptor() { result.setGoalPrefix( pluginDescriptor.getGoalPrefix() != null ? pluginDescriptor.getGoalPrefix() - : PluginDescriptor.getGoalPrefixFromArtifactId(pluginDescriptor.getGav().getArtifactId()) - ); + : PluginDescriptor.getGoalPrefixFromArtifactId( + pluginDescriptor.getGav().getArtifactId())); result.setName(pluginDescriptor.getName()); result.setDescription(pluginDescriptor.getDescription()); result.setDependencies(getRuntimeDependencies().get().stream() - .map( DependencyDescriptor::toComponentDependency) - .collect(Collectors.toList()) - ); + .map(DependencyDescriptor::toComponentDependency) + .collect(Collectors.toList())); return result; } - protected PluginToolsRequest createPluginToolsRequest(MavenProject mavenProject, PluginDescriptor pluginDescriptor) { + protected PluginToolsRequest createPluginToolsRequest( + MavenProject mavenProject, PluginDescriptor pluginDescriptor) { DefaultPluginToolsRequest request = new DefaultPluginToolsRequest(mavenProject, pluginDescriptor); request.setSkipErrorNoDescriptorsFound(true); return request; diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/DependencyDescriptor.java b/src/main/java/org/gradlex/maven/plugin/development/task/DependencyDescriptor.java index e3179520..485e5673 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/DependencyDescriptor.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/DependencyDescriptor.java @@ -1,19 +1,4 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; import org.codehaus.plexus.component.repository.ComponentDependency; @@ -50,4 +35,4 @@ public ComponentDependency toComponentDependency() { dep.setType(type); return dep; } -} \ No newline at end of file +} diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/GAV.java b/src/main/java/org/gradlex/maven/plugin/development/task/GAV.java index 72491e98..eb35bcc2 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/GAV.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/GAV.java @@ -1,24 +1,8 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; -import org.gradle.api.tasks.Input; - import java.util.Objects; +import org.gradle.api.tasks.Input; public final class GAV { @@ -55,7 +39,9 @@ public String getVersion() { public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; GAV gav = (GAV) o; - return Objects.equals(group, gav.group) && Objects.equals(artifactId, gav.artifactId) && Objects.equals(version, gav.version); + return Objects.equals(group, gav.group) + && Objects.equals(artifactId, gav.artifactId) + && Objects.equals(version, gav.version); } @Override @@ -65,10 +51,9 @@ public int hashCode() { @Override public String toString() { - return "GAV{" + - "group='" + group + '\'' + - ", name='" + artifactId + '\'' + - ", version='" + version + '\'' + - '}'; + return "GAV{" + "group='" + + group + '\'' + ", name='" + + artifactId + '\'' + ", version='" + + version + '\'' + '}'; } } diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/GenerateHelpMojoSourcesTask.java b/src/main/java/org/gradlex/maven/plugin/development/task/GenerateHelpMojoSourcesTask.java index 08dd1c58..3620007b 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/GenerateHelpMojoSourcesTask.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/GenerateHelpMojoSourcesTask.java @@ -1,21 +1,7 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; +import java.io.File; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifact; @@ -33,8 +19,6 @@ import org.gradle.api.tasks.TaskAction; import org.gradlex.maven.plugin.development.internal.MavenLoggerAdapter; -import java.io.File; - @CacheableTask public abstract class GenerateHelpMojoSourcesTask extends AbstractMavenPluginDevelopmentTask { @@ -48,8 +32,6 @@ public abstract class GenerateHelpMojoSourcesTask extends AbstractMavenPluginDev @Input public abstract Property getHelpMojoPackage(); - - private final MavenLoggerAdapter loggerAdapter = new MavenLoggerAdapter(getLogger()); @TaskAction @@ -81,7 +63,8 @@ private MavenProject mavenProject() { } private VelocityComponent createVelocityComponent() { - // fix for broken debugging due to reflection happening inside Velocity (RuntimeInstance#initializeResourceManager()) + // fix for broken debugging due to reflection happening inside Velocity + // (RuntimeInstance#initializeResourceManager()) ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); @@ -90,4 +73,4 @@ private VelocityComponent createVelocityComponent() { Thread.currentThread().setContextClassLoader(currentContextClassLoader); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.java b/src/main/java/org/gradlex/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.java index 2b13dc7a..de3dca54 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.java @@ -1,21 +1,9 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; +import java.io.File; +import java.util.Collection; +import java.util.Collections; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.model.Build; @@ -43,10 +31,6 @@ import org.gradlex.maven.plugin.development.internal.MavenLoggerAdapter; import org.gradlex.maven.plugin.development.internal.MavenServiceFactory; -import java.io.File; -import java.util.Collection; -import java.util.Collections; - @CacheableTask public abstract class GenerateMavenPluginDescriptorTask extends AbstractMavenPluginDevelopmentTask { @@ -83,13 +67,18 @@ public void generateDescriptor() throws GeneratorException { private void checkArtifactId() { String artifactId = getPluginDescriptor().get().getGav().getArtifactId(); if (artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { - getLogger().warn("ArtifactIds of the form maven-___-plugin are reserved for plugins of the maven team. Please change the plugin artifactId to the format ___-maven-plugin."); + getLogger() + .warn( + "ArtifactIds of the form maven-___-plugin are reserved for plugins of the maven team. Please change the plugin artifactId to the format ___-maven-plugin."); } } private void writeDescriptor(PluginDescriptor pluginDescriptor) throws GeneratorException { - MavenProject mavenProject = mavenProject(getSourcesDirs(), getOutputDirectory().getAsFile().get()); - generator.execute(getOutputDirectory().dir("META-INF/maven").get().getAsFile(), createPluginToolsRequest(mavenProject, pluginDescriptor)); + MavenProject mavenProject = + mavenProject(getSourcesDirs(), getOutputDirectory().getAsFile().get()); + generator.execute( + getOutputDirectory().dir("META-INF/maven").get().getAsFile(), + createPluginToolsRequest(mavenProject, pluginDescriptor)); } private PluginDescriptor extractPluginDescriptor() { @@ -104,12 +93,18 @@ private PluginDescriptor extractPluginDescriptor() { GAV gav = it.getGav(); for (File dir : dirs) { DefaultArtifact artifact = new DefaultArtifact( - gav.getGroup(), gav.getArtifactId(), gav.getVersion(), "compile", "jar", null, new DefaultArtifactHandler() - ); + gav.getGroup(), + gav.getArtifactId(), + gav.getVersion(), + "compile", + "jar", + null, + new DefaultArtifactHandler()); artifact.setFile(dir); pluginToolsRequest.getDependencies().add(artifact); } - mavenProject.addProjectReference(mavenProject(gav.getGroup(), gav.getArtifactId(), gav.getVersion(), it.getSourceDirectories(), classesDir)); + mavenProject.addProjectReference(mavenProject( + gav.getGroup(), gav.getArtifactId(), gav.getVersion(), it.getSourceDirectories(), classesDir)); }); populatePluginDescriptor(pluginToolsRequest); }); @@ -127,42 +122,21 @@ private void populatePluginDescriptor(PluginToolsRequest pluginToolsRequest) { private MavenProject mavenProject(FileCollection sourcesDirs, File outputDirectory) { GAV gav = getPluginDescriptor().get().getGav(); - return mavenProject( - gav.getGroup(), - gav.getArtifactId(), - gav.getVersion(), - sourcesDirs, - outputDirectory - ); + return mavenProject(gav.getGroup(), gav.getArtifactId(), gav.getVersion(), sourcesDirs, outputDirectory); } private MavenProject mavenProject( - String groupId, - String artifactId, - String version, - FileCollection sourcesDirs, - File outputDirectory - ) { + String groupId, String artifactId, String version, FileCollection sourcesDirs, File outputDirectory) { return mavenProject(groupId, artifactId, version, sourcesDirs.getFiles(), outputDirectory); } private MavenProject mavenProject( - String groupId, - String artifactId, - String version, - File sourcesDirs, - File outputDirectory - ) { + String groupId, String artifactId, String version, File sourcesDirs, File outputDirectory) { return mavenProject(groupId, artifactId, version, Collections.singleton(sourcesDirs), outputDirectory); } private MavenProject mavenProject( - String groupId, - String artifactId, - String version, - Collection sourcesDirs, - File outputDirectory - ) { + String groupId, String artifactId, String version, Collection sourcesDirs, File outputDirectory) { MavenProject project = new MavenProject(); project.setGroupId(groupId); @@ -179,4 +153,3 @@ private MavenProject mavenProject( return project; } } - diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/MavenPluginDescriptor.java b/src/main/java/org/gradlex/maven/plugin/development/task/MavenPluginDescriptor.java index 447bf066..44f7783d 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/MavenPluginDescriptor.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/MavenPluginDescriptor.java @@ -1,19 +1,4 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; import org.gradle.api.tasks.Input; diff --git a/src/main/java/org/gradlex/maven/plugin/development/task/UpstreamProjectDescriptor.java b/src/main/java/org/gradlex/maven/plugin/development/task/UpstreamProjectDescriptor.java index 0be53b71..6c2144b5 100644 --- a/src/main/java/org/gradlex/maven/plugin/development/task/UpstreamProjectDescriptor.java +++ b/src/main/java/org/gradlex/maven/plugin/development/task/UpstreamProjectDescriptor.java @@ -1,19 +1,4 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// SPDX-License-Identifier: Apache-2.0 package org.gradlex.maven.plugin.development.task; import org.gradle.api.file.FileCollection; @@ -56,4 +41,3 @@ public FileCollection getSourceDirectories() { return sourceDirectories; } } - diff --git a/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTest.java b/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTest.java new file mode 100644 index 00000000..51c0c799 --- /dev/null +++ b/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTest.java @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +package org.gradlex.maven.plugin.development.documentation; + +import org.gradle.exemplar.test.runner.SampleModifiers; +import org.gradle.exemplar.test.runner.SamplesRoot; +import org.gradle.exemplar.test.runner.SamplesRunner; +import org.junit.runner.RunWith; + +@RunWith(SamplesRunner.class) +@SamplesRoot("src/docs/snippets") +@SampleModifiers(DocumentationSnippetsTestModifier.class) +public class DocumentationSnippetsTest {} diff --git a/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTestModifier.java b/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTestModifier.java new file mode 100644 index 00000000..bdf5ff26 --- /dev/null +++ b/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/DocumentationSnippetsTestModifier.java @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 +package org.gradlex.maven.plugin.development.documentation; + +import java.io.File; +import org.gradle.exemplar.model.Command; +import org.gradle.exemplar.model.Sample; +import org.gradle.exemplar.test.runner.SampleModifier; + +public class DocumentationSnippetsTestModifier implements SampleModifier { + @Override + public Sample modify(Sample sampleIn) { + Command cmd = sampleIn.getCommands().remove(0); + sampleIn.getCommands().add(copyCommand(cmd, "groovy")); + sampleIn.getCommands().add(copyCommand(cmd, "kotlin")); + return sampleIn; + } + + private Command copyCommand(Command cmd, String executionSubdirectory) { + File pluginProjectDir = new File("."); + return new Command( + new File(pluginProjectDir, "gradlew").getAbsolutePath(), + executionSubdirectory, + cmd.getArgs(), + cmd.getFlags(), + cmd.getExpectedOutput(), + cmd.isExpectFailure(), + cmd.isAllowAdditionalOutput(), + cmd.isAllowDisorderedOutput(), + cmd.getUserInputs()); + } +} diff --git a/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/SamplesIntegrationTest.java b/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/SamplesIntegrationTest.java deleted file mode 100644 index dbebcc87..00000000 --- a/src/testSamples/java/org/gradlex/maven/plugin/development/documentation/SamplesIntegrationTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright the GradleX team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gradlex.maven.plugin.development.documentation; - -import org.gradle.exemplar.test.runner.GradleSamplesRunner; -import org.gradle.exemplar.test.runner.SamplesRoot; -import org.junit.runner.RunWith; - -@RunWith(GradleSamplesRunner.class) -@SamplesRoot("src/docs/snippets") -class DocumentationSnippetsTest { -}