Search in sources :

Example 1 with ArtifactRepositoryStub

use of org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub in project maven-plugins by apache.

the class DeployMojoTest method testBasicDeployWithPackagingAsPom.

public void testBasicDeployWithPackagingAsPom() 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);
    File pomFile = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/target/" + "deploy-test-file-1.0-SNAPSHOT.pom");
    assertTrue(pomFile.exists());
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setArtifactHandlerExtension(project.getPackaging());
    artifact.setFile(pomFile);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    repo.setAppendToUrl("basic-deploy-pom");
    mojo.execute();
    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.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");
    remoteRepo = new File(remoteRepo, "basic-deploy-pom");
    File[] files = remoteRepo.listFiles();
    for (File file : files) {
        addFileToList(file, 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 2 with ArtifactRepositoryStub

use of org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub in project maven-plugins by apache.

the class DeployMojoTest method testBasicDeploy.

public void testBasicDeploy() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/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);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
    assertTrue(file.exists());
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    String packaging = project.getPackaging();
    assertEquals("jar", packaging);
    artifact.setFile(file);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    assertNotNull(repo);
    repo.setAppendToUrl("basic-deploy-test");
    assertEquals("deploy-test", repo.getId());
    assertEquals("deploy-test", repo.getKey());
    assertEquals("file", repo.getProtocol());
    assertEquals("file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl());
    mojo.execute();
    //check the artifact in local 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-deploy-test.xml");
    // expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
    // expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
    // as we are in SNAPSHOT the file is here twice
    expectedFiles.add("maven-metadata-deploy-test.xml");
    // extra Aether files
    expectedFiles.add("resolver-status.properties");
    expectedFiles.add("resolver-status.properties");
    File localRepo = new File(LOCAL_REPO, "");
    File[] files = localRepo.listFiles();
    for (File file2 : files) {
        addFileToList(file2, fileList);
    }
    assertEquals(expectedFiles.size(), fileList.size());
    assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
    //check the artifact in remote repository
    expectedFiles = new ArrayList<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");
    remoteRepo = new File(remoteRepo, "basic-deploy-test");
    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 3 with ArtifactRepositoryStub

use of org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub 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 4 with ArtifactRepositoryStub

use of org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub 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 5 with ArtifactRepositoryStub

use of org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub in project maven-plugins by apache.

the class DeployMojoTest method testSkippingDeploy.

public void testSkippingDeploy() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
    DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
    assertNotNull(mojo);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
    assertTrue(file.exists());
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    String packaging = project.getPackaging();
    assertEquals("jar", packaging);
    artifact.setFile(file);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    assertNotNull(repo);
    repo.setAppendToUrl("basic-deploy-test");
    assertEquals("deploy-test", repo.getId());
    assertEquals("deploy-test", repo.getKey());
    assertEquals("file", repo.getProtocol());
    assertEquals("file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl());
    setVariableValueToObject(mojo, "skip", Boolean.TRUE);
    mojo.execute();
    File localRepo = new File(LOCAL_REPO, "");
    File[] files = localRepo.listFiles();
    assertNull(files);
    remoteRepo = new File(remoteRepo, "basic-deploy-test");
    files = remoteRepo.listFiles();
    assertNull(files);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactRepositoryStub(org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub) File(java.io.File)

Aggregations

File (java.io.File)5 ArtifactRepositoryStub (org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub)5 MavenProject (org.apache.maven.project.MavenProject)5 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)4 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)4 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)4 ArrayList (java.util.ArrayList)3