diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml new file mode 100644 index 0000000..01f2615 --- /dev/null +++ b/.github/workflows/dependency-submission.yml @@ -0,0 +1,19 @@ +name: Dependency Submission + +on: [ push ] + +permissions: + contents: write + +jobs: + dependency-submission: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v5 + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@v5 + with: + build-scan-publish: true + build-scan-terms-of-use-url: "https://gradle.com/terms-of-service" + build-scan-terms-of-use-agree: "yes" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0250b1d..5e1b80c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,9 +13,9 @@ jobs: distribution: temurin java-version: 17.0.16 - uses: gradle/actions/setup-gradle@v5 - - run: "./gradlew publishAggregationToCentralPortal -Psign=true" + - run: "./gradlew publishAggregationToCentralPortal" env: SIGNING_KEY: ${{ secrets.SIGNING_KEY }} SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} - MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} - MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index 61683ca..7a744c8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,5 @@ -plugins { - val nmcpVersion = "1.2.0" - val mavenPluginDevVersion = "1.0.3" +plugins { id("org.gradlex.maven-plugin-development") version "1.0.3" } - id("com.gradleup.nmcp") version nmcpVersion - id("com.gradleup.nmcp.aggregation") version nmcpVersion - id("org.gradlex.maven-plugin-development") version mavenPluginDevVersion - id("maven-publish") - id("signing") - id("checkstyle") -} - -group = "org.gradlex" version = "1.2" val mvnVersion = "3.9.11" @@ -21,98 +10,28 @@ dependencies { compileOnly("org.apache.maven:maven-core:$mvnVersion") compileOnly("org.apache.maven:maven-plugin-api:$mvnVersion") compileOnly("org.apache.maven.plugin-tools:maven-plugin-annotations:3.15.2") - - nmcpAggregation(project(path)) } -mavenPlugin { - name = "Gradle Module Metadata Maven Plugin" - description = "A Maven plugin to publish Gradle Module Metadata" - helpMojoPackage = "org.gradlex.maven.gmm" -} - -java { - toolchain.languageVersion = JavaLanguageVersion.of(17) - withSourcesJar() - withJavadocJar() -} - -tasks.compileJava { - options.release = 8 - options.compilerArgs.add("-Werror") +configurations.api { + withDependencies { clear() } // remove gradleApi() dependency } tasks.javadoc { options { this as StandardJavadocDocletOptions - addStringOption("Xdoclint:all,-missing", "-Xwerror") - tags( - "goal:a:Goal:", - "requiresProject:a:Requires Project:", - "threadSafe:a:Thread Safe:" - ) - } -} - -@Suppress("UnstableApiUsage") -testing.suites.named("test") { - useJUnitJupiter() - dependencies { - implementation(gradleTestKit()) - implementation("org.assertj:assertj-core:3.27.6") - } -} - -publishing { - publications.register("mavenPlugin") { - from(components["java"]) - pom { - name = mavenPlugin.name - description = mavenPlugin.description - url = "https://github.com/gradlex-org/gradle-module-metadata-maven-plugin" - licenses { - license { - name = "Apache License, Version 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" - } - } - scm { - connection = "scm:git:git://github.com/gradlex-org/gradle-module-metadata-maven-plugin.git" - developerConnection = "scm:git:git://github.com/gradlex-org/gradle-module-metadata-maven-plugin.git" - url = "https://github.com/gradlex-org/gradle-module-metadata-maven-plugin" - } - developers { - developer { - name = "Jendrik Johannes" - email = "jendrik@gradlex.org" - } - } - } + tags("goal:a:Goal:", "requiresProject:a:Requires Project:", "threadSafe:a:Thread Safe:") } } -signing { - if (providers.gradleProperty("sign").getOrElse("false").toBoolean()) { - useInMemoryPgpKeys( - providers.environmentVariable("SIGNING_KEY").getOrNull(), - providers.environmentVariable("SIGNING_PASSPHRASE").getOrNull() - ) - sign(publishing.publications["mavenPlugin"]) - } +mavenPlugin { + name = "Gradle Module Metadata Maven Plugin" + description = "A Maven plugin to publish Gradle Module Metadata" + helpMojoPackage = "org.gradlex.maven.gmm" } -nmcpAggregation { - centralPortal { - username = providers.environmentVariable("MAVEN_CENTRAL_USERNAME") - password = providers.environmentVariable("MAVEN_CENTRAL_PASSWORD") - publishingType = "AUTOMATIC" // "USER_MANAGED" +publishingConventions { + mavenCentral { + displayName = mavenPlugin.name + description = mavenPlugin.description } } - -checkstyle { - configDirectory = layout.projectDirectory.dir("gradle/checkstyle") -} - -tasks.checkstyleMain { - exclude("**/HelpMojo.java") -} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..6f78d3f --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.caching=true +org.gradle.configuration-cache=true diff --git a/gradle/checkstyle/checkstyle.xml b/gradle/checkstyle/checkstyle.xml deleted file mode 100644 index e7521b0..0000000 --- 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 4fe8a00..0000000 --- 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/settings.gradle.kts b/settings.gradle.kts index 1ac977a..60f9b23 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,22 +1,3 @@ -plugins { - id("com.gradle.develocity") version "4.2.2" -} +plugins { id("org.gradlex.internal-build-conventions") version "0.8" } rootProject.name = "gradle-module-metadata-maven-plugin" - -@Suppress("UnstableApiUsage") -dependencyResolutionManagement { - repositories.mavenCentral() -} - -develocity { - buildScan { - val isCi = providers.environmentVariable("CI").getOrElse("false").toBoolean() - if (isCi) { - termsOfUseUrl = "https://gradle.com/help/legal-terms-of-use" - termsOfUseAgree = "yes" - } else { - publishing.onlyIf { false } - } - } -} diff --git a/src/main/java/org/gradlex/maven/gmm/Capability.java b/src/main/java/org/gradlex/maven/gmm/Capability.java index ec41a60..37dc29d 100644 --- a/src/main/java/org/gradlex/maven/gmm/Capability.java +++ b/src/main/java/org/gradlex/maven/gmm/Capability.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.gmm; /** diff --git a/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataMojo.java b/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataMojo.java index 0450226..3cd9996 100644 --- a/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataMojo.java +++ b/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataMojo.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.gmm; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.util.List; +import javax.inject.Inject; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -25,13 +16,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; -import javax.inject.Inject; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.util.List; - /** * Goal that generates Gradle Module Metadata. */ @@ -99,7 +83,8 @@ private void addMarkerToPomIfNotPresent() { try { String pomContent = new String(Files.readAllBytes(pomFile.toPath())); if (!pomContent.contains(marker)) { - String newContent = pomContent.replaceFirst("", " "); + String newContent = + pomContent.replaceFirst("", " "); Files.write(pomFile.toPath(), newContent.getBytes()); } } catch (IOException e) { diff --git a/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataWriter.java b/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataWriter.java index bba2838..a5e0caa 100644 --- a/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataWriter.java +++ b/src/main/java/org/gradlex/maven/gmm/GradleModuleMetadataWriter.java @@ -1,28 +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.gmm; import com.google.gson.stream.JsonWriter; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Exclusion; -import org.apache.maven.project.MavenProject; -import org.gradlex.maven.gmm.checksums.HashUtil; - import java.io.File; import java.io.IOException; import java.io.Writer; @@ -32,6 +11,11 @@ import java.util.Map; import java.util.Optional; import java.util.TreeMap; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Exclusion; +import org.apache.maven.project.MavenProject; +import org.gradlex.maven.gmm.checksums.HashUtil; /** * The Gradle module metadata file generator is responsible for generating a JSON file describing module metadata. @@ -42,18 +26,25 @@ public class GradleModuleMetadataWriter { private enum Variant { API_ELEMENTS("apiElements", "java-api", "library", "jar", null, Collections.singletonList("compile")), - RUNTIME_ELEMENTS("runtimeElements", "java-runtime", "library", "jar", null, Arrays.asList("compile", "runtime")), + RUNTIME_ELEMENTS( + "runtimeElements", "java-runtime", "library", "jar", null, Arrays.asList("compile", "runtime")), JAVADOC_ELEMENTS("javadocElements", "java-runtime", "documentation", null, "javadoc", Collections.emptyList()), SOURCES_ELEMENTS("sourcesElements", "java-runtime", "documentation", null, "sources", Collections.emptyList()); private final String name; private final String usage; private final String category; - private final String libraryelements; //nullable + private final String libraryelements; // nullable private final String docstype; // nullable private final List scopes; - Variant(String name, String usage, String category, String libraryelements, String docstype, List scopes) { + Variant( + String name, + String usage, + String category, + String libraryelements, + String docstype, + List scopes) { this.name = name; this.usage = usage; this.category = category; @@ -63,15 +54,24 @@ private enum Variant { } } - public static void generateTo(MavenProject project, - List platformDependencies, List capabilities, - List removedDependencies, - List compileOnlyApiDependencies, - Writer writer) throws IOException { + public static void generateTo( + MavenProject project, + List platformDependencies, + List capabilities, + List removedDependencies, + List compileOnlyApiDependencies, + Writer writer) + throws IOException { JsonWriter jsonWriter = new JsonWriter(writer); jsonWriter.setHtmlSafe(false); jsonWriter.setIndent(" "); - writeComponentWithVariants(project, platformDependencies, capabilities, removedDependencies, compileOnlyApiDependencies, jsonWriter); + writeComponentWithVariants( + project, + platformDependencies, + capabilities, + removedDependencies, + compileOnlyApiDependencies, + jsonWriter); jsonWriter.flush(); writer.append('\n'); } @@ -103,16 +103,24 @@ private static Map variantAttributes(Variant variant) { return attributes; } - private static void writeComponentWithVariants(MavenProject project, - List platformDependencies, - List capabilities, - List removedDependencies, - List compileOnlyApiDependencies, - JsonWriter jsonWriter) throws IOException { + private static void writeComponentWithVariants( + MavenProject project, + List platformDependencies, + List capabilities, + List removedDependencies, + List compileOnlyApiDependencies, + JsonWriter jsonWriter) + throws IOException { jsonWriter.beginObject(); writeFormat(jsonWriter); writeIdentity(project, jsonWriter); - writeVariants(project, platformDependencies, capabilities, removedDependencies, compileOnlyApiDependencies, jsonWriter); + writeVariants( + project, + platformDependencies, + capabilities, + removedDependencies, + compileOnlyApiDependencies, + jsonWriter); jsonWriter.endObject(); } @@ -131,21 +139,42 @@ private static void writeIdentity(MavenProject project, JsonWriter jsonWriter) t jsonWriter.endObject(); } - - private static void writeVariants(MavenProject project, - List platformDependencies, - List capabilities, - List removedDependencies, - List compileOnlyApiDependencies, - JsonWriter jsonWriter) throws IOException { - - Optional javadocJar = project.getAttachedArtifacts().stream().filter(jar -> "javadoc".equals(jar.getClassifier())).findFirst(); - Optional sourcesJar = project.getAttachedArtifacts().stream().filter(jar -> "sources".equals(jar.getClassifier())).findFirst(); + private static void writeVariants( + MavenProject project, + List platformDependencies, + List capabilities, + List removedDependencies, + List compileOnlyApiDependencies, + JsonWriter jsonWriter) + throws IOException { + + Optional javadocJar = project.getAttachedArtifacts().stream() + .filter(jar -> "javadoc".equals(jar.getClassifier())) + .findFirst(); + Optional sourcesJar = project.getAttachedArtifacts().stream() + .filter(jar -> "sources".equals(jar.getClassifier())) + .findFirst(); jsonWriter.name("variants"); jsonWriter.beginArray(); - writeVariant(project, Variant.API_ELEMENTS, platformDependencies, capabilities, removedDependencies, compileOnlyApiDependencies, project.getArtifact(), jsonWriter); - writeVariant(project, Variant.RUNTIME_ELEMENTS, platformDependencies, capabilities, removedDependencies, null, project.getArtifact(), jsonWriter); + writeVariant( + project, + Variant.API_ELEMENTS, + platformDependencies, + capabilities, + removedDependencies, + compileOnlyApiDependencies, + project.getArtifact(), + jsonWriter); + writeVariant( + project, + Variant.RUNTIME_ELEMENTS, + platformDependencies, + capabilities, + removedDependencies, + null, + project.getArtifact(), + jsonWriter); if (javadocJar.isPresent()) { writeVariant(project, Variant.JAVADOC_ELEMENTS, null, null, null, null, javadocJar.get(), jsonWriter); } @@ -160,17 +189,27 @@ private static void writeFormat(JsonWriter jsonWriter) throws IOException { jsonWriter.value(FORMAT_VERSION); } - private static void writeVariant(MavenProject project, Variant variant, - List platformDependencies, - List capabilities, - List removedDependencies, - List addedDependencies, - Artifact artifact, JsonWriter jsonWriter) throws IOException { + private static void writeVariant( + MavenProject project, + Variant variant, + List platformDependencies, + List capabilities, + List removedDependencies, + List addedDependencies, + Artifact artifact, + JsonWriter jsonWriter) + throws IOException { jsonWriter.beginObject(); jsonWriter.name("name"); jsonWriter.value(variant.name); writeAttributes(variantAttributes(variant), jsonWriter); - writeDependencies(variant, project.getDependencies(), platformDependencies, removedDependencies, addedDependencies, jsonWriter); + writeDependencies( + variant, + project.getDependencies(), + platformDependencies, + removedDependencies, + addedDependencies, + jsonWriter); writeArtifacts(artifact, jsonWriter); writeCapabilities(project, capabilities, jsonWriter); @@ -245,12 +284,14 @@ private static void writeChecksums(File artifact, JsonWriter jsonWriter) throws jsonWriter.value(HashUtil.md5(artifact).asHexString()); } - private static void writeDependencies(Variant variant, - List dependencies, - List platformDependencies, - List removedDependencies, - List addedDependencies, - JsonWriter jsonWriter) throws IOException { + private static void writeDependencies( + Variant variant, + List dependencies, + List platformDependencies, + List removedDependencies, + List addedDependencies, + JsonWriter jsonWriter) + throws IOException { if (dependencies.isEmpty() && isNullOrEmpty(platformDependencies) && isNullOrEmpty(addedDependencies)) { return; } @@ -265,8 +306,10 @@ private static void writeDependencies(Variant variant, // Dependency is not in scope continue; } - if (removedDependencies != null && removedDependencies.stream().anyMatch(removed -> - dependency.getGroupId().equals(removed.getGroupId()) && dependency.getArtifactId().equals(removed.getArtifactId()))) { + if (removedDependencies != null + && removedDependencies.stream() + .anyMatch(removed -> dependency.getGroupId().equals(removed.getGroupId()) + && dependency.getArtifactId().equals(removed.getArtifactId()))) { // Dependency is explicitly removed (e.g. because the shade plugin removes it from the POM as well) continue; } @@ -289,8 +332,8 @@ private static void writeDependencies(Variant variant, jsonWriter.endArray(); } - private static void writeDependency(Dependency dependency, boolean toPlatform, - JsonWriter jsonWriter) throws IOException { + private static void writeDependency(Dependency dependency, boolean toPlatform, JsonWriter jsonWriter) + throws IOException { jsonWriter.beginObject(); jsonWriter.name("group"); jsonWriter.value(dependency.getGroupId()); @@ -356,8 +399,8 @@ private static void writeExcludes(List excludes, JsonWriter jsonWrite jsonWriter.endArray(); } - private static void writeCapabilities(MavenProject project, List capabilities, - JsonWriter jsonWriter) throws IOException { + private static void writeCapabilities(MavenProject project, List capabilities, JsonWriter jsonWriter) + throws IOException { if (capabilities != null && !capabilities.isEmpty()) { jsonWriter.name("capabilities"); jsonWriter.beginArray(); diff --git a/src/main/java/org/gradlex/maven/gmm/checksums/HashUtil.java b/src/main/java/org/gradlex/maven/gmm/checksums/HashUtil.java index f70052b..5230972 100644 --- a/src/main/java/org/gradlex/maven/gmm/checksums/HashUtil.java +++ b/src/main/java/org/gradlex/maven/gmm/checksums/HashUtil.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.gmm.checksums; import java.io.File; diff --git a/src/main/java/org/gradlex/maven/gmm/checksums/HashValue.java b/src/main/java/org/gradlex/maven/gmm/checksums/HashValue.java index de1b290..94b643a 100644 --- a/src/main/java/org/gradlex/maven/gmm/checksums/HashValue.java +++ b/src/main/java/org/gradlex/maven/gmm/checksums/HashValue.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.gmm.checksums; import java.util.Arrays; diff --git a/src/test/java/org/gradlex/maven/gmm/test/GMMMavenPluginTest.java b/src/test/java/org/gradlex/maven/gmm/test/GMMMavenPluginTest.java index 15823bc..f0d3623 100644 --- a/src/test/java/org/gradlex/maven/gmm/test/GMMMavenPluginTest.java +++ b/src/test/java/org/gradlex/maven/gmm/test/GMMMavenPluginTest.java @@ -1,30 +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.gmm.test; +import static java.nio.file.Files.createDirectories; +import static java.nio.file.Files.writeString; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import org.gradle.testkit.runner.BuildResult; -import org.gradle.testkit.runner.GradleRunner; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -34,10 +16,12 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; - -import static java.nio.file.Files.createDirectories; -import static java.nio.file.Files.writeString; -import static org.assertj.core.api.Assertions.assertThat; +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; class GMMMavenPluginTest { @@ -66,7 +50,9 @@ void setup() throws IOException { void producerGMMPluginConfiguration(String pluginConfiguration, String packaging) { try { - writeString(mavenProducerBuild.toPath(), """ + writeString( + mavenProducerBuild.toPath(), + """ 4.0.0 org.gradlex @@ -74,7 +60,7 @@ void producerGMMPluginConfiguration(String pluginConfiguration, String packaging 1.0 $packaging Test GMM - + commons-io @@ -82,7 +68,7 @@ void producerGMMPluginConfiguration(String pluginConfiguration, String packaging 2.6 - + @@ -100,7 +86,9 @@ void producerGMMPluginConfiguration(String pluginConfiguration, String packaging - """.replace("$pluginConfiguration", pluginConfiguration).replace("$packaging", packaging)); + """ + .replace("$pluginConfiguration", pluginConfiguration) + .replace("$packaging", packaging)); } catch (IOException e) { throw new RuntimeException(e); } @@ -109,7 +97,9 @@ void producerGMMPluginConfiguration(String pluginConfiguration, String packaging void consumerDependencies(String dependencyDeclarations) { try { - writeString(gradleConsumerBuild.toPath(), """ + writeString( + gradleConsumerBuild.toPath(), + """ plugins { id 'java-library' } @@ -125,7 +115,8 @@ void consumerDependencies(String dependencyDeclarations) { configurations.compileClasspath.files.forEach { println(it.name) } } } - """.replace("$dependencyDeclarations", dependencyDeclarations)); + """ + .replace("$dependencyDeclarations", dependencyDeclarations)); } catch (IOException e) { throw new RuntimeException(e); } @@ -134,13 +125,15 @@ void consumerDependencies(String dependencyDeclarations) { @Test void marker_comment_is_added_to_pom() { producerGMMPluginConfiguration("", "jar"); - assertThat(mavenProducerBuild).content().contains( - "4.0.0 "); + assertThat(mavenProducerBuild) + .content() + .contains("4.0.0 "); } @Test void capabilities_are_available() { - producerGMMPluginConfiguration(""" + producerGMMPluginConfiguration( + """ @@ -154,9 +147,11 @@ void capabilities_are_available() { - """, "jar"); + """, + "jar"); - consumerDependencies(""" + consumerDependencies( + """ implementation("org.gradlex:gradle-module-metadata-maven-plugin-integration-test:1.0") { capabilities { requireCapability("org.foo:another") @@ -165,13 +160,14 @@ void capabilities_are_available() { """); moduleJsonGenerated(); - assertThat(resolve()).containsExactly( - "gradle-module-metadata-maven-plugin-integration-test-1.0.jar", "commons-io-2.6.jar"); + assertThat(resolve()) + .containsExactly("gradle-module-metadata-maven-plugin-integration-test-1.0.jar", "commons-io-2.6.jar"); } @Test void platform_dependencies_are_available() { - producerGMMPluginConfiguration(""" + producerGMMPluginConfiguration( + """ @@ -181,18 +177,21 @@ void platform_dependencies_are_available() { - """, "jar"); + """, + "jar"); - consumerDependencies(""" + consumerDependencies( + """ implementation("org.gradlex:gradle-module-metadata-maven-plugin-integration-test:1.0") implementation("com.fasterxml.jackson.core:jackson-core") """); moduleJsonGenerated(); - assertThat(resolve()).containsExactly( - "gradle-module-metadata-maven-plugin-integration-test-1.0.jar", - "jackson-core-2.10.2.jar", - "commons-io-2.6.jar"); + assertThat(resolve()) + .containsExactly( + "gradle-module-metadata-maven-plugin-integration-test-1.0.jar", + "jackson-core-2.10.2.jar", + "commons-io-2.6.jar"); } @Test @@ -266,17 +265,18 @@ List resolve() { BuildResult buildResult = GradleRunner.create() .forwardOutput() .withProjectDir(gradleConsumerBuild.getParentFile()) - .withArguments("resolve", "-q").build(); + .withArguments("resolve", "-q") + .build(); return Arrays.asList(buildResult.getOutput().trim().split("\n")); } private static void installPluginLocally() { exec("./gradlew publishToMavenLocal", null); - } private void installProducerLocally() { - exec("mvn clean install -DskipTests -Dgpg.skip --no-transfer-progress --batch-mode", + exec( + "mvn clean install -DskipTests -Dgpg.skip --no-transfer-progress --batch-mode", mavenProducerBuild.getParentFile()); } @@ -285,11 +285,13 @@ private void packageProducer() { } private void moduleJsonGenerated() { - assertThat(new File(mavenProducerBuild.getParentFile(), "target/publications/maven/module.json")).exists(); + assertThat(new File(mavenProducerBuild.getParentFile(), "target/publications/maven/module.json")) + .exists(); } private void moduleJsonNotGenerated() { - assertThat(new File(mavenProducerBuild.getParentFile(), "target/publications/maven/module.json")).doesNotExist(); + assertThat(new File(mavenProducerBuild.getParentFile(), "target/publications/maven/module.json")) + .doesNotExist(); } private void assertExpectedGMM(String name) { @@ -307,7 +309,8 @@ private void assertExpectedGMM(String name) { Files.copy(testPomParent.toPath(), mavenProducerParent.toPath()); } if (javaClass.exists()) { - Path target = mavenProducerBuild.getParentFile().toPath().resolve("src/main/java/org/example/Dummy.java"); + Path target = + mavenProducerBuild.getParentFile().toPath().resolve("src/main/java/org/example/Dummy.java"); Files.createDirectories(target.getParent()); Files.copy(javaClass.toPath(), target); } diff --git a/src/test/java/org/gradlex/maven/gmm/test/HashUtilTest.java b/src/test/java/org/gradlex/maven/gmm/test/HashUtilTest.java index d79b920..fa6542f 100644 --- a/src/test/java/org/gradlex/maven/gmm/test/HashUtilTest.java +++ b/src/test/java/org/gradlex/maven/gmm/test/HashUtilTest.java @@ -1,30 +1,14 @@ -/* - * 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.gmm.test; -import org.gradlex.maven.gmm.checksums.HashUtil; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; import java.nio.file.Files; - -import static org.assertj.core.api.Assertions.assertThat; +import org.gradlex.maven.gmm.checksums.HashUtil; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; class HashUtilTest { @@ -49,5 +33,4 @@ void checksums_have_expected_length() throws IOException { assertThat(HashUtil.sha512(example).asHexString().length()).isEqualTo(128); assertThat(HashUtil.md5(example).asHexString().length()).isEqualTo(32); } - }