sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Remove the "stylesheet.css" copy from the custom doclet, replaced by the standard "--add-stylesheet" option.
Date Thu, 16 Aug 2018 10:20:31 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new d4664f6  Remove the "stylesheet.css" copy from the custom doclet, replaced by the
standard "--add-stylesheet" option.
d4664f6 is described below

commit d4664f68ebd3759af88ea70a3d5bb91d82a319c2
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Aug 16 12:19:37 2018 +0200

    Remove the "stylesheet.css" copy from the custom doclet, replaced by the standard "--add-stylesheet"
option.
---
 .../org/apache/sis/internal/doclet/Doclet.java     | 180 +++++++--------------
 pom.xml                                            |   8 +-
 src/main/javadoc/{stylesheet.css => sis.css}       |   1 -
 3 files changed, 59 insertions(+), 130 deletions(-)

diff --git a/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
b/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
index 103cd70..dce22e1 100644
--- a/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
+++ b/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java
@@ -20,18 +20,14 @@ import java.util.Set;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileNotFoundException;
+import java.io.UncheckedIOException;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.nio.file.FileSystemException;
 import java.nio.file.Files;
 import javax.tools.Diagnostic;
 import jdk.javadoc.doclet.Reporter;
@@ -64,24 +60,9 @@ import com.sun.source.util.DocTrees;
  */
 public final class Doclet extends StandardDoclet {
     /**
-     * The name of the standard stylesheet file generated by Javadoc.
+     * The name of the SIS-specific stylesheet file.
      */
-    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";
+    private static final String STYLESHEET = "sis.css";
 
     /**
      * The directory where HTML pages will be written.
@@ -174,45 +155,40 @@ public final class Doclet extends StandardDoclet {
      * @return {@code true} on success, or {@code false} on failure.
      */
     @Override
-    @SuppressWarnings("CallToPrintStackTrace")
     public boolean run(final DocletEnvironment environment) {
         trees = environment.getDocTrees();
         final boolean success = super.run(environment);
         if (success && outputDirectory != null) try {
-            final File output = new File(outputDirectory);
-            final File customCSS = customCSS(output);
-            copyStylesheet(customCSS, output);
-            copyResources(customCSS.getParentFile(), output);
+            final Path output = Paths.get(outputDirectory);
+            final Path resources = resources(output);
+            copyResources(resources, output);
             final Rewriter r = new Rewriter();
-            for (final File file : output.listFiles()) {
+            for (final File file : output.toFile().listFiles()) {
                 if (file.isDirectory()) {       // Do not process files in the root directory,
only in sub-directories.
                     r.processDirectory(file);
                 }
             }
         } catch (IOException e) {
-            if (reporter != null) {
-                final StringWriter buffer = new StringWriter();
-                final PrintWriter p = new PrintWriter(buffer);
-                e.printStackTrace(p);
-                reporter.print(Diagnostic.Kind.ERROR, buffer.toString());
-            } else {
-                e.printStackTrace();            // This fallback should not be needed, but
we are paranoiac.
-            }
+            error(e);
+            return false;
+        } catch (UncheckedIOException e) {
+            error(e.getCause());
             return false;
         }
         return success;
     }
 
     /**
-     * Scans parents of the given directory until we find the root of the Maven project and
the custom CSS file.
+     * Returns the {@code src/main/javadoc/} directory relative to the root of the Maven
project.
+     * This method scans parents of the given directory until we find the root of the Maven
project.
      */
-    private static File customCSS(File directory) throws FileNotFoundException {
+    private static Path resources(Path directory) throws FileNotFoundException {
         boolean isModuleDirectory = false;
-        while ((directory = directory.getParentFile()) != null && directory.canRead())
{
-            if (new File(directory, "pom.xml").isFile()) {
+        while ((directory = directory.getParent()) != null && Files.isDirectory(directory))
{
+            if (Files.isRegularFile(directory.resolve("pom.xml"))) {
                 isModuleDirectory = true;
-                final File candidate = new File(directory, CUSTOM_CSS);
-                if (candidate.exists()) {
+                final Path candidate = directory.resolve("src").resolve("main").resolve("javadoc");
+                if (Files.isRegularFile(candidate.resolve(STYLESHEET))) {
                     return candidate;
                 }
             } else if (isModuleDirectory) {
@@ -221,65 +197,7 @@ public final class Doclet extends StandardDoclet {
                 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 {
-        return new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING));
-    }
-
-    /**
-     * Opens a CSS file for writing.
-     */
-    private static BufferedWriter openWriter(final File file) throws IOException {
-        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), ENCODING));
-    }
-
-    /**
-     * Copies the standard CSS file, then copies the custom CSS file.
-     * If the {@value #RENAMED_CSS} file already exists, it will not be overwritten.
-     *
-     * @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);
-        final File standardFile   = new File(outputDirectory, RENAMED_CSS);
-        if (!standardFile.exists()) {
-            /*
-             * Copy the standard CSS file, skipping the import of DejaVu font
-             * since our custom CSS file does not use it.
-             */
-            try (BufferedReader in  = openReader(stylesheetFile);
-                 BufferedWriter out = openWriter(standardFile))
-            {
-                String line;
-                while ((line = in.readLine()) != null) {
-                    if (!line.equals("@import url('resources/fonts/dejavu.css');")) {
-                        out.write(line);
-                        out.newLine();
-                    }
-                }
-            }
-        }
-        /*
-         * Copy the custom CSS file, skipping comments for more compact file.
-         */
-        try (BufferedReader in  = openReader(inputFile);
-             BufferedWriter out = openWriter(stylesheetFile))
-        {
-            String line;
-            while ((line = in.readLine()) != null) {
-                if (line.length() < 2 || line.charAt(1) != '*') {
-                    out.write(line);
-                    out.newLine();
-                }
-            }
-        }
+        throw new FileNotFoundException("Can not locate \"src/main/javadoc\" from the root
of this Maven project.");
     }
 
     /**
@@ -292,31 +210,43 @@ public final class Doclet extends StandardDoclet {
      * @param  outputDirectory  the directory where to copy the resource files.
      * @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((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());
-                if (!output.exists()) { // For avoiding a failure if the target exists.
-                    Files.createLink(output.toPath(), input.toPath());
-                }
-            }
-        } catch (UnsupportedOperationException | FileSystemException e) {
-            /*
-             * If hard links are not supported, performs plain copy instead.
-             */
-            final byte[] buffer = new byte[4096];
-            for (final File input : inputFiles) {
-                try (FileInputStream  in  = new FileInputStream(input);
-                     FileOutputStream out = new FileOutputStream(new File(outputDirectory,
input.getName())))
-                {
-                    int c;
-                    while ((c = in.read(buffer)) >= 0) {
-                        out.write(buffer, 0, c);
+    private static void copyResources(final Path inputDirectory, final Path outputDirectory)
throws IOException {
+        Files.walk(inputDirectory).forEach((input) -> {
+            if (Files.isRegularFile(input)) {
+                final Path file = input.getFileName();
+                switch (file.toString()) {
+                    case "overview.html":
+                    case STYLESHEET: break;
+                    default: {
+                        final Path output = outputDirectory.resolve(input.getFileName());
+                        if (!Files.exists(output)) try {
+                            try {
+                                Files.createLink(output, input);
+                            } catch (UnsupportedOperationException e) {
+                                Files.copy(input, output);
+                            }
+                        } catch (IOException e) {
+                            throw new UncheckedIOException(e);
+                        }
+                        break;
                     }
                 }
             }
+        });
+    }
+
+    /**
+     * Reports an I/O errors.
+     */
+    @SuppressWarnings("CallToPrintStackTrace")
+    private void error(final IOException e) {
+        if (reporter != null) {
+            final StringWriter buffer = new StringWriter();
+            final PrintWriter p = new PrintWriter(buffer);
+            e.printStackTrace(p);
+            reporter.print(Diagnostic.Kind.ERROR, buffer.toString());
+        } else {
+            e.printStackTrace();            // This fallback should not be needed, but we
are paranoiac.
         }
     }
 }
diff --git a/pom.xml b/pom.xml
index 88023c8..2a552e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -575,7 +575,7 @@
             <configuration>
               <rules>
                 <requireJavaVersion>
-                  <version>9</version>
+                  <version>10</version>
                 </requireJavaVersion>
               </rules>
             </configuration>
@@ -802,9 +802,9 @@
             <link>http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/javadoc</link>
           </links>
 
-          <additionalparam>
-              -Xdoclint:syntax -Xdoclint:html -Xdoclint:missing -Xdoclint:accessibility
-          </additionalparam>
+          <additionalOptions>
+            <additionalOption>--add-stylesheet "${maven.multiModuleProjectDirectory}/src/main/javadoc/sis.css"</additionalOption>
+          </additionalOptions>
 
           <!-- Separates packages on the overview page into the groups specified. -->
           <groups>
diff --git a/src/main/javadoc/stylesheet.css b/src/main/javadoc/sis.css
similarity index 99%
rename from src/main/javadoc/stylesheet.css
rename to src/main/javadoc/sis.css
index e44e8ea..b9eb105 100644
--- a/src/main/javadoc/stylesheet.css
+++ b/src/main/javadoc/sis.css
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@import url('standard.css');
 
 /*
  * This file is divided in two parts. The first part is specific to the SIS project


Mime
View raw message