Search in sources :

Example 96 with MavenSession

use of org.apache.maven.execution.MavenSession 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 97 with MavenSession

use of org.apache.maven.execution.MavenSession 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)

Example 98 with MavenSession

use of org.apache.maven.execution.MavenSession 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 99 with MavenSession

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

the class InstallMojoTest method createMavenSession.

private MavenSession createMavenSession() {
    MavenSession session = mock(MavenSession.class);
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManager(new File(LOCAL_REPO)));
    ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
    buildingRequest.setRepositorySession(repositorySession);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) EnhancedLocalRepositoryManager(org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 100 with MavenSession

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

the class InstallMojoTest method testBasicInstallAndCreateChecksumIsTrue.

public void testBasicInstallAndCreateChecksumIsTrue() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    MavenSession mavenSession = createMavenSession();
    updateMavenProject(project);
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    setVariableValueToObject(mojo, "session", mavenSession);
    artifact = (InstallArtifactStub) project.getArtifact();
    boolean createChecksum = (Boolean) getVariableValueFromObject(mojo, "createChecksum");
    assertTrue(createChecksum);
    artifact.setFile(file);
    mojo.execute();
    ArtifactMetadata metadata = null;
    for (Object o : artifact.getMetadataList()) {
        metadata = (ArtifactMetadata) o;
        if (metadata.getRemoteFilename().endsWith("pom")) {
            break;
        }
    }
    RepositoryManager repoManager = (RepositoryManager) getVariableValueFromObject(mojo, "repositoryManager");
    ProjectBuildingRequest pbr = mavenSession.getProjectBuildingRequest();
    File pom = new File(repoManager.getLocalRepositoryBasedir(pbr), repoManager.getPathForLocalMetadata(pbr, metadata));
    assertTrue(pom.exists());
    String groupId = dotToSlashReplacer(artifact.getGroupId());
    String packaging = project.getPackaging();
    String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
    // get the actual checksum of the pom
    Map<String, Object> csums = ChecksumUtils.calc(pom, Utils.CHECKSUM_ALGORITHMS);
    for (Map.Entry<String, Object> csum : csums.entrySet()) {
        Object actualPomSum = csum.getValue();
        File pomSum = new File(localPath + ".pom." + csum.getKey().toLowerCase().replace("-", ""));
        assertTrue(pomSum.exists());
        String generatedPomSum = FileUtils.fileRead(pomSum, "UTF-8");
        assertEquals(actualPomSum, generatedPomSum);
    }
    // get the actual checksum of the artifact
    csums = ChecksumUtils.calc(file, Utils.CHECKSUM_ALGORITHMS);
    for (Map.Entry<String, Object> csum : csums.entrySet()) {
        Object actualSum = csum.getValue();
        File sum = new File(localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace("-", ""));
        assertTrue(sum.exists());
        String generatedSum = FileUtils.fileRead(sum, "UTF-8");
        assertEquals(actualSum, generatedSum);
    }
    File installedArtifact = new File(localPath + "." + packaging);
    assertTrue(installedArtifact.exists());
    assertEquals(9, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) EnhancedLocalRepositoryManager(org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) File(java.io.File) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Map(java.util.Map)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)118 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)20 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 Properties (java.util.Properties)17 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)12 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