Skip to content

Commit a46f8b3

Browse files
committed
[MNG-7615] Multithreaded model builder
1 parent f27b975 commit a46f8b3

File tree

31 files changed

+1343
-1137
lines changed

31 files changed

+1343
-1137
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,18 @@ public interface Source {
3232
InputStream getInputStream() throws IOException;
3333

3434
String getLocation();
35+
36+
/**
37+
* Returns a new source identified by a relative path. Implementation <strong>MUST</strong>
38+
* be able to accept <code>relPath</code> parameter values that
39+
* <ul>
40+
* <li>use either / or \ file path separator</li>
41+
* <li>have .. parent directory references</li>
42+
* <li>point either at file or directory.</li>
43+
* </ul>
44+
*
45+
* @param relative is the path of the requested source relative to this source.
46+
* @return related source or <code>null</code> if no such source.
47+
*/
48+
Source resolve(String relative);
3549
}

maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.io.InputStream;
24+
import java.net.URI;
2425
import java.nio.file.Path;
2526
import java.util.Collection;
2627
import java.util.List;
@@ -44,7 +45,7 @@
4445
import org.apache.maven.artifact.DefaultArtifact;
4546
import org.apache.maven.artifact.repository.ArtifactRepository;
4647
import org.apache.maven.model.building.ModelProblem;
47-
import org.apache.maven.model.building.ModelSource;
48+
import org.apache.maven.model.building.ModelSource2;
4849
import org.apache.maven.project.DefaultProjectBuildingRequest;
4950
import org.apache.maven.project.ProjectBuildingException;
5051
import org.apache.maven.project.ProjectBuildingRequest;
@@ -80,17 +81,7 @@ public ProjectBuilderResult build(ProjectBuilderRequest request)
8081
res = builder.build(path.toFile(), req);
8182
} else if (request.getSource().isPresent()) {
8283
Source source = request.getSource().get();
83-
ModelSource modelSource = new ModelSource() {
84-
@Override
85-
public InputStream getInputStream() throws IOException {
86-
return source.getInputStream();
87-
}
88-
89-
@Override
90-
public String getLocation() {
91-
return source.getLocation();
92-
}
93-
};
84+
ModelSource2 modelSource = new SourceWrapper(source);
9485
res = builder.build(modelSource, req);
9586
} else if (request.getArtifact().isPresent()) {
9687
Artifact a = request.getArtifact().get();
@@ -226,4 +217,33 @@ public Node getRoot() {
226217
throw new ProjectBuilderException("Unable to build project", e);
227218
}
228219
}
220+
221+
private static class SourceWrapper implements ModelSource2 {
222+
private final Source source;
223+
224+
SourceWrapper(Source source) {
225+
this.source = source;
226+
}
227+
228+
@Override
229+
public InputStream getInputStream() throws IOException {
230+
return source.getInputStream();
231+
}
232+
233+
@Override
234+
public String getLocation() {
235+
return source.getLocation();
236+
}
237+
238+
@Override
239+
public ModelSource2 getRelatedSource(String relPath) {
240+
Source rel = source.resolve(relPath);
241+
return rel != null ? new SourceWrapper(rel) : null;
242+
}
243+
244+
@Override
245+
public URI getLocationURI() {
246+
return null;
247+
}
248+
}
229249
}

0 commit comments

Comments
 (0)