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>"));
}
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");
}
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\"/>"));
}
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;
}
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;
}
Aggregations