Search in sources :

Example 6 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestIncludeExcludeUnpackMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("unpack", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
    mojo = (UnpackMojo) lookupMojo("unpack", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    // mojo.silent = true;
    // it needs to get the archivermanager
    // stubFactory.setUnpackableFile( mojo.getArchiverManager() );
    // i'm using one file repeatedly to archive so I can test the name
    // programmatically.
    stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
    Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
    ArtifactItem item = stubFactory.getArtifactItem(artifact);
    List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
    list.add(item);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
    mojo.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setArtifactItems(list);
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestCopyMojo method setUp.

protected void setUp() throws Exception {
    super.setUp("copy", false, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml");
    mojo = (CopyMojo) lookupMojo("copy", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    mojo.setSilent(true);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    // MavenProject project = mojo.getProject();
    // init classifier things
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File)

Example 8 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestClassifierTypeTranslator method setUp.

protected void setUp() throws Exception {
    super.setUp("classifiertype-translator", false);
    artifactHandlerManager = new DefaultArtifactHandlerManager();
    this.setVariableValueToObject(artifactHandlerManager, "artifactHandlers", new HashMap());
    artifactFactory = new DefaultArtifactFactory();
    this.setVariableValueToObject(artifactFactory, "artifactHandlerManager", artifactHandlerManager);
    artifactRepository = new StubArtifactRepository(null);
    DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory(null, false);
    artifacts = factory.getMixedArtifacts();
    repoManager = lookup(RepositoryManager.class);
    MavenSession session = newMavenSession(new MavenProjectStub());
    buildingRequest = session.getProjectBuildingRequest();
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) HashMap(java.util.HashMap) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Example 9 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestBuildClasspathMojo method testPath.

public void testPath() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml");
    BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo("build-classpath", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
    Artifact artifact = stubFactory.getReleaseArtifact();
    StringBuilder sb = new StringBuilder();
    mojo.setPrefix(null);
    mojo.setStripVersion(false);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals(artifact.getFile().getPath(), sb.toString());
    mojo.setLocalRepoProperty("$M2_REPO");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("$M2_REPO" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setLocalRepoProperty("%M2_REPO%");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("%M2_REPO%" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setLocalRepoProperty("%M2_REPO%");
    sb.setLength(0);
    mojo.setPrependGroupId(true);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("If prefix is null, prependGroupId has no impact ", "%M2_REPO%" + File.separator + DependencyUtil.getFormattedFileName(artifact, false, false), sb.toString());
    mojo.setLocalRepoProperty("");
    mojo.setPrefix("prefix");
    sb.setLength(0);
    mojo.setPrependGroupId(true);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + DependencyUtil.getFormattedFileName(artifact, false, true), sb.toString());
    mojo.setPrependGroupId(false);
    mojo.setLocalRepoProperty("");
    mojo.setPrefix("prefix");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setPrefix("prefix");
    mojo.setStripVersion(true);
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + DependencyUtil.getFormattedFileName(artifact, true), sb.toString());
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with MavenSession

use of org.apache.maven.execution.MavenSession in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReaderTest method setupMockSession.

private MavenSession setupMockSession() {
    MavenSession session = mock(MavenSession.class);
    MavenProject project = mock(MavenProject.class);
    when(session.getProjects()).thenReturn(Arrays.asList(project));
    when(project.getGroupId()).thenReturn("myGroupId");
    when(project.getArtifactId()).thenReturn("myArtifactId");
    when(project.getVersion()).thenReturn("myVersion");
    when(project.getBasedir()).thenReturn(new File("/basedir/"));
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)117 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)19 Properties (java.util.Properties)18 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)11 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6