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


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java:
##########
@@ -97,47 +101,50 @@ 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) 
throws IOException {
         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()));
-                    if (model.isPresent()) {
-                        return model.get().withPomFile(pomFile);
+                    Optional<Model> parent = readParent(request, pomFile, 
parser);
+                    if (parent.isPresent()) {
+                        return parent.get().withPomFile(pomFile);
                     }
                 } catch (ModelParserException e) {
                     exceptions.add(e);
                 }
             }
             try {
-                return doRead(request);
+                return readOnSelf(request);
             } catch (IOException e) {
                 exceptions.forEach(e::addSuppressed);
                 throw e;
             }
         } else {
-            return doRead(request);
+            return readOnSelf(request);
         }
     }
 
-    private Path doLocateExistingPom(Path project) {
-        if (project == null) {
-            project = Paths.get(System.getProperty("user.dir"));
-        }
+    private static Optional<Model> readParent(XmlReaderRequest request, Path 
pomFile, ModelParser parser) {
+        return parser.locateAndParse(pomFile.getParent(), Map.of(STRICT, 
request.isStrict()));
+    }
+
+    private Path locateExistingPomWithUserDirDefault(Path project) {
+        return locateExistingPomInDirOrFile(project != null ? project : 
Paths.get(System.getProperty("user.dir")));
+    }
+
+    private static Path locateExistingPomInDirOrFile(Path project) {
         if (Files.isDirectory(project)) {
             Path pom = project.resolve("pom.xml");
             return Files.isRegularFile(pom) ? pom : null;
-        } else if (Files.isRegularFile(project)) {
-            return project;
-        } else {
-            return null;
         }
+        return project;
     }
 
-    private Model doRead(XmlReaderRequest request) throws IOException {
+    private Model readOnSelf(XmlReaderRequest request) throws IOException {

Review Comment:
   It's DRY  anyway, with a lot of abstraction obfuscating the code. I usually 
overdo the layering. This might actually help bring some cohesion.



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