use of org.apache.maven.model.Contributor in project maven-plugins by apache.
the class DoapMojo method doWrite.
private void doWrite(MavenProject project, File outputFile, Writer w) throws MojoExecutionException {
if (asfExtOptions.isIncluded()) {
getLog().info("Generating an ASF DOAP file " + outputFile.getAbsolutePath());
} else {
getLog().info("Generating a pure DOAP file " + outputFile.getAbsolutePath());
}
XMLWriter writer = new PrettyPrintXMLWriter(w, project.getModel().getModelEncoding(), null);
// ----------------------------------------------------------------------------
// Convert POM to DOAP
// ----------------------------------------------------------------------------
DoapUtil.writeHeader(writer);
// Heading
DoapUtil.writeStartElement(writer, "rdf", "RDF");
if (Arrays.binarySearch(Locale.getISOLanguages(), lang) < 0) {
messages.addMessage(new String[] { "doapOptions", "lang" }, lang, UserMessages.INVALID_ISO_DATE);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xml:lang", lang);
if (StringUtils.isEmpty(doapOptions.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(doapOptions.getXmlnsPrefix()) ? "" : ":" + doapOptions.getXmlnsPrefix()), doapOptions.getXmlnsNamespaceURI());
writer.addAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
writer.addAttribute("xmlns:foaf", "http://xmlns.com/foaf/0.1/");
if (asfExtOptions.isIncluded()) {
if (StringUtils.isEmpty(asfExtOptions.getXmlnsPrefix())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsPrefix" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
if (StringUtils.isEmpty(asfExtOptions.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(asfExtOptions.getXmlnsPrefix()) ? "" : ":" + asfExtOptions.getXmlnsPrefix()), asfExtOptions.getXmlnsNamespaceURI());
}
if (extOptions != null && extOptions.length > 0 && !extOptions[0].getExtensions().isEmpty()) {
for (ExtOptions extOption : extOptions) {
if (StringUtils.isEmpty(extOption.getXmlnsPrefix())) {
messages.addMessage(new String[] { "extOptions", "extOption", "xmlnsPrefix" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
if (StringUtils.isEmpty(extOption.getXmlnsNamespaceURI())) {
messages.addMessage(new String[] { "extOptions", "extOption", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED);
throw new MojoExecutionException(messages.getErrorMessages().get(0));
}
writer.addAttribute("xmlns" + (StringUtils.isEmpty(extOption.getXmlnsPrefix()) ? "" : ":" + extOption.getXmlnsPrefix()), extOption.getXmlnsNamespaceURI());
}
}
// Project
DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), "Project");
boolean added = false;
if (artifact != null) {
String about = project.getUrl();
if (StringUtils.isNotEmpty(about)) {
try {
new URL(about);
writer.addAttribute("rdf:about", about);
added = true;
} catch (MalformedURLException e) {
// ignore
}
}
if (!added) {
messages.getWarnMessages().add("The project's url defined from " + artifact.toConfiguration() + " is empty or not a valid URL, using <about/> parameter.");
}
}
if (!added) {
if (StringUtils.isNotEmpty(about)) {
try {
new URL(about);
writer.addAttribute("rdf:about", about);
} catch (MalformedURLException e) {
messages.addMessage(new String[] { "about" }, about, UserMessages.INVALID_URL);
}
added = true;
}
}
if (!added) {
messages.addMessage(new String[] { "about" }, null, UserMessages.RECOMMENDED);
}
// name
writeName(writer, project);
// description
writeDescription(writer, project);
// implements
writeImplements(writer);
// Audience
writeAudience(writer);
// Vendor
writeVendor(writer, project);
// created
writeCreated(writer, project);
// homepage and old-homepage
writeHomepage(writer, project);
// Blog
writeBlog(writer);
// licenses
writeLicenses(writer, project);
// programming-language
writeProgrammingLanguage(writer, project);
// category
writeCategory(writer, project);
// os
writeOS(writer, project);
// Plateform
writePlateform(writer);
// Language
writeLanguage(writer);
// SCM
writeSourceRepositories(writer, project);
// bug-database
writeBugDatabase(writer, project);
// mailing list
writeMailingList(writer, project);
// download-page and download-mirror
writeDownloadPage(writer, project);
// screenshots
writeScreenshots(writer, project);
// service-endpoint
writeServiceEndpoint(writer);
// wiki
writeWiki(writer, project);
// Releases
writeReleases(writer, project);
// Developers
List<Contributor> developers = project.getDevelopers();
writeContributors(writer, developers);
// Contributors
List<Contributor> contributors = project.getContributors();
writeContributors(writer, contributors);
// Extra DOAP
Map<Object, String> map = doapOptions.getExtra();
writeExtra(writer, project, "Extra DOAP vocabulary.", map, doapOptions.getXmlnsPrefix());
// ASFext
writeASFext(writer, project);
// Extra extensions
writeExtensions(writer);
// Project
writer.endElement();
writeOrganizations(writer);
// rdf:RDF
writer.endElement();
}
use of org.apache.maven.model.Contributor in project maven-plugins by apache.
the class MavenJDOMWriter method iterateContributor.
// -- void insertAtPreferredLocation(Element, Element, Counter)
/**
* Method iterateContributor
*
* @param counter
* @param childTag
* @param parentTag
* @param list
* @param parent
*/
protected void iterateContributor(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
boolean shouldExist = list != null && list.size() > 0;
Element element = updateElement(counter, parent, parentTag, shouldExist);
if (shouldExist) {
Iterator it = list.iterator();
Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
if (!elIt.hasNext()) {
elIt = null;
}
Counter innerCount = new Counter(counter.getDepth() + 1);
while (it.hasNext()) {
Contributor value = (Contributor) it.next();
Element el;
if (elIt != null && elIt.hasNext()) {
el = (Element) elIt.next();
if (!elIt.hasNext()) {
elIt = null;
}
} else {
el = factory.element(childTag, element.getNamespace());
insertAtPreferredLocation(element, el, innerCount);
}
updateContributor(value, childTag, innerCount, el);
innerCount.increaseCount();
}
if (elIt != null) {
while (elIt.hasNext()) {
elIt.next();
elIt.remove();
}
}
}
}
use of org.apache.maven.model.Contributor in project buck by facebook.
the class Pom method merge.
private Model merge(Model first, @Nullable Model second) {
if (second == null) {
return first;
}
Model model = first.clone();
//---- Values from ModelBase
List<String> modules = second.getModules();
if (modules != null) {
for (String module : modules) {
model.addModule(module);
}
}
DistributionManagement distributionManagement = second.getDistributionManagement();
if (distributionManagement != null) {
model.setDistributionManagement(distributionManagement);
}
Properties properties = second.getProperties();
if (properties != null) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
model.addProperty((String) entry.getKey(), (String) entry.getValue());
}
}
DependencyManagement dependencyManagement = second.getDependencyManagement();
if (dependencyManagement != null) {
model.setDependencyManagement(dependencyManagement);
}
List<Dependency> dependencies = second.getDependencies();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
model.addDependency(dependency);
}
}
List<Repository> repositories = second.getRepositories();
if (repositories != null) {
for (Repository repository : repositories) {
model.addRepository(repository);
}
}
List<Repository> pluginRepositories = second.getPluginRepositories();
if (pluginRepositories != null) {
for (Repository pluginRepository : pluginRepositories) {
model.addPluginRepository(pluginRepository);
}
}
// Ignore reports, reporting, and locations
//----- From Model
Parent parent = second.getParent();
if (parent != null) {
model.setParent(parent);
}
Organization organization = second.getOrganization();
if (organization != null) {
model.setOrganization(organization);
}
List<License> licenses = second.getLicenses();
Set<String> currentLicenseUrls = new HashSet<>();
if (model.getLicenses() != null) {
for (License license : model.getLicenses()) {
currentLicenseUrls.add(license.getUrl());
}
}
if (licenses != null) {
for (License license : licenses) {
if (!currentLicenseUrls.contains(license.getUrl())) {
model.addLicense(license);
currentLicenseUrls.add(license.getUrl());
}
}
}
List<Developer> developers = second.getDevelopers();
Set<String> currentDevelopers = new HashSet<>();
if (model.getDevelopers() != null) {
for (Developer developer : model.getDevelopers()) {
currentDevelopers.add(developer.getName());
}
}
if (developers != null) {
for (Developer developer : developers) {
if (!currentDevelopers.contains(developer.getName())) {
model.addDeveloper(developer);
currentDevelopers.add(developer.getName());
}
}
}
List<Contributor> contributors = second.getContributors();
Set<String> currentContributors = new HashSet<>();
if (model.getContributors() != null) {
for (Contributor contributor : model.getContributors()) {
currentDevelopers.add(contributor.getName());
}
}
if (contributors != null) {
for (Contributor contributor : contributors) {
if (!currentContributors.contains(contributor.getName())) {
model.addContributor(contributor);
currentContributors.add(contributor.getName());
}
}
}
List<MailingList> mailingLists = second.getMailingLists();
if (mailingLists != null) {
for (MailingList mailingList : mailingLists) {
model.addMailingList(mailingList);
}
}
Prerequisites prerequisites = second.getPrerequisites();
if (prerequisites != null) {
model.setPrerequisites(prerequisites);
}
Scm scm = second.getScm();
if (scm != null) {
model.setScm(scm);
}
String url = second.getUrl();
if (url != null) {
model.setUrl(url);
}
String description = second.getDescription();
if (description != null) {
model.setDescription(description);
}
IssueManagement issueManagement = second.getIssueManagement();
if (issueManagement != null) {
model.setIssueManagement(issueManagement);
}
CiManagement ciManagement = second.getCiManagement();
if (ciManagement != null) {
model.setCiManagement(ciManagement);
}
Build build = second.getBuild();
if (build != null) {
model.setBuild(build);
}
List<Profile> profiles = second.getProfiles();
Set<String> currentProfileIds = new HashSet<>();
if (model.getProfiles() != null) {
for (Profile profile : model.getProfiles()) {
currentProfileIds.add(profile.getId());
}
}
if (profiles != null) {
for (Profile profile : profiles) {
if (!currentProfileIds.contains(profile.getId())) {
model.addProfile(profile);
currentProfileIds.add(profile.getId());
}
}
}
return model;
}
use of org.apache.maven.model.Contributor in project maven-plugins by apache.
the class DoapUtilTest method testDevelopersOrContributorsByDoapRoles.
/**
* Test method for:
* {@link DoapUtil#getContributorsWithDeveloperRole(I18N, List)}
* {@link DoapUtil#getContributorsWithDocumenterRole(I18N, List)}
* {@link DoapUtil#getContributorsWithHelperRole(I18N, List)}
* {@link DoapUtil#getContributorsWithMaintainerRole(I18N, List)}
* {@link DoapUtil#getContributorsWithTesterRole(I18N, List)}
* {@link DoapUtil#getContributorsWithTranslatorRole(I18N, List)}
* {@link DoapUtil#getContributorsWithUnknownRole(I18N, List)}
*
* @throws Exception if any
*/
public void testDevelopersOrContributorsByDoapRoles() throws Exception {
I18N i18n = (I18N) getContainer().lookup(I18N.ROLE);
assertNotNull(i18n);
assertNotNull(i18n.getBundle());
List<Contributor> developersOrContributors = new ArrayList<Contributor>();
// One role
Developer dev = new Developer();
dev.setId("dev1");
dev.addRole("maintainer");
developersOrContributors.add(dev);
assertTrue(DoapUtil.getContributorsWithDeveloperRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithDocumenterRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithHelperRole(i18n, developersOrContributors).isEmpty());
assertFalse(DoapUtil.getContributorsWithMaintainerRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithTesterRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithTranslatorRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithUnknownRole(i18n, developersOrContributors).isEmpty());
// Several roles
developersOrContributors.clear();
dev = new Developer();
dev.setId("dev1");
dev.addRole(" MAINTAINER");
dev.addRole("tesTER ");
dev.addRole("blabla");
dev.addRole("translato r");
developersOrContributors.add(dev);
assertTrue(DoapUtil.getContributorsWithDeveloperRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithDocumenterRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithHelperRole(i18n, developersOrContributors).isEmpty());
assertFalse(DoapUtil.getContributorsWithMaintainerRole(i18n, developersOrContributors).isEmpty());
assertFalse(DoapUtil.getContributorsWithTesterRole(i18n, developersOrContributors).isEmpty());
assertTrue(DoapUtil.getContributorsWithTranslatorRole(i18n, developersOrContributors).isEmpty());
assertFalse(DoapUtil.getContributorsWithUnknownRole(i18n, developersOrContributors).isEmpty());
// Skip emeritus role
developersOrContributors.clear();
dev = new Developer();
dev.setId("dev1");
dev.addRole("maintainer");
dev.addRole("unknown");
developersOrContributors.add(dev);
int sizeBeforeEmeritus = DoapUtil.getContributorsWithUnknownRole(i18n, developersOrContributors).size();
dev.addRole(" Emeritus");
assertTrue(DoapUtil.getContributorsWithUnknownRole(i18n, developersOrContributors).size() == sizeBeforeEmeritus);
}
use of org.apache.maven.model.Contributor in project maven-plugins by apache.
the class DoapUtil method filterContributorsByDoapRoles.
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
* Filter the developers/contributors roles by the keys from {@link I18N#getBundle()}. <br/>
* I18N roles supported in DOAP, i.e. <code>maintainer</code>, <code>developer</code>, <code>documenter</code>,
* <code>translator</code>, <code>tester</code>, <code>helper</code>. <br/>
* <b>Note:</b> Actually, only English keys are used.
*
* @param i18n i18n component
* @param developersOrContributors list of <code>{@link Contributor}</code>
* @return a none null map with <code>maintainers</code>, <code>developers</code>, <code>documenters</code>,
* <code>translators</code>, <code>testers</code>, <code>helpers</code>, <code>unknowns</code> as keys and
* list of <code>{@link Contributor}</code> as value.
*/
private static Map<String, List<Contributor>> filterContributorsByDoapRoles(I18N i18n, List<Contributor> developersOrContributors) {
Map<String, List<Contributor>> returnMap = new HashMap<String, List<Contributor>>(7);
returnMap.put("maintainers", new ArrayList<Contributor>());
returnMap.put("developers", new ArrayList<Contributor>());
returnMap.put("documenters", new ArrayList<Contributor>());
returnMap.put("translators", new ArrayList<Contributor>());
returnMap.put("testers", new ArrayList<Contributor>());
returnMap.put("helpers", new ArrayList<Contributor>());
returnMap.put("unknowns", new ArrayList<Contributor>());
if (developersOrContributors == null || developersOrContributors.isEmpty()) {
return returnMap;
}
for (Contributor contributor : developersOrContributors) {
List<String> roles = contributor.getRoles();
if (roles != null && roles.size() != 0) {
for (String role : roles) {
role = role.toLowerCase(Locale.ENGLISH);
if (role.contains(getLowerCaseString(i18n, "doap.maintainer"))) {
if (!returnMap.get("maintainers").contains(contributor)) {
returnMap.get("maintainers").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.developer"))) {
if (!returnMap.get("developers").contains(contributor)) {
returnMap.get("developers").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.documenter"))) {
if (!returnMap.get("documenters").contains(contributor)) {
returnMap.get("documenters").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.translator"))) {
if (!returnMap.get("translators").contains(contributor)) {
returnMap.get("translators").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.tester"))) {
if (!returnMap.get("testers").contains(contributor)) {
returnMap.get("testers").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.helper"))) {
if (!returnMap.get("helpers").contains(contributor)) {
returnMap.get("helpers").add(contributor);
}
} else if (role.contains(getLowerCaseString(i18n, "doap.emeritus"))) {
// Don't add as developer nor as contributor as the person is no longer involved
} else {
if (!returnMap.get("unknowns").contains(contributor)) {
returnMap.get("unknowns").add(contributor);
}
}
}
} else {
if (!returnMap.get("unknowns").contains(contributor)) {
returnMap.get("unknowns").add(contributor);
}
}
}
return returnMap;
}
Aggregations