gnodet commented on code in PR #2304: URL: https://github.com/apache/maven/pull/2304#discussion_r2080232540
########## impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java: ########## @@ -94,50 +97,45 @@ public Path locateExistingPom(Path projectDirectory) { return pom; } + private Path doLocateExistingPom(Path project) { + if (project == null) { + project = Paths.get(System.getProperty("user.dir")); + } else if (Files.isDirectory(project)) { + Path pom = project.resolve("pom.xml"); + return Files.isRegularFile(pom) ? pom : null; + } + return project; + } + @Override public Model read(XmlReaderRequest request) throws IOException { - Objects.requireNonNull(request, "source cannot be null"); - Path pomFile = request.getPath(); + Path pomFile = requireNonNull(request, "source cannot be null").getPath(); 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 = parent(request, parser, pomFile.getParent()); + if (parent.isPresent()) { + return parent.get().withPomFile(pomFile); } } catch (ModelParserException e) { exceptions.add(e); } } - try { - return doRead(request); - } catch (IOException e) { - exceptions.forEach(e::addSuppressed); - throw e; - } - } else { - return doRead(request); + throwErrorsSuppressed(exceptions); } + return modelXmlFactory.read(request); } - private Path doLocateExistingPom(Path project) { - if (project == null) { - project = Paths.get(System.getProperty("user.dir")); - } - 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; - } + private static Optional<Model> parent(XmlReaderRequest request, ModelParser parser, Path projectDirectory) { Review Comment: A parent usually refers to the parent model, so I'd rather use parentDirectory to make it clear what we're looking for. ########## impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java: ########## @@ -94,50 +97,45 @@ public Path locateExistingPom(Path projectDirectory) { return pom; } + private Path doLocateExistingPom(Path project) { + if (project == null) { + project = Paths.get(System.getProperty("user.dir")); + } else if (Files.isDirectory(project)) { + Path pom = project.resolve("pom.xml"); + return Files.isRegularFile(pom) ? pom : null; + } + return project; + } + @Override public Model read(XmlReaderRequest request) throws IOException { - Objects.requireNonNull(request, "source cannot be null"); - Path pomFile = request.getPath(); + Path pomFile = requireNonNull(request, "source cannot be null").getPath(); 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 = parent(request, parser, pomFile.getParent()); + if (parent.isPresent()) { + return parent.get().withPomFile(pomFile); } } catch (ModelParserException e) { exceptions.add(e); } } - try { - return doRead(request); - } catch (IOException e) { - exceptions.forEach(e::addSuppressed); - throw e; - } - } else { - return doRead(request); + throwErrorsSuppressed(exceptions); } + return modelXmlFactory.read(request); } - private Path doLocateExistingPom(Path project) { - if (project == null) { - project = Paths.get(System.getProperty("user.dir")); - } - 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; - } + private static Optional<Model> parent(XmlReaderRequest request, ModelParser parser, Path projectDirectory) { + return parser.locateAndParse(projectDirectory, Map.of(STRICT, request.isStrict())); } - private Model doRead(XmlReaderRequest request) throws IOException { - return modelXmlFactory.read(request); + private static void throwErrorsSuppressed(List<ModelParserException> exceptions) throws IOException { Review Comment: We're not using the IOException in the API, so not sure why we'd want to build one here. Model parsing exception aren't necessarily IoExceptions. -- 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