gnodet commented on code in PR #11185:
URL: https://github.com/apache/maven/pull/11185#discussion_r2388468182


##########
src/mdo/reader-stax.vm:
##########
@@ -263,32 +263,58 @@ public class ${className} {
 #if ( $needXmlContext )
         Deque<Object> context = new ArrayDeque<>();
 #end
-        $rootUcapName $rootLcapName = null;
-        int eventType = parser.getEventType();
-        boolean parsed = false;
-        while (eventType != XMLStreamReader.END_DOCUMENT) {
-            if (eventType == XMLStreamReader.START_ELEMENT) {
-                if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
-                    throw new XMLStreamException("Expected root element 
'${rootTag}' but found '" + parser.getName() + "'", parser.getLocation(), null);
-                } else if (parsed) {
-                    // fallback, already expected a XMLStreamException due to 
invalid XML
-                    throw new XMLStreamException("Duplicated tag: 
'${rootTag}'", parser.getLocation(), null);
-                }
-#if ( $locationTracking )
-                $rootLcapName = parse${rootUcapName}(parser, strict, 
parser.getNamespaceURI(), inputSrc);
-#elseif ( $needXmlContext )
-                $rootLcapName = parse${rootUcapName}(parser, strict, 
parser.getNamespaceURI(), context);
-#else
-                $rootLcapName = parse${rootUcapName}(parser, strict, 
parser.getNamespaceURI());
-#end
-                parsed = true;
+$rootUcapName $rootLcapName = null;
+    int eventType = parser.getEventType();
+    boolean parsed = false;
+    while (eventType != XMLStreamReader.END_DOCUMENT) {
+    if (eventType == XMLStreamReader.START_ELEMENT) {
+    if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
+    throw new XMLStreamException("Expected root element '${rootTag}' but found 
'" + parser.getName() + "'", parser.getLocation(), null);
+    } else if (parsed) {
+    throw new XMLStreamException("Duplicated tag: '${rootTag}'", 
parser.getLocation(), null);
+    }
+    // Root namespace policy:
+    //  - POM ('project'): allow no namespace or any 
http://maven.apache.org/POM/<version>
+    //  - METADATA ('metadata'): allow no namespace or any 
http://maven.apache.org/METADATA/<version>
+    //  - Other readers: do not enforce root namespace here (child checks 
still apply when strict)
+    if (strict) {
+        final String rootNs = parser.getNamespaceURI();
+        final boolean hasNs = rootNs != null && !rootNs.isEmpty();
+
+        if ("project".equals("${rootTag}")) {
+            if (hasNs && !rootNs.startsWith("http://maven.apache.org/POM/";)) {

Review Comment:
   This is wrong.  We have generators to generate specific readers, not a 
generic one which covers all use cases.  So it's wrong to put hardcoded values 
for one or two models in the output of all readers.
   The way to go is to retrieve the namespace using modello.  The `helper` 
needs to be enhanced:
   
https://github.com/codehaus-plexus/modello/blob/ca30aba14346bf0e183efd2c442f061024c40111/modello-plugins/modello-plugin-velocity/src/main/java/org/codehaus/modello/plugin/velocity/Helper.java
   It needs a new method `xmlModelMetadata` which would return the 
`XmlModelMetadata` from which we can get the target _namespace_.
   Once modello is fixed, we can update the velocity templates to leverage that 
using `Helper.xmlModelMetadata(model).namespace`.



-- 
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]

Reply via email to