Search in sources :

Example 36 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager 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 37 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-plugins by apache.

the class DeployFileMojoTest method testDeployIfClassifierIsSet.

public void testDeployIfClassifierIsSet() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml");
    mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    String classifier = (String) getVariableValueFromObject(mojo, "classifier");
    String groupId = (String) getVariableValueFromObject(mojo, "groupId");
    String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
    String version = (String) getVariableValueFromObject(mojo, "version");
    assertEquals("bin", classifier);
    mojo.execute();
    File deployedArtifact = new File(remoteRepo, "deploy-file-classifier/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-" + classifier + ".jar");
    assertTrue(deployedArtifact.exists());
    mojo.setClassifier("prod");
    assertEquals("prod", mojo.getClassifier());
    mojo.execute();
    File prodDeployedArtifact = new File(remoteRepo, "deploy-file-classifier/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-" + mojo.getClassifier() + ".jar");
    assertTrue(prodDeployedArtifact.exists());
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 38 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-plugins by apache.

the class DeployMojoTest method testUpdateReleaseParamSetToTrue.

public void testUpdateReleaseParamSetToTrue() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml");
    mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    boolean updateReleaseInfo = (Boolean) getVariableValueFromObject(mojo, "updateReleaseInfo");
    assertTrue(updateReleaseInfo);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setFile(testPom);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    repo.setAppendToUrl("basic-deploy-updateReleaseParam");
    mojo.execute();
    assertTrue(artifact.isRelease());
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepositoryStub(org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 39 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-plugins by apache.

the class DeployMojoTest method testDeployWithAttachedArtifacts.

public void testDeployWithAttachedArtifacts() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "plugin-config.xml");
    mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
    artifact.setFile(file);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    repo.setAppendToUrl("basic-deploy-with-attached-artifacts");
    mojo.execute();
    // check the artifacts in remote repository
    List<String> expectedFiles = new ArrayList<String>();
    List<String> fileList = new ArrayList<String>();
    expectedFiles.add("org");
    expectedFiles.add("apache");
    expectedFiles.add("maven");
    expectedFiles.add("test");
    expectedFiles.add("maven-deploy-test");
    expectedFiles.add("1.0-SNAPSHOT");
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.md5");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.sha1");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
    expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
    // as we are in SNAPSHOT the file is here twice
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    expectedFiles.add("attached-artifact-test-0");
    expectedFiles.add("1.0-SNAPSHOT");
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar");
    expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.md5");
    expectedFiles.add("attached-artifact-test-0-1.0-SNAPSHOT.jar.sha1");
    // as we are in SNAPSHOT the file is here twice
    expectedFiles.add("maven-metadata.xml");
    expectedFiles.add("maven-metadata.xml.md5");
    expectedFiles.add("maven-metadata.xml.sha1");
    remoteRepo = new File(remoteRepo, "basic-deploy-with-attached-artifacts");
    File[] files = remoteRepo.listFiles();
    for (File file1 : files) {
        addFileToList(file1, fileList);
    }
    assertEquals(expectedFiles.size(), fileList.size());
    assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepositoryStub(org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub) ArrayList(java.util.ArrayList) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 40 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-plugins by apache.

the class JavadocReportTest method testTaglets.

/**
 * Method to test the taglet artifact configuration
 *
 * @throws Exception if any
 */
public void testTaglets() throws Exception {
    // ----------------------------------------------------------------------
    // taglet-test: check if a taglet is used
    // ----------------------------------------------------------------------
    File testPom = new File(unit, "taglet-test/taglet-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File apidocs = new File(getBasedir(), "target/test/unit/taglet-test/target/site/apidocs");
    assertTrue(new File(apidocs, "index.html").exists());
    File appFile = new File(apidocs, "taglet/test/App.html");
    assertTrue(appFile.exists());
    String appString = readFile(appFile);
    assertTrue(appString.contains("<b>To Do:</b>"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Aggregations

SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)49 File (java.io.File)44 MavenSession (org.apache.maven.execution.MavenSession)30 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)29 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)28 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)20 LegacySupport (org.apache.maven.plugin.LegacySupport)16 MavenProject (org.apache.maven.project.MavenProject)16 Artifact (org.apache.maven.artifact.Artifact)11 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)9 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArrayList (java.util.ArrayList)6 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)6 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)5 Archetype (org.apache.maven.archetype.catalog.Archetype)5 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)5