use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method getExcludedPackages.
/**
* Method to get the packages specified in the <code>excludePackageNames</code> parameter. The packages are split
* with ',', ':', or ';' and then formatted.
*
* @return an array of String objects that contain the package names
* @throws MavenReportException
*/
private String[] getExcludedPackages() throws MavenReportException {
Set<String> excluded = new LinkedHashSet<String>();
if (includeDependencySources) {
try {
resolveDependencyBundles();
} catch (IOException e) {
throw new MavenReportException("Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e);
}
if (isNotEmpty(dependencyJavadocBundles)) {
for (JavadocBundle bundle : dependencyJavadocBundles) {
JavadocOptions options = bundle.getOptions();
if (options != null && isNotEmpty(options.getExcludePackageNames())) {
excluded.addAll(options.getExcludePackageNames());
}
}
}
}
// for the specified excludePackageNames
if (StringUtils.isNotEmpty(excludePackageNames)) {
List<String> packageNames = Arrays.asList(excludePackageNames.split("[,:;]"));
excluded.addAll(trimValues(packageNames));
}
String[] result = new String[excluded.size()];
if (isNotEmpty(excluded)) {
int idx = 0;
for (String exclude : excluded) {
result[idx] = exclude.replace('.', File.separatorChar);
idx++;
}
}
return result;
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method getDependencySourcePaths.
/**
* Resolve dependency sources so they can be included directly in the javadoc process. To customize this,
* override {@link AbstractJavadocMojo#configureDependencySourceResolution(SourceResolverConfig)}.
* @return List of source paths.
* @throws MavenReportException {@link MavenReportException}
*/
protected final List<String> getDependencySourcePaths() throws MavenReportException {
try {
if (sourceDependencyCacheDir.exists()) {
FileUtils.forceDelete(sourceDependencyCacheDir);
sourceDependencyCacheDir.mkdirs();
}
} catch (IOException e) {
throw new MavenReportException("Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e);
}
final SourceResolverConfig config = getDependencySourceResolverConfig();
final List<TransformableFilter> andFilters = new ArrayList<TransformableFilter>();
final List<String> dependencyIncludes = dependencySourceIncludes;
final List<String> dependencyExcludes = dependencySourceExcludes;
if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes) || isNotEmpty(dependencyExcludes)) {
if (!includeTransitiveDependencySources) {
andFilters.add(createDependencyArtifactFilter());
}
if (isNotEmpty(dependencyIncludes)) {
andFilters.add(new PatternInclusionsFilter(dependencyIncludes));
}
if (isNotEmpty(dependencyExcludes)) {
andFilters.add(new PatternExclusionsFilter(dependencyExcludes));
}
config.withFilter(new AndFilter(andFilters));
}
try {
return resourceResolver.resolveDependencySourcePaths(config);
} catch (final ArtifactResolutionException e) {
throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
} catch (final ArtifactNotFoundException e) {
throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method executeJavadocCommandLine.
/**
* Execute the Javadoc command line
*
* @param cmd not null
* @param javadocOutputDirectory not null
* @throws MavenReportException if any errors occur
*/
private void executeJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException {
if (getLog().isDebugEnabled()) {
// no quoted arguments
getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
}
String cmdLine = null;
if (debug) {
cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
String output = (StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim());
if (exitCode != 0) {
if (cmdLine == null) {
cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
}
writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
if (StringUtils.isNotEmpty(output) && StringUtils.isEmpty(err.getOutput()) && isJavadocVMInitError(output)) {
throw new MavenReportException(output + '\n' + '\n' + JavadocUtil.ERROR_INIT_VM + '\n' + "Or, try to reduce the Java heap size for the Javadoc goal using " + "-Dminmemory=<size> and -Dmaxmemory=<size>." + '\n' + '\n' + "Command line was: " + cmdLine + '\n' + '\n' + "Refer to the generated Javadoc files in '" + javadocOutputDirectory + "' dir.\n");
}
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
StringBuilder msg = new StringBuilder("\nExit code: ");
msg.append(exitCode);
if (StringUtils.isNotEmpty(err.getOutput())) {
msg.append(" - ").append(err.getOutput());
}
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
msg.append("Refer to the generated Javadoc files in '").append(javadocOutputDirectory).append("' dir.\n");
throw new MavenReportException(msg.toString());
}
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
} catch (CommandLineException e) {
throw new MavenReportException("Unable to execute javadoc command: " + e.getMessage(), e);
}
if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
getLog().warn("Javadoc Warnings");
StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
while (token.hasMoreTokens()) {
String current = token.nextToken().trim();
getLog().warn(current);
}
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method addCommandLineOptions.
/**
* Generate an <code>options</code> file for all options and arguments and add the <code>@options</code> in the
* command line.
*
* @param cmd not null
* @param arguments not null
* @param javadocOutputDirectory not null
* @throws MavenReportException if any
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#argumentfiles">
* Reference Guide, Command line argument files</a>
* @see #OPTIONS_FILE_NAME
*/
private void addCommandLineOptions(Commandline cmd, List<String> arguments, File javadocOutputDirectory) throws MavenReportException {
File optionsFile = new File(javadocOutputDirectory, OPTIONS_FILE_NAME);
StringBuilder options = new StringBuilder();
options.append(StringUtils.join(arguments.toArray(new String[arguments.size()]), SystemUtils.LINE_SEPARATOR));
try {
FileUtils.fileWrite(optionsFile.getAbsolutePath(), null, /* platform encoding */
options.toString());
} catch (IOException e) {
throw new MavenReportException("Unable to write '" + optionsFile.getName() + "' temporary file for command execution", e);
}
cmd.createArg().setValue("@" + OPTIONS_FILE_NAME);
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class CpdReport method executeCpd.
private void executeCpd() throws MavenReportException {
if (cpd != null) {
// CPD has already been run
getLog().debug("CPD has already been run - skipping redundant execution.");
return;
}
Properties p = new Properties();
if (ignoreLiterals) {
p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
}
if (ignoreIdentifiers) {
p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
}
try {
if (filesToProcess == null) {
filesToProcess = getFilesToProcess();
}
try {
excludeDuplicationsFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
} catch (MojoExecutionException e) {
throw new MavenReportException("Error loading exclusions", e);
}
String encoding = determineEncoding(!filesToProcess.isEmpty());
Language cpdLanguage;
if ("java".equals(language) || null == language) {
cpdLanguage = new JavaLanguage(p);
} else if ("javascript".equals(language)) {
cpdLanguage = new EcmascriptLanguage();
} else if ("jsp".equals(language)) {
cpdLanguage = new JSPLanguage();
} else {
cpdLanguage = LanguageFactory.createLanguage(language, p);
}
CPDConfiguration cpdConfiguration = new CPDConfiguration();
cpdConfiguration.setMinimumTileSize(minimumTokens);
cpdConfiguration.setLanguage(cpdLanguage);
cpdConfiguration.setSourceEncoding(encoding);
cpd = new CPD(cpdConfiguration);
for (File file : filesToProcess.keySet()) {
cpd.add(file);
}
} catch (UnsupportedEncodingException e) {
throw new MavenReportException("Encoding '" + getSourceEncoding() + "' is not supported.", e);
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
}
getLog().debug("Executing CPD...");
cpd.go();
getLog().debug("CPD finished.");
// so the "check" goals can check for violations
if (isXml()) {
writeNonHtml(cpd);
}
}
Aggregations