use of org.apache.maven.plugins.assembly.model.ModuleSet in project maven-plugins by apache.
the class DefaultDependencyResolverTest method test_getModuleSetResolutionRequirements.
public void test_getModuleSetResolutionRequirements() throws DependencyResolutionException {
final EasyMockSupport mm = new EasyMockSupport();
final AssemblerConfigurationSource cs = mm.createMock(AssemblerConfigurationSource.class);
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);
expect(cs.getReactorProjects()).andReturn(allProjects).anyTimes();
expect(cs.getProject()).andReturn(project).anyTimes();
expect(cs.getMavenSession()).andReturn(newMavenSession(project)).anyTimes();
final ResolutionManagementInfo info = new ResolutionManagementInfo(project);
final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();
final ModuleSet ms1 = new ModuleSet();
final DependencySet ds1 = new DependencySet();
{
ms1.addInclude("*module1*");
ms1.setIncludeSubModules(false);
final ModuleBinaries mb = new ModuleBinaries();
ds1.setScope(Artifact.SCOPE_COMPILE);
mb.addDependencySet(ds1);
ms1.setBinaries(mb);
moduleSets.add(ms1);
}
final ModuleSet ms2 = new ModuleSet();
final DependencySet ds2 = new DependencySet();
{
ms2.addInclude("main-group:*");
ms2.setIncludeSubModules(true);
final ModuleBinaries mb = new ModuleBinaries();
ds2.setScope(Artifact.SCOPE_TEST);
mb.addDependencySet(ds2);
ms2.setBinaries(mb);
moduleSets.add(ms2);
}
mm.replayAll();
resolver.enableLogging(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
final Assembly assembly = new Assembly();
assembly.setModuleSets(moduleSets);
resolver.updateModuleSetResolutionRequirements(AssemblyId.createAssemblyId(assembly), ms1, ds1, info, cs);
resolver.updateModuleSetResolutionRequirements(AssemblyId.createAssemblyId(assembly), ms2, ds2, 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().getIncluded().contains(Artifact.SCOPE_TEST));
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_COMPILE));
// this combination should be implied by the two direct scopes set above.
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_RUNTIME));
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_PROVIDED));
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_SYSTEM));
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.ModuleSet in project maven-plugins by apache.
the class ModuleSetAssemblyPhaseTest method testGetModuleProjects_ShouldReturnModuleOfCurrentProject.
public void testGetModuleProjects_ShouldReturnModuleOfCurrentProject() throws ArchiveCreationException {
final EasyMockSupport mm = new EasyMockSupport();
final MavenProject project = createProject("group", "artifact", "version", null);
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
final MavenProject project2 = createProject("group", "artifact2", "version", project);
final List<MavenProject> projects = new ArrayList<MavenProject>();
projects.add(project);
projects.add(project2);
macTask.expectGetReactorProjects(projects);
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules(true);
mm.replayAll();
final Set<MavenProject> moduleProjects = ModuleSetAssemblyPhase.getModuleProjects(moduleSet, macTask.configSource, logger);
assertFalse(moduleProjects.isEmpty());
final MavenProject result = moduleProjects.iterator().next();
assertEquals("artifact2", result.getArtifactId());
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.ModuleSet in project maven-plugins by apache.
the class ModuleSetAssemblyPhaseTest method testGetModuleProjects_ShouldReturnNothingWhenReactorContainsOnlyCurrentProject.
public void testGetModuleProjects_ShouldReturnNothingWhenReactorContainsOnlyCurrentProject() throws ArchiveCreationException {
final EasyMockSupport mm = new EasyMockSupport();
final MavenProject project = createProject("group", "artifact", "version", null);
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
final List<MavenProject> projects = Collections.singletonList(project);
macTask.expectGetReactorProjects(projects);
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules(true);
mm.replayAll();
final Set<MavenProject> moduleProjects = ModuleSetAssemblyPhase.getModuleProjects(moduleSet, macTask.configSource, logger);
assertTrue(moduleProjects.isEmpty());
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.ModuleSet in project maven-plugins by apache.
the class DefaultAssemblyReader method mergeComponentWithAssembly.
/**
* Add the content of a single Component to main assembly
*
* @param component The component
* @param assembly The assembly
*/
protected void mergeComponentWithAssembly(final Component component, final Assembly assembly) {
final List<ContainerDescriptorHandlerConfig> containerHandlerDescriptors = component.getContainerDescriptorHandlers();
for (final ContainerDescriptorHandlerConfig cfg : containerHandlerDescriptors) {
assembly.addContainerDescriptorHandler(cfg);
}
final List<DependencySet> dependencySetList = component.getDependencySets();
for (final DependencySet dependencySet : dependencySetList) {
assembly.addDependencySet(dependencySet);
}
final List<FileSet> fileSetList = component.getFileSets();
for (final FileSet fileSet : fileSetList) {
assembly.addFileSet(fileSet);
}
final List<FileItem> fileList = component.getFiles();
for (final FileItem fileItem : fileList) {
assembly.addFile(fileItem);
}
final List<Repository> repositoriesList = component.getRepositories();
for (final Repository repository : repositoriesList) {
assembly.addRepository(repository);
}
final List<ModuleSet> moduleSets = component.getModuleSets();
for (final ModuleSet moduleSet : moduleSets) {
assembly.addModuleSet(moduleSet);
}
}
use of org.apache.maven.plugins.assembly.model.ModuleSet in project maven-plugins by apache.
the class ModuleSetAssemblyPhase method addModuleBinaries.
void addModuleBinaries(final Assembly assembly, ModuleSet moduleSet, final ModuleBinaries binaries, final Set<MavenProject> projects, final Archiver archiver, final AssemblerConfigurationSource configSource) throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException, DependencyResolutionException {
if (binaries == null) {
return;
}
final Set<MavenProject> moduleProjects = new LinkedHashSet<MavenProject>();
MavenProjects.select(projects, "pom", log(getLogger()), addTo(moduleProjects));
final String classifier = binaries.getAttachmentClassifier();
final Map<MavenProject, Artifact> chosenModuleArtifacts = new HashMap<MavenProject, Artifact>();
for (final MavenProject project : moduleProjects) {
Artifact artifact;
if (classifier == null) {
getLogger().debug("Processing binary artifact for module project: " + project.getId());
artifact = project.getArtifact();
} else {
getLogger().debug("Processing binary attachment: " + classifier + " for module project: " + project.getId());
artifact = MavenProjects.findArtifactByClassifier(project, classifier);
if (artifact == null) {
throw new InvalidAssemblerConfigurationException("Cannot find attachment with classifier: " + classifier + " in module project: " + project.getId() + ". Please exclude this module from the module-set.");
}
}
chosenModuleArtifacts.put(project, artifact);
addModuleArtifact(artifact, project, archiver, configSource, binaries);
}
final List<DependencySet> depSets = getDependencySets(binaries);
if (depSets != null) {
Map<DependencySet, Set<Artifact>> dependencySetSetMap = dependencyResolver.resolveDependencySets(assembly, moduleSet, configSource, depSets);
for (final DependencySet ds : depSets) {
// NOTE: Disabling useProjectArtifact flag, since module artifact has already been handled!
ds.setUseProjectArtifact(false);
}
// TODO: The following should be moved into a shared component, cause this
// test is the same as in maven-enforce rules ReactorModuleConvergence.
List<MavenProject> validateModuleVersions = validateModuleVersions(moduleProjects);
if (!validateModuleVersions.isEmpty()) {
StringBuilder sb = new StringBuilder().append("The current modules seemed to be having different versions.");
sb.append(LINE_SEPARATOR);
for (MavenProject mavenProject : validateModuleVersions) {
sb.append(" --> ");
sb.append(mavenProject.getId());
sb.append(LINE_SEPARATOR);
}
getLogger().warn(sb.toString());
}
for (final MavenProject moduleProject : moduleProjects) {
getLogger().debug("Processing binary dependencies for module project: " + moduleProject.getId());
for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : dependencySetSetMap.entrySet()) {
final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySetSetEntry.getKey()), dependencySetSetEntry.getValue(), moduleProject, projectBuilder, getLogger());
task.setModuleProject(moduleProject);
task.setModuleArtifact(chosenModuleArtifacts.get(moduleProject));
task.setDefaultOutputDirectory(binaries.getOutputDirectory());
task.setDefaultOutputFileNameMapping(binaries.getOutputFileNameMapping());
task.execute(archiver, configSource);
}
}
}
}
Aggregations