[jboss-svn-commits] JBL Code SVN: r15870 - in labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools: brms/server/rules and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 17 02:17:41 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-10-17 02:17:41 -0400 (Wed, 17 Oct 2007)
New Revision: 15870

Added:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/server/rules/ClassWalker.java
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/client/modeldriven/testing/AssertFactValue.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java
Log:
attemping to improve the auto importing

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/client/modeldriven/testing/AssertFactValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/client/modeldriven/testing/AssertFactValue.java	2007-10-17 05:19:59 UTC (rev 15869)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/client/modeldriven/testing/AssertFactValue.java	2007-10-17 06:17:41 UTC (rev 15870)
@@ -2,12 +2,8 @@
 
 public class AssertFactValue implements Assertion {
 
-	public AssertFieldValue[] fieldValues;
+	public AssertFieldValue[] fieldValues = new AssertFieldValue[0];
 
-	/**
-	 * An MVEL expression that will resolve to true or false
-	 */
-	public String expression;
 
 
 }

Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/server/rules/ClassWalker.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/server/rules/ClassWalker.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/server/rules/ClassWalker.java	2007-10-17 06:17:41 UTC (rev 15870)
@@ -0,0 +1,139 @@
+package org.drools.brms.server.rules;
+/*
+ * Copyright 2007 Mark Derricutt
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+
+/**
+ * This is a utility to walk a tree of classes (recursively) and return a set
+ * of classes that match a package name.
+ *
+ * This is not currently used, as I can't work out a way to make it work including the dynamically added stuff into the MapBackedClassloader
+ * (ie classes added in memory only). It requires some more surgery to cope with this. Was worth a try though !
+ * (can be wired into the loadClass method of the SuggestionCompletionLoader).
+ *
+ * @author Mark Derricutt
+ * @author Michael Neale
+ */
+public class ClassWalker {
+
+
+    public static Set<Class> findClassesInPackage(String packageName, ClassLoader loader) {
+
+        Set<Class> acceptedClasses = new HashSet<Class>();
+
+        try {
+            String packageOnly = packageName;
+            boolean recursive = false;
+            if (packageName.endsWith(".*")) {
+                packageOnly = packageName.substring(0, packageName.lastIndexOf(".*"));
+                recursive = true;
+            }
+
+            String packageDirName = packageOnly.replace('.', '/');
+            Enumeration<URL> dirs = loader.getResources(packageDirName);
+
+            while (dirs.hasMoreElements()) {
+                URL url = dirs.nextElement();
+                if ("file".equals(url.getProtocol())) {
+                    findClassesInDirPackage(packageOnly,
+                            URLDecoder.decode(url.getFile(), "UTF-8"),
+                            recursive, acceptedClasses, loader
+                    );
+                } else if ("jar".equals(url.getProtocol())) {
+                    JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile();
+
+                    Enumeration<JarEntry> entries = jar.entries();
+                    while (entries.hasMoreElements()) {
+                        JarEntry entry = entries.nextElement();
+                        String name = entry.getName();
+
+                        if (!name.endsWith("/")) {
+                            String className = name.replaceAll("/", ".").replaceAll("\\.class", "");
+                            checkValidClass(className, acceptedClasses, loader);
+                        }
+                    }
+                }
+
+
+            }
+        } catch (IOException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+
+        return acceptedClasses;
+
+
+    }
+
+    private static void checkValidClass(String className, Set<Class> acceptedClasses, ClassLoader loader) {
+        try {
+            Class classClass = loader.loadClass(className);
+
+
+                acceptedClasses.add(classClass);
+
+
+        } catch (ClassNotFoundException e) {
+            // e.printStackTrace();
+        } catch (NoClassDefFoundError e) {
+            //
+        }
+    }
+
+    private static void findClassesInDirPackage(String packageName,
+                                                String packagePath,
+                                                final boolean recursive,
+                                                Set<Class> classes, ClassLoader loader) {
+        File dir = new File(packagePath);
+
+        if (!dir.exists() || !dir.isDirectory()) {
+            return;
+        }
+
+        File[] dirfiles = dir.listFiles(new FileFilter() {
+            public boolean accept(File file) {
+                return (recursive && file.isDirectory()) || (file.getName().endsWith(".class"));
+            }
+        });
+
+        for (File file : dirfiles) {
+            if (file.isDirectory()) {
+                findClassesInDirPackage(packageName + "." + file.getName(),
+                        file.getAbsolutePath(),
+                        recursive,
+                        classes, loader);
+            } else {
+                String className = file.getName().substring(0, file.getName().length() - 6);
+                checkValidClass(packageName + "." + className, classes, loader);
+            }
+        }
+    }
+
+
+}
+


Property changes on: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/brms/server/rules/ClassWalker.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java	2007-10-17 05:19:59 UTC (rev 15869)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/testframework/ScenarioRunner.java	2007-10-17 06:17:41 UTC (rev 15870)
@@ -7,6 +7,7 @@
 
 import org.drools.base.TypeResolver;
 import org.drools.brms.client.modeldriven.testing.AssertFactValue;
+import org.drools.brms.client.modeldriven.testing.AssertFieldValue;
 import org.drools.brms.client.modeldriven.testing.Assertion;
 import org.drools.brms.client.modeldriven.testing.FactData;
 import org.drools.brms.client.modeldriven.testing.FieldData;
@@ -59,7 +60,11 @@
 
 
 	private void verify(AssertFactValue value) {
-		
+		for (int i = 0; i < value.fieldValues.length; i++) {
+			AssertFieldValue verify = value.fieldValues[i];
+			verify.isChecked = true;
+
+		}
 	}
 
 




More information about the jboss-svn-commits mailing list