Search in sources :

Example 16 with XMLWriter

use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.

the class ApplicationXmlWriter method initializeRootElementFive.

private XMLWriter initializeRootElementFive(Writer w) {
    XMLWriter writer = initializeXmlWriter(w, null);
    writer.startElement(APPLICATION_ELEMENT);
    writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
    writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    writer.addAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd");
    writer.addAttribute("version", "5");
    return writer;
}
Also used : XMLWriter(org.codehaus.plexus.util.xml.XMLWriter)

Example 17 with XMLWriter

use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.

the class JbossAppXmlWriter method write.

public void write(File destinationFile, JbossConfiguration jbossConfiguration, List<EarModule> earModules) throws EarPluginException {
    final Writer w = initializeWriter(destinationFile);
    XMLWriter writer;
    if (jbossConfiguration.isJbossThreeDotTwo()) {
        writer = initializeXmlWriter(w, DOCTYPE_3_2);
    } else if (jbossConfiguration.isJbossFour()) {
        writer = initializeXmlWriter(w, DOCTYPE_4);
    } else if (jbossConfiguration.isJbossFourDotTwo()) {
        writer = initializeXmlWriter(w, DOCTYPE_4_2);
    } else {
        writer = initializeXmlWriter(w, DOCTYPE_5);
    }
    writer.startElement(JBOSS_APP_ELEMENT);
    // module-order (only available as from 4.2)
    if (jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null) {
        writer.startElement(JbossConfiguration.MODULE_ORDER);
        writer.writeText(jbossConfiguration.getModuleOrder());
        writer.endElement();
    }
    // If JBoss 4, write the jboss4 specific stuff
    if (jbossConfiguration.isJbossFourOrHigher()) {
        if (jbossConfiguration.getSecurityDomain() != null) {
            writer.startElement(JbossConfiguration.SECURITY_DOMAIN);
            writer.writeText(jbossConfiguration.getSecurityDomain());
            writer.endElement();
        }
        if (jbossConfiguration.getUnauthenticatedPrincipal() != null) {
            writer.startElement(JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL);
            writer.writeText(jbossConfiguration.getUnauthenticatedPrincipal());
            writer.endElement();
        }
    }
    // CHECKSTYLE_OFF: LineLength
    if (jbossConfiguration.getLoaderRepository() != null || jbossConfiguration.getLoaderRepositoryConfig() != null) // CHECKSTYLE_ON: LineLength
    {
        writer.startElement(JbossConfiguration.LOADER_REPOSITORY);
        // classloader repository class
        if (jbossConfiguration.getLoaderRepositoryClass() != null) {
            writer.addAttribute(JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE, jbossConfiguration.getLoaderRepositoryClass());
        }
        // we don't need to write any text if only the loader repo configuration is changed
        if (jbossConfiguration.getLoaderRepository() != null) {
            writer.writeText(jbossConfiguration.getLoaderRepository());
        }
        // classloader configuration
        if (jbossConfiguration.getLoaderRepositoryConfig() != null) {
            writer.startElement(JbossConfiguration.LOADER_REPOSITORY_CONFIG);
            // classloader configuration parser
            if (jbossConfiguration.getConfigParserClass() != null) {
                writer.addAttribute(JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE, jbossConfiguration.getConfigParserClass());
            }
            writer.writeText(jbossConfiguration.getLoaderRepositoryConfig());
            writer.endElement();
        }
        writer.endElement();
    }
    // jmx name
    if (jbossConfiguration.getJmxName() != null) {
        writer.startElement(JbossConfiguration.JMX_NAME);
        writer.writeText(jbossConfiguration.getJmxName());
        writer.endElement();
    }
    // library-directory (only available as from 4.2)
    if (jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null) {
        writer.startElement(JbossConfiguration.LIBRARY_DIRECTORY);
        writer.writeText(jbossConfiguration.getLibraryDirectory());
        writer.endElement();
    }
    // Modules
    List<String> dataSources = jbossConfiguration.getDataSources();
    // Write out data source modules first
    if (dataSources != null) {
        for (String dsPath : dataSources) {
            writer.startElement(MODULE_ELEMENT);
            writer.startElement(SERVICE_ELEMENT);
            writer.writeText(dsPath);
            writer.endElement();
            writer.endElement();
        }
    }
    // Write the JBoss specific modules
    for (EarModule earModule : earModules) {
        if (JbossEarModule.class.isInstance(earModule)) {
            JbossEarModule jbossEarModule = (JbossEarModule) earModule;
            jbossEarModule.appendJbossModule(writer, jbossConfiguration.getVersion());
        }
    }
    writer.endElement();
    close(w);
}
Also used : XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) Writer(java.io.Writer)

Example 18 with XMLWriter

use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.

the class EffectiveSettingsMojo method execute.

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    Settings copySettings;
    if (showPasswords) {
        copySettings = settings;
    } else {
        copySettings = copySettings(settings);
        hidePasswords(copySettings);
    }
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), copySettings.getModelEncoding(), null);
    writeHeader(writer);
    writeEffectiveSettings(copySettings, writer);
    String effectiveSettings = w.toString();
    if (output != null) {
        try {
            writeXmlFile(output, effectiveSettings, copySettings.getModelEncoding());
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot write effective-settings to output: " + output, e);
        }
        getLog().info("Effective-settings written to: " + output);
    } else {
        StringBuilder message = new StringBuilder();
        message.append(LS).append("Effective user-specific configuration settings:").append(LS).append(LS);
        message.append(effectiveSettings);
        message.append(LS);
        getLog().info(message.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) Settings(org.apache.maven.settings.Settings)

Example 19 with XMLWriter

use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.

the class EffectivePomMojo method execute.

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException {
    if (StringUtils.isNotEmpty(artifact)) {
        project = getMavenProject(artifact);
    }
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), project.getModel().getModelEncoding(), null);
    writeHeader(writer);
    String effectivePom;
    if (shouldWriteAllEffectivePOMsInReactor()) {
        // outer root element
        writer.startElement("projects");
        for (MavenProject subProject : projects) {
            writeEffectivePom(subProject, writer);
        }
        writer.endElement();
        effectivePom = w.toString();
        effectivePom = prettyFormat(effectivePom);
    } else {
        writeEffectivePom(project, writer);
        effectivePom = w.toString();
    }
    if (output != null) {
        try {
            writeXmlFile(output, effectivePom, project.getModel().getModelEncoding());
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot write effective-POM to output: " + output, e);
        }
        getLog().info("Effective-POM written to: " + output);
    } else {
        StringBuilder message = new StringBuilder();
        message.append(LS);
        message.append("Effective POMs, after inheritance, interpolation, and profiles are applied:");
        message.append(LS).append(LS);
        message.append(effectivePom);
        message.append(LS);
        getLog().info(message.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)

Example 20 with XMLWriter

use of org.codehaus.plexus.util.xml.XMLWriter in project maven-plugins by apache.

the class EffectiveSiteMojo method execute.

/**
 * {@inheritDoc}
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    DecorationModel decorationModel = prepareDecorationModel(getLocales().get(0));
    StringWriter w = new StringWriter();
    XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), decorationModel.getModelEncoding(), null);
    writeHeader(writer);
    writeEffectiveSite(decorationModel, writer);
    String effectiveSite = w.toString();
    if (output != null) {
        try {
            writeXmlFile(output, effectiveSite);
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot write effective site descriptor to output: " + output, e);
        }
        if (getLog().isInfoEnabled()) {
            getLog().info("Effective site descriptor written to: " + output);
        }
    } else {
        StringBuilder message = new StringBuilder();
        message.append("\nEffective site descriptor, after inheritance and interpolation:\n\n");
        message.append(effectiveSite);
        message.append("\n");
        if (getLog().isInfoEnabled()) {
            getLog().info(message.toString());
        }
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)

Aggregations

XMLWriter (org.codehaus.plexus.util.xml.XMLWriter)20 PrettyPrintXMLWriter (org.codehaus.plexus.util.xml.PrettyPrintXMLWriter)13 StringWriter (java.io.StringWriter)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 IOException (java.io.IOException)4 File (java.io.File)3 MavenProject (org.apache.maven.project.MavenProject)3 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2 ProjectBuildingResult (org.apache.maven.project.ProjectBuildingResult)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)1 Contributor (org.apache.maven.model.Contributor)1