}
public void test_getModuleSetResolutionRequirements()
throws DependencyResolutionException
{
final MockManager mm = new MockManager();
final MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
mm.add( csControl );
final AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();
final File rootDir = new File( "root" );
final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", rootDir );
final File module1Dir = new File( rootDir, "module-1" );
final MavenProject module1 = createMavenProject( "main-group", "module-1", "1", module1Dir );
final MavenProject module1a =
createMavenProject( "group1", "module-1a", "1", new File( module1Dir, "module-1a" ) );
final MavenProject module1b =
createMavenProject( "group1.b", "module-1b", "1", new File( module1Dir, "module-1b" ) );
module1.getModel().addModule( module1a.getArtifactId() );
module1.getModel().addModule( module1b.getArtifactId() );
final File module2Dir = new File( rootDir, "module-2" );
final MavenProject module2 = createMavenProject( "main-group", "module-2", "1", module2Dir );
final MavenProject module2a =
createMavenProject( "main-group", "module-2a", "1", new File( module2Dir, "module-2a" ) );
module2.getModel().addModule( module2a.getArtifactId() );
project.getModel().addModule( module1.getArtifactId() );
project.getModel().addModule( module2.getArtifactId() );
final List<MavenProject> allProjects = new ArrayList<MavenProject>();
allProjects.add( project );
allProjects.add( module1 );
allProjects.add( module1a );
allProjects.add( module1b );
allProjects.add( module2 );
allProjects.add( module2a );
cs.getReactorProjects();
csControl.setReturnValue( allProjects, MockControl.ZERO_OR_MORE );
cs.getProject();
csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();
{
final ModuleSet ms = new ModuleSet();
ms.addInclude( "*module1*" );
ms.setIncludeSubModules( false );
final ModuleBinaries mb = new ModuleBinaries();
final DependencySet ds = new DependencySet();
ds.setScope( Artifact.SCOPE_COMPILE );
mb.addDependencySet( ds );
ms.setBinaries( mb );
moduleSets.add( ms );
}
{
final ModuleSet ms = new ModuleSet();
ms.addInclude( "main-group:*" );
ms.setIncludeSubModules( true );
final ModuleBinaries mb = new ModuleBinaries();
final DependencySet ds = new DependencySet();
ds.setScope( Artifact.SCOPE_TEST );
mb.addDependencySet( ds );
ms.setBinaries( mb );
moduleSets.add( ms );
}
mm.replayAll();
final DefaultDependencyResolver resolver =
new DefaultDependencyResolver( this.resolver, metadataSource, factory, collector, logger );
resolver.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
final Assembly assembly = new Assembly();
assembly.setModuleSets( moduleSets );
resolver.getModuleSetResolutionRequirements( assembly, info, cs );
assertTrue( info.isResolutionRequired() );
final Set<MavenProject> enabledProjects = info.getEnabledProjects();
assertTrue( enabledProjects.contains( project ) );
assertTrue( enabledProjects.contains( module1 ) );
// these should be excluded since sub-modules are not traversable
assertFalse( enabledProjects.contains( module1a ) );
assertFalse( enabledProjects.contains( module1b ) );
assertTrue( enabledProjects.contains( module2 ) );
assertTrue( enabledProjects.contains( module2a ) );
// these are the two we directly set above.
assertTrue( info.getScopeFilter().isIncludeTestScope() );
assertTrue( info.getScopeFilter().isIncludeCompileScope() );
// this combination should be implied by the two direct scopes set above.
assertTrue( info.getScopeFilter().isIncludeRuntimeScope() );
assertTrue( info.getScopeFilter().isIncludeProvidedScope() );
assertTrue( info.getScopeFilter().isIncludeSystemScope() );
mm.verifyAll();
}