Search in sources :

Example 11 with DependencySet

use of org.apache.maven.plugins.assembly.model.DependencySet 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 12 with DependencySet

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

the class AddArtifactTaskTest method testShouldAddArchiveFileWithDefaultOutputLocation.

public void testShouldAddArchiveFileWithDefaultOutputLocation() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    String artifactId = "myArtifact";
    String version = "1";
    String ext = "jar";
    String outputDir = "tmp/";
    ArtifactMock mock = new ArtifactMock(mockManager, "group", artifactId, version, ext, false);
    File file = mock.setNewFile();
    mock.setExtension(ext);
    mac.expectGetMode(0222, 0222);
    mac.expectGetDestFile(new File("junk"));
    mac.expectAddFile(file, outputDir + artifactId + "-" + version + "." + ext);
    mac.expectInterpolators();
    mockManager.replayAll();
    AddArtifactTask task = new AddArtifactTask(mock.getArtifact(), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null);
    task.setOutputDirectory(outputDir);
    task.setFileNameMapping(new DependencySet().getOutputFileNameMapping());
    Model model = new Model();
    model.setArtifactId(artifactId);
    model.setVersion(version);
    MavenProject project = new MavenProject(model);
    task.setProject(project);
    task.execute(mac.archiver, mac.configSource);
    mockManager.verifyAll();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) File(java.io.File)

Example 13 with DependencySet

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

the class AddDependencySetsTaskTest method testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping.

public void testAddDependencySet_ShouldInterpolateDefaultOutputFileNameMapping() throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, IOException {
    final String outDir = "tmp/";
    final String mainAid = "main";
    final String mainGid = "org.maingrp";
    final String mainVer = "9";
    final String depAid = "dep";
    final String depGid = "org.depgrp";
    final String depVer = "1";
    final String depExt = "war";
    final DependencySet ds = new DependencySet();
    ds.setOutputDirectory(outDir);
    ds.setDirectoryMode(Integer.toString(10, 8));
    ds.setFileMode(Integer.toString(10, 8));
    final Model mainModel = new Model();
    mainModel.setArtifactId(mainAid);
    mainModel.setGroupId(mainGid);
    mainModel.setVersion(mainVer);
    final MavenProject mainProject = new MavenProject(mainModel);
    final ArtifactMock mainArtifactMock = new ArtifactMock(mockManager, mainGid, mainAid, mainVer, "jar", false);
    mainProject.setArtifact(mainArtifactMock.getArtifact());
    final Model depModel = new Model();
    depModel.setArtifactId(depAid);
    depModel.setGroupId(depGid);
    depModel.setVersion(depVer);
    depModel.setPackaging(depExt);
    final MavenProject depProject = new MavenProject(depModel);
    final ArtifactMock depArtifactMock = new ArtifactMock(mockManager, depGid, depAid, depVer, depExt, false);
    final File newFile = depArtifactMock.setNewFile();
    depProject.setArtifact(depArtifactMock.getArtifact());
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager, mainProject);
    macTask.expectBuildFromRepository(depProject);
    macTask.expectCSGetFinalName(mainAid + "-" + mainVer);
    macTask.expectCSGetRepositories(null, null);
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectAddFile(newFile, outDir + depAid + "-" + depVer + "." + depExt, 10);
    //        macTask.expectGetSession( null );
    macTask.expectGetMode(0222, 0222);
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(ds), Collections.singleton(depArtifactMock.getArtifact()), depProject, macTask.projectBuilder, logger);
    task.addDependencySet(ds, macTask.archiver, macTask.configSource);
    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) File(java.io.File) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Example 14 with DependencySet

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

the class AddDependencySetsTaskTest method verifyOneDependencyAdded.

private void verifyOneDependencyAdded(final String outputLocation, final boolean unpack) throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException {
    final MavenProject project = new MavenProject(new Model());
    final DependencySet ds = new DependencySet();
    ds.setOutputDirectory(outputLocation);
    ds.setOutputFileNameMapping("artifact");
    ds.setUnpack(unpack);
    ds.setScope(Artifact.SCOPE_COMPILE);
    ds.setDirectoryMode(Integer.toString(10, 8));
    ds.setFileMode(Integer.toString(10, 8));
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager, new MavenProject(new Model()));
    final ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
    final File artifactFile = artifactMock.setNewFile();
    if (unpack) {
        macTask.expectAddArchivedFileSet();
    //            macTask.expectModeChange( -1, -1, 10, 10, 2 );
    } else {
        macTask.expectAddFile(artifactFile, outputLocation + "/artifact", 10);
    }
    macTask.expectGetDestFile(new File("junk"));
    macTask.expectCSGetFinalName("final-name");
    macTask.expectCSGetRepositories(null, null);
    final MavenProject depProject = new MavenProject(new Model());
    macTask.expectBuildFromRepository(depProject);
    macTask.expectGetMode(0222, 0222);
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(ds), Collections.singleton(artifactMock.getArtifact()), project, macTask.projectBuilder, logger);
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    task.addDependencySet(ds, macTask.archiver, macTask.configSource);
    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) File(java.io.File) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Example 15 with DependencySet

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

the class AddDependencySetsTaskTest method testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed.

// TODO: Find a better way of testing the project-stubbing behavior when a ProjectBuildingException takes place.
public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed() throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, IOException {
    final MavenProject project = new MavenProject(new Model());
    final ProjectBuildingException pbe = new ProjectBuildingException("test", "Test error.", new Throwable());
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager, new MavenProject(new Model()));
    final String gid = "org.test";
    final String aid = "test-dep";
    final String version = "2.0-SNAPSHOT";
    final String type = "jar";
    final File file = new File("dep-artifact.jar");
    final ArtifactMock depMock = new ArtifactMock(mockManager, gid, aid, version, type, true);
    depMock.setBaseVersion(version);
    depMock.setFile(file);
    final File destFile = new File("assembly-dep-set.zip");
    macTask.expectGetDestFile(destFile);
    macTask.expectBuildFromRepository(pbe);
    macTask.expectCSGetRepositories(null, null);
    macTask.expectCSGetFinalName("final-name");
    macTask.expectAddFile(file, "out/" + aid + "-" + version + "." + type);
    macTask.expectGetMode(0222, 0222);
    final DependencySet ds = new DependencySet();
    ds.setOutputDirectory("/out");
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(ds), Collections.singleton(depMock.getArtifact()), project, macTask.projectBuilder, logger);
    task.addDependencySet(ds, macTask.archiver, macTask.configSource);
    mockManager.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) 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) File(java.io.File) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Aggregations

DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)21 MavenProject (org.apache.maven.project.MavenProject)16 Model (org.apache.maven.model.Model)11 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)10 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)8 MockAndControlForAddDependencySetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)8 Logger (org.codehaus.plexus.logging.Logger)8 Assembly (org.apache.maven.plugins.assembly.model.Assembly)7 File (java.io.File)6 Artifact (org.apache.maven.artifact.Artifact)6 ModuleSet (org.apache.maven.plugins.assembly.model.ModuleSet)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AddDependencySetsTask (org.apache.maven.plugins.assembly.archive.task.AddDependencySetsTask)2 FileSet (org.apache.maven.plugins.assembly.model.FileSet)2 AssemblyId (org.apache.maven.plugins.assembly.resolved.AssemblyId)2 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)2