From 2ccce67f3e874a0848a4f84b97b48aedcdaae70b Mon Sep 17 00:00:00 2001 From: Jan Luehe Date: Fri, 16 Aug 2024 22:37:19 +0200 Subject: [PATCH] [ISSUE 606] transformer-maven-plugin integration --- .../bnd/analyzer/BndAnalyzerPluginTest.java | 6 ++++++ .../transformer-maven-plugin/README.md | 3 ++- .../maven/AbstractTransformerMojo.java | 2 +- .../maven/TransformerMojoOptions.java | 3 +++ .../maven/configuration/TransformerRules.java | 19 +++++++++++++++++-- .../transformer/test/TestCommandLine.java | 16 ++++++---------- .../action/impl/ZipActionImpl.java | 4 ---- .../transformer/test/TestTransformClass.java | 10 +++++----- .../test/TestTransformServiceConfig.java | 2 +- 9 files changed, 41 insertions(+), 24 deletions(-) diff --git a/bnd-plugins/org.eclipse.transformer.bnd.analyzer/src/test/java/org/eclipse/transformer/bnd/analyzer/BndAnalyzerPluginTest.java b/bnd-plugins/org.eclipse.transformer.bnd.analyzer/src/test/java/org/eclipse/transformer/bnd/analyzer/BndAnalyzerPluginTest.java index 059af680..04e4ca54 100644 --- a/bnd-plugins/org.eclipse.transformer.bnd.analyzer/src/test/java/org/eclipse/transformer/bnd/analyzer/BndAnalyzerPluginTest.java +++ b/bnd-plugins/org.eclipse.transformer.bnd.analyzer/src/test/java/org/eclipse/transformer/bnd/analyzer/BndAnalyzerPluginTest.java @@ -230,6 +230,7 @@ void options_test() throws Exception { try (Processor processor = new Processor()) { processor.setProperty("-transformer", "tb;arg=value1"); processor.setProperty("-transformer.overwrite", "overwrite"); + processor.setProperty("-transformer.stripSignatures", "strip-signatures"); processor.setProperty("-transformer.morebundles", "bundles;arg=value2"); processor.setProperty("-transformer.immediate", "immediate;option=tv;package=org.eclipse.transformer.test.api;version=\"[2.0\\,3.0);Export-Package=2.0.0\""); @@ -253,6 +254,11 @@ void options_test() throws Exception { assertThat(options.getOptionValues(AppOption.WIDEN_ARCHIVE_NESTING)).isNull(); assertThat(options.getOptionValue(AppOption.WIDEN_ARCHIVE_NESTING)).isNull(); + assertThat(options.getDefaultValue(AppOption.STRIP_SIGNATURES)).isNull(); + assertThat(options.hasOption(AppOption.STRIP_SIGNATURES)).isTrue(); + assertThat(options.getOptionValues(AppOption.STRIP_SIGNATURES)).isEmpty(); + assertThat(options.getOptionValue(AppOption.STRIP_SIGNATURES)).isNull(); + assertThat(options.getOptionValues(AppOption.RULES_IMMEDIATE_DATA)).containsExactly("tv", "org.eclipse.transformer.test.api", "[2.0\\,3.0);Export-Package=2.0.0"); } diff --git a/maven-plugins/transformer-maven-plugin/README.md b/maven-plugins/transformer-maven-plugin/README.md index 2138fd57..9178d0cd 100644 --- a/maven-plugins/transformer-maven-plugin/README.md +++ b/maven-plugins/transformer-maven-plugin/README.md @@ -51,8 +51,9 @@ A list value of `-` (Hyphen-minus) is ignored. This can be used to configure an |`immediates` | A list of immediate options. | |`invert` | If `true`, invert the rename rules. _Defaults to `false`_. | |`overwrite` | If `true`, the items which transform to the same path as an existing item overwrite the existing item. _Defaults to `false`_. | -|`widen` | If `true`, By default, archive nesting is restricted to JavaEE active locations. This may be relaxed to enable JAR and ZIP within JAR, ZIP within ZIP, and ZIP within EAR, WAR, and RAR. _Defaults to `false`_. | +|`widen` | If `true`, by default, archive nesting is restricted to JavaEE active locations. This may be relaxed to enable JAR and ZIP within JAR, ZIP within ZIP, and ZIP within EAR, WAR, and RAR. _Defaults to `false`_. | |`jakartaDefaults` | If `true`, the Jakarta rule defaults are included. _Defaults to `false`_. | +|`strip-signatures` | If `true`, signature files will be removed from signed JAR files. _Defaults to `false`_. | ```xml diff --git a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/AbstractTransformerMojo.java b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/AbstractTransformerMojo.java index cf5c2029..63bb3fee 100644 --- a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/AbstractTransformerMojo.java +++ b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/AbstractTransformerMojo.java @@ -58,7 +58,7 @@ public abstract class AbstractTransformerMojo extends AbstractMojo { *

* The rules configuration includes: selections, renames, versions, bundles, * directs, texts, perClassConstants, immediates, invert, overwrite, widen, - * and jakartaDefaults. + * jakartaDefaults, and stripSignatures. */ @Parameter private TransformerRules rules = new TransformerRules(); diff --git a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/TransformerMojoOptions.java b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/TransformerMojoOptions.java index 2dc5fb5b..ee09d92b 100644 --- a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/TransformerMojoOptions.java +++ b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/TransformerMojoOptions.java @@ -109,6 +109,9 @@ public boolean hasOption(AppOption option) { case WIDEN_ARCHIVE_NESTING : has = rules.isWiden(); break; + case STRIP_SIGNATURES : + has = rules.isStripSignatures(); + break; default : has = TransformOptions.super.hasOption(option); break; diff --git a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/configuration/TransformerRules.java b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/configuration/TransformerRules.java index f4cc6bab..6a60df69 100644 --- a/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/configuration/TransformerRules.java +++ b/maven-plugins/transformer-maven-plugin/src/main/java/org/eclipse/transformer/maven/configuration/TransformerRules.java @@ -29,6 +29,7 @@ public class TransformerRules { private boolean overwrite; private boolean widen; private boolean jakartaDefaults; + private boolean stripSignatures; public TransformerRules() {} @@ -134,12 +135,26 @@ public void setWiden(boolean widen) { this.widen = widen; } + /** + * @return the stripSignatures + */ + public boolean isStripSignatures() { + return stripSignatures; + } + + /** + * @param stripSignatures the stripSignatures to set + */ + public void setStripSignatures(boolean stripSignatures) { + this.stripSignatures = stripSignatures; + } + @Override public String toString() { return String.format( - "selections=%s, renames=%s, versions=%s, bundles=%s, directs=%s, texts=%s, perClassConstants=%s, immediates=%s, invert=%s, overwrite=%s, widen=%s, jakartaDefaults=%s", + "selections=%s, renames=%s, versions=%s, bundles=%s, directs=%s, texts=%s, perClassConstants=%s, immediates=%s, invert=%s, overwrite=%s, widen=%s, jakartaDefaults=%s, stripSignatures=%s", getSelections(), getRenames(), getVersions(), getBundles(), getDirects(), getTexts(), - getPerClassConstants(), getImmediates(), isInvert(), isOverwrite(), isWiden(), isJakartaDefaults()); + getPerClassConstants(), getImmediates(), isInvert(), isOverwrite(), isWiden(), isJakartaDefaults(), isStripSignatures()); } } diff --git a/org.eclipse.transformer.cli/src/test/java/transformer/test/TestCommandLine.java b/org.eclipse.transformer.cli/src/test/java/transformer/test/TestCommandLine.java index 244975d8..69537555 100644 --- a/org.eclipse.transformer.cli/src/test/java/transformer/test/TestCommandLine.java +++ b/org.eclipse.transformer.cli/src/test/java/transformer/test/TestCommandLine.java @@ -83,14 +83,14 @@ public void tearDown() { void testManifestActionAccepted() throws Exception { String inputFileName = STATIC_CONTENT_DIR + "/command-line/MANIFEST.MF"; String outputFileName = DYNAMIC_CONTENT_DIR + "/MANIFEST.MF"; - verifyAction(ManifestActionImpl.class.getName(), inputFileName, outputFileName, outputFileName); + verifyAction(ManifestActionImpl.class.getName(), inputFileName, outputFileName, outputFileName, false); } @Test void testJavaActionAccepted() throws Exception { String inputFileName = STATIC_CONTENT_DIR + "/command-line/A.java"; String outputFileName = DYNAMIC_CONTENT_DIR + "/A.java"; - verifyAction(JavaActionImpl.class.getName(), inputFileName, outputFileName, outputFileName); + verifyAction(JavaActionImpl.class.getName(), inputFileName, outputFileName, outputFileName, false); } @Test @@ -117,7 +117,7 @@ void testInputFileNameOnlyAccepted() throws Exception { String inputFileName = inputFile.getCanonicalPath().replace(File.separatorChar, '/'); String expectedOutputFileName = new File(inputFile.getParentFile(), Transformer.OUTPUT_PREFIX + inputFile.getName()).getCanonicalPath() .replace(File.separatorChar, '/'); - verifyAction(JavaActionImpl.class.getName(), inputFileName, null, expectedOutputFileName); + verifyAction(JavaActionImpl.class.getName(), inputFileName, null, expectedOutputFileName, false); } @Test @@ -133,7 +133,7 @@ void testInvalidOutputDirectoryRejected() throws Exception { void zip_entry_creation() throws Exception { String inputFileName = STATIC_CONTENT_DIR + "/command-line/sac-1.3.jar"; String outputFileName = DYNAMIC_CONTENT_DIR + "/sac-1.3.jar"; - verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName); + verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName, false); } /* @@ -168,7 +168,7 @@ void testSignatureFilesPreservedByDefault() throws Exception { // Assert that signed input jar file contains 2 signature files: META-INF/MYKEY.SF and META-INF/MYKEY.DSA Map inputJarSigFilesMap = extractSignatureFileEntries(inputFileName); assertThat(inputJarSigFilesMap).containsOnlyKeys("META-INF/MYKEY.SF", "META-INF/MYKEY.DSA"); - verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName); + verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName, false); // Assert that signature files have been preserved in output jar file Map outputJarSigFilesMap = extractSignatureFileEntries(outputFileName); assertThat(outputJarSigFilesMap).containsOnlyKeys("META-INF/MYKEY.SF", "META-INF/MYKEY.DSA"); @@ -181,7 +181,7 @@ void testSignatureFilesPreservedByDefault() throws Exception { void zip_nested_stored_archive() throws Exception { String inputFileName = STATIC_CONTENT_DIR + "/command-line/nested_stored_archive.war"; String outputFileName = DYNAMIC_CONTENT_DIR + "/nested_stored_archive.war"; - verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName); + verifyAction(ZipActionImpl.class.getName(), inputFileName, outputFileName, outputFileName, false); } // Test zip with entry names encoded with a charset other than UTF-8. @@ -341,10 +341,6 @@ void testSetLogFile() throws Exception { } - private void verifyAction(String actionClassName, String inputFileName, String outputFileName, String expectedOutputFileName) throws Exception { - verifyAction(actionClassName, inputFileName, outputFileName, expectedOutputFileName, false); - } - private void verifyAction(String actionClassName, String inputFileName, String outputFileName, String expectedOutputFileName, boolean stripSignatures) throws Exception { verifyAction(actionClassName, inputFileName, outputFileName, expectedOutputFileName, 0, stripSignatures); diff --git a/org.eclipse.transformer/src/main/java/org/eclipse/transformer/action/impl/ZipActionImpl.java b/org.eclipse.transformer/src/main/java/org/eclipse/transformer/action/impl/ZipActionImpl.java index 6f9b7364..e90031e7 100644 --- a/org.eclipse.transformer/src/main/java/org/eclipse/transformer/action/impl/ZipActionImpl.java +++ b/org.eclipse.transformer/src/main/java/org/eclipse/transformer/action/impl/ZipActionImpl.java @@ -52,10 +52,6 @@ */ public class ZipActionImpl extends ContainerActionImpl implements ElementAction { - public ZipActionImpl(ActionContext context, ActionType actionType) { - this(context, actionType, false); - } - public ZipActionImpl(ActionContext context, ActionType actionType, boolean stripSignatures) { super(context); this.actionType = actionType; diff --git a/org.eclipse.transformer/src/test/java/transformer/test/TestTransformClass.java b/org.eclipse.transformer/src/test/java/transformer/test/TestTransformClass.java index 4a4800b4..e7aaae33 100644 --- a/org.eclipse.transformer/src/test/java/transformer/test/TestTransformClass.java +++ b/org.eclipse.transformer/src/test/java/transformer/test/TestTransformClass.java @@ -345,7 +345,7 @@ public ZipActionImpl getJavaxToJakartaJarAction() { createSelectionRule(useLogger, getIncludes(), getExcludes()), createSignatureRule(useLogger, getToJakartaRenames(), null, null, null, Collections.emptyMap())); - toJakartaJarAction = new ZipActionImpl(context, ActionType.JAR); + toJakartaJarAction = new ZipActionImpl(context, ActionType.JAR, false); } return toJakartaJarAction; @@ -363,7 +363,7 @@ public ZipActionImpl getJakartaToJavaxJarAction() { createSelectionRule(useLogger, getIncludes(), getExcludes()), createSignatureRule(useLogger, toJavaxRenames, null, null, null, Collections.emptyMap())); - toJavaxJarAction = new ZipActionImpl(context, ActionType.JAR); + toJavaxJarAction = new ZipActionImpl(context, ActionType.JAR, false); } return toJavaxJarAction; @@ -379,7 +379,7 @@ public ZipActionImpl getJavaxToJakartaJarAction_DirectOverride() { createSelectionRule(useLogger, getOverrideIncludes(), getExcludes()), createSignatureRule(useLogger, getToJakartaRenames(), null, null, toJakartaDirectStrings(), null)); - toJakartaJarAction_DirectOverride = new ZipActionImpl(context, ActionType.JAR); + toJakartaJarAction_DirectOverride = new ZipActionImpl(context, ActionType.JAR, false); } return toJakartaJarAction_DirectOverride; @@ -396,7 +396,7 @@ public ZipActionImpl getJavaxToJakartaJarAction_PerClassDirectOverride() { createSignatureRule(useLogger, getToJakartaRenames(), null, null, toJakartaDirectStrings(), toJakartaPerClassDirectStrings())); - toJakartaJarAction_PerClassDirectOverride = new ZipActionImpl(context, ActionType.JAR); + toJakartaJarAction_PerClassDirectOverride = new ZipActionImpl(context, ActionType.JAR, false); } return toJakartaJarAction_PerClassDirectOverride; @@ -412,7 +412,7 @@ public ZipActionImpl getJavaxToJakartaJarAction_PackageRenamesOnly() { createSelectionRule(useLogger, getOverrideIncludes(), getExcludes()), createSignatureRule(useLogger, getToJakartaRenames(), null, null, null, null)); - toJakartaJarAction_PackageRenamesOnly = new ZipActionImpl(context, ActionType.JAR); + toJakartaJarAction_PackageRenamesOnly = new ZipActionImpl(context, ActionType.JAR, false); } return toJakartaJarAction_PackageRenamesOnly; diff --git a/org.eclipse.transformer/src/test/java/transformer/test/TestTransformServiceConfig.java b/org.eclipse.transformer/src/test/java/transformer/test/TestTransformServiceConfig.java index 36047889..565e6d1d 100644 --- a/org.eclipse.transformer/src/test/java/transformer/test/TestTransformServiceConfig.java +++ b/org.eclipse.transformer/src/test/java/transformer/test/TestTransformServiceConfig.java @@ -193,7 +193,7 @@ public ZipActionImpl getJarJavaxServiceAction() { createSelectionRule(useLogger, Collections.emptyMap(), getExcludes()), createSignatureRule(useLogger, invertedRenames, null, null, null)); - jarJavaxServiceAction = new ZipActionImpl(context, ActionType.JAR); + jarJavaxServiceAction = new ZipActionImpl(context, ActionType.JAR, false); jarJavaxServiceAction.addUsing(PropertiesActionImpl::new); jarJavaxServiceAction.addUsing(ServiceLoaderConfigActionImpl::new); }