Search in sources :

Example 21 with XmlPullParserException

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

the class PomUtils method loadPom.

/**
     * Loads the (raw) model from the specified POM file.
     *
     * @param pomFile The path to the POM file to load, must not be <code>null</code>.
     * @return The raw model, never <code>null</code>.
     * @throws MojoExecutionException If the POM file could not be loaded.
     */
public static Model loadPom(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader, false);
        reader.close();
        reader = null;
        return model;
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Failed to parse POM: " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to read POM: " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 22 with XmlPullParserException

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

the class BundlePackMojo method readPom.

/**
     * Read the POM file.
     *
     * @param pom The file to read
     * @return A Maven Model
     * @throws MojoExecutionException if something goes wrong when reading the file
     */
private Model readPom(File pom) throws MojoExecutionException {
    Model model;
    XmlStreamReader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pom);
        model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Unable to parse POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to read POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to read POM at " + pom.getAbsolutePath() + ": " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    return model;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 23 with XmlPullParserException

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

the class DefaultAssemblyReader method mergeComponentsWithMainAssembly.

/**
     * Add the contents of all included components to main assembly
     *
     * @param assembly The assembly
     * @param assemblyDir The assembly directory
     * @param transformer The component interpolator
     * @throws AssemblyReadException .
     */
protected void mergeComponentsWithMainAssembly(final Assembly assembly, final File assemblyDir, final AssemblerConfigurationSource configSource, ComponentXpp3Reader.ContentTransformer transformer) throws AssemblyReadException {
    final Locator locator = new Locator();
    if (assemblyDir != null && assemblyDir.exists() && assemblyDir.isDirectory()) {
        locator.addStrategy(new RelativeFileLocatorStrategy(assemblyDir));
    }
    // allow absolute paths in componentDescriptor... MASSEMBLY-486
    locator.addStrategy(new RelativeFileLocatorStrategy(configSource.getBasedir()));
    locator.addStrategy(new FileLocatorStrategy());
    locator.addStrategy(new ClasspathResourceLocatorStrategy());
    final AssemblyExpressionEvaluator aee = new AssemblyExpressionEvaluator(configSource);
    final List<String> componentLocations = assembly.getComponentDescriptors();
    for (String location : componentLocations) {
        // allow expressions in path to component descriptor... MASSEMBLY-486
        try {
            location = aee.evaluate(location).toString();
        } catch (final Exception eee) {
            getLogger().error("Error interpolating componentDescriptor: " + location, eee);
        }
        final Location resolvedLocation = locator.resolve(location);
        if (resolvedLocation == null) {
            throw new AssemblyReadException("Failed to locate component descriptor: " + location);
        }
        Component component = null;
        Reader reader = null;
        try {
            reader = new InputStreamReader(resolvedLocation.getInputStream());
            component = new ComponentXpp3Reader(transformer).read(reader);
        } catch (final IOException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } catch (final XmlPullParserException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } finally {
            IOUtil.close(reader);
        }
        mergeComponentWithAssembly(component, assembly);
    }
}
Also used : AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) InputStreamReader(java.io.InputStreamReader) FileLocatorStrategy(org.apache.maven.shared.io.location.FileLocatorStrategy) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Locator(org.apache.maven.shared.io.location.Locator) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Component(org.apache.maven.plugins.assembly.model.Component) ClasspathResourceLocatorStrategy(org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy) Location(org.apache.maven.shared.io.location.Location)

Example 24 with XmlPullParserException

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

the class ComponentsXmlArchiverFileFilter method isSelected.

@Override
public boolean isSelected(@Nonnull final FileInfo fileInfo) throws IOException {
    if (fileInfo.isFile()) {
        if (excludeOverride) {
            return true;
        }
        String entry = fileInfo.getName().replace('\\', '/');
        if (entry.startsWith("/")) {
            entry = entry.substring(1);
        }
        if (ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH.equals(entry)) {
            Reader reader = null;
            try {
                reader = new BufferedReader(ReaderFactory.newXmlReader(fileInfo.getContents()));
                addComponentsXml(reader);
                reader.close();
                reader = null;
            } catch (final XmlPullParserException e) {
                final IOException error = new IOException("Error finalizing component-set for archive. Reason: " + e.getMessage());
                error.initCause(e);
                throw error;
            } finally {
                IOUtil.close(reader);
            }
            return false;
        } else {
            return true;
        }
    } else {
        return true;
    }
}
Also used : BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 25 with XmlPullParserException

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

the class DefaultAssemblyArchiver method configureArchiver.

private void configureArchiver(final Archiver archiver, final AssemblerConfigurationSource configSource) {
    Xpp3Dom config;
    try {
        config = Xpp3DomBuilder.build(new StringReader(configSource.getArchiverConfig()));
    } catch (final XmlPullParserException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    } catch (final IOException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("Configuring archiver: '" + archiver.getClass().getName() + "' -->");
    try {
        configureComponent(archiver, config, configSource);
    } catch (final ComponentConfigurationException e) {
        throw new ArchiverException("Failed to configure archiver: " + archiver.getClass().getName(), e);
    } catch (final ComponentLookupException e) {
        throw new ArchiverException("Failed to lookup configurator for setup of archiver: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("-- end configuration --");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) StringReader(java.io.StringReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Aggregations

IOException (java.io.IOException)28 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 Reader (java.io.Reader)11 File (java.io.File)10 Model (org.apache.maven.model.Model)8 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)8 StringReader (java.io.StringReader)7 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 FileReader (java.io.FileReader)3 FileWriter (java.io.FileWriter)3 InputStreamReader (java.io.InputStreamReader)3 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2