Search in sources :

Example 1 with MavenXpp3Writer

use of org.apache.maven.model.io.xpp3.MavenXpp3Writer in project che by eclipse.

the class EffectivePomWriter method writeEffectivePom.

/**
     * method from org.apache.maven.plugins.help.EffectivePomMojo
     * Method for writing the effective pom informations of the current build.
     *
     * @param project the project of the current build, not null.
     * @param writer the XML writer , not null, not null.
     * @throws MojoExecutionException if any
     */
private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException {
    Model pom = project.getModel();
    cleanModel(pom);
    String effectivePom;
    StringWriter sWriter = new StringWriter();
    MavenXpp3Writer pomWriter = new MavenXpp3Writer();
    try {
        pomWriter.write(sWriter, pom);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot serialize POM to XML.", e);
    }
    effectivePom = addMavenNamespace(sWriter.toString(), true);
    writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
    writer.writeMarkup(effectivePom);
}
Also used : StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 2 with MavenXpp3Writer

use of org.apache.maven.model.io.xpp3.MavenXpp3Writer in project intellij-community by JetBrains.

the class MavenEffectivePomDumper method writeEffectivePom.

/**
   * org.apache.maven.plugins.help.EffectivePomMojo#writeEffectivePom
   */
private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException {
    Model pom = project.getModel();
    cleanModel(pom);
    String effectivePom;
    StringWriter sWriter = new StringWriter();
    MavenXpp3Writer pomWriter = new MavenXpp3Writer();
    try {
        pomWriter.write(sWriter, pom);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot serialize POM to XML.", e);
    }
    effectivePom = addMavenNamespace(sWriter.toString(), true);
    writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
    writer.writeMarkup(effectivePom);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 3 with MavenXpp3Writer

use of org.apache.maven.model.io.xpp3.MavenXpp3Writer in project maven-plugins by apache.

the class DeployFileMojo method generatePomFile.

/**
     * Generates a minimal POM from the user-supplied artifact information.
     * 
     * @return The path to the generated POM file, never <code>null</code>.
     * @throws MojoExecutionException If the generation failed.
     */
private File generatePomFile() throws MojoExecutionException {
    Model model = generateModel();
    Writer fw = null;
    try {
        File tempFile = File.createTempFile("mvndeploy", ".pom");
        tempFile.deleteOnExit();
        fw = WriterFactory.newXmlWriter(tempFile);
        new MavenXpp3Writer().write(fw, model);
        fw.close();
        fw = null;
        return tempFile;
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e);
    } finally {
        IOUtil.close(fw);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer) Writer(java.io.Writer) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 4 with MavenXpp3Writer

use of org.apache.maven.model.io.xpp3.MavenXpp3Writer in project maven-plugins by apache.

the class InstallFileMojo method generatePomFile.

/**
     * Generates a (temporary) POM file from the plugin configuration. It's the responsibility of the caller to delete
     * the generated file when no longer needed.
     * 
     * @return The path to the generated POM file, never <code>null</code>.
     * @throws MojoExecutionException If the POM file could not be generated.
     */
private File generatePomFile() throws MojoExecutionException {
    Model model = generateModel();
    Writer writer = null;
    try {
        File pomFile = File.createTempFile("mvninstall", ".pom");
        writer = WriterFactory.newXmlWriter(pomFile);
        new MavenXpp3Writer().write(writer, model);
        writer.close();
        writer = null;
        return pomFile;
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing temporary POM file: " + e.getMessage(), e);
    } finally {
        IOUtil.close(writer);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer) Writer(java.io.Writer) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 5 with MavenXpp3Writer

use of org.apache.maven.model.io.xpp3.MavenXpp3Writer in project maven-plugins by apache.

the class EffectivePomMojo method writeEffectivePom.

// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
     * Method for writing the effective pom informations of the current build.
     *
     * @param project the project of the current build, not null.
     * @param writer the XML writer , not null, not null.
     * @throws MojoExecutionException if any
     */
private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException {
    Model pom = project.getModel();
    cleanModel(pom);
    String effectivePom;
    StringWriter sWriter = new StringWriter();
    MavenXpp3Writer pomWriter = new MavenXpp3Writer();
    try {
        pomWriter.write(sWriter, pom);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot serialize POM to XML.", e);
    }
    effectivePom = addMavenNamespace(sWriter.toString(), true);
    writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
    writer.writeMarkup(effectivePom);
}
Also used : StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Aggregations

MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)7 File (java.io.File)5 StringWriter (java.io.StringWriter)3 Writer (java.io.Writer)3 JarFile (java.util.jar.JarFile)2 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 License (org.apache.maven.model.License)1 Scm (org.apache.maven.model.Scm)1 MavenProject (org.apache.maven.project.MavenProject)1 Settings (org.apache.maven.settings.Settings)1 SettingsXpp3Writer (org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 ExpressionEvaluationException (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException)1