gnodet commented on code in PR #402:
URL: https://github.com/apache/maven-archiver/pull/402#discussion_r4108641143
##########
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:
Fixed in b340abf.
--
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]