From 382bd1d6dfc91d5d66a32503a947757b60ac57dc Mon Sep 17 00:00:00 2001 From: Stewart Francis Date: Wed, 20 Sep 2023 10:15:01 +0100 Subject: [PATCH] Use project.build.finalName to derive artifact name Signed-off-by: Stewart Francis Update pom.xml Update TestEndpoint.java Update PostBuildTestBundleWarFinalName.java --- cics-bundle-maven-plugin/pom.xml | 1 + .../src/it/test-bundle-war-final-name/pom.xml | 74 +++++++++++++++++++ .../test-bundle-war-final-name/postbuild.bsh | 1 + .../src/main/java/test_war/TestEndpoint.java | 39 ++++++++++ .../ibm/cics/cbmp/AbstractBundleJavaMojo.java | 10 ++- .../ibm/cics/cbmp/PackageCICSBundleMojo.java | 11 ++- .../cbmp/PostBuildTestBundleWarFinalName.java | 56 ++++++++++++++ 7 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/pom.xml create mode 100644 cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/postbuild.bsh create mode 100644 cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/src/main/java/test_war/TestEndpoint.java create mode 100644 cics-bundle-maven-plugin/src/test/java/com/ibm/cics/cbmp/PostBuildTestBundleWarFinalName.java diff --git a/cics-bundle-maven-plugin/pom.xml b/cics-bundle-maven-plugin/pom.xml index 24c26511..7cf139b5 100644 --- a/cics-bundle-maven-plugin/pom.xml +++ b/cics-bundle-maven-plugin/pom.xml @@ -190,6 +190,7 @@ true install true + test-bundle-war-final-name/pom.xml ${wiremockPort} diff --git a/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/pom.xml b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/pom.xml new file mode 100644 index 00000000..0f639a14 --- /dev/null +++ b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + com.ibm.cics.test-bundle-war + test-bundle-war + 0.0.1-SNAPSHOT + war + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + provided + + + + + + ${project.artifactId} + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + pom.xml + test-war + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + bundle-war + + + EYUCMCIJ + + + + + + + + diff --git a/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/postbuild.bsh b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/postbuild.bsh new file mode 100644 index 00000000..d580e573 --- /dev/null +++ b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/postbuild.bsh @@ -0,0 +1 @@ +com.ibm.cics.cbmp.PostBuildTestBundleWarFinalName.assertOutput(basedir); diff --git a/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/src/main/java/test_war/TestEndpoint.java b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/src/main/java/test_war/TestEndpoint.java new file mode 100644 index 00000000..4632f97b --- /dev/null +++ b/cics-bundle-maven-plugin/src/it/test-bundle-war-final-name/src/main/java/test_war/TestEndpoint.java @@ -0,0 +1,39 @@ +package test_war; + +/*- + * #%L + * CICS Bundle Maven Plugin + * %% + * Copyright (C) 2024 IBM Corp. + * %% + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * #L% + */ + +import java.util.Optional; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@ApplicationPath("") +@Path("") +public class TestEndpoint extends javax.ws.rs.core.Application { + + public TestEndpoint() { + } + + @GET + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response get() { + return Response.ok().build(); + } + +} diff --git a/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/AbstractBundleJavaMojo.java b/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/AbstractBundleJavaMojo.java index ff59d835..80793d1d 100644 --- a/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/AbstractBundleJavaMojo.java +++ b/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/AbstractBundleJavaMojo.java @@ -31,9 +31,6 @@ public abstract class AbstractBundleJavaMojo extends AbstractBundlePublisherMojo implements DefaultsProvider { - @Parameter(defaultValue = "${project.build.directory}/${project.artifactId}-${project.version}-cics-bundle.zip", required = true, readonly = true) - private File cicsBundleArchive; - /** * The CICS JVM server that the Java code will execute in. */ @@ -52,6 +49,12 @@ public abstract class AbstractBundleJavaMojo extends AbstractBundlePublisherMojo @Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true) private File buildDir; + /** + * The base name to use for the generated bundle archive. + */ + @Parameter(property="project.build.finalName", required = true, readonly = true) + private String finalName; + @Component private MavenProjectHelper projectHelper; @@ -97,6 +100,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { bundlePublisher, classifier, project, + finalName, projectHelper ); } diff --git a/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/PackageCICSBundleMojo.java b/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/PackageCICSBundleMojo.java index 48747964..bf68f4e2 100644 --- a/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/PackageCICSBundleMojo.java +++ b/cics-bundle-maven-plugin/src/main/java/com/ibm/cics/cbmp/PackageCICSBundleMojo.java @@ -46,6 +46,12 @@ public class PackageCICSBundleMojo extends AbstractAutoConfigureBundlePublisherM */ @Parameter(property="cicsbundle.classifier", required = false, readonly = false) private String classifier; + + /** + * The base name to use for the generated bundle archive. + */ + @Parameter(property="project.build.finalName", required = true, readonly = true) + private String finalName; @Component private MavenProjectHelper projectHelper; @@ -62,6 +68,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { bundlePublisher, classifier, project, + finalName, projectHelper ); @@ -75,13 +82,15 @@ static File createCICSBundle( BundlePublisher bundlePublisher, String classifier, MavenProject project, + String finalName, MavenProjectHelper projectHelper) throws MojoExecutionException { try { bundlePublisher.publishDynamicResources(); ZipArchiver zipArchiver = new ZipArchiver(); zipArchiver.addDirectory(workDir); - File cicsBundle = new File(outputDir, project.getArtifactId() + "-" + project.getVersion() + (classifier != null ? "-" + classifier : "") + "." + CICS_BUNDLE_EXTENSION); + + File cicsBundle = new File(outputDir, finalName + (classifier != null ? "-" + classifier : "") + "." + CICS_BUNDLE_EXTENSION); zipArchiver.setDestFile(cicsBundle); zipArchiver.createArchive(); diff --git a/cics-bundle-maven-plugin/src/test/java/com/ibm/cics/cbmp/PostBuildTestBundleWarFinalName.java b/cics-bundle-maven-plugin/src/test/java/com/ibm/cics/cbmp/PostBuildTestBundleWarFinalName.java new file mode 100644 index 00000000..ee33ddb8 --- /dev/null +++ b/cics-bundle-maven-plugin/src/test/java/com/ibm/cics/cbmp/PostBuildTestBundleWarFinalName.java @@ -0,0 +1,56 @@ +package com.ibm.cics.cbmp; + +/*- + * #%L + * CICS Bundle Maven Plugin + * %% + * Copyright (C) 2024 IBM Corp. + * %% + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * #L% + */ + +import static com.ibm.cics.cbmp.BundleValidator.assertBundleContents; +import static com.ibm.cics.cbmp.BundleValidator.bfv; +import static com.ibm.cics.cbmp.BundleValidator.manifestValidator; + +import static org.junit.Assert.assertThat; + +import java.io.File; + +import org.xmlunit.matchers.CompareMatcher; + +public class PostBuildTestBundleWarFinalName { + + private static final String EXPECTED_MANIFEST = + "\n" + + "\n" + + " \n" + + " 2019-09-10T20:24:32.893Z\n" + + " \n" + + " \n" + + ""; + + private static final String EXPECTED_BUNDLE_PART = + "\n" + + ""; + + static void assertOutput(File root) throws Exception { + assertBundleContents( + root.toPath().resolve("target/test-bundle-war-cics-bundle.zip"), + manifestValidator(EXPECTED_MANIFEST), + bfv( + "/test-bundle-war-0.0.1-SNAPSHOT.warbundle", + is -> assertThat(is, CompareMatcher.isIdenticalTo(EXPECTED_BUNDLE_PART)) + ), + bfv( + "/test-bundle-war-0.0.1-SNAPSHOT.war", + is -> {} + ) + ); + } +}