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();
}
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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations