Search in sources :

Example 11 with ArtifactMock

use of org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock in project maven-plugins by apache.

the class AssemblyFormatUtilsTest method testEvalFileNameMapping_ShouldResolveArtifactIdAndBaseVersionInOutDir_UseArtifactInfo_WithValidMainProject.

public void testEvalFileNameMapping_ShouldResolveArtifactIdAndBaseVersionInOutDir_UseArtifactInfo_WithValidMainProject() throws AssemblyFormattingException {
    final MavenProject mainProject = createProject("group", "main", "1", null);
    final String artifactVersion = "2-20070807.112233-1";
    final String artifactBaseVersion = "2-SNAPSHOT";
    final MavenProject artifactProject = createProject("group", "artifact", artifactVersion, null);
    final ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", artifactVersion, "jar", true, artifactBaseVersion);
    artifactProject.setArtifact(artifactMock.getArtifact());
    final MavenSession session = mockManager.createMock(MavenSession.class);
    expect(session.getExecutionProperties()).andReturn(null).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final AssemblerConfigurationSource cs = mockManager.createMock(AssemblerConfigurationSource.class);
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(cs);
    mockManager.replayAll();
    final String result = AssemblyFormatUtils.evaluateFileNameMapping("${artifact.artifactId}-${artifact.baseVersion}", artifactMock.getArtifact(), mainProject, null, cs, AssemblyFormatUtils.moduleProjectInterpolator(null), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
    /*
        final Artifact artifact = artifactMock.getArtifact();
        final String result =
            AssemblyFormatUtils.evaluateFileNameMapping( "${artifact.artifactId}-${artifact.baseVersion}",
                                                         moduleArtifactInterpolator( null ),
                                                         moduleProjectInterpolator( null ),
                                                         artifactInterpolator( artifact ),
                                                         artifactProjectInterpolator( artifactProject ),
                                                         mainArtifactPropsOnly( mainProject ),
                                                         classifierRules( artifact ),
                                                         FixedStringSearchInterpolator.empty() );

         */
    assertEquals("artifact-2-SNAPSHOT", result);
    mockManager.verifyAll();
    // clear out for next call.
    mockManager.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties)

Example 12 with ArtifactMock

use of org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock 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 13 with ArtifactMock

use of org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method addArtifact.

private ArtifactMock addArtifact(final MavenProject project, final EasyMockSupport mm, final boolean expectDepTrailCheck) {
    final ArtifactMock macArtifact = new ArtifactMock(mm, project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), false);
    if (expectDepTrailCheck) {
        final LinkedList<String> depTrail = new LinkedList<String>();
        MavenProject parent = project.getParent();
        while (parent != null) {
            depTrail.addLast(parent.getId());
            parent = parent.getParent();
        }
        macArtifact.setDependencyTrail(depTrail);
    }
    project.setArtifact(macArtifact.getArtifact());
    return macArtifact;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) LinkedList(java.util.LinkedList)

Example 14 with ArtifactMock

use of org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock 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)

Example 15 with ArtifactMock

use of org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDirsIsTrue.

public void testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDirsIsTrue() throws AssemblyFormattingException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, null);
    macTask.expectGetFinalName(null);
    final FileSet fs = new FileSet();
    final ModuleSources sources = new ModuleSources();
    sources.setExcludeSubModuleDirectories(true);
    final Model model = new Model();
    model.setArtifactId("artifact");
    model.addModule("submodule");
    final MavenProject project = new MavenProject(model);
    final File basedir = fileManager.createTempDir();
    project.setFile(new File(basedir, "pom.xml"));
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", false);
    project.setArtifact(artifactMock.getArtifact());
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final FileSet result = createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).createFileSet(fs, sources, project, macTask.configSource);
    assertEquals(1, result.getExcludes().size());
    assertEquals("submodule/**", result.getExcludes().get(0));
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ModuleSources(org.apache.maven.plugins.assembly.model.ModuleSources) File(java.io.File)

Aggregations

ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)26 MavenProject (org.apache.maven.project.MavenProject)20 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)20 File (java.io.File)16 MockAndControlForAddArtifactTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask)14 Logger (org.codehaus.plexus.logging.Logger)12 EasyMockSupport (org.easymock.classextension.EasyMockSupport)11 Model (org.apache.maven.model.Model)10 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)8 MockAndControlForAddDependencySetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)7 ModuleBinaries (org.apache.maven.plugins.assembly.model.ModuleBinaries)6 FileSet (org.apache.maven.plugins.assembly.model.FileSet)4 ModuleSources (org.apache.maven.plugins.assembly.model.ModuleSources)4 Artifact (org.apache.maven.artifact.Artifact)3 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 MavenSession (org.apache.maven.execution.MavenSession)2 AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)2 Assembly (org.apache.maven.plugins.assembly.model.Assembly)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2