Author: desruisseaux
Date: Thu Jan 8 10:21:33 2015
New Revision: 1650243
URL: http://svn.apache.org/r1650243
Log:
Change in the custom doclet implementation strategy, trying to avoid wrapping
the standard RootDoc.
With the previous implementation (using a wrapper), the doc-files directory
were correctly copied
on JDK6 and JDK7, but not on JDK8.
Removed:
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/FilteredRootDoc.java
Modified:
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/package-info.java
sis/branches/JDK8/pom.xml
Modified:
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java?rev=1650243&r1=1650242&r2=1650243&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
[UTF-8] Thu Jan 8 10:21:33 2015
@@ -16,16 +16,15 @@
*/
package org.apache.sis.internal.doclet;
-import java.util.Arrays;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.FilenameFilter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.FileSystemException;
@@ -35,10 +34,18 @@ import com.sun.tools.doclets.formats.htm
/**
- * A doclet which delegates the work to the standard doclet, except for the
{@code -stylesheet} option.
- * Rather than overwriting the standard stylesheet with the given one, this
keep both the standard and
- * the specified stylesheets as separated files. The standard stylesheet will
be renamed {@code standard.css}.
- * The stylesheet provided by the user shall contains an import statement for
the standard stylesheet.
+ * A doclet which delegates the work to the standard doclet, then performs
additional actions.
+ * The post-javadoc actions are:
+ *
+ * <ul>
+ * <li>Rename {@code "stylesheet.css"} as {@code "standarc.css"}.</li>
+ * <li>Copy {@code "src/main/javadoc/stylesheet.css"} (from the project
root) to {@code "stylesheet.css"}.</li>
+ * <li>Copy additional resources.</li>
+ * </ul>
+ *
+ * We do not use the standard {@code "-stylesheet"} Javadoc option because it
replaces the standard
+ * CSS by the specified one. Instead, we want to keep both the standard CSS
and our customized one.
+ * Our customized CSS shall contain an import statement for the standard
stylesheet.
*
* <p>This class presumes that all CSS files are encoded in UTF-8.</p>
*
@@ -49,6 +56,21 @@ import com.sun.tools.doclets.formats.htm
*/
public final class Doclet extends HtmlDoclet {
/**
+ * The name of the standard stylesheet file generated by Javadoc.
+ */
+ private static final String STYLESHEET = "stylesheet.css";
+
+ /**
+ * The name of the standard stylesheet after renaming by this doclet.
+ */
+ private static final String RENAMED_CSS = "standard.css";
+
+ /**
+ * Path to the custom CSS (relative to the project home).
+ */
+ private static final String CUSTOM_CSS = "src/main/javadoc/" + STYLESHEET;
+
+ /**
* The encoding to use for reading and writing CSS files.
*/
private static final String ENCODING = "UTF-8";
@@ -60,33 +82,20 @@ public final class Doclet extends HtmlDo
* @return {@code true} on success, or {@code false} on failure.
*/
public static boolean start(final RootDoc root) {
- String stylesheetFile = null;
String outputDirectory = null;
- final String[][] options = root.options();
- final String[][] filteredOptions = new String[options.length][];
- int n = 0;
- for (final String[] option : options) {
+ for (final String[] option : root.options()) {
if (option.length == 2) {
- switch (option[0]) {
- case "-d":{
- outputDirectory = option[1];
- break;
- }
- case "-stylesheet":
- case "-stylesheetfile": {
- stylesheetFile = option[1];
- continue; // Do not copy this option.
- }
+ if ("-d".equals(option[0])) {
+ outputDirectory = option[1];
}
}
- filteredOptions[n++] = option;
}
- final boolean status = HtmlDoclet.start(new FilteredRootDoc(root,
Arrays.copyOf(filteredOptions, n)));
- if (stylesheetFile != null && outputDirectory != null) try {
- final File input = new File(stylesheetFile);
+ final boolean status = HtmlDoclet.start(root);
+ if (outputDirectory != null) try {
final File output = new File(outputDirectory);
- copyStylesheet(input, output);
- copyResources(input.getParentFile(), output);
+ final File customCSS = customCSS(output);
+ copyStylesheet(customCSS, output);
+ copyResources(customCSS.getParentFile(), output);
} catch (IOException e) {
final StringWriter buffer = new StringWriter();
final PrintWriter p = new PrintWriter(buffer);
@@ -98,6 +107,27 @@ public final class Doclet extends HtmlDo
}
/**
+ * Scans parents of the given directory until we find the root of the
Maven project and the custom CSS file.
+ */
+ private static File customCSS(File directory) throws FileNotFoundException
{
+ boolean isModuleDirectory = false;
+ while ((directory = directory.getParentFile()) != null &&
directory.canRead()) {
+ if (new File(directory, "pom.xml").isFile()) {
+ isModuleDirectory = true;
+ final File candidate = new File(directory, CUSTOM_CSS);
+ if (candidate.exists()) {
+ return candidate;
+ }
+ } else if (isModuleDirectory) {
+ // If we were in a Maven module and the parent directory does
not
+ // have a pom.xml file, then we are no longer in the Maven
project.
+ break;
+ }
+ }
+ throw new FileNotFoundException("Can not locate " + CUSTOM_CSS + "
from the root of this Maven project.");
+ }
+
+ /**
* Opens a CSS file for reading.
*/
private static BufferedReader openReader(final File file) throws
IOException {
@@ -114,13 +144,13 @@ public final class Doclet extends HtmlDo
/**
* Copies the standard CSS file, then copies the custom CSS file.
*
- * @param inputFile The standard CSS file generated by the
standard doclet.
+ * @param inputFile The custom CSS file to copy in the destination
directory.
* @param outputDirectory The directory where to copy the CSS file.
* @throws IOException If an error occurred while reading or writing.
*/
private static void copyStylesheet(final File inputFile, final File
outputDirectory) throws IOException {
- final File stylesheetFile = new File(outputDirectory,
"stylesheet.css");
- final File standardFile = new File(outputDirectory, "standard.css");
+ final File stylesheetFile = new File(outputDirectory, STYLESHEET);
+ final File standardFile = new File(outputDirectory, RENAMED_CSS);
/*
* Copy the standard CSS file, skipping the import of DejaVu font
* since our custom CSS file does not use it.
@@ -163,13 +193,8 @@ public final class Doclet extends HtmlDo
* @throws IOException If an error occurred while reading or writing.
*/
private static void copyResources(final File inputDirectory, final File
outputDirectory) throws IOException {
- final File[] inputFiles = inputDirectory.listFiles(new
FilenameFilter() {
- @Override public boolean accept(final File dir, final String name)
{
- return !name.startsWith(".") &&
- !name.equals("overview.html") &&
- !name.equals("stylesheet.css");
- }
- });
+ final File[] inputFiles = inputDirectory.listFiles((final File dir,
final String name) ->
+ !name.startsWith(".") && !name.equals("overview.html") &&
!name.equals(STYLESHEET));
try {
for (final File input : inputFiles) {
final File output = new File(outputDirectory, input.getName());
Modified:
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/package-info.java?rev=1650243&r1=1650242&r2=1650243&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/package-info.java
[UTF-8] Thu Jan 8 10:21:33 2015
@@ -17,7 +17,7 @@
/**
- * Doclet that modify the behavior of some standard options.
+ * Doclet performing post-processing after Javadoc generation.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.5
Modified: sis/branches/JDK8/pom.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1650243&r1=1650242&r2=1650243&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Thu Jan 8 10:21:33 2015
@@ -537,8 +537,7 @@ Apache SIS is a free software, Java lang
<quiet>true</quiet> <!-- Shuts off
non-error and non-warning messages. -->
<keywords>true</keywords> <!-- Adds HTML
meta keyword tags to the generated files. -->
<breakiterator>true</breakiterator> <!-- Better
boundary detection when determining the end of the first sentence. -->
- <stylesheetfile>src/main/javadoc/stylesheet.css</stylesheetfile>
- <validateLinks>true</validateLinks>
+ <validateLinks>true</validateLinks> <!-- Validates
content of package-list resources. -->
<links>
<link>http://www.geoapi.org/snapshot/pending</link>
</links>