gnodet-bot commented on code in PR #402:
URL: https://github.com/apache/maven-archiver/pull/402#discussion_r4087792322
##########
src/main/java/org/apache/maven/shared/archiver/MavenArchiver.java:
##########
@@ -112,6 +116,28 @@ static boolean isValidModuleName(String name) {
return SourceVersion.isName(name);
}
+ /**
+ * Sanitizes a candidate module name by applying the same algorithm the
JDK uses to derive
+ * an automatic module name from a JAR file name (see {@code
ModulePath.cleanModuleName()}):
+ * replaces non-alphanumeric characters with {@code '.'}, collapses
repeated dots, and strips
+ * leading/trailing dots.
+ *
+ * @param name the raw module name
+ * @return a sanitized module name, or an empty string if nothing remains
after sanitization
+ */
+ static String cleanModuleName(String name) {
+ // Replace non-alphanumeric (including hyphens) with dots — mirrors
JDK ModulePath.cleanModuleName()
+ name = NON_ALPHANUM.matcher(name).replaceAll(".");
+ // Collapse repeated dots
+ name = REPEATING_DOTS.matcher(name).replaceAll(".");
+ // Strip leading/trailing dots
+ name = name.replaceAll("^\\.+|\\.+$", "");
+ return name;
+ }
+
+ private static final Pattern NON_ALPHANUM =
Pattern.compile("[^A-Za-z0-9]");
+ private static final Pattern REPEATING_DOTS = Pattern.compile("\\.{2,}");
Review Comment:
nit: These two `Pattern` constants are declared *after* the
`cleanModuleName()` method that uses them. While this is valid Java (static
methods can reference fields regardless of declaration order), every other
`static final` field in this class (`CREATED_BY`,
`SPECIFICATION_VERSION_PATTERN`, `ARTIFACT_EXPRESSION_PREFIXES`, etc.) is
declared before the methods. Moving `NON_ALPHANUM` and `REPEATING_DOTS` up —
e.g. next to `SPECIFICATION_VERSION_PATTERN` at line 106 — would keep the
field-then-method convention consistent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]