mirror of https://github.com/apache/maven.git
[MNG-7985] Provide project access to modified resources / test-resources and to the executionProject (#1356)
This commit is contained in:
parent
732e3649e1
commit
b4e78d7c43
|
@ -30,6 +30,7 @@ import org.apache.maven.api.Service;
|
|||
import org.apache.maven.api.Session;
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
import org.apache.maven.api.model.Resource;
|
||||
|
||||
/**
|
||||
* Interface to manage the project during its lifecycle.
|
||||
|
@ -75,7 +76,18 @@ public interface ProjectManager extends Service {
|
|||
|
||||
void addTestCompileSourceRoot(Project project, String sourceRoot);
|
||||
|
||||
List<Resource> getResources(Project project);
|
||||
|
||||
void addResource(Project project, Resource resource);
|
||||
|
||||
List<Resource> getTestResources(Project project);
|
||||
|
||||
void addTestResource(Project project, Resource resource);
|
||||
|
||||
List<RemoteRepository> getRepositories(Project project);
|
||||
|
||||
void setProperty(Project project, String key, String value);
|
||||
|
||||
@Nonnull
|
||||
Optional<Project> getExecutionProject(@Nonnull Project project);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.maven.RepositoryUtils;
|
|||
import org.apache.maven.api.*;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
import org.apache.maven.api.di.SessionScoped;
|
||||
import org.apache.maven.api.model.Resource;
|
||||
import org.apache.maven.api.services.*;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -103,6 +104,26 @@ public class DefaultProjectManager implements ProjectManager {
|
|||
roots.add(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> getResources(Project project) {
|
||||
return getMavenProject(project).getBuild().getDelegate().getResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResource(Project project, Resource resource) {
|
||||
getMavenProject(project).addResource(new org.apache.maven.model.Resource(resource));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> getTestResources(Project project) {
|
||||
return getMavenProject(project).getBuild().getDelegate().getTestResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTestResource(Project project, Resource resource) {
|
||||
getMavenProject(project).addTestResource(new org.apache.maven.model.Resource(resource));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RemoteRepository> getRepositories(Project project) {
|
||||
return ((DefaultProject) project)
|
||||
|
@ -116,6 +137,15 @@ public class DefaultProjectManager implements ProjectManager {
|
|||
getMavenProject(project).getProperties().setProperty(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Project> getExecutionProject(Project project) {
|
||||
// Session keep tracks of the Project per project id,
|
||||
// so we cannot use session.getProject(p) for forked projects
|
||||
// which are temporary clones
|
||||
return Optional.ofNullable(getMavenProject(project).getExecutionProject())
|
||||
.map(p -> new DefaultProject(session, p));
|
||||
}
|
||||
|
||||
private MavenProject getMavenProject(Project project) {
|
||||
return ((DefaultProject) project).getProject();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue