Skip to content

Commit

Permalink
[MNG-7615] Multithreaded model builder
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 7, 2022
1 parent f27b975 commit a46f8b3
Show file tree
Hide file tree
Showing 31 changed files with 1,343 additions and 1,137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ public interface Source {
InputStream getInputStream() throws IOException;

String getLocation();

/**
* Returns a new source identified by a relative path. Implementation <strong>MUST</strong>
* be able to accept <code>relPath</code> parameter values that
* <ul>
* <li>use either / or \ file path separator</li>
* <li>have .. parent directory references</li>
* <li>point either at file or directory.</li>
* </ul>
*
* @param relative is the path of the requested source relative to this source.
* @return related source or <code>null</code> if no such source.
*/
Source resolve(String relative);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
Expand All @@ -44,7 +45,7 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.ModelSource2;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
Expand Down Expand Up @@ -80,17 +81,7 @@ public ProjectBuilderResult build(ProjectBuilderRequest request)
res = builder.build(path.toFile(), req);
} else if (request.getSource().isPresent()) {
Source source = request.getSource().get();
ModelSource modelSource = new ModelSource() {
@Override
public InputStream getInputStream() throws IOException {
return source.getInputStream();
}

@Override
public String getLocation() {
return source.getLocation();
}
};
ModelSource2 modelSource = new SourceWrapper(source);
res = builder.build(modelSource, req);
} else if (request.getArtifact().isPresent()) {
Artifact a = request.getArtifact().get();
Expand Down Expand Up @@ -226,4 +217,33 @@ public Node getRoot() {
throw new ProjectBuilderException("Unable to build project", e);
}
}

private static class SourceWrapper implements ModelSource2 {
private final Source source;

SourceWrapper(Source source) {
this.source = source;
}

@Override
public InputStream getInputStream() throws IOException {
return source.getInputStream();
}

@Override
public String getLocation() {
return source.getLocation();
}

@Override
public ModelSource2 getRelatedSource(String relPath) {
Source rel = source.resolve(relPath);
return rel != null ? new SourceWrapper(rel) : null;
}

@Override
public URI getLocationURI() {
return null;
}
}
}
Loading

0 comments on commit a46f8b3

Please sign in to comment.