gnodet commented on code in PR #1197: URL: https://github.com/apache/maven/pull/1197#discussion_r1253424076
########## maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java: ########## @@ -63,32 +75,110 @@ @Typed(ModelProcessor.class) public class DefaultModelProcessor implements ModelProcessor { - private final ModelLocator locator; - private final ModelReader reader; + private final Collection<ModelParser> modelParsers; + private final ModelLocator modelLocator; + private final ModelReader modelReader; @Inject - public DefaultModelProcessor(ModelLocator locator, ModelReader reader) { - this.locator = locator; - this.reader = reader; + public DefaultModelProcessor( + Collection<ModelParser> modelParsers, ModelLocator modelLocator, ModelReader modelReader) { + this.modelParsers = modelParsers; + this.modelLocator = modelLocator; + this.modelReader = modelReader; } @Override public File locatePom(File projectDirectory) { - return locator.locatePom(projectDirectory); + return locatePom(projectDirectory.toPath()).toFile(); + } + + public Path locatePom(Path projectDirectory) { + // Note that the ModelProcessor#locatePom never returns null + // while the ModelParser#locatePom needs to return an existing path ! + Path pom = modelParsers.stream() + .map(m -> m.locatePom(projectDirectory)) + .filter(Objects::nonNull) + .filter(Files::exists) + .findFirst() + .orElseGet( + () -> modelLocator.locatePom(projectDirectory.toFile()).toPath()); + if (!pom.getParent().equals(projectDirectory)) { + throw new IllegalArgumentException("The POM found does not belong to the given directory: " + pom); Review Comment: Well, for once, this can't be done easily without breaking the v3 API. This method implements [`ModelLocator`](https://github.com/apache/maven/blob/de19cfcd2bc8e774818d87472e8e64dc37c0b93d/maven-model-builder/src/main/java/org/apache/maven/model/locator/ModelLocator.java#L40) which does not throw any checked exception. -- 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