Search in sources :

Example 6 with AssemblerConfigurationSource

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

the class AssemblyFormatUtilsTest method verifyOutputDir.

private void verifyOutputDir(final String outDir, final String finalName, final MavenProject mainProject, final MavenProject moduleProject, final MavenProject artifactProject, final String checkValue) throws AssemblyFormattingException {
    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);
    String result;
    mockManager.replayAll();
    result = AssemblyFormatUtils.getOutputDirectory(outDir, finalName, cs, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
    assertEquals(checkValue, result);
    mockManager.verifyAll();
    mockManager.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties)

Example 7 with AssemblerConfigurationSource

use of org.apache.maven.plugins.assembly.AssemblerConfigurationSource 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)

Example 8 with AssemblerConfigurationSource

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

the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldCreateZipArchiver.

@Test
public void testCreateArchiver_ShouldCreateZipArchiver() throws NoSuchArchiverException, ArchiverException {
    final EasyMockSupport mm = new EasyMockSupport();
    final ZipArchiver archiver = new ZipArchiver();
    final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
    macArchiverManager.expectGetArchiver("zip", archiver);
    final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
    expect(configSource.isDryRun()).andReturn(false).anyTimes();
    expect(configSource.getArchiverConfig()).andReturn(null).anyTimes();
    expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
    expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
    expect(configSource.getJarArchiveConfiguration()).andReturn(null).anyTimes();
    expect(configSource.isIgnorePermissions()).andReturn(true).anyTimes();
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
    subject.createArchiver("zip", false, null, configSource, null, false, null);
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) File(java.io.File) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Example 9 with AssemblerConfigurationSource

use of org.apache.maven.plugins.assembly.AssemblerConfigurationSource 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 10 with AssemblerConfigurationSource

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

the class AssemblyExpressionEvaluatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.

public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws ExpressionEvaluationException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Properties props = new Properties();
    props.setProperty("groupId", "other.id");
    model.setProperties(props);
    final EasyMockSupport mm = new EasyMockSupport();
    MavenSession session = mm.createControl().createMock(MavenSession.class);
    final Properties execProps = new Properties();
    execProps.setProperty("groupId", "still.another.id");
    PropertiesBasedValueSource cliProps = new PropertiesBasedValueSource(execProps);
    expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    AssemblerConfigurationSource cs = mm.createControl().createMock(AssemblerConfigurationSource.class);
    expect(cs.getCommandLinePropsInterpolator()).andReturn(FixedStringSearchInterpolator.create(cliProps)).anyTimes();
    expect(cs.getRepositoryInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
    expect(cs.getEnvInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    expect(cs.getProject()).andReturn(new MavenProject(model));
    final IMocksControl lrCtl = mm.createControl();
    final ArtifactRepository lr = lrCtl.createMock(ArtifactRepository.class);
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    expect(cs.getLocalRepository()).andReturn(lr).anyTimes();
    mm.replayAll();
    final Object result = new AssemblyExpressionEvaluator(cs).evaluate("assembly.${groupId}");
    assertEquals("assembly.still.another.id", result);
    mm.verifyAll();
}
Also used : IMocksControl(org.easymock.classextension.IMocksControl) MavenSession(org.apache.maven.execution.MavenSession) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Aggregations

AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)11 EasyMockSupport (org.easymock.classextension.EasyMockSupport)8 Test (org.junit.Test)6 File (java.io.File)4 Properties (java.util.Properties)4 MavenSession (org.apache.maven.execution.MavenSession)4 MavenProject (org.apache.maven.project.MavenProject)4 AssemblyArchiverPhase (org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)3 Assembly (org.apache.maven.plugins.assembly.model.Assembly)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 Model (org.apache.maven.model.Model)2 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)1 ModuleBinaries (org.apache.maven.plugins.assembly.model.ModuleBinaries)1 ModuleSet (org.apache.maven.plugins.assembly.model.ModuleSet)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)1 ZipArchiver (org.codehaus.plexus.archiver.zip.ZipArchiver)1