|
22 | 22 | import java.nio.file.Files; |
23 | 23 | import java.nio.file.Path; |
24 | 24 | import java.nio.file.Paths; |
25 | | -import java.util.ArrayList; |
26 | 25 | import java.util.List; |
27 | 26 | import java.util.Map; |
28 | 27 | import java.util.Objects; |
|
37 | 36 | import org.apache.maven.api.services.xml.ModelXmlFactory; |
38 | 37 | import org.apache.maven.api.services.xml.XmlReaderRequest; |
39 | 38 | import org.apache.maven.api.spi.ModelParser; |
40 | | -import org.apache.maven.api.spi.ModelParserException; |
41 | 39 |
|
42 | 40 | /** |
43 | 41 | * |
@@ -97,18 +95,20 @@ public Path locateExistingPom(Path projectDirectory) { |
97 | 95 | @Override |
98 | 96 | public Model read(XmlReaderRequest request) throws IOException { |
99 | 97 | Objects.requireNonNull(request, "source cannot be null"); |
100 | | - Path pomFile = request.getPath(); |
101 | | - if (pomFile != null) { |
102 | | - return modelParsers.stream() |
103 | | - .flatMap( |
104 | | - parser -> parser |
105 | | - .locateAndParse(pomFile.getParent(), Map.of(ModelParser.STRICT, request.isStrict())) |
106 | | - .stream()) |
107 | | - .findFirst() |
| 98 | + return read(request, request.getPath()); |
| 99 | + } |
| 100 | + |
| 101 | + private Model read(XmlReaderRequest request, Path pomFile) throws IOException { |
| 102 | + return pomFile == null |
| 103 | + ? doRead(request) |
| 104 | + : modelParsers |
| 105 | + .stream() |
| 106 | + .map(parser -> parser.locateAndParse(pomFile.getParent(), Map.of(ModelParser.STRICT, request.isStrict()))) |
| 107 | + .filter(Optional::isPresent) |
| 108 | + .map(Optional::get) |
108 | 109 | .map(model -> model.withPomFile(pomFile)) |
109 | | - .orElse(null); |
110 | | - } |
111 | | - return doRead(request); |
| 110 | + .findFirst() |
| 111 | + .orElse(doRead(request)); |
112 | 112 | } |
113 | 113 |
|
114 | 114 | private Path doLocateExistingPom(Path project) { |
|
0 commit comments