Search in sources :

Example 66 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AssemblyInterpolatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.

public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    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 Assembly assembly = new Assembly();
    assembly.setId("assembly.${groupId}");
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenSession session = mm.createMock(MavenSession.class);
    final Properties execProps = new Properties();
    execProps.setProperty("groupId", "still.another.id");
    expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final PojoConfigSource cs = new PojoConfigSource();
    final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
    cs.setLocalRepository(lr);
    cs.setMavenSession(session);
    cs.setRootInterpolator(FixedStringSearchInterpolator.create());
    cs.setEnvironmentInterpolator(FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(execProps)));
    cs.setEnvInterpolator(FixedStringSearchInterpolator.empty());
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    mm.replayAll();
    final MavenProject project = new MavenProject(model);
    cs.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, cs);
    assertEquals("assembly.still.another.id", result.getId());
    mm.verifyAll();
    mm.resetAll();
}
Also used : 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) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 67 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AssemblyInterpolatorTest method testShouldNotTouchUnresolvedExpression.

public void testShouldNotTouchUnresolvedExpression() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Assembly assembly = new Assembly();
    assembly.setId("assembly.${unresolved}");
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    final MavenProject project = new MavenProject(model);
    configSourceStub.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, configSourceStub);
    assertEquals("assembly.${unresolved}", result.getId());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 68 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultDependencyResolverTest method test_getRepositoryResolutionRequirements.

public void test_getRepositoryResolutionRequirements() {
    final List<Repository> repositories = new ArrayList<Repository>();
    {
        final Repository r = new Repository();
        r.setScope(Artifact.SCOPE_COMPILE);
        repositories.add(r);
    }
    {
        final Repository r = new Repository();
        r.setScope(Artifact.SCOPE_SYSTEM);
        repositories.add(r);
    }
    final MavenProject project = createMavenProject("group", "artifact", "1.0", null);
    final Assembly assembly = new Assembly();
    assembly.setRepositories(repositories);
    final ResolutionManagementInfo info = new ResolutionManagementInfo(project);
    resolver.updateRepositoryResolutionRequirements(assembly, info);
    assertTrue(info.isResolutionRequired());
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_COMPILE));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_SYSTEM));
    assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_PROVIDED));
    assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_RUNTIME));
    assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_TEST));
}
Also used : ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Repository(org.apache.maven.plugins.assembly.model.Repository) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 69 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class ResolutionManagementInfoTest method testAddSingleArtifactWithReplacemen.

public void testAddSingleArtifactWithReplacemen() throws Exception {
    ResolutionManagementInfo rmi = new ResolutionManagementInfo(new MavenProject());
    Artifact a1 = new DefaultArtifact("groupid", "1", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler());
    rmi.addArtifacts(Collections.singleton(a1));
    Artifact a2 = new DefaultArtifact("groupid", "1", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler());
    rmi.addArtifacts(Collections.singleton(a2));
    assertEquals(1, rmi.getArtifacts().size());
    Artifact next = rmi.getArtifacts().iterator().next();
    assertEquals("compile", next.getScope());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 70 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AssemblyInterpolatorTest method testShouldInterpolateMultiDotProjectExpression.

public void testShouldInterpolateMultiDotProjectExpression() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    final Build build = new Build();
    build.setFinalName("final-name");
    final Model model = new Model();
    model.setBuild(build);
    final Assembly assembly = new Assembly();
    assembly.setId("assembly.${project.build.finalName}");
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    final MavenProject project = new MavenProject(model);
    configSourceStub.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, configSourceStub);
    assertEquals("assembly.final-name", result.getId());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15