Pankraz76 commented on code in PR #2292:
URL: https://github.com/apache/maven/pull/2292#discussion_r2077330309


##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelProcessorTest.java:
##########
@@ -0,0 +1,139 @@
+package org.apache.maven.impl.model;
+
+import org.apache.maven.api.model.Model;
+import org.apache.maven.api.services.Source;
+import org.apache.maven.api.services.xml.Location;
+import org.apache.maven.api.services.xml.ModelXmlFactory;
+import org.apache.maven.api.services.xml.XmlReaderException;
+import org.apache.maven.api.services.xml.XmlReaderRequest;
+import org.apache.maven.api.spi.ModelParser;
+import org.apache.maven.api.spi.ModelParserException;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+class DefaultModelProcessorTest {

Review Comment:
   tc:
   <img width="603" alt="image" 
src="https://github.com/user-attachments/assets/ae426643-f070-4f51-8c74-fe06a5907e98";
 />
   
   <img width="1905" alt="image" 
src="https://github.com/user-attachments/assets/f265206a-2452-4774-a54e-86f950a91f21";
 />
   



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java:
##########
@@ -97,32 +99,32 @@ public Path locateExistingPom(Path projectDirectory) {
     @Override
     public Model read(XmlReaderRequest request) throws IOException {
         Objects.requireNonNull(request, "source cannot be null");
-        Path pomFile = request.getPath();
+        return readOnSelfOrParent(request, request.getPath());
+    }
+
+    private Model readOnSelfOrParent(XmlReaderRequest request, Path pomFile) {
         if (pomFile != null) {
-            Path projectDirectory = pomFile.getParent();
             List<ModelParserException> exceptions = new ArrayList<>();
             for (ModelParser parser : modelParsers) {
                 try {
-                    Optional<Model> model =
-                            parser.locateAndParse(projectDirectory, 
Map.of(ModelParser.STRICT, request.isStrict()));
+                    Optional<Model> model = locateAndParseParent(request, 
pomFile, parser);
                     if (model.isPresent()) {
                         return model.get().withPomFile(pomFile);
                     }
                 } catch (ModelParserException e) {
                     exceptions.add(e);
                 }
             }
-            try {
-                return doRead(request);
-            } catch (IOException e) {
-                exceptions.forEach(e::addSuppressed);

Review Comment:
   Then this is the last branch not covered.



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java:
##########
@@ -137,7 +139,7 @@ private Path doLocateExistingPom(Path project) {
         }
     }
 
-    private Model doRead(XmlReaderRequest request) throws IOException {

Review Comment:
   this changes the whole code as this "can not happen"; or if needed then we 
should change API, if we can, to make code more concise.
   
   <img width="1731" alt="image" 
src="https://github.com/user-attachments/assets/414af308-5c71-4c5c-ab45-c4d0bcae14c0";
 />
   



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