Search in sources :

Example 1 with ArtifactMock

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

the class DependencySetAssemblyPhaseTest method testExecute_ShouldAddOneDependencyFromProject.

public void testExecute_ShouldAddOneDependencyFromProject() throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final String outputLocation = "/out";
    final MavenProject project = newMavenProject("group", "project", "0");
    final ArtifactMock projectArtifactMock = new ArtifactMock(mm, "group", "project", "0", "jar", false);
    project.setArtifact(projectArtifactMock.getArtifact());
    final DependencySet ds = new DependencySet();
    ds.setUseProjectArtifact(false);
    ds.setOutputDirectory(outputLocation);
    ds.setOutputFileNameMapping("${artifact.artifactId}");
    ds.setUnpack(false);
    ds.setScope(Artifact.SCOPE_COMPILE);
    ds.setFileMode(Integer.toString(10, 8));
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    assembly.addDependencySet(ds);
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "dep", "1", "jar", false);
    System.out.println("On test setup, hashcode for dependency artifact: " + artifactMock.getArtifact().hashCode());
    macTask.expectCSGetRepositories(null, null);
    macTask.expectGetDestFile(new File("junk"));
    //        macTask.expectAddFile( artifactFile, "out/dep", 10 );
    project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
    macTask.expectCSGetFinalName("final-name");
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final MavenProject depProject = newMavenProject("group", "dep", "1");
    macTask.expectBuildFromRepository(depProject);
    macTask.expectResolveDependencySets();
    mm.replayAll();
    createPhase(macTask, logger, macTask.dependencyResolver).execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) 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) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 2 with ArtifactMock

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

the class ModuleSetAssemblyPhaseTest method testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided.

public void testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided() throws AssemblyFormattingException {
    final EasyMockSupport mm = new EasyMockSupport();
    final Model model = new Model();
    model.setArtifactId("artifact");
    final MavenProject project = new MavenProject(model);
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, project);
    macTask.expectGetFinalName(null);
    final FileSet fs = new FileSet();
    fs.setOutputDirectory("out");
    final ModuleSources sources = new ModuleSources();
    sources.setIncludeModuleDirectory(true);
    final MavenProject artifactProject = new MavenProject(new Model());
    final File basedir = fileManager.createTempDir();
    artifactProject.setFile(new File(basedir, "pom.xml"));
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", false);
    artifactProject.setArtifact(artifactMock.getArtifact());
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final FileSet result = createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).createFileSet(fs, sources, artifactProject, macTask.configSource);
    assertEquals("artifact/out/", result.getOutputDirectory());
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.maven.plugins.assembly.model.FileSet) 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)

Example 3 with ArtifactMock

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

the class AddArtifactTaskTest method testShouldAddArchiveFileWithUnpackAndModes.

public void testShouldAddArchiveFileWithUnpackAndModes() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    int directoryMode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    int fileMode = TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    mac.expectModeChange(-1, -1, directoryMode, fileMode, 2);
    mac.expectInterpolators();
    ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
    artifactMock.setNewFile();
    mac.expectGetDestFile(new File("junk"));
    try {
        mac.archiver.addArchivedFileSet((ArchivedFileSet) anyObject(), (Charset) anyObject());
    } catch (ArchiverException e) {
        fail("Should never happen.");
    }
    mockManager.replayAll();
    AddArtifactTask task = createTask(artifactMock.getArtifact());
    task.setUnpack(true);
    task.setDirectoryMode(directoryMode);
    task.setFileMode(fileMode);
    task.execute(mac.archiver, mac.configSource);
    mockManager.verifyAll();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) File(java.io.File)

Example 4 with ArtifactMock

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

the class AddDependencySetsTaskTest method testGetDependencyArtifacts_ShouldGetOneDependencyArtifact.

public void testGetDependencyArtifacts_ShouldGetOneDependencyArtifact() throws ArchiveCreationException, InvalidAssemblerConfigurationException {
    final MavenProject project = new MavenProject(new Model());
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager);
    final ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
    project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
    final DependencySet dependencySet = new DependencySet();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    mockManager.replayAll();
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(dependencySet), Collections.singleton(artifactMock.getArtifact()), project, macTask.projectBuilder, logger);
    final Set<Artifact> result = task.resolveDependencyArtifacts(dependencySet);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertSame(artifactMock.getArtifact(), result.iterator().next());
    mockManager.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) 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) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Example 5 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)

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