use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method getArtifactsAbsolutePath.
/**
* Return the Javadoc artifact path and its transitive dependencies path from the local repository
*
* @param javadocArtifact not null
* @return a list of locale artifacts absolute path
* @throws MavenReportException if any
*/
private List<String> getArtifactsAbsolutePath(JavadocPathArtifact javadocArtifact) throws MavenReportException {
if ((StringUtils.isEmpty(javadocArtifact.getGroupId())) && (StringUtils.isEmpty(javadocArtifact.getArtifactId())) && (StringUtils.isEmpty(javadocArtifact.getVersion()))) {
return Collections.emptyList();
}
List<String> path = new ArrayList<String>();
try {
Artifact artifact = createAndResolveArtifact(javadocArtifact);
path.add(artifact.getFile().getAbsolutePath());
DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
coordinate.setGroupId(javadocArtifact.getGroupId());
coordinate.setArtifactId(javadocArtifact.getArtifactId());
coordinate.setVersion(javadocArtifact.getVersion());
Iterable<ArtifactResult> deps = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), coordinate, ScopeFilter.including("compile", "provided"));
for (ArtifactResult a : deps) {
path.add(a.getArtifact().getFile().getAbsolutePath());
}
return path;
} catch (ArtifactResolverException e) {
throw new MavenReportException("Unable to resolve artifact:" + javadocArtifact, e);
} catch (DependencyResolverException e) {
throw new MavenReportException("Unable to resolve dependencies for:" + javadocArtifact, e);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method executeReport.
/**
* The <a href="package-summary.html">package documentation</a> details the
* Javadoc Options used by this Plugin.
*
* @param unusedLocale the wanted locale (actually unused).
* @throws MavenReportException if any
*/
protected void executeReport(Locale unusedLocale) throws MavenReportException {
if (skip) {
getLog().info("Skipping javadoc generation");
return;
}
if (isAggregator() && !project.isExecutionRoot()) {
return;
}
if (getLog().isDebugEnabled()) {
this.debug = true;
}
// useDependencySources in a distro module build.
try {
buildJavadocOptions();
} catch (IOException e) {
throw new MavenReportException("Failed to generate javadoc options file: " + e.getMessage(), e);
}
List<String> sourcePaths = getSourcePaths();
List<String> files = getFiles(sourcePaths);
if (!canGenerateReport(files)) {
return;
}
List<String> packageNames = getPackageNames(sourcePaths, files);
List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages(sourcePaths, files);
// ----------------------------------------------------------------------
// Find the javadoc executable and version
// ----------------------------------------------------------------------
String jExecutable;
try {
jExecutable = getJavadocExecutable();
} catch (IOException e) {
throw new MavenReportException("Unable to find javadoc command: " + e.getMessage(), e);
}
setFJavadocVersion(new File(jExecutable));
// ----------------------------------------------------------------------
// Javadoc output directory as File
// ----------------------------------------------------------------------
File javadocOutputDirectory = new File(getOutputDirectory());
if (javadocOutputDirectory.exists() && !javadocOutputDirectory.isDirectory()) {
throw new MavenReportException("IOException: " + getOutputDirectory() + " is not a directory.");
}
if (javadocOutputDirectory.exists() && !javadocOutputDirectory.canWrite()) {
throw new MavenReportException("IOException: " + getOutputDirectory() + " is not writable.");
}
javadocOutputDirectory.mkdirs();
// ----------------------------------------------------------------------
// Copy all resources
// ----------------------------------------------------------------------
copyAllResources(javadocOutputDirectory);
// ----------------------------------------------------------------------
// Create command line for Javadoc
// ----------------------------------------------------------------------
Commandline cmd = new Commandline();
// for Javadoc JVM args
cmd.getShell().setQuotedArgumentsEnabled(false);
cmd.setWorkingDirectory(javadocOutputDirectory.getAbsolutePath());
cmd.setExecutable(jExecutable);
// ----------------------------------------------------------------------
// Wrap Javadoc JVM args
// ----------------------------------------------------------------------
addMemoryArg(cmd, "-Xmx", this.maxmemory);
addMemoryArg(cmd, "-Xms", this.minmemory);
addProxyArg(cmd);
if (StringUtils.isNotEmpty(additionalJOption)) {
cmd.createArg().setValue(additionalJOption);
}
if (additionalJOptions != null && additionalJOptions.length != 0) {
for (String jo : additionalJOptions) {
cmd.createArg().setValue(jo);
}
}
List<String> arguments = new ArrayList<String>();
// ----------------------------------------------------------------------
// Wrap Javadoc options
// ----------------------------------------------------------------------
addJavadocOptions(arguments, sourcePaths);
if (StringUtils.isEmpty(doclet) || useStandardDocletOptions) {
addStandardDocletOptions(javadocOutputDirectory, arguments);
}
if (arguments.size() > 0) {
addCommandLineOptions(cmd, arguments, javadocOutputDirectory);
}
// ----------------------------------------------------------------------
// Write packages file and include it in the command line
// ----------------------------------------------------------------------
// MJAVADOC-365 if includes/excludes are specified, these take precedence over the default
// package-based mode and force javadoc into file-based mode unless subpackages are
// specified. Subpackages take precedence over file-based include/excludes. Why? Because
// getFiles(...) returns an empty list when subpackages are specified.
boolean includesExcludesActive = (sourceFileIncludes != null && !sourceFileIncludes.isEmpty()) || (sourceFileExcludes != null && !sourceFileExcludes.isEmpty());
if (includesExcludesActive && !StringUtils.isEmpty(subpackages)) {
getLog().warn("sourceFileIncludes and sourceFileExcludes have no effect when subpackages are specified!");
includesExcludesActive = false;
}
if (!packageNames.isEmpty() && !includesExcludesActive) {
addCommandLinePackages(cmd, javadocOutputDirectory, packageNames);
if (!filesWithUnnamedPackages.isEmpty()) {
addCommandLineArgFile(cmd, javadocOutputDirectory, filesWithUnnamedPackages);
}
} else {
if (!files.isEmpty()) {
addCommandLineArgFile(cmd, javadocOutputDirectory, files);
}
}
// ----------------------------------------------------------------------
// Execute command line
// ----------------------------------------------------------------------
executeJavadocCommandLine(cmd, javadocOutputDirectory);
// prevent these files from making their way into archives.
if (!debug) {
for (int i = 0; i < cmd.getArguments().length; i++) {
String arg = cmd.getArguments()[i].trim();
if (!arg.startsWith("@")) {
continue;
}
File argFile = new File(javadocOutputDirectory, arg.substring(1));
if (argFile.exists()) {
argFile.delete();
}
}
File scriptFile = new File(javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME);
if (scriptFile.exists()) {
scriptFile.delete();
}
}
if (applyJavadocSecurityFix) {
// finally, patch the Javadoc vulnerability in older Javadoc tools (CVE-2013-1571):
try {
final int patched = fixFrameInjectionBug(javadocOutputDirectory, getDocencoding());
if (patched > 0) {
getLog().info(String.format("Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in %d files.", patched));
}
} catch (IOException e) {
throw new MavenReportException("Failed to patch javadocs vulnerability: " + e.getMessage(), e);
}
} else {
getLog().info("applying javadoc security fix has been disabled");
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method getClasspath.
/**
* Method that sets the classpath elements that will be specified in the javadoc <code>-classpath</code>
* parameter. Since we have all the sources of the current reactor, it is sufficient to consider the
* dependencies of the reactor modules, excluding the module artifacts which may not yet be available
* when the reactor project is built for the first time.
*
* @return a String that contains the concatenated classpath elements, separated by the System pathSeparator
* string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
* @throws MavenReportException if any.
* @see File#pathSeparator
*/
private String getClasspath() throws MavenReportException {
List<String> classpathElements = new ArrayList<String>();
Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
if (isTest()) {
classpathElements.addAll(getProjectBuildOutputDirs(project));
}
populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(project));
if (isAggregator() && project.isExecutionRoot()) {
List<Artifact> reactorArtifacts = new ArrayList<Artifact>();
for (MavenProject p : reactorProjects) {
reactorArtifacts.add(p.getArtifact());
}
try {
for (MavenProject subProject : reactorProjects) {
if (subProject != project) {
classpathElements.addAll(getProjectBuildOutputDirs(subProject));
Set<Artifact> dependencyArtifacts = subProject.createArtifacts(factory, null, null);
// do not attempt to resolve artifacts of the current reactor which may not exist yet
dependencyArtifacts.removeAll(reactorArtifacts);
if (!dependencyArtifacts.isEmpty()) {
ArtifactResolutionResult result = null;
try {
result = resolver.resolveTransitively(dependencyArtifacts, subProject.getArtifact(), subProject.getManagedVersionMap(), localRepository, subProject.getRemoteArtifactRepositories(), artifactMetadataSource);
} catch (ArtifactNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (ArtifactResolutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
if (result == null) {
continue;
}
populateCompileArtifactMap(compileArtifactMap, getCompileArtifacts(result.getArtifacts()));
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Compiled artifacts for ");
sb.append(subProject.getGroupId()).append(":");
sb.append(subProject.getArtifactId()).append(":");
sb.append(subProject.getVersion()).append('\n');
for (Artifact a : compileArtifactMap.values()) {
sb.append(a.getFile()).append('\n');
}
getLog().debug(sb.toString());
}
}
}
}
} catch (InvalidDependencyVersionException e) {
throw new MavenReportException(e.getMessage(), e);
}
}
for (Artifact a : compileArtifactMap.values()) {
classpathElements.add(a.getFile().toString());
}
if (additionalDependencies != null) {
for (Dependency dependency : additionalDependencies) {
Artifact artifact = resolveDependency(dependency);
String path = artifact.getFile().toString();
getLog().debug("add additional artifact with path " + path);
classpathElements.add(path);
}
}
return StringUtils.join(classpathElements.iterator(), File.pathSeparator);
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method getModulesLinks.
/**
* Using Maven, a Javadoc link is given by <code>${project.url}/apidocs</code>.
*
* @return the detected Javadoc links using the Maven conventions for all modules defined in the current project
* or an empty list.
* @throws MavenReportException if any
* @see #detectOfflineLinks
* @see #reactorProjects
* @since 2.6
*/
private List<OfflineLink> getModulesLinks() throws MavenReportException {
if (!detectOfflineLinks || isAggregator() || reactorProjects == null) {
return Collections.emptyList();
}
getLog().debug("Trying to add links for modules...");
Set<String> dependencyArtifactIds = new HashSet<String>();
final Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
for (Artifact artifact : dependencyArtifacts) {
dependencyArtifactIds.add(artifact.getId());
}
List<OfflineLink> modulesLinks = new ArrayList<OfflineLink>();
String javadocDirRelative = PathUtils.toRelative(project.getBasedir(), getOutputDirectory());
for (MavenProject p : reactorProjects) {
if (!dependencyArtifactIds.contains(p.getArtifact().getId()) || (p.getUrl() == null)) {
continue;
}
File location = new File(p.getBasedir(), javadocDirRelative);
if (!location.exists()) {
if (getLog().isDebugEnabled()) {
getLog().debug("Javadoc directory not found: " + location);
}
String javadocGoal = getFullJavadocGoal();
getLog().info("The goal '" + javadocGoal + "' has not been previously called for the module: '" + p.getId() + "'. Trying to invoke it...");
File invokerDir = new File(project.getBuild().getDirectory(), "invoker");
invokerDir.mkdirs();
File invokerLogFile = FileUtils.createTempFile("maven-javadoc-plugin", ".txt", invokerDir);
try {
JavadocUtil.invokeMaven(getLog(), new File(localRepository.getBasedir()), p.getFile(), Collections.singletonList(javadocGoal), null, invokerLogFile);
} catch (MavenInvocationException e) {
logError("MavenInvocationException: " + e.getMessage(), e);
String invokerLogContent = JavadocUtil.readFile(invokerLogFile, null);
// the JVM won't start (opposite of what it was).
if (invokerLogContent != null && invokerLogContent.contains(JavadocUtil.ERROR_INIT_VM)) {
throw new MavenReportException(e.getMessage(), e);
}
} finally {
// just create the directory to prevent repeated invocations..
if (!location.exists()) {
getLog().warn("Creating fake javadoc directory to prevent repeated invocations: " + location);
location.mkdirs();
}
}
}
if (location.exists()) {
String url = getJavadocLink(p);
OfflineLink ol = new OfflineLink();
ol.setUrl(url);
ol.setLocation(location.getAbsolutePath());
if (getLog().isDebugEnabled()) {
getLog().debug("Added Javadoc offline link: " + url + " for the module: " + p.getId());
}
modulesLinks.add(ol);
}
}
return modulesLinks;
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method populateCompileArtifactMap.
/**
* Method to put the artifacts in the hashmap.
*
* @param compileArtifactMap the hashmap that will contain the artifacts
* @param artifactList the list of artifacts that will be put in the map
* @throws MavenReportException if any
*/
private void populateCompileArtifactMap(Map<String, Artifact> compileArtifactMap, Collection<Artifact> artifactList) throws MavenReportException {
if (artifactList == null) {
return;
}
for (Artifact newArtifact : artifactList) {
File file = newArtifact.getFile();
if (file == null) {
throw new MavenReportException("Error in plugin descriptor - " + "dependency was not resolved for artifact: " + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":" + newArtifact.getVersion());
}
if (compileArtifactMap.get(newArtifact.getDependencyConflictId()) != null) {
Artifact oldArtifact = compileArtifactMap.get(newArtifact.getDependencyConflictId());
ArtifactVersion oldVersion = new DefaultArtifactVersion(oldArtifact.getVersion());
ArtifactVersion newVersion = new DefaultArtifactVersion(newArtifact.getVersion());
if (newVersion.compareTo(oldVersion) > 0) {
compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
} else {
compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
}
}
Aggregations