[jboss-svn-commits] JBL Code SVN: r21621 - in labs/jbossrules/trunk/drools-core: src/main/java/org/drools/agent and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 19 02:33:54 EDT 2008


Author: Rikkola
Date: 2008-08-19 02:33:53 -0400 (Tue, 19 Aug 2008)
New Revision: 21621

Modified:
   labs/jbossrules/trunk/drools-core/.classpath
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/DirectoryScannerTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
Log:
JBRULES-1731: RuleAgent has some outstanding FIXME items in RuleAgentTest - specifically for windows

Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath	2008-08-19 05:23:08 UTC (rev 21620)
+++ labs/jbossrules/trunk/drools-core/.classpath	2008-08-19 06:33:53 UTC (rev 21621)
@@ -5,8 +5,8 @@
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.2.2/xstream-1.2.2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.2.2/xstream-1.2.2.jar" sourcepath="M2_REPO/com/thoughtworks/xstream/xstream/1.2.2/xstream-1.2.2-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel/2.0-dp4/mvel-2.0-dp4.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java	2008-08-19 05:23:08 UTC (rev 21620)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/FileScanner.java	2008-08-19 06:33:53 UTC (rev 21621)
@@ -14,157 +14,169 @@
 
 /**
  * This will monitor a file to a binary package.
+ * 
  * @author Michael Neale
- *
+ * 
  */
 public class FileScanner extends PackageProvider {
 
-    File[]              files;
-    Map                 lastUpdated   = new HashMap();
-    Map<String, String> pathToPackage = null;
+	File[] files;
+	Map lastUpdated = new HashMap();
+	Map<String, String> pathToPackage = null;
 
-    /**
-     * This sets the list of files to be monitored.
-     * This takes a list of paths and files (not directories).
-     */
-    void configure(Properties config) {
-        List paths = RuleAgent.list( config.getProperty( RuleAgent.FILES ) );
-        files = new File[paths.size()];
-        for ( int i = 0; i < paths.size(); i++ ) {
-            File file = new File( (String) paths.get( i ) );
-            if ( !file.exists() ) {
-                throw new IllegalArgumentException( "The file " + file.getName() + " does not exist." );
-            }
-            files[i] = file;
-        }
-    }
+	/**
+	 * This sets the list of files to be monitored. This takes a list of paths
+	 * and files (not directories).
+	 */
+	void configure(Properties config) {
+		List paths = RuleAgent.list(config.getProperty(RuleAgent.FILES));
+		files = new File[paths.size()];
+		for (int i = 0; i < paths.size(); i++) {
+			File file = new File((String) paths.get(i));
+			if (!file.exists()) {
+				throw new IllegalArgumentException("The file " + file.getName()
+						+ " does not exist.");
+			}
+			files[i] = file;
+		}
+	}
 
-    /**
-     * An alternative way to configure.
-     */
-    void setFiles(File[] files) {
-        this.files = files;
-    }
+	/**
+	 * An alternative way to configure.
+	 */
+	void setFiles(File[] files) {
+		this.files = files;
+	}
 
-    /**
-     * Perform the scan.
-     * If there was an error reading the packages, this will not fail, it will
-     * just do nothing (as there may be a temporary IO issue).
-     */
-    PackageChangeInfo loadPackageChanges() {
-        PackageChangeInfo changes = getChangeSet();
-        return changes;
-    }
+	/**
+	 * Perform the scan. If there was an error reading the packages, this will
+	 * not fail, it will just do nothing (as there may be a temporary IO issue).
+	 */
+	PackageChangeInfo loadPackageChanges() {
+		PackageChangeInfo changes = getChangeSet();
+		return changes;
+	}
 
-    /**
-     * Calculate a change set, based on last updated times.
-     * (keep a map of files).
-     */
-    private PackageChangeInfo getChangeSet() {
-        PackageChangeInfo info = new PackageChangeInfo();
-        if ( this.files == null ) return info;
+	/**
+	 * Calculate a change set, based on last updated times. (keep a map of
+	 * files).
+	 */
+	private PackageChangeInfo getChangeSet() {
+		PackageChangeInfo info = new PackageChangeInfo();
+		if (this.files == null)
+			return info;
 
-        if ( pathToPackage == null ) pathToPackage = new HashMap<String, String>();
+		if (pathToPackage == null)
+			pathToPackage = new HashMap<String, String>();
 
-        for ( int i = 0; i < files.length; i++ ) {
-            File f = files[i];
+		for (int i = 0; i < files.length; i++) {
+			File f = files[i];
 
-            if ( !f.exists() ) {
-                String name = pathToPackage.get( f.getPath() );
-                if ( name != null ) {
-                    info.addRemovedPackage( name );
-                }
-            } else if ( hasChanged( f.getPath(),
-                                    this.lastUpdated,
-                                    f.lastModified() ) ) {
-                Package p = readPackage( f );
-                if ( p != null ) {
-                    info.addPackage( p );
-                    pathToPackage.put( f.getPath(),
-                                       p.getName() );
-                }
-            }
-        }
-        return info;
-    }
+			if (!f.exists()) {
+				String name = pathToPackage.get(f.getPath());
+				if (name != null) {
+					info.addRemovedPackage(name);
+				}
+			} else if (hasChanged(f.getPath(), this.lastUpdated, f
+					.lastModified())) {
+				Package p = readPackage(f);
+				if (p != null) {
+					info.addPackage(p);
+					pathToPackage.put(f.getPath(), p.getName());
+				}
+			}
+		}
+		return info;
+	}
 
-    /**
-     * If an exception occurs, it is noted, but ignored.
-     * Especially IO, as generally they are temporary.
-     */
-    private Package readPackage(File pkgFile) {
+	/**
+	 * If an exception occurs, it is noted, but ignored. Especially IO, as
+	 * generally they are temporary.
+	 */
+	private Package readPackage(File pkgFile) {
 
-        String name = pkgFile.getName();
-        if ( !(name.endsWith( ".pkg" ) || name.endsWith( ".drl" ) || name.endsWith( ".xls" )) ) {
-            return null;
-        }
-        //use reflection to load if its DRL, the provider lives in drools compiler.
-        if ( pkgFile.getName().endsWith( ".drl" ) ) {
-            try {
-                FileLoader fl = (FileLoader) Class.forName( "org.drools.compiler.SourcePackageProvider" ).newInstance();
-                return fl.loadPackage( pkgFile );
-            } catch ( Exception e ) {
-                this.listener.exception( e );
-                return null;
-            }
+		String name = pkgFile.getName();
+		if (!(name.endsWith(".pkg") || name.endsWith(".drl") || name
+				.endsWith(".xls"))) {
+			return null;
+		}
+		// use reflection to load if its DRL, the provider lives in drools
+		// compiler.
+		if (pkgFile.getName().endsWith(".drl")) {
+			try {
+				FileLoader fl = (FileLoader) Class.forName(
+						"org.drools.compiler.SourcePackageProvider")
+						.newInstance();
+				return fl.loadPackage(pkgFile);
+			} catch (Exception e) {
+				this.listener.exception(e);
+				return null;
+			}
 
-            //use reflection to load if its XLS, the provider lives in drools decision tables.
-        } else if ( pkgFile.getName().endsWith( ".xls" ) ) {
-            try {
-                FileLoader fl = (FileLoader) Class.forName( "org.drools.decisiontable.SourcePackageProvider" ).newInstance();
-                return fl.loadPackage( pkgFile );
-            } catch ( Exception e ) {
-                this.listener.exception( e );
-                return null;
-            }
+			// use reflection to load if its XLS, the provider lives in drools
+			// decision tables.
+		} else if (pkgFile.getName().endsWith(".xls")) {
+			try {
+				FileLoader fl = (FileLoader) Class.forName(
+						"org.drools.decisiontable.SourcePackageProvider")
+						.newInstance();
+				return fl.loadPackage(pkgFile);
+			} catch (Exception e) {
+				this.listener.exception(e);
+				return null;
+			}
 
-        } else {
+		} else {
 
-            Package p1_ = null;
-            try {
-                p1_ = (Package) DroolsStreamUtils.streamIn( new FileInputStream( pkgFile ) );
-            } catch ( FileNotFoundException e ) {
-                this.listener.exception( e );
-                this.listener.warning( "Was unable to find the file " + pkgFile.getPath() );
-            } catch ( IOException e ) {
-                this.listener.exception( e );
-            } catch ( ClassNotFoundException e ) {
-                this.listener.exception( e );
-                this.listener.warning( "Was unable to load a class when loading a package. Perhaps it is missing from this application." );
-            }
-            return p1_;
-        }
-    }
+			Package p1_ = null;
+			try {
 
-    boolean hasChanged(String path,
-                       Map updates,
-                       long fileLastModified) {
+				FileInputStream fis = new FileInputStream(pkgFile);
 
-        if ( !updates.containsKey( path ) ) {
-            updates.put( path,
-                         new Long( fileLastModified ) );
-            return true;
-        } else {
-            Long last = (Long) updates.get( path );
-            if ( last.longValue() < fileLastModified ) {
-                updates.put( path,
-                             new Long( fileLastModified ) );
-                return true;
-            } else {
-                return false;
-            }
-        }
+				p1_ = (Package) DroolsStreamUtils.streamIn(fis);
 
-    }
+				fis.close();
 
-    public String toString() {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "FileScanner scanning: " );
-        for ( int i = 0; i < files.length; i++ ) {
-            File f = files[i];
-            buf.append( f.getPath() + " " );
-        }
-        return buf.toString();
-    }
+			} catch (FileNotFoundException e) {
+				this.listener.exception(e);
+				this.listener.warning("Was unable to find the file "
+						+ pkgFile.getPath());
+			} catch (IOException e) {
+				this.listener.exception(e);
+			} catch (ClassNotFoundException e) {
+				this.listener.exception(e);
+				this.listener
+						.warning("Was unable to load a class when loading a package. Perhaps it is missing from this application.");
+			}
+			return p1_;
+		}
+	}
 
+	boolean hasChanged(String path, Map updates, long fileLastModified) {
+
+		if (!updates.containsKey(path)) {
+			updates.put(path, new Long(fileLastModified));
+			return true;
+		} else {
+			Long last = (Long) updates.get(path);
+			if (last.longValue() < fileLastModified) {
+				updates.put(path, new Long(fileLastModified));
+				return true;
+			} else {
+				return false;
+			}
+		}
+
+	}
+
+	public String toString() {
+		StringBuffer buf = new StringBuffer();
+		buf.append("FileScanner scanning: ");
+		for (int i = 0; i < files.length; i++) {
+			File f = files[i];
+			buf.append(f.getPath() + " ");
+		}
+		return buf.toString();
+	}
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/DirectoryScannerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/DirectoryScannerTest.java	2008-08-19 05:23:08 UTC (rev 21620)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/DirectoryScannerTest.java	2008-08-19 06:33:53 UTC (rev 21621)
@@ -46,7 +46,7 @@
 		assertEquals(3, rb.getPackages().length);
 	}
 
-	public void FIXME_testScanDRLFileReplace() throws Exception {
+	public void testScanDRLFileReplace() throws Exception {
 		File dir = RuleBaseAssemblerTest.getTempDirectory();
 
 		Package p1 = new Package("p1");

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java	2008-08-19 05:23:08 UTC (rev 21620)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java	2008-08-19 06:33:53 UTC (rev 21621)
@@ -224,7 +224,7 @@
 
     }
     
-    public void FIXME_testPollingFilesRuleBaseRemoveNewInstanceFalse() throws Exception {
+    public void testPollingFilesRuleBaseRemoveNewInstanceFalse() throws Exception {
     	File dir = RuleBaseAssemblerTest.getTempDirectory();
     	
     	Package p1 = new Package("p1");
@@ -248,9 +248,9 @@
     	RuleBase rb = ag.getRuleBase();
     	assertEquals(2, rb.getPackages().length);
     	
-    	
+
     	boolean success = p2f.delete();
-    	assertTrue(success); // <-- does not work on windows
+    	assertTrue(success); 
     	
     	ag.refreshRuleBase();
 
@@ -275,7 +275,7 @@
     	
     }
     
-    public void FIXME_testPollingFilesRuleBaseRemoveNewInstanceTrue() throws Exception {
+    public void testPollingFilesRuleBaseRemoveNewInstanceTrue() throws Exception {
     	File dir = RuleBaseAssemblerTest.getTempDirectory();
     	
     	Package p1 = new Package("p1");




More information about the jboss-svn-commits mailing list