Search in sources :

Example 1 with ModuleBinaries

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

the class ModuleSetAssemblyPhaseTest method testAddModuleArtifact_ShouldAddOneArtifact.

public void testAddModuleArtifact_ShouldAddOneArtifact() throws AssemblyFormattingException, IOException, ArchiveCreationException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "type", false);
    final File artifactFile = artifactMock.setNewFile();
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.setArtifact(artifactMock.getArtifact());
    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.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).addModuleArtifact(artifactMock.getArtifact(), project, macTask.archiver, macTask.configSource, binaries);
    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) File(java.io.File)

Example 2 with ModuleBinaries

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

the class ModuleSetAssemblyPhaseTest method testAddModuleBinaries_ShouldAddOneModuleArtifactAndNoDeps.

public void testAddModuleBinaries_ShouldAddOneModuleArtifactAndNoDeps() throws ArchiveCreationException, AssemblyFormattingException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", false);
    final File artifactFile = artifactMock.setNewFile();
    macTask.expectGetFinalName("final-name");
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectAddFile(artifactFile, "out/artifact", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macTask.expectGetMode(0222, 0222);
    final ModuleBinaries binaries = new ModuleBinaries();
    binaries.setIncludeDependencies(false);
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    binaries.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.setArtifact(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 3 with ModuleBinaries

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

the class DefaultDependencyResolver method updateModuleSetResolutionRequirements.

void updateModuleSetResolutionRequirements(AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet, final ResolutionManagementInfo requirements, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final ModuleBinaries binaries = set.getBinaries();
    if (binaries != null) {
        Set<MavenProject> projects;
        try {
            projects = ModuleSetAssemblyPhase.getModuleProjects(set, configSource, getLogger());
        } catch (final ArchiveCreationException e) {
            throw new DependencyResolutionException("Error determining project-set for moduleSet with binaries.", e);
        }
        if (!projects.isEmpty()) {
            for (final MavenProject p : projects) {
                requirements.enableProjectResolution(p);
                if (p.getArtifact() == null) {
                    // TODO: such a call in MavenMetadataSource too - packaging not really the intention of
                    // type
                    final Artifact artifact = resolver.createArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging());
                    p.setArtifact(artifact);
                }
            }
        }
        if (binaries.isIncludeDependencies()) {
            updateDependencySetResolutionRequirements(dependencySet, requirements, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), projects.toArray(new MavenProject[projects.size()]));
        }
    }
}
Also used : ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with ModuleBinaries

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

the class ModuleSetAssemblyPhaseTest method testAddModuleBinaries_ShouldFailWhenOneModuleDoesntHaveAttachmentWithMatchingClassifier.

public void testAddModuleBinaries_ShouldFailWhenOneModuleDoesntHaveAttachmentWithMatchingClassifier() throws ArchiveCreationException, AssemblyFormattingException, IOException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", "test", false);
    artifactMock.setNewFile();
    final ModuleBinaries binaries = new ModuleBinaries();
    binaries.setUnpack(false);
    binaries.setFileMode("777");
    binaries.setOutputDirectory("out");
    binaries.setOutputFileNameMapping("artifact");
    binaries.setAttachmentClassifier("test");
    final MavenProject project = createProject("group", "artifact", "version", null);
    project.setArtifact(artifactMock.getArtifact());
    final Set<MavenProject> projects = singleton(project);
    mm.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    try {
        createPhase(logger, null).addModuleBinaries(null, null, binaries, projects, macTask.archiver, macTask.configSource);
        fail("Should throw an invalid configuration exception because of module with missing attachment.");
    } catch (final InvalidAssemblerConfigurationException e) {
    // should throw this because of missing attachment.
    }
    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) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger)

Example 5 with ModuleBinaries

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

the class ModuleSetAssemblyPhaseTest method testExecute_ShouldAddOneModuleSetWithOneModuleInIt.

public void testExecute_ShouldAddOneModuleSetWithOneModuleInIt() throws ArchiveCreationException, AssemblyFormattingException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenProject project = createProject("group", "artifact", "version", null);
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, project);
    final MavenProject module = createProject("group", "module", "version", project);
    final ArtifactMock moduleArtifactMock = new ArtifactMock(mm, "group", "module", "version", "jar", false);
    final File moduleArtifactFile = moduleArtifactMock.setNewFile();
    module.setArtifact(moduleArtifactMock.getArtifact());
    final List<MavenProject> projects = new ArrayList<MavenProject>();
    projects.add(module);
    macTask.expectGetReactorProjects(projects);
    macTask.expectGetFinalName("final-name");
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectGetMode(0777, 0777);
    final int mode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    macTask.expectAddFile(moduleArtifactFile, "out/artifact", mode);
    final Assembly assembly = new Assembly();
    assembly.setIncludeBaseDirectory(false);
    final ModuleSet ms = new ModuleSet();
    final ModuleBinaries bin = new ModuleBinaries();
    bin.setOutputFileNameMapping("artifact");
    bin.setOutputDirectory("out");
    bin.setFileMode("777");
    bin.setUnpack(false);
    bin.setIncludeDependencies(false);
    ms.setBinaries(bin);
    assembly.addModuleSet(ms);
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    macTask.expectResolveDependencySets();
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final ModuleSetAssemblyPhase phase = createPhase(logger, macTask.dependencyResolver, null);
    phase.execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) ArrayList(java.util.ArrayList) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) 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)

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