changeset 1037:136bdf5e6223

Only generate plugin docs for supported API Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-March/006078.html
author Omair Majid <omajid@redhat.com>
date Tue, 19 Mar 2013 18:16:29 -0400
parents 361b7725dfce
children 597cef77dc73
files distribution/tools/MergePluginDocs.java
diffstat 1 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/distribution/tools/MergePluginDocs.java	Tue Mar 19 17:54:56 2013 -0400
+++ b/distribution/tools/MergePluginDocs.java	Tue Mar 19 18:16:29 2013 -0400
@@ -60,7 +60,15 @@
     private static final String DOCS_FILE_NAME = CORE + ".xml";
     private static final String DOCS_ELEMENT = CORE;
 
+    private static final List<Path> corePaths = new LinkedList<>();
+
     public static void main(String[] args) throws IOException, XMLStreamException {
+        corePaths.add(Paths.get("agent").toAbsolutePath().normalize());
+        corePaths.add(Paths.get("launcher").toAbsolutePath().normalize());
+        corePaths.add(Paths.get("client").toAbsolutePath().normalize());
+        corePaths.add(Paths.get("common").toAbsolutePath().normalize());
+        corePaths.add(Paths.get("storage", "core").toAbsolutePath().normalize());
+
         String startPath = ".";
         if (args.length > 0) {
             startPath = args[0];
@@ -76,11 +84,15 @@
 
         Files.walkFileTree(Paths.get(startPath), new SimpleFileVisitor<Path>() {
             @Override
+            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+                if (!shouldEnter(dir)) {
+                    return FileVisitResult.SKIP_SUBTREE;
+                }
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                if (!Files.isRegularFile(file)) {
-                    throw new AssertionError("lrn2code, nub!");
-                }
-
                 if (file.getFileName().toString().equals(DOCS_FILE_NAME)) {
                     paths.add(file);
                 }
@@ -91,6 +103,17 @@
         return paths;
     }
 
+    /** Only enter a directory if it is (or could lead to) a directory we want to check */
+    private static boolean shouldEnter(Path toCheck) {
+        toCheck = toCheck.toAbsolutePath().normalize();
+        for (Path path : corePaths) {
+            if (toCheck.startsWith(path) || path.startsWith(toCheck)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private static String mergePluginDocs(List<Path> paths) throws IOException, XMLStreamException {
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         XMLEventFactory eventFactory = XMLEventFactory.newFactory();