sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1626610 - in /sis/branches/JDK8: core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.java pom.xml
Date Sun, 21 Sep 2014 17:28:52 GMT
Author: desruisseaux
Date: Sun Sep 21 17:28:52 2014
New Revision: 1626610

URL: http://svn.apache.org/r1626610
Log:
Replace the 'maven-resources-plugin' (previously declared in the root pom.xml) by Java code
in our custom doclet.
The reason is that I didn't found a way to get 'maven-resources-plugin' executed when 'mvn
javadoc" is executed,
rather than when "mvn install" is executed. The better alternative would have been to use
the <javadocDirectory>
or <javadocResourcesDirectory> maven-javadoc-plugin configuration, but I have been unable
to get it to work even
with absolute paths.

Modified:
    sis/branches/JDK8/core/sis-build-helper/src/main/java/org/apache/sis/internal/doclet/Doclet.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=1626610&r1=1626609&r2=1626610&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] Sun Sep 21 17:28:52 2014
@@ -25,6 +25,9 @@ import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
+import java.io.FilenameFilter;
+import java.nio.file.FileSystemException;
+import java.nio.file.Files;
 import com.sun.javadoc.RootDoc;
 import com.sun.tools.doclets.formats.html.HtmlDoclet;
 
@@ -78,7 +81,10 @@ public final class Doclet extends HtmlDo
         }
         final boolean status = HtmlDoclet.start(new FilteredRootDoc(root, Arrays.copyOf(filteredOptions,
n)));
         if (stylesheetFile != null && outputDirectory != null) try {
-            copyStylesheet(new File(stylesheetFile), new File(outputDirectory));
+            final File input  = new File(stylesheetFile);
+            final File output = new File(outputDirectory);
+            copyStylesheet(input, output);
+            copyResources(input.getParentFile(), output);
         } catch (IOException e) {
             root.printError(e.toString());
             return false;
@@ -140,4 +146,47 @@ public final class Doclet extends HtmlDo
             }
         }
     }
+
+    /**
+     * Creates links to Javadoc resources in the top-level directory (not from "{@code doc-files}"
subdirectories).
+     * While the Maven documentation said that the "{@code src/main/javadoc}" directory is
copied by default, or a
+     * directory can be specified with {@code <javadocResourcesDirectory>}, I have
been unable to make it work even
+     * with absolute paths.
+     *
+     * @param  inputFile        The directory containing resources.
+     * @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(new FilenameFilter() {
+            @Override public boolean accept(final File dir, final String name) {
+                return !name.startsWith(".") &&
+                       !name.equals("overview.html") &&
+                       !name.equals("stylesheet.css");
+            }
+        });
+        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 (final FileInputStream  in  = new FileInputStream(input);
+                     final FileOutputStream out = new FileOutputStream(new File(outputDirectory,
input.getName())))
+                {
+                    int c;
+                    while ((c = in.read(buffer)) >= 0) {
+                        out.write(buffer, 0, c);
+                    }
+                }
+            }
+        }
+    }
 }

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1626610&r1=1626609&r2=1626610&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Sun Sep 21 17:28:52 2014
@@ -521,39 +521,6 @@ Apache SIS is a free software, Java lang
         </configuration>
       </plugin>
 
-      <!-- Copy Javadoc resources in the top-level directory (not from "doc-files" subdirectories).
-           While the Maven documentation said that the "src/main/javadoc" directory is copied
by default,
-           or a directory can be specified with <javadocResourcesDirectory>, I have
been unable to make it
-           work even with absolute paths.
-        -->
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-resources-plugin</artifactId>
-        <configuration>
-          <encoding>${project.build.sourceEncoding}</encoding>
-        </configuration>
-        <executions>
-          <execution>
-            <id>copy-resources</id>
-            <phase>prepare-package</phase> <!-- TODO: find some way to execute
this plugin only before javadoc, not before JAR. -->
-            <goals>
-              <goal>copy-resources</goal>
-            </goals>
-            <configuration>
-              <resources>
-                <resource>
-                  <directory>src/main/javadoc/</directory>
-                  <includes>
-                    <include>*.png</include>
-                  </includes>
-                </resource>
-              </resources>
-              <outputDirectory>${basedir}/target/site/apidocs/</outputDirectory>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-
       <!-- JavaDoc configuration. -->
       <plugin>
         <artifactId>maven-javadoc-plugin</artifactId>



Mime
View raw message