Skip to content

Commit

Permalink
[ISSUE 606] transformer-maven-plugin integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jluehe committed Aug 16, 2024
1 parent 7f7d105 commit 2ccce67
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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\"");
Expand All @@ -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");
}
Expand Down
3 changes: 2 additions & 1 deletion maven-plugins/transformer-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<rules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public abstract class AbstractTransformerMojo extends AbstractMojo {
* <p>
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class TransformerRules {
private boolean overwrite;
private boolean widen;
private boolean jakartaDefaults;
private boolean stripSignatures;

public TransformerRules() {}

Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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<String, byte[]> 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<String, byte[]> outputJarSigFilesMap = extractSignatureFileEntries(outputFileName);
assertThat(outputJarSigFilesMap).containsOnlyKeys("META-INF/MYKEY.SF", "META-INF/MYKEY.DSA");
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2ccce67

Please sign in to comment.