Pankraz76 commented on code in PR #2292: URL: https://github.com/apache/maven/pull/2292#discussion_r2081373513
########## 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)) { Review Comment: tested: <img width="1821" alt="image" src="https://github.com/user-attachments/assets/3c745922-f957-4f00-9a36-9d0d3df05be3" /> -- 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: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org