use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class PmdReport method writeNonHtml.
/**
* Use the PMD renderers to render in any format aside from HTML.
*
* @param report
* @throws MavenReportException
*/
private void writeNonHtml(Report report) throws MavenReportException {
Renderer r = createRenderer();
if (r == null) {
return;
}
File targetFile = new File(targetDirectory, "pmd." + format);
try (Writer writer = new OutputStreamWriter(new FileOutputStream(targetFile), getOutputEncoding())) {
targetDirectory.mkdirs();
r.setWriter(writer);
r.start();
r.renderFileReport(report);
r.end();
if (includeXmlInSite) {
File siteDir = getReportOutputDirectory();
siteDir.mkdirs();
FileUtils.copyFile(targetFile, new File(siteDir, "pmd." + format));
}
} catch (IOException ioe) {
throw new MavenReportException(ioe.getMessage(), ioe);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class PmdReport method getPMDConfiguration.
/**
* Constructs the PMD configuration class, passing it an argument that configures the target JDK.
*
* @return the resulting PMD
* @throws org.apache.maven.reporting.MavenReportException if targetJdk is not supported
*/
public PMDConfiguration getPMDConfiguration() throws MavenReportException {
PMDConfiguration configuration = new PMDConfiguration();
LanguageVersion languageVersion = null;
if (("java".equals(language) || null == language) && null != targetJdk) {
languageVersion = LanguageRegistry.findLanguageVersionByTerseName("java " + targetJdk);
if (languageVersion == null) {
throw new MavenReportException("Unsupported targetJdk value '" + targetJdk + "'.");
}
} else if ("javascript".equals(language) || "ecmascript".equals(language)) {
languageVersion = LanguageRegistry.findLanguageVersionByTerseName("ecmascript");
} else if ("jsp".equals(language)) {
languageVersion = LanguageRegistry.findLanguageVersionByTerseName("jsp");
}
if (languageVersion != null) {
getLog().debug("Using language " + languageVersion);
configuration.setDefaultLanguageVersion(languageVersion);
}
if (typeResolution) {
try {
@SuppressWarnings("unchecked") List<String> classpath = includeTests ? project.getTestClasspathElements() : project.getCompileClasspathElements();
getLog().debug("Using aux classpath: " + classpath);
configuration.prependClasspath(StringUtils.join(classpath.iterator(), File.pathSeparator));
} catch (Exception e) {
throw new MavenReportException(e.getMessage(), e);
}
}
if (null != suppressMarker) {
configuration.setSuppressMarker(suppressMarker);
}
configuration.setBenchmark(benchmark);
if (analysisCache) {
configuration.setAnalysisCacheLocation(analysisCacheLocation);
getLog().debug("Using analysis cache location: " + analysisCacheLocation);
}
return configuration;
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class PmdReport method processFilesWithPMD.
private void processFilesWithPMD(PMDConfiguration pmdConfiguration, List<DataSource> dataSources) throws MavenReportException {
RuleSetFactory ruleSetFactory = new RuleSetFactory(RuleSetFactory.class.getClassLoader(), RulePriority.valueOf(this.minimumPriority), false, true);
RuleContext ruleContext = new RuleContext();
try {
getLog().debug("Executing PMD...");
PMD.processFiles(pmdConfiguration, ruleSetFactory, dataSources, ruleContext, Arrays.<Renderer>asList(renderer));
if (getLog().isDebugEnabled()) {
getLog().debug("PMD finished. Found " + renderer.getViolations().size() + " violations.");
}
} catch (Exception e) {
String message = "Failure executing PMD: " + e.getLocalizedMessage();
if (!skipPmdError) {
throw new MavenReportException(message, e);
}
getLog().warn(message, e);
}
}
Aggregations