}
private ProjectDependencyGraph createDependencyGraph( ProjectSorter sorter, MavenExecutionRequest request )
throws MavenExecutionException
{
ProjectDependencyGraph graph = new DefaultProjectDependencyGraph( sorter );
Collection<MavenProject> activeProjects = sorter.getSortedProjects();
File reactorDirectory;
if ( request.getBaseDirectory() != null )
{
reactorDirectory = new File( request.getBaseDirectory() );
}
else
{
reactorDirectory = null;
}
if ( !request.getSelectedProjects().isEmpty() )
{
List<MavenProject> selectedProjects = new ArrayList<MavenProject>( request.getSelectedProjects().size() );
for ( String selectedProject : request.getSelectedProjects() )
{
MavenProject project = null;
for ( MavenProject activeProject : activeProjects )
{
if ( isMatchingProject( activeProject, selectedProject, reactorDirectory ) )
{
project = activeProject;
break;
}
}
if ( project != null )
{
selectedProjects.add( project );
}
else
{
throw new MavenExecutionException( "Could not find the selected project in the reactor: "
+ selectedProject, request.getPom() );
}
}
activeProjects = selectedProjects;
boolean makeUpstream = false;
boolean makeDownstream = false;
if ( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals( request.getMakeBehavior() ) )
{
makeUpstream = true;
}
else if ( MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM.equals( request.getMakeBehavior() ) )
{
makeDownstream = true;
}
else if ( MavenExecutionRequest.REACTOR_MAKE_BOTH.equals( request.getMakeBehavior() ) )
{
makeUpstream = true;
makeDownstream = true;
}
else if ( StringUtils.isNotEmpty( request.getMakeBehavior() ) )
{
throw new MavenExecutionException( "Invalid reactor make behavior: " + request.getMakeBehavior(),
request.getPom() );
}
if ( makeUpstream || makeDownstream )
{
activeProjects = new LinkedHashSet<MavenProject>( selectedProjects );
for ( MavenProject selectedProject : selectedProjects )
{
if ( makeUpstream )
{
activeProjects.addAll( graph.getUpstreamProjects( selectedProject, true ) );
}
if ( makeDownstream )
{
activeProjects.addAll( graph.getDownstreamProjects( selectedProject, true ) );
}
}
}
}