Search in sources :

Example 6 with ArtifactMock

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

the class AddDependencySetsTaskTest method testGetDependencyArtifacts_ShouldIgnoreTransitivePathFilteringWhenIncludeNotTransitive.

public void testGetDependencyArtifacts_ShouldIgnoreTransitivePathFilteringWhenIncludeNotTransitive() throws ArchiveCreationException, InvalidAssemblerConfigurationException {
    final MavenProject project = new MavenProject(new Model());
    final Set<Artifact> artifacts = new HashSet<Artifact>();
    final ArtifactMock am = new ArtifactMock(mockManager, "group", "artifact", "1.0", "jar", false);
    artifacts.add(am.getArtifact());
    final ArtifactMock am2 = new ArtifactMock(mockManager, "group2", "artifact2", "1.0", "jar", false);
    artifacts.add(am2.getArtifact());
    final DependencySet dependencySet = new DependencySet();
    dependencySet.addInclude("group:artifact");
    dependencySet.setUseTransitiveFiltering(false);
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    mockManager.replayAll();
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySet), artifacts, project, null, logger);
    final Set<Artifact> result = task.resolveDependencyArtifacts(dependencySet);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertSame(am.getArtifact(), result.iterator().next());
    mockManager.verifyAll();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Example 7 with ArtifactMock

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

the class ModuleSetAssemblyPhaseTest method testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull.

public void testAddModuleArtifact_ShouldThrowExceptionWhenArtifactFileIsNull() throws AssemblyFormattingException, IOException {
    final EasyMockSupport mm = new EasyMockSupport();
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "type", false);
    artifactMock.setNullFile();
    mm.replayAll();
    try {
        createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).addModuleArtifact(artifactMock.getArtifact(), null, null, null, null);
        fail("Expected ArchiveCreationException since artifact file is null.");
    } catch (final ArchiveCreationException e) {
    // expected
    }
    mm.verifyAll();
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)

Example 8 with ArtifactMock

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

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

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

the class AssemblyFormatUtilsTest method verifyEvalFileNameMapping.

private void verifyEvalFileNameMapping(final String expression, final String classifier, final String extension, final MavenProject mainProject, final MavenProject moduleProject, final MavenProject artifactProject, final String checkValue) throws AssemblyFormattingException {
    final ArtifactMock artifactMock = new ArtifactMock(mockManager, artifactProject.getGroupId(), artifactProject.getArtifactId(), artifactProject.getVersion(), extension, classifier, false, null);
    final ArtifactMock moduleArtifactMock = new ArtifactMock(mockManager, moduleProject.getGroupId(), moduleProject.getArtifactId(), moduleProject.getVersion(), "jar", false, null);
    final MavenSession session = mockManager.createMock(MavenSession.class);
    expect(session.getExecutionProperties()).andReturn(System.getProperties()).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final AssemblerConfigurationSource cs = mockManager.createMock(AssemblerConfigurationSource.class);
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(cs, mainProject);
    mockManager.replayAll();
    final String result = AssemblyFormatUtils.evaluateFileNameMapping(expression, artifactMock.getArtifact(), mainProject, moduleArtifactMock.getArtifact(), cs, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
    /*
                final String result =
            AssemblyFormatUtils.evaluateFileNameMapping( expression,
                                                         moduleArtifactInterpolator( moduleArtifactMock.getArtifact() ),
                                                         moduleProjectInterpolator( moduleProject ),
                                                         artifactInterpolator( artifactMock.getArtifact() ),
                                                         artifactProjectInterpolator( artifactProject ),
                                                         mainArtifactPropsOnly( mainProject ),
                                                         classifierRules( artifactMock.getArtifact() ),
                                                         FixedStringSearchInterpolator.create( new
                                                         PropertiesBasedValueSource( System.getProperties()  )) );

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

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