Search in sources :

Example 6 with ModuleBinaries

use of org.apache.maven.plugins.assembly.model.ModuleBinaries 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();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) ArrayList(java.util.ArrayList) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 7 with ModuleBinaries

use of org.apache.maven.plugins.assembly.model.ModuleBinaries in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method testAddModuleBinaries_ShouldAddOneModuleAttachmentArtifactAndNoDeps.

public void testAddModuleBinaries_ShouldAddOneModuleAttachmentArtifactAndNoDeps() throws ArchiveCreationException, AssemblyFormattingException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, null);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", "test", false);
    final File artifactFile = artifactMock.setNewFile();
    macTask.expectGetFinalName("final-name");
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectGetMode(0222, 0222);
    macTask.expectAddFile(artifactFile, "out/artifact", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    final ModuleBinaries binaries = new ModuleBinaries();
    binaries.setIncludeDependencies(false);
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    binaries.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    binaries.setAttachmentClassifier("test");
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.addAttachedArtifact(artifactMock.getArtifact());
    final Set<MavenProject> projects = singleton(project);
    macTask.expectResolveDependencySets();
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    createPhase(logger, macTask.dependencyResolver, null).addModuleBinaries(null, null, binaries, projects, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) File(java.io.File)

Example 8 with ModuleBinaries

use of org.apache.maven.plugins.assembly.model.ModuleBinaries in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method testAddModuleBinaries_ShouldFilterPomModule.

public void testAddModuleBinaries_ShouldFilterPomModule() throws ArchiveCreationException, AssemblyFormattingException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm);
    final ModuleBinaries binaries = new ModuleBinaries();
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    binaries.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.setPackaging("pom");
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "pom", false);
    project.setArtifact(artifactMock.getArtifact());
    final Set<MavenProject> projects = singleton(project);
    mm.replayAll();
    createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).addModuleBinaries(null, null, binaries, projects, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)

Aggregations

ModuleBinaries (org.apache.maven.plugins.assembly.model.ModuleBinaries)8 MavenProject (org.apache.maven.project.MavenProject)8 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)7 EasyMockSupport (org.easymock.classextension.EasyMockSupport)7 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)6 MockAndControlForAddArtifactTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask)6 File (java.io.File)5 Logger (org.codehaus.plexus.logging.Logger)4 ArrayList (java.util.ArrayList)2 Assembly (org.apache.maven.plugins.assembly.model.Assembly)2 ModuleSet (org.apache.maven.plugins.assembly.model.ModuleSet)2 Artifact (org.apache.maven.artifact.Artifact)1 AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)1 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)1