Search in sources :

Example 66 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 67 with XmlPullParserException

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

the class SignAndDeployFileMojo method readModel.

/**
 * Extract the model from the specified POM file.
 *
 * @param pomFile The path of the POM file to parse, must not be <code>null</code>.
 * @return The model from the POM file, never <code>null</code>.
 * @throws MojoExecutionException If the file doesn't exist of cannot be read.
 */
private Model readModel(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
        return model;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("POM not found " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading POM " + pomFile, e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Error parsing POM " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) 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 68 with XmlPullParserException

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

the class InstallFileMojo method readModel.

/**
 * Parses a POM.
 *
 * @param pomFile The path of the POM file to parse, must not be <code>null</code>.
 * @return The model from the POM file, never <code>null</code>.
 * @throws MojoExecutionException If the POM could not be parsed.
 */
private Model readModel(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(pomFile);
        final Model model = new MavenXpp3Reader().read(reader);
        reader.close();
        reader = null;
        return model;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("File not found " + pomFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading POM " + pomFile, e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Error parsing POM " + pomFile, e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) 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 69 with XmlPullParserException

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

the class ResourceResolver method resolveBundleFromProject.

private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project, Artifact artifact) throws IOException {
    List<JavadocBundle> bundles = new ArrayList<>();
    List<String> classifiers = new ArrayList<>();
    if (config.includeCompileSources()) {
        classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    if (config.includeTestSources()) {
        classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    for (String classifier : classifiers) {
        File optionsFile = new File(project.getBuild().getDirectory(), "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
        if (!optionsFile.exists()) {
            continue;
        }
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(optionsFile);
            JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);
            stream.close();
            stream = null;
            bundles.add(new JavadocBundle(options, new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
        } catch (XmlPullParserException e) {
            IOException error = new IOException("Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
            error.initCause(e);
            throw error;
        } finally {
            close(stream);
        }
    }
    return bundles;
}
Also used : JavadocOptionsXpp3Reader(org.apache.maven.plugins.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) ArrayList(java.util.ArrayList) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 70 with XmlPullParserException

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

the class AbstractPmdViolationCheckMojo method executeCheck.

protected void executeCheck(final String filename, final String tagName, final String key, final int failurePriority) throws MojoFailureException, MojoExecutionException {
    if (aggregate && !project.isExecutionRoot()) {
        return;
    }
    if ("pom".equals(project.getPackaging()) && !aggregate) {
        return;
    }
    excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
    final File outputFile = new File(targetDirectory, filename);
    if (outputFile.exists()) {
        try {
            final ViolationDetails<D> violations = getViolations(outputFile, failurePriority);
            final List<D> failures = violations.getFailureDetails();
            final List<D> warnings = violations.getWarningDetails();
            if (verbose) {
                printErrors(failures, warnings);
            }
            final int failureCount = failures.size();
            final int warningCount = warnings.size();
            final String message = getMessage(failureCount, warningCount, key, outputFile);
            getLog().debug("PMD failureCount: " + failureCount + ", warningCount: " + warningCount);
            if (failureCount > 0 && isFailOnViolation()) {
                throw new MojoFailureException(message);
            }
            this.getLog().info(message);
        } catch (final IOException e) {
            throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
        } catch (final XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
        }
    } else {
        throw new MojoFailureException("Unable to perform check, " + "unable to find " + outputFile);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Aggregations

XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)79 IOException (java.io.IOException)73 File (java.io.File)37 Model (org.apache.maven.model.Model)32 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)30 FileNotFoundException (java.io.FileNotFoundException)20 Reader (java.io.Reader)20 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)19 FileReader (java.io.FileReader)15 FileInputStream (java.io.FileInputStream)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 Path (java.nio.file.Path)7 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)6 HashMap (java.util.HashMap)5