Repository navigation
Sanitize invalid Automatic-Module-Name instead of failing - #402
Conversation
0b97ab1 to
3d8fa92
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Solid change. I verified cleanModuleName() is functionally equivalent to the JDK's ModulePath.cleanModuleName() — same regex replacement strategy, same edge-case handling. The two new test methods (manifestWithUnsanitizableAutomaticModuleNameWarnsAndOmits, manifestWithHyphenatedAutomaticModuleNameIsSanitized) cover both sanitization paths well. I confirmed SourceVersion.isName("123.in.valid.new.name") returns false (both the digit-leading segment and "new" being a keyword contribute), so the unsanitizable test value is correctly chosen. All tests pass locally.
One minor nit below.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-reviewed after b340abf. The previous nit (move NON_ALPHANUM and REPEATING_DOTS constants up with the other static final fields) is addressed — both patterns now sit right after SPECIFICATION_VERSION_PATTERN, consistent with the class convention. No other changes in this commit. Good to merge.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…-archiver-3.x] - Replace hard build failure with warn+sanitize for invalid JPMS module names in manifestEntries - Apply JDK ModulePath.cleanModuleName() algorithm: replace non-alphanum with '.', collapse repeated dots, strip leading/trailing dots - Emit warning so the user is notified of the sanitization - Omit the attribute (with warning) when the sanitized name is still invalid - Add parameterized tests for the sanitization algorithm and the warn+omit path Backport of #402 to maven-archiver-3.x.
- Replace hard ManifestException with warn+sanitize for invalid JPMS module names in manifestEntries - Apply JDK ModulePath.cleanModuleName() algorithm: replace non-alphanumeric chars with '.', collapse repeated dots, strip leading/trailing dots - Emit warning so user is notified of the sanitization (e.g. 'org.apache.foo-bar' → 'org.apache.foo.bar') - Omit the attribute with a warning when the sanitized name is still invalid (digit-leading, reserved keyword) - Add cleanModuleNames parameterized test and update manifestWithInvalidAutomaticModuleName test to verify warn+omit path
b340abf to
6fa3fed
Compare
Fixes apache/maven-jar-plugin#596
Projects that configure
Automatic-Module-Namein<archive><manifestEntries>using a property derived from the artifactId (e.g.${project.groupId}.${project.artifactId}) can produce invalid JPMS module names when the artifactId contains hyphens. This previously caused a hard build failure withManifestException: Invalid automatic module name.This change sanitizes the invalid name using the same algorithm the JDK applies when deriving an automatic module name from a JAR file name (
ModulePath.cleanModuleName()): non-alphanumeric characters are replaced with., repeated dots are collapsed, and leading/trailing dots are stripped. A warning is emitted so the user is aware.For example,
org.apache.geronimo.arthur.integration-testbecomesorg.apache.geronimo.arthur.integration.test.If the sanitized name is still not a valid Java module name (e.g. starts with a digit, contains a keyword), the attribute is omitted with a warning — it cannot be fixed automatically in that case.
Affected projects include:
geronimo-arthur— e.g.org.apache.geronimo.arthur.integration-testkaraf-winegrower— e.g.org.apache.winegrower.cepages.winegrower-cepage-osgi-cdiChanges:
MavenArchiver.java: AddcleanModuleName()sanitization method; replace hard failure with sanitize-then-warn for invalid module names; only omit the attribute when sanitization still yields an invalid nameMavenArchiverTest.java: Updated tests to verify sanitization behavior; addedcleanModuleNamesparameterized test for the sanitization algorithm