From 1fa0f8df05e014ca456b3ba067fd79c4608f4cde Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 19 Apr 2011 08:59:48 +0000 Subject: [PATCH] Support listing all server side classes svn changeset:18372/svn branch:6.6 --- tests/src/com/vaadin/tests/VaadinClasses.java | 55 ++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/tests/src/com/vaadin/tests/VaadinClasses.java b/tests/src/com/vaadin/tests/VaadinClasses.java index 9aef3f5277..f6a737b957 100644 --- a/tests/src/com/vaadin/tests/VaadinClasses.java +++ b/tests/src/com/vaadin/tests/VaadinClasses.java @@ -42,6 +42,12 @@ public class VaadinClasses { for (Class 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> getComponents() { @@ -53,6 +59,17 @@ public class VaadinClasses { } } + public static List> 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> getComponentContainers() { try { return findClasses(ComponentContainer.class, "com.vaadin.ui"); @@ -97,8 +114,12 @@ public class VaadinClasses { private static List> findClasses(Class baseClass, String basePackage) throws IOException { - List> componentContainers = new ArrayList>(); + return findClasses(baseClass, basePackage, new String[] {}); + } + private static List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) throws IOException { + List> classes = new ArrayList>(); 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>() { + Collections.sort(classes, new Comparator>() { - public int compare(Class o1, - Class o2) { - return o1.getName().compareTo(o2.getName()); - } + public int compare(Class o1, Class o2) { + return o1.getName().compareTo(o2.getName()); + } - }); - return componentContainers; + }); + return classes; } @@ -147,11 +167,18 @@ public class VaadinClasses { } private static void findPackages(File parent, String javaPackage, - Class baseClass, Collection> result) { + Class baseClass, Collection> 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 } } -- 2.39.5