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);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class JiraMojo method executeReport.
public void executeReport(Locale locale) throws MavenReportException {
// Validate parameters
List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, JIRA_COLUMNS);
if (columnIds.isEmpty()) {
// This can happen if the user has configured column names and they are all invalid
throw new MavenReportException("maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid.");
}
try {
// Download issues
AbstractJiraDownloader issueDownloader;
if (mockDownloader != null) {
issueDownloader = mockDownloader;
} else {
AdaptiveJiraDownloader downloader = new AdaptiveJiraDownloader();
downloader.setForceClassic(forceRss);
issueDownloader = downloader;
}
configureIssueDownloader(issueDownloader);
issueDownloader.doExecute();
List<Issue> issueList = issueDownloader.getIssueList();
if (StringUtils.isNotEmpty(versionPrefix)) {
int originalNumberOfIssues = issueList.size();
issueList = IssueUtils.filterIssuesWithVersionPrefix(issueList, versionPrefix);
getLog().debug("Filtered out " + issueList.size() + " issues of " + originalNumberOfIssues + " that matched the versionPrefix '" + versionPrefix + "'.");
}
if (onlyCurrentVersion) {
String version = (versionPrefix == null ? "" : versionPrefix) + project.getVersion();
issueList = IssueUtils.getIssuesForVersion(issueList, version);
getLog().info("The JIRA Report will contain issues only for the current version.");
}
// Generate the report
IssuesReportGenerator report = new IssuesReportGenerator(IssuesReportHelper.toIntArray(columnIds));
if (issueList.isEmpty()) {
report.doGenerateEmptyReport(getBundle(locale), getSink());
} else {
report.doGenerateReport(getBundle(locale), getSink(), issueList);
}
} catch (Exception e) {
getLog().warn(e);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class ChangesMojo method copyStaticResources.
private void copyStaticResources() throws MavenReportException {
final String pluginResourcesBase = "org/apache/maven/plugins/changes";
String[] resourceNames = { "images/add.gif", "images/fix.gif", "images/icon_help_sml.gif", "images/remove.gif", "images/rss.png", "images/update.gif" };
try {
getLog().debug("Copying static resources.");
for (String resourceName : resourceNames) {
URL url = this.getClass().getClassLoader().getResource(pluginResourcesBase + "/" + resourceName);
FileUtils.copyURLToFile(url, new File(getReportOutputDirectory(), resourceName));
}
} catch (IOException e) {
throw new MavenReportException("Unable to copy static resources.");
}
}
Aggregations