use of org.apache.maven.plugin.javadoc.options.OfflineLink in project maven-plugins by apache.
the class AbstractJavadocMojo method getDefaultJavadocApiLink.
/**
* @return if {@link #detectJavaApiLink}, the Java API link based on the {@link #javaApiLinks} properties and the
* value of the <code>source</code> parameter in the
* <code>org.apache.maven.plugins:maven-compiler-plugin</code>
* defined in <code>${project.build.plugins}</code> or in <code>${project.build.pluginManagement}</code>,
* or the {@link #fJavadocVersion}, or <code>null</code> if not defined.
* @see #detectJavaApiLink
* @see #javaApiLinks
* @see #DEFAULT_JAVA_API_LINKS
* @see <a href="http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source">source parameter</a>
* @since 2.6
*/
private OfflineLink getDefaultJavadocApiLink() {
if (!detectJavaApiLink) {
return null;
}
final String pluginId = "org.apache.maven.plugins:maven-compiler-plugin";
float sourceVersion = fJavadocVersion;
String sourceConfigured = getPluginParameter(project, pluginId, "source");
if (sourceConfigured != null) {
try {
sourceVersion = Float.parseFloat(sourceConfigured);
} catch (NumberFormatException e) {
getLog().debug("NumberFormatException for the source parameter in the maven-compiler-plugin. " + "Ignored it", e);
}
} else {
getLog().debug("No maven-compiler-plugin defined in ${build.plugins} or in " + "${project.build.pluginManagement} for the " + project.getId() + ". Added Javadoc API link according the javadoc executable version i.e.: " + fJavadocVersion);
}
// CHECKSTYLE_OFF: MagicNumber
String apiVersion = null;
if (sourceVersion >= 1.3f && sourceVersion < 1.4f) {
apiVersion = "1.3";
} else if (sourceVersion >= 1.4f && sourceVersion < 1.5f) {
apiVersion = "1.4";
} else if (sourceVersion >= 1.5f && sourceVersion < 1.6f) {
apiVersion = "1.5";
} else if (sourceVersion >= 1.6f && sourceVersion < 1.7f) {
apiVersion = "1.6";
} else if (sourceVersion >= 1.7f && sourceVersion < 1.8f) {
apiVersion = "1.7";
} else if (sourceVersion >= 1.8f) {
apiVersion = "1.8";
}
String javaApiLink = javaApiLinks.getProperty("api_" + apiVersion, null);
if (getLog().isDebugEnabled()) {
if (StringUtils.isNotEmpty(javaApiLink)) {
getLog().debug("Found Java API link: " + javaApiLink);
} else {
getLog().debug("No Java API link found.");
}
}
if (javaApiLink == null) {
return null;
}
File javaApiPackageListFile = new File(getJavadocOptionsFile().getParentFile(), "package-list");
OfflineLink link = new OfflineLink();
link.setLocation(javaApiPackageListFile.getParentFile().getAbsolutePath());
link.setUrl(javaApiLink);
InputStream in = null;
OutputStream out = null;
try {
in = this.getClass().getResourceAsStream("java-api-package-list-" + apiVersion);
out = new FileOutputStream(javaApiPackageListFile);
IOUtil.copy(in, out);
out.close();
out = null;
in.close();
in = null;
} catch (IOException ioe) {
logError("Can't get java-api-package-list-" + apiVersion + ": " + ioe.getMessage(), ioe);
return null;
} finally {
IOUtil.close(in);
IOUtil.close(out);
}
return link;
}
use of org.apache.maven.plugin.javadoc.options.OfflineLink in project maven-plugins by apache.
the class AbstractJavadocMojo method collectOfflineLinks.
private Set<OfflineLink> collectOfflineLinks() throws MavenReportException {
Set<OfflineLink> result = new LinkedHashSet<OfflineLink>();
OfflineLink javaApiLink = getDefaultJavadocApiLink();
if (javaApiLink != null) {
result.add(javaApiLink);
}
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.getOfflineLinks())) {
result.addAll(options.getOfflineLinks());
}
}
}
}
if (this.offlineLinks != null && this.offlineLinks.length > 0) {
result.addAll(Arrays.asList(this.offlineLinks));
}
return result;
}
use of org.apache.maven.plugin.javadoc.options.OfflineLink 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.plugin.javadoc.options.OfflineLink in project maven-plugins by apache.
the class AbstractJavadocMojo method addLinkofflineArguments.
/**
* Convenience method to process {@link #offlineLinks} values as individual <code>-linkoffline</code>
* javadoc options.
* <br/>
* If {@link #detectOfflineLinks}, try to add javadoc apidocs according Maven conventions for all modules given
* in the project.
*
* @param arguments a list of arguments, not null
* @throws MavenReportException if any
* @see #offlineLinks
* @see #getModulesLinks()
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#package-list">package-list spec</a>
*/
private void addLinkofflineArguments(List<String> arguments) throws MavenReportException {
Set<OfflineLink> offlineLinksList = collectOfflineLinks();
offlineLinksList.addAll(getModulesLinks());
for (OfflineLink offlineLink : offlineLinksList) {
String url = offlineLink.getUrl();
if (StringUtils.isEmpty(url)) {
continue;
}
url = cleanUrl(url);
String location = offlineLink.getLocation();
if (StringUtils.isEmpty(location)) {
continue;
}
if (isValidJavadocLink(location, false)) {
addArgIfNotEmpty(arguments, "-linkoffline", JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location), true);
}
}
}
Aggregations