Search in sources :

Example 1 with ExtOptions

use of org.apache.maven.plugin.doap.options.ExtOptions 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();
}
Also used : MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Contributor(org.apache.maven.model.Contributor) ExtOptions(org.apache.maven.plugin.doap.options.ExtOptions) ASFExtOptions(org.apache.maven.plugin.doap.options.ASFExtOptions) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) URL(java.net.URL)

Example 2 with ExtOptions

use of org.apache.maven.plugin.doap.options.ExtOptions in project maven-plugins by apache.

the class DoapMojo method writeExtensions.

/**
     * Write the extra DOAP extensions.
     *
     * @param writer not null
     * @since 1.1
     */
private void writeExtensions(XMLWriter writer) {
    if (!(extOptions != null && extOptions.length > 0 && !extOptions[0].getExtensions().isEmpty())) {
        return;
    }
    for (ExtOptions extOption : extOptions) {
        Map<Object, String> map = extOption.getExtensions();
        writeExtra(writer, project, "Other extension vocabulary.", map, extOption.getXmlnsPrefix());
    }
}
Also used : ExtOptions(org.apache.maven.plugin.doap.options.ExtOptions) ASFExtOptions(org.apache.maven.plugin.doap.options.ASFExtOptions)

Aggregations

ASFExtOptions (org.apache.maven.plugin.doap.options.ASFExtOptions)2 ExtOptions (org.apache.maven.plugin.doap.options.ExtOptions)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Contributor (org.apache.maven.model.Contributor)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 PrettyPrintXMLWriter (org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)1 XMLWriter (org.codehaus.plexus.util.xml.XMLWriter)1