]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support listing all server side classes
authorArtur Signell <artur.signell@itmill.com>
Tue, 19 Apr 2011 08:59:48 +0000 (08:59 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 19 Apr 2011 08:59:48 +0000 (08:59 +0000)
svn changeset:18372/svn branch:6.6

tests/src/com/vaadin/tests/VaadinClasses.java

index 9aef3f527733d51a69aea011025d8245c59b80e0..f6a737b95775eb2e909affe51dcfa1955771b18d 100644 (file)
@@ -42,6 +42,12 @@ public class VaadinClasses {
         for (Class<? extends Component> c : getComponents()) {
             System.out.println(c.getName());
         }
+        System.out.println();
+        System.out.println("Server side classes");
+        System.out.println("===================");
+        for (Class<?> c : getAllServerSideClasses()) {
+            System.out.println(c.getName());
+        }
     }
 
     public static List<Class<? extends Component>> getComponents() {
@@ -53,6 +59,17 @@ public class VaadinClasses {
         }
     }
 
+    public static List<Class<? extends Object>> getAllServerSideClasses() {
+        try {
+            return findClasses(Object.class, "com.vaadin", new String[] {
+                    "com.vaadin.tests", "com.vaadin.demo",
+                    "com.vaadin.terminal.gwt.client" });
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
     public static List<Class<? extends ComponentContainer>> getComponentContainers() {
         try {
             return findClasses(ComponentContainer.class, "com.vaadin.ui");
@@ -97,8 +114,12 @@ public class VaadinClasses {
 
     private static <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
             String basePackage) throws IOException {
-        List<Class<? extends T>> componentContainers = new ArrayList<Class<? extends T>>();
+        return findClasses(baseClass, basePackage, new String[] {});
+    }
 
+    private static <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
+            String basePackage, String[] ignoredPackages) throws IOException {
+        List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
         String basePackageDirName = "/" + basePackage.replace('.', '/');
         URL location = Application.class.getResource(basePackageDirName);
         if (location.getProtocol().equals("file")) {
@@ -108,25 +129,24 @@ public class VaadinClasses {
                     throw new IOException("Directory " + f.toString()
                             + " does not exist");
                 }
-                findPackages(f, basePackage, baseClass, componentContainers);
+                findPackages(f, basePackage, baseClass, classes,
+                        ignoredPackages);
             } catch (URISyntaxException e) {
                 throw new IOException(e.getMessage());
             }
         } else if (location.getProtocol().equals("jar")) {
             JarURLConnection juc = (JarURLConnection) location.openConnection();
-            findPackages(juc, basePackage, baseClass, componentContainers);
+            findPackages(juc, basePackage, baseClass, classes);
         }
 
-        Collections.sort(componentContainers,
-                new Comparator<Class<? extends T>>() {
+        Collections.sort(classes, new Comparator<Class<? extends T>>() {
 
-                    public int compare(Class<? extends T> o1,
-                            Class<? extends T> o2) {
-                        return o1.getName().compareTo(o2.getName());
-                    }
+            public int compare(Class<? extends T> o1, Class<? extends T> o2) {
+                return o1.getName().compareTo(o2.getName());
+            }
 
-                });
-        return componentContainers;
+        });
+        return classes;
 
     }
 
@@ -147,11 +167,18 @@ public class VaadinClasses {
     }
 
     private static <T> void findPackages(File parent, String javaPackage,
-            Class<T> baseClass, Collection<Class<? extends T>> result) {
+            Class<T> baseClass, Collection<Class<? extends T>> result,
+            String[] ignoredPackages) {
+        for (String ignoredPackage : ignoredPackages) {
+            if (javaPackage.equals(ignoredPackage)) {
+                return;
+            }
+        }
+
         for (File file : parent.listFiles()) {
             if (file.isDirectory()) {
                 findPackages(file, javaPackage + "." + file.getName(),
-                        baseClass, result);
+                        baseClass, result, ignoredPackages);
             } else if (file.getName().endsWith(".class")) {
                 String fullyQualifiedClassName = javaPackage + "."
                         + file.getName().replace(".class", "");
@@ -176,6 +203,8 @@ public class VaadinClasses {
         } catch (Exception e) {
             // Could ignore that class cannot be loaded
             e.printStackTrace();
+        } catch (LinkageError e) {
+            // Ignore. Client side classes will at least throw LinkageErrors
         }
 
     }