Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ public interface ProjectBuilderSource
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.
*/
ProjectBuilderSource resolve( String relative );
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -46,7 +47,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 @@ -88,20 +89,7 @@ public ProjectBuilderResult build( ProjectBuilderRequest request )
else if ( request.getSource().isPresent() )
{
ProjectBuilderSource 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 ProjectBuilderSourceWrapper( source );
res = builder.build( modelSource, req );
}
else if ( request.getArtifact().isPresent() )
Expand Down Expand Up @@ -264,4 +252,39 @@ public Node getRoot()
throw new ProjectBuilderException( "Unable to build project", e );
}
}

private static class ProjectBuilderSourceWrapper implements ModelSource2
{
private final ProjectBuilderSource source;

ProjectBuilderSourceWrapper( ProjectBuilderSource 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 )
{
ProjectBuilderSource rel = source.resolve( relPath );
return rel != null ? new ProjectBuilderSourceWrapper( rel ) : null;
}

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