Search in sources :

Example 11 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.

the class TestGetMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("markers", false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
    assert testPom.exists();
    mojo = (GetMojo) lookupMojo("get", testPom);
    assertNotNull(mojo);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(newMavenSession(new MavenProjectStub()));
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
    setVariableValueToObject(mojo, "session", legacySupport.getSession());
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File)

Example 12 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.

the class TestUnpackMojo method setUp.

protected void setUp() throws Exception {
    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.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setSilent(true);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    // MavenProject project = mojo.getProject();
    // init classifier things
    // 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 + "target/test-classes/unit/unpack-dependencies-test/test.txt"));
    mojo.setUseJvmChmod(true);
    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 13 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins 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 14 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins 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 15 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.

the class TestCopyDependenciesMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("copy-dependencies", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
    mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
    mojo.outputDirectory = new File(this.testDir, "outputDirectory");
    // mojo.silent = true;
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    MavenSession session = newMavenSession(project);
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.markersDirectory = new File(this.testDir, "markers");
    ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
    setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)17 File (java.io.File)13 MavenSession (org.apache.maven.execution.MavenSession)11 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)10 Artifact (org.apache.maven.artifact.Artifact)6 MavenProject (org.apache.maven.project.MavenProject)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 ArtifactHandlerManager (org.apache.maven.artifact.handler.manager.ArtifactHandlerManager)2 LegacySupport (org.apache.maven.plugin.LegacySupport)2 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)2 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)2 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)2 Dependency (org.sonatype.aether.graph.Dependency)2 EnhancedLocalRepositoryManager (org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager)2 THashSet (gnu.trove.THashSet)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1