diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
index 308adde257..9b393d668d 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/Source.java
@@ -72,4 +72,18 @@ public interface Source {
*/
@Nonnull
String getLocation();
+
+ /**
+ * Returns a new source identified by a relative path. Implementation MUST
+ * be able to accept relative
parameter values that
+ *
null
if no such source
+ */
+ Source resolve(String relative);
}
diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java
index 30520920be..cd41925c9a 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectBuilder.java
@@ -25,6 +25,7 @@ import javax.inject.Singleton;
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;
@@ -46,7 +47,7 @@ import org.apache.maven.api.services.Source;
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;
@@ -82,17 +83,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
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.openStream();
- }
-
- @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();
@@ -228,4 +219,34 @@ public class DefaultProjectBuilder implements ProjectBuilder {
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.openStream();
+ }
+
+ @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() {
+ Path path = source.getPath();
+ return path != null ? path.toUri() : URI.create(source.getLocation());
+ }
+ }
}