Search in sources :

Example 6 with XmlPullParserException

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

the class InvokerReport method executeReport.

protected void executeReport(Locale locale) throws MavenReportException {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    percentFormat = new DecimalFormat(getText(locale, "report.invoker.format.percent"), symbols);
    secondsFormat = new DecimalFormat(getText(locale, "report.invoker.format.seconds"), symbols);
    Sink sink = getSink();
    sink.head();
    sink.title();
    sink.text(getText(locale, "report.invoker.result.title"));
    sink.title_();
    sink.head_();
    sink.body();
    sink.section1();
    sink.sectionTitle1();
    sink.text(getText(locale, "report.invoker.result.title"));
    sink.sectionTitle1_();
    sink.paragraph();
    sink.text(getText(locale, "report.invoker.result.description"));
    sink.paragraph_();
    sink.section1_();
    // ----------------------------------
    // build buildJob beans
    // ----------------------------------
    File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory);
    if (reportFiles.length <= 0) {
        getLog().info("no invoker report files found, skip report generation");
        return;
    }
    List<BuildJob> buildJobs = new ArrayList<BuildJob>(reportFiles.length);
    for (File reportFile : reportFiles) {
        try {
            BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
            buildJobs.add(reader.read(ReaderFactory.newXmlReader(reportFile)));
        } catch (XmlPullParserException e) {
            throw new MavenReportException("Failed to parse report file: " + reportFile, e);
        } catch (IOException e) {
            throw new MavenReportException("Failed to read report file: " + reportFile, e);
        }
    }
    // ----------------------------------
    // summary
    // ----------------------------------
    constructSummarySection(buildJobs, locale);
    // ----------------------------------
    // per file/it detail
    // ----------------------------------
    sink.section2();
    sink.sectionTitle2();
    sink.text(getText(locale, "report.invoker.detail.title"));
    sink.sectionTitle2_();
    sink.section2_();
    // detail tests table header
    sink.table();
    sink.tableRow();
    // -------------------------------------------
    // name | Result | time | message
    // -------------------------------------------
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.name"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.result"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.time"));
    sinkTableHeader(sink, getText(locale, "report.invoker.detail.message"));
    sink.tableRow_();
    for (BuildJob buildJob : buildJobs) {
        renderBuildJob(buildJob, locale);
    }
    sink.table_();
    sink.body_();
    sink.flush();
    sink.close();
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Sink(org.apache.maven.doxia.sink.Sink) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) BuildJobXpp3Reader(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) BuildJob(org.apache.maven.plugins.invoker.model.BuildJob) IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 7 with XmlPullParserException

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

the class MetadataUtils method readMetadata.

private static Xpp3Dom readMetadata(File metadataFile) throws IOException {
    if (!metadataFile.isFile()) {
        return null;
    }
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(metadataFile);
        final Xpp3Dom xpp3Dom = Xpp3DomBuilder.build(reader);
        reader.close();
        reader = null;
        return xpp3Dom;
    } catch (XmlPullParserException e) {
        throw (IOException) new IOException(e.getMessage()).initCause(e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Reader(java.io.Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 8 with XmlPullParserException

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

the class VerifyMojo method execute.

/**
     * Invokes Maven on the configured test projects.
     *
     * @throws org.apache.maven.plugin.MojoExecutionException If the goal encountered severe errors.
     * @throws org.apache.maven.plugin.MojoFailureException If any of the Maven builds failed.
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipInvocation) {
        getLog().info("Skipping invocation per configuration." + " If this is incorrect, ensure the skipInvocation parameter is not set to true.");
        return;
    }
    File[] reportFiles = ReportUtils.getReportFiles(reportsDirectory);
    if (reportFiles.length <= 0) {
        if (Boolean.TRUE.equals(failIfNoProjects)) {
            throw new MojoFailureException("No projects to invoke!");
        }
        getLog().info("No invoker report files found, nothing to check.");
        return;
    }
    InvokerSession invokerSession = new InvokerSession();
    for (File reportFile : reportFiles) {
        try {
            BuildJobXpp3Reader reader = new BuildJobXpp3Reader();
            invokerSession.addJob(reader.read(ReaderFactory.newXmlReader(reportFile)));
        } catch (XmlPullParserException e) {
            throw new MojoExecutionException("Failed to parse report file: " + reportFile, e);
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to read report file: " + reportFile, e);
        }
    }
    if (!suppressSummaries) {
        invokerSession.logSummary(getLog(), ignoreFailures);
    }
    invokerSession.handleFailures(getLog(), ignoreFailures);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BuildJobXpp3Reader(org.apache.maven.plugins.invoker.model.io.xpp3.BuildJobXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Example 9 with XmlPullParserException

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

the class CheckstyleViolationCheckMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
    checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories");
    if (skip) {
        return;
    }
    outputXmlFile = outputFile;
    if (!skipExec) {
        if (checkstyleRules != null) {
            if (!"sun_checks.xml".equals(configLocation)) {
                throw new MojoExecutionException("If you use inline configuration for rules, don't specify " + "a configLocation");
            }
            if (checkstyleRules.getChildCount() > 1) {
                throw new MojoExecutionException("Currently only one root module is supported");
            }
            PlexusConfiguration checkerModule = checkstyleRules.getChild(0);
            try {
                FileUtils.forceMkdir(rulesFiles.getParentFile());
                FileUtils.fileWrite(rulesFiles, CHECKSTYLE_FILE_HEADER + checkerModule.toString());
            } catch (final IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            configLocation = rulesFiles.getAbsolutePath();
        }
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
            request.setConsoleListener(getConsoleListener()).setConsoleOutput(consoleOutput).setExcludes(excludes).setFailsOnError(failsOnError).setIncludes(includes).setResourceIncludes(resourceIncludes).setResourceExcludes(resourceExcludes).setIncludeResources(includeResources).setIncludeTestResources(includeTestResources).setIncludeTestSourceDirectory(includeTestSourceDirectory).setListener(getListener()).setProject(project).setSourceDirectories(getSourceDirectories()).setResources(resources).setTestResources(testResources).setStringOutputStream(stringOutputStream).setSuppressionsLocation(suppressionsLocation).setTestSourceDirectories(getTestSourceDirectories()).setConfigLocation(configLocation).setConfigurationArtifacts(collectArtifacts("config")).setPropertyExpansion(propertyExpansion).setHeaderLocation(headerLocation).setLicenseArtifacts(collectArtifacts("license")).setCacheFile(cacheFile).setSuppressionsFileExpression(suppressionsFileExpression).setEncoding(encoding).setPropertiesLocation(propertiesLocation).setOmitIgnoredModules(omitIgnoredModules);
            checkstyleExecutor.executeCheckstyle(request);
        } catch (CheckstyleException e) {
            throw new MojoExecutionException("Failed during checkstyle configuration", e);
        } catch (CheckstyleExecutorException e) {
            throw new MojoExecutionException("Failed during checkstyle execution", e);
        } finally {
            //be sure to restore original context classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    }
    if (!"xml".equals(outputFileFormat) && skipExec) {
        throw new MojoExecutionException("Output format is '" + outputFileFormat + "', checkstyle:check requires format to be 'xml' when using skipExec.");
    }
    if (!outputXmlFile.exists()) {
        getLog().info("Unable to perform checkstyle:check, unable to find checkstyle:checkstyle outputFile.");
        return;
    }
    try (Reader reader = new BufferedReader(ReaderFactory.newXmlReader(outputXmlFile))) {
        XmlPullParser xpp = new MXParser();
        xpp.setInput(reader);
        int violations = countViolations(xpp);
        if (violations > maxAllowedViolations) {
            if (failOnViolation) {
                String msg = "You have " + violations + " Checkstyle violation" + ((violations > 1) ? "s" : "") + ".";
                if (maxAllowedViolations > 0) {
                    msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
                }
                throw new MojoFailureException(msg);
            }
            getLog().warn("checkstyle:check violations detected but failOnViolation set to false");
        }
    } catch (IOException | XmlPullParserException e) {
        throw new MojoExecutionException("Unable to read Checkstyle results xml: " + outputXmlFile.getAbsolutePath(), e);
    }
}
Also used : PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MXParser(org.codehaus.plexus.util.xml.pull.MXParser) CheckstyleExecutorRequest(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest) CheckstyleExecutorException(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException) XmlPullParser(org.codehaus.plexus.util.xml.pull.XmlPullParser) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 10 with XmlPullParserException

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

the class DocumentDescriptorReader method readAndFilterDocumentDescriptor.

/**
     * Read and filter the <code>docDescriptor</code> file.
     *
     * @param docDescriptor not null.
     * @return a DocumentModel instance.
     * @throws XmlPullParserException if an error occurs during parsing.
     * @throws IOException if an error occurs during reading.
     */
public DocumentModel readAndFilterDocumentDescriptor(final File docDescriptor) throws XmlPullParserException, IOException {
    Reader reader = null;
    try {
        // System properties
        final Properties filterProperties = System.getProperties();
        // Project properties
        if (project != null && project.getProperties() != null) {
            filterProperties.putAll(project.getProperties());
        }
        final Interpolator interpolator = new RegexBasedInterpolator();
        interpolator.addValueSource(new MapBasedValueSource(filterProperties));
        interpolator.addValueSource(new EnvarBasedValueSource());
        interpolator.addValueSource(new ObjectBasedValueSource(project) {

            /** {@inheritDoc} */
            public Object getValue(final String expression) {
                try {
                    return ReflectionValueExtractor.evaluate(expression, project);
                } catch (Exception e) {
                    addFeedback("Failed to extract \'" + expression + "\' from: " + project, e);
                }
                return null;
            }
        });
        final DateBean bean = new DateBean();
        interpolator.addValueSource(new ObjectBasedValueSource(bean));
        reader = ReaderFactory.newXmlReader(docDescriptor);
        final String interpolatedDoc = interpolator.interpolate(IOUtil.toString(reader));
        reader.close();
        reader = null;
        if (log != null && log.isDebugEnabled()) {
            log.debug("Interpolated document descriptor (" + docDescriptor.getAbsolutePath() + ")\n" + interpolatedDoc);
        }
        // No Strict
        return new DocumentXpp3Reader().read(new StringReader(interpolatedDoc), false);
    } catch (InterpolationException e) {
        final IOException io = new IOException("Error interpolating document descriptor");
        io.initCause(e);
        throw io;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) DocumentXpp3Reader(org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Reader) Reader(java.io.Reader) StringReader(java.io.StringReader) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) IOException(java.io.IOException) Properties(java.util.Properties) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) DocumentXpp3Reader(org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Reader) StringReader(java.io.StringReader) Interpolator(org.codehaus.plexus.interpolation.Interpolator) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) ObjectBasedValueSource(org.codehaus.plexus.interpolation.ObjectBasedValueSource) MapBasedValueSource(org.codehaus.plexus.interpolation.MapBasedValueSource) EnvarBasedValueSource(org.codehaus.plexus.interpolation.EnvarBasedValueSource)

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