Search in sources :

Example 51 with MavenProject

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

the class DoapMojoTest method testGeneratedExtraDoap.

/**
     * Verify the generation of a DOAP file with extra extension.
     *
     * @throws Exception if any
     */
public void testGeneratedExtraDoap() throws Exception {
    File pluginXmlFile = new File(getBasedir(), "src/test/resources/unit/doap-configuration/doap-extra-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", mavenProject.getUrl());
    mojo.execute();
    File doapFile = new File(getBasedir(), "target/test/unit/doap-configuration/doap-extra-configuration.rdf");
    assertTrue("Doap File was not generated!", doapFile.exists());
    String readed = readFile(doapFile);
    assertTrue(readed.contains("<ciManagement rdf:resource=\"http://ci.foo.org\"/>"));
    assertTrue(readed.contains("<asfext:status>active</asfext:status>"));
    assertTrue(readed.contains("<labs:status>active</labs:status>"));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) File(java.io.File)

Example 52 with MavenProject

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

the class DoapUtilTest method testInterpolate.

/**
     * Test method for:
     * {@link DoapUtil#interpolate(String, MavenProject, org.apache.maven.settings.Settings)}
     *
     * @throws Exception if any
     */
public void testInterpolate() throws Exception {
    License license = new License();
    license.setName("licenseName");
    license.setUrl("licenseUrl");
    List<Developer> developers = new ArrayList<Developer>();
    Developer developer1 = new Developer();
    developer1.setId("id1");
    developer1.setName("developerName1");
    developers.add(developer1);
    Developer developer2 = new Developer();
    developer2.setId("id1");
    developer2.setName("developerName2");
    developers.add(developer2);
    MavenProject project = new MavenProject();
    project.setName("projectName");
    project.setDescription("projectDescription");
    project.setLicenses(Collections.singletonList(license));
    project.setDevelopers(developers);
    project.getProperties().put("myKey", "myValue");
    assertEquals(DoapUtil.interpolate("${project.name}", project, null), "projectName");
    assertEquals(DoapUtil.interpolate("my name is ${project.name}", project, null), "my name is projectName");
    assertEquals(DoapUtil.interpolate("my name is ${project.invalid}", project, null), "my name is ${project.invalid}");
    assertEquals(DoapUtil.interpolate("${pom.description}", project, null), "projectDescription");
    assertNull(DoapUtil.interpolate("${project.licenses.name}", project, null));
    assertEquals(DoapUtil.interpolate("${project.licenses[0].name}", project, null), "licenseName");
    assertNull(DoapUtil.interpolate("${project.licenses[1].name}", project, null));
    assertNotNull(DoapUtil.interpolate("${project.developers}", project, null));
    assertEquals(DoapUtil.interpolate("${project.developers[0].name}", project, null), "developerName1");
    assertEquals(DoapUtil.interpolate("${project.developers[1].name}", project, null), "developerName2");
    assertEquals(DoapUtil.interpolate("${myKey}", project, null), "myValue");
}
Also used : MavenProject(org.apache.maven.project.MavenProject) License(org.apache.maven.model.License) ArrayList(java.util.ArrayList) Developer(org.apache.maven.model.Developer)

Example 53 with MavenProject

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

the class DoapMojoTest method testGeneratedDoapArtifact.

/**
     * Verify the generation of a DOAP file from an artifact.
     *
     * @throws Exception if any
     */
public void testGeneratedDoapArtifact() 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", mavenProject.getUrl());
    DoapOptions doapOptions = (DoapOptions) getVariableValueFromObject(mojo, "doapOptions");
    doapOptions.setDescription("Common Utilities");
    doapOptions.setShortdesc("Common Utilities");
    doapOptions.setDownloadPage("http://plexus.codehaus.org/download-binaries.html");
    setVariableValueToObject(mojo, "doapOptions", doapOptions);
    DoapArtifact artifact = new DoapArtifact();
    artifact.setGroupId("org.codehaus.plexus");
    artifact.setArtifactId("plexus-utils");
    artifact.setVersion("1.5.5");
    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_plexus-utils.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 rdf:about=\"http://plexus.codehaus.org/plexus-utils\">"));
    assertTrue(readed.contains("<name>Plexus Common Utilities</name>"));
    assertTrue(readed.contains("<description xml:lang=\"en\">Common Utilities</description>"));
    assertTrue(readed.contains("<shortdesc xml:lang=\"en\">Common Utilities</shortdesc>"));
    assertTrue(readed.contains("<created>2001-01-01</created>"));
    assertTrue(readed.contains("<download-page rdf:resource=\"http://plexus.codehaus.org/download-binaries.html\"/>"));
    assertTrue(readed.contains("<programming-language>Java</programming-language>"));
    assertTrue(readed.contains("<bug-database rdf:resource=\"http://jira.codehaus.org/browse/PLXUTILS\"/>"));
    assertTrue(readed.contains("<license rdf:resource=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"/>"));
    assertTrue(readed.contains("<SVNRepository>"));
    assertTrue(readed.contains("<location rdf:resource=\"http://svn.codehaus.org/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>"));
    assertTrue(readed.contains("<browse rdf:resource=\"http://fisheye.codehaus.org/browse/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>"));
    // conf
    assertTrue(readed.contains("<audience>developers</audience>"));
    assertTrue(readed.contains("<blog rdf:resource=\"http://myblog.foo.org\"/>"));
    assertTrue(readed.contains("<implements>JSR-foo</implements>"));
    assertTrue(readed.contains("<language>en</language>"));
    assertTrue(readed.contains("<language>fr</language>"));
    assertTrue(readed.contains("<old-homepage rdf:resource=\"http://old.foo.org\"/>"));
    assertTrue(readed.contains("<os>windows</os>"));
    assertTrue(readed.contains("<os>linux</os>"));
    assertTrue(readed.contains("<os>mac</os>"));
    assertTrue(readed.contains("<platform>java</platform>"));
    assertTrue(readed.contains("<screenshots rdf:resource=\"http://plexus.codehaus.org/plexus-utils/screenshots.html\"/>"));
    assertTrue(readed.contains("<service-endpoint rdf:resource=\"http://webservice.foo.org\"/>"));
    assertTrue(readed.contains("<wiki rdf:resource=\"http://wiki.foo.org\"/>"));
}
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)

Example 54 with MavenProject

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

the class JLinkMojo method findDependencyInProjects.

private MavenProject findDependencyInProjects(Dependency dep) {
    List<MavenProject> sortedProjects = getSession().getProjectDependencyGraph().getSortedProjects();
    MavenProject result = null;
    for (MavenProject mavenProject : sortedProjects) {
        if (dep.getGroupId().equals(mavenProject.getGroupId()) && dep.getArtifactId().equals(mavenProject.getArtifactId()) && dep.getVersion().equals(mavenProject.getVersion())) {
            result = mavenProject;
        }
    }
    return result;
}
Also used : MavenProject(org.apache.maven.project.MavenProject)

Example 55 with MavenProject

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

the class PdfMojo method isValidGeneratedReport.

/**
     * Parsing the generated report to see if it is correct or not. Log the error for the user.
     *
     * @param mojoDescriptor not null
     * @param generatedReport not null
     * @param localReportName not null
     * @return <code>true</code> if Doxia is able to parse the generated report, <code>false</code> otherwise.
     * @since 1.1
     */
private boolean isValidGeneratedReport(Artifact pluginArtifact, File generatedReport, String localReportName) {
    SinkAdapter sinkAdapter = new SinkAdapter();
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(generatedReport);
        doxia.parse(reader, generatedReport.getParentFile().getName(), sinkAdapter);
        reader.close();
        reader = null;
    } catch (ParseException e) {
        StringBuilder sb = new StringBuilder(1024);
        sb.append(EOL).append(EOL);
        sb.append("Error when parsing the generated report: ").append(generatedReport.getAbsolutePath());
        sb.append(EOL);
        sb.append(e.getMessage());
        sb.append(EOL).append(EOL);
        sb.append("You could:").append(EOL);
        sb.append("  * exclude all reports using -DincludeReports=false").append(EOL);
        sb.append("  * remove the ");
        sb.append(pluginArtifact.getGroupId());
        sb.append(":");
        sb.append(pluginArtifact.getArtifactId());
        sb.append(":");
        sb.append(pluginArtifact.getVersion());
        sb.append(" from the <reporting/> part. To not affect the site generation, ");
        sb.append("you could create a PDF profile.").append(EOL);
        sb.append(EOL);
        MavenProject pluginProject = getReportPluginProject(pluginArtifact);
        if (pluginProject == null) {
            sb.append("You could also contact the Plugin team.").append(EOL);
        } else {
            sb.append("You could also contact the Plugin team:").append(EOL);
            if (pluginProject.getMailingLists() != null && !pluginProject.getMailingLists().isEmpty()) {
                boolean appended = false;
                for (Object o : pluginProject.getMailingLists()) {
                    MailingList mailingList = (MailingList) o;
                    if (StringUtils.isNotEmpty(mailingList.getName()) && StringUtils.isNotEmpty(mailingList.getPost())) {
                        if (!appended) {
                            sb.append("  Mailing Lists:").append(EOL);
                            appended = true;
                        }
                        sb.append("    ").append(mailingList.getName());
                        sb.append(": ").append(mailingList.getPost());
                        sb.append(EOL);
                    }
                }
            }
            if (StringUtils.isNotEmpty(pluginProject.getUrl())) {
                sb.append("  Web Site:").append(EOL);
                sb.append("    ").append(pluginProject.getUrl());
                sb.append(EOL);
            }
            if (pluginProject.getIssueManagement() != null && StringUtils.isNotEmpty(pluginProject.getIssueManagement().getUrl())) {
                sb.append("  Issue Tracking:").append(EOL);
                sb.append("    ").append(pluginProject.getIssueManagement().getUrl());
                sb.append(EOL);
            }
        }
        sb.append(EOL).append("Ignoring the \"").append(localReportName).append("\" report in the PDF.").append(EOL);
        getLog().error(sb.toString());
        getLog().debug(e);
        return false;
    } catch (ParserNotFoundException e) {
        getLog().error("ParserNotFoundException: " + e.getMessage());
        getLog().debug(e);
        return false;
    } catch (IOException e) {
        getLog().error("IOException: " + e.getMessage());
        getLog().debug(e);
        return false;
    } finally {
        IOUtil.close(reader);
    }
    return true;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ParserNotFoundException(org.apache.maven.doxia.parser.manager.ParserNotFoundException) MailingList(org.apache.maven.model.MailingList) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) Reader(java.io.Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) StringReader(java.io.StringReader) ParseException(org.apache.maven.doxia.parser.ParseException) IOException(java.io.IOException) SinkAdapter(org.apache.maven.doxia.sink.impl.SinkAdapter)

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