Search in sources :

Example 46 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DeployMojoTest method testDeployIfArtifactFileIsNull.

public void testDeployIfArtifactFileIsNull() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
    DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    setVariableValueToObject(mojo, "session", session);
    assertNotNull(mojo);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setFile(null);
    assertNull(artifact.getFile());
    try {
        mojo.execute();
        fail("Did not throw mojo execution exception");
    } catch (MojoExecutionException e) {
    //expected
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 47 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DeployMojoTest method _testBasicDeployWithScpAsProtocol.

@Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.")
public void _testBasicDeployWithScpAsProtocol() throws Exception {
    String originalUserHome = System.getProperty("user.home");
    // FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
    File altHome = new File(getBasedir(), "target/ssh-user-home");
    altHome.mkdirs();
    System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath());
    Properties props = System.getProperties();
    props.setProperty("user.home", altHome.getCanonicalPath());
    System.setProperties(props);
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml");
    mojo = (DeployMojo) lookupMojo("deploy", testPom);
    assertNotNull(mojo);
    ArtifactDeployerStub deployer = new ArtifactDeployerStub();
    setVariableValueToObject(mojo, "deployer", deployer);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/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();
    artifact.setFile(file);
    String altUserHome = System.getProperty("user.home");
    if (altUserHome.equals(originalUserHome)) {
        // this is *very* bad!
        throw new IllegalStateException("Setting 'user.home' system property to alternate value did NOT work. Aborting test.");
    }
    File sshFile = new File(altUserHome, ".ssh");
    System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());
    //delete first the .ssh folder if existing before executing the mojo
    if (sshFile.exists()) {
        FileUtils.deleteDirectory(sshFile);
    }
    mojo.execute();
    assertTrue(sshFile.exists());
    FileUtils.deleteDirectory(sshFile);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Properties(java.util.Properties) File(java.io.File) ArtifactDeployerStub(org.apache.maven.plugins.deploy.stubs.ArtifactDeployerStub) Ignore(org.junit.Ignore)

Example 48 with MavenProject

use of org.apache.maven.project.MavenProject 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 49 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DoapMojo method execute.

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
     * {@inheritDoc}
     */
public void execute() throws MojoExecutionException {
    if (skip) {
        getLog().info("Skipping DOAP generation");
        return;
    }
    // single artifact
    if (artifact != null) {
        MavenProject givenProject = getMavenProject(artifact);
        if (givenProject != null) {
            File outDir = new File(outputDirectory);
            if (!outDir.isAbsolute()) {
                outDir = new File(project.getBasedir(), outputDirectory);
            }
            File outFile = new File(outDir, artifact.getDoapFileName());
            writeDoapFile(givenProject, outFile);
            return;
        }
    }
    // current project
    File outFile = new File(doapFile);
    if (!outFile.isAbsolute()) {
        outFile = new File(project.getBasedir(), doapFile);
    }
    if (!doapFile.replaceAll("\\\\", "/").contains("/")) {
        File outDir = new File(outputDirectory);
        if (!outDir.isAbsolute()) {
            outDir = new File(project.getBasedir(), outputDirectory);
        }
        outFile = new File(outDir, doapFile);
    }
    writeDoapFile(project, outFile);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) File(java.io.File)

Example 50 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DoapMojoTest method testGeneratedDoapArtifactMinimalist.

/**
     * Verify the generation of a DOAP file from a minimalist artifact.
     *
     * @throws Exception if any
     */
public void testGeneratedDoapArtifactMinimalist() throws Exception {
    File pluginXmlFile = new File(getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml");
    DoapMojo mojo = (DoapMojo) lookupMojo("generate", pluginXmlFile);
    assertNotNull("Mojo found.", mojo);
    MavenProject mavenProject = (MavenProject) getVariableValueFromObject(mojo, "project");
    assertNotNull(mavenProject);
    // Set some Mojo parameters
    setVariableValueToObject(mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories());
    setVariableValueToObject(mojo, "about", "foo");
    DoapOptions doapOptions = new DoapOptions();
    doapOptions.setName("XStream");
    doapOptions.setDescription("XStream is a simple library to serialize objects to XML and back again.");
    doapOptions.setShortdesc("XML Serializer");
    doapOptions.setHomepage("http://xstream.codehaus.org/");
    doapOptions.setDownloadPage("http://xstream.codehaus.org/download.html");
    doapOptions.setBugDatabase("http://jira.codehaus.org/browse/XSTR");
    doapOptions.setLicense("http://xstream.codehaus.org/license.html");
    doapOptions.setScmDeveloper("http://svn.codehaus.org/xstream/trunk/xstream");
    doapOptions.setMailingList("http://xstream.codehaus.org/list-user.html");
    doapOptions.setCreated("2000-01-01");
    setVariableValueToObject(mojo, "doapOptions", doapOptions);
    DoapArtifact artifact = new DoapArtifact();
    artifact.setGroupId("xstream");
    artifact.setArtifactId("xstream");
    artifact.setVersion("1.1");
    setVariableValueToObject(mojo, "artifact", artifact);
    setVariableValueToObject(mojo, "outputDirectory", "target/test/unit/doap-configuration/");
    mojo.execute();
    File doapFile = new File(getBasedir(), "target/test/unit/doap-configuration/doap_xstream.rdf");
    assertTrue("Doap File was not generated!", doapFile.exists());
    String readed = readFile(doapFile);
    // Validate
    // Pure DOAP
    assertTrue(readed.contains("<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" " + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">"));
    assertTrue(readed.contains("<Project>"));
    assertTrue(readed.contains("<name>XStream</name>"));
    assertTrue(readed.contains("<description xml:lang=\"en\">XStream is a simple library to serialize objects to XML and back again.</description>"));
    assertTrue(readed.contains("<shortdesc xml:lang=\"en\">XML Serializer</shortdesc>"));
    assertTrue(readed.contains("<created>2000-01-01</created>"));
    assertTrue(readed.contains("<download-page rdf:resource=\"http://xstream.codehaus.org/download.html\"/>"));
    assertTrue(readed.contains("<programming-language>Java</programming-language>"));
    assertTrue(readed.contains("<bug-database rdf:resource=\"http://jira.codehaus.org/browse/XSTR\"/>"));
    assertTrue(readed.contains("<license rdf:resource=\"http://xstream.codehaus.org/license.html\"/>"));
    assertTrue(readed.contains("<Repository>"));
    assertTrue(readed.contains("<location rdf:resource=\"http://svn.codehaus.org/xstream/trunk/xstream\"/>"));
    assertTrue(readed.contains("<mailing-list rdf:resource=\"http://xstream.codehaus.org/list-user.html\"/>"));
    // conf
    assertFalse(readed.contains("<audience>"));
    assertFalse(readed.contains("<blog rdf:resource="));
    assertFalse(readed.contains("<implements>"));
    assertFalse(readed.contains("<language>"));
    assertFalse(readed.contains("<old-homepage rdf:resource="));
    assertFalse(readed.contains("<os>"));
    assertFalse(readed.contains("<platform>"));
    assertFalse(readed.contains("<screenshots rdf:resource="));
    assertFalse(readed.contains("<service-endpoint rdf:resource="));
    assertFalse(readed.contains("<wiki rdf:resource="));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DoapArtifact(org.apache.maven.plugin.doap.options.DoapArtifact) DoapOptions(org.apache.maven.plugin.doap.options.DoapOptions) File(java.io.File)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15