[jboss-svn-commits] JBL Code SVN: r24270 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Dec 6 23:03:33 EST 2008
Author: mark.proctor at jboss.com
Date: 2008-12-06 23:03:33 -0500 (Sat, 06 Dec 2008)
New Revision: 24270
Added:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FileManager.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java
Log:
JBRULES-1885 Update KnowledgeAgent to use new Resource api
-Stop it scanning sub directories
JBRULES-1874 Create Resource Framework
JBRULES-1875 Load ChangeSet XML files for multiple resources
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-06 12:41:03 UTC (rev 24269)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -511,6 +511,9 @@
if ( iNestedResourceResource.isDirectory() ) {
this.resourceDirectories.add( iNestedResourceResource );
for ( Resource childResource : iNestedResourceResource.listResources() ) {
+ if ( ((InternalResource)childResource).isDirectory() ) {
+ continue; // ignore sub directories
+ }
((InternalResource)childResource).setResourceType( iNestedResourceResource.getResourceType() );
addKnowledgeResource( childResource, iNestedResourceResource.getResourceType(), iNestedResourceResource.getConfiguration() );
}
Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -0,0 +1,262 @@
+package org.drools.agent;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.drools.builder.ResourceType;
+import org.drools.io.ResourceChangeScannerConfiguration;
+import org.drools.io.ResourceFactory;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.util.FileManager;
+
+public class KnowledgeAgentTest extends TestCase {
+ FileManager fileManager;
+
+ protected void setUp() throws Exception {
+ fileManager = new FileManager();
+ fileManager.setUp();
+ ResourceFactory.getResourceChangeNotifierService().start();
+ ResourceFactory.getResourceChangeScannerService().start();
+ }
+
+
+ protected void tearDown() throws Exception {
+ //fileManager.tearDown();
+ ResourceFactory.getResourceChangeNotifierService().stop();
+ ResourceFactory.getResourceChangeScannerService().stop();
+ }
+
+ public void testModifyFile() throws IOException,
+ InterruptedException {
+ String rule1 = "";
+ rule1 += "package org.drools.test\n";
+ rule1 += "global java.util.List list\n";
+ rule1 += "rule rule1\n";
+ rule1 += "when\n";
+ rule1 += "then\n";
+ rule1 += "list.add( drools.getRule().getName() );\n";
+ rule1 += "end\n";
+ File f1 = fileManager.newFile( "rule1.drl" );
+ f1.deleteOnExit();
+ Writer output = new BufferedWriter( new FileWriter( f1 ) );
+ output.write( rule1 );
+ output.close();
+
+ String rule2 = "";
+ rule2 += "package org.drools.test\n";
+ rule2 += "global java.util.List list\n";
+ rule2 += "rule rule2\n";
+ rule2 += "when\n";
+ rule2 += "then\n";
+ rule2 += "list.add( drools.getRule().getName() );\n";
+ rule2 += "end\n";
+ File f2 = fileManager.newFile( "rule2.drl" );
+ f2.deleteOnExit();
+ output = new BufferedWriter( new FileWriter( f2 ) );
+ output.write( rule2 );
+ output.close();
+
+ String xml = "";
+ xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'";
+ xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
+ xml += " xs:schemaLocation='http://drools.org/drools-5.0/change-set drools-change-set-4.0.xsd' >";
+ xml += " <add> ";
+ xml += " <resource source='" + f1.toURI().toURL() + "' type='DRL' />";
+ xml += " <resource source='" + f2.toURI().toURL() + "' type='DRL' />";
+ xml += " </add> ";
+ xml += "</change-set>";
+ File fxml = fileManager.newFile( "changeset.xml" );
+ fxml.deleteOnExit();
+ output = new BufferedWriter( new FileWriter( fxml ) );
+ output.write( xml );
+ output.close();
+
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+
+ ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
+ sconf.setProperty( "drools.resource.scanner.interval",
+ "2" );
+ ResourceFactory.getResourceChangeScannerService().configure( sconf );
+
+ KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
+ aconf.setProperty( "drools.agent.scanDirectories",
+ "true" );
+ aconf.setProperty( "drools.agent.scanResources",
+ "true" );
+ aconf.setProperty( "drools.agent.newInstance",
+ "true" );
+ KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
+ kbase,
+ aconf );
+
+ kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
+
+ StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ List list = new ArrayList();
+ ksession.setGlobal( "list",
+ list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2,
+ list.size() );
+ assertTrue( list.contains( "rule1" ) );
+ assertTrue( list.contains( "rule2" ) );
+
+ list.clear();
+ rule1 = "";
+ rule1 += "package org.drools.test\n";
+ rule1 += "global java.util.List list\n";
+ rule1 += "rule rule3\n";
+ rule1 += "when\n";
+ rule1 += "then\n";
+ rule1 += "list.add( drools.getRule().getName() );\n";
+ rule1 += "end\n";
+ output = new BufferedWriter( new FileWriter( f1 ) );
+ output.write( rule1 );
+ output.close();
+ Thread.sleep( 3000 );
+
+ ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ list = new ArrayList();
+ ksession.setGlobal( "list",
+ list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2,
+ list.size() );
+
+ assertTrue( list.contains( "rule3" ) );
+ assertTrue( list.contains( "rule2" ) );
+ kagent.monitorResourceChangeEvents( false );
+ }
+
+ public void testModifyDirectory() throws IOException,
+ InterruptedException {
+ String rule1 = "";
+ rule1 += "package org.drools.test\n";
+ rule1 += "global java.util.List list\n";
+ rule1 += "rule rule1\n";
+ rule1 += "when\n";
+ rule1 += "then\n";
+ rule1 += "list.add( drools.getRule().getName() );\n";
+ rule1 += "end\n";
+ File f1 = fileManager.newFile( "rule1.drl" );
+
+ Writer output = new BufferedWriter( new FileWriter( f1 ) );
+ output.write( rule1 );
+ output.close();
+
+ String rule2 = "";
+ rule2 += "package org.drools.test\n";
+ rule2 += "global java.util.List list\n";
+ rule2 += "rule rule2\n";
+ rule2 += "when\n";
+ rule2 += "then\n";
+ rule2 += "list.add( drools.getRule().getName() );\n";
+ rule2 += "end\n";
+ File f2 = fileManager.newFile( "rule2.drl" );
+ output = new BufferedWriter( new FileWriter( f2 ) );
+ output.write( rule2 );
+ output.close();
+
+ String xml = "";
+ xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'";
+ xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
+ xml += " xs:schemaLocation='http://drools.org/drools-5.0/change-set drools-change-set-5.0.xsd' >";
+ xml += " <add> ";
+ xml += " <resource source='" + f1.getParentFile().toURI().toURL() + "' type='DRL' />";
+ xml += " </add> ";
+ xml += "</change-set>";
+ File newDir = fileManager.newFile( "changeset" );
+ newDir.mkdir();
+ File fxml = fileManager.newFile( newDir, "changeset.xml" );
+ output = new BufferedWriter( new FileWriter( fxml ) );
+ output.write( xml );
+ output.close();
+
+// KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+// kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
+// ResourceType.ChangeSet );
+// assertFalse( kbuilder.hasErrors() );
+
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ //kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
+ sconf.setProperty( "drools.resource.scanner.interval",
+ "2" );
+ ResourceFactory.getResourceChangeScannerService().configure( sconf );
+
+ KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
+ aconf.setProperty( "drools.agent.scanDirectories",
+ "true" );
+ aconf.setProperty( "drools.agent.newInstance",
+ "true" );
+
+ KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
+ kbase,
+ aconf );
+ kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
+
+ Thread.sleep( 3000 ); // give it 2 seconds to detect and build the changes
+ StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ List list = new ArrayList();
+ ksession.setGlobal( "list",
+ list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2,
+ list.size() );
+ assertTrue( list.contains( "rule1" ) );
+ assertTrue( list.contains( "rule2" ) );
+
+ list.clear();
+ String rule3 = "";
+ rule3 += "package org.drools.test\n";
+ rule3 += "global java.util.List list\n";
+ rule3 += "rule rule3\n";
+ rule3 += "when\n";
+ rule3 += "then\n";
+ rule3 += "list.add( drools.getRule().getName() );\n";
+ rule3 += "end\n";
+ File f3 = fileManager.newFile( "rule3.drl" );
+ output = new BufferedWriter( new FileWriter( f3 ) );
+ output.write( rule3 );
+ output.close();
+
+ assertTrue( f1.delete() );
+
+
+ Thread.sleep( 3000 );
+
+ ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ list = new ArrayList();
+ ksession.setGlobal( "list",
+ list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2,
+ list.size() );
+ assertTrue( list.contains( "rule2" ) );
+ assertTrue( list.contains( "rule3" ) );
+
+ kagent.monitorResourceChangeEvents( false );
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-06 12:41:03 UTC (rev 24269)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -10,7 +10,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-import java.util.UUID;
import junit.framework.TestCase;
@@ -36,21 +35,12 @@
import org.drools.io.impl.ResourceChangeNotifierImpl;
import org.drools.io.impl.UrlResource;
import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.util.FileManager;
import org.drools.xml.XmlChangeSetReader;
import org.xml.sax.SAXException;
public class ChangeSetTest extends TestCase {
- protected void setUp() throws Exception {
- ResourceFactory.getResourceChangeNotifierService().start();
- ResourceFactory.getResourceChangeScannerService().start();
- }
-
- protected void tearDown() throws Exception {
- ResourceFactory.getResourceChangeNotifierService().stop();
- ResourceFactory.getResourceChangeScannerService().stop();
- }
-
public void testXmlParser() throws SAXException,
IOException {
@@ -113,249 +103,4 @@
assertTrue( list.containsAll( Arrays.asList( new String[]{"rule1", "rule2"} ) ) );
}
- public void testModifyFile() throws IOException,
- InterruptedException {
- String rule1 = "";
- rule1 += "package org.drools.test\n";
- rule1 += "global java.util.List list\n";
- rule1 += "rule rule1\n";
- rule1 += "when\n";
- rule1 += "then\n";
- rule1 += "list.add( drools.getRule().getName() );\n";
- rule1 += "end\n";
- File f1 = File.createTempFile( "rule1",
- ".drl" );
- f1.deleteOnExit();
- Writer output = new BufferedWriter( new FileWriter( f1 ) );
- output.write( rule1 );
- output.close();
-
- String rule2 = "";
- rule2 += "package org.drools.test\n";
- rule2 += "global java.util.List list\n";
- rule2 += "rule rule2\n";
- rule2 += "when\n";
- rule2 += "then\n";
- rule2 += "list.add( drools.getRule().getName() );\n";
- rule2 += "end\n";
- File f2 = File.createTempFile( "rule2",
- ".drl" );
- f2.deleteOnExit();
- output = new BufferedWriter( new FileWriter( f2 ) );
- output.write( rule2 );
- output.close();
-
- String xml = "";
- xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'";
- xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
- xml += " xs:schemaLocation='http://drools.org/drools-5.0/change-set drools-change-set-4.0.xsd' >";
- xml += " <add> ";
- xml += " <resource source='" + f1.toURI().toURL() + "' type='DRL' />";
- xml += " <resource source='" + f2.toURI().toURL() + "' type='DRL' />";
- xml += " </add> ";
- xml += "</change-set>";
- File fxml = File.createTempFile( "changeset",
- ".xml" );
- fxml.deleteOnExit();
- output = new BufferedWriter( new FileWriter( fxml ) );
- output.write( xml );
- output.close();
-
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
-
- ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
- sconf.setProperty( "drools.resource.scanner.interval",
- "2" );
- ResourceFactory.getResourceChangeScannerService().configure( sconf );
-
- KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
- aconf.setProperty( "drools.agent.scanDirectories",
- "true" );
- aconf.setProperty( "drools.agent.scanResources",
- "true" );
- aconf.setProperty( "drools.agent.newInstance",
- "true" );
- KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
- kbase,
- aconf );
-
- kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
-
- StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
- List list = new ArrayList();
- ksession.setGlobal( "list",
- list );
- ksession.fireAllRules();
- ksession.dispose();
-
- assertEquals( 2,
- list.size() );
- assertTrue( list.contains( "rule1" ) );
- assertTrue( list.contains( "rule2" ) );
-
- list.clear();
- rule1 = "";
- rule1 += "package org.drools.test\n";
- rule1 += "global java.util.List list\n";
- rule1 += "rule rule3\n";
- rule1 += "when\n";
- rule1 += "then\n";
- rule1 += "list.add( drools.getRule().getName() );\n";
- rule1 += "end\n";
- output = new BufferedWriter( new FileWriter( f1 ) );
- output.write( rule1 );
- output.close();
- Thread.sleep( 3000 );
-
- ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
- list = new ArrayList();
- ksession.setGlobal( "list",
- list );
- ksession.fireAllRules();
- ksession.dispose();
-
- assertEquals( 2,
- list.size() );
-
- assertTrue( list.contains( "rule3" ) );
- assertTrue( list.contains( "rule2" ) );
- kagent.monitorResourceChangeEvents( false );
- }
-
- public void testModifyDirectory() throws IOException,
- InterruptedException {
- File dir = File.createTempFile( UUID.randomUUID().toString(),
- "" );
- dir = dir.getParentFile();
- dir.deleteOnExit();
-
- dir = new File( dir, UUID.randomUUID().toString() );
- dir.mkdir();
- dir.deleteOnExit();
-
- String rule1 = "";
- rule1 += "package org.drools.test\n";
- rule1 += "global java.util.List list\n";
- rule1 += "rule rule1\n";
- rule1 += "when\n";
- rule1 += "then\n";
- rule1 += "list.add( drools.getRule().getName() );\n";
- rule1 += "end\n";
- File f1 = File.createTempFile( "rule1",
- ".drl",
- dir );
- f1.deleteOnExit();
- Writer output = new BufferedWriter( new FileWriter( f1 ) );
- output.write( rule1 );
- output.close();
-
- String rule2 = "";
- rule2 += "package org.drools.test\n";
- rule2 += "global java.util.List list\n";
- rule2 += "rule rule2\n";
- rule2 += "when\n";
- rule2 += "then\n";
- rule2 += "list.add( drools.getRule().getName() );\n";
- rule2 += "end\n";
- File f2 = File.createTempFile( "rule2",
- ".drl",
- dir );
- f2.deleteOnExit();
- output = new BufferedWriter( new FileWriter( f2 ) );
- output.write( rule2 );
- output.close();
-
- String xml = "";
- xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'";
- xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
- xml += " xs:schemaLocation='http://drools.org/drools-5.0/change-set drools-change-set-5.0.xsd' >";
- xml += " <add> ";
- xml += " <resource source='" + f1.getParentFile().toURI().toURL() + "' type='DRL' />";
- xml += " </add> ";
- xml += "</change-set>";
- File fxml = File.createTempFile( "changeset",
- ".xml" );
- fxml.deleteOnExit();
- output = new BufferedWriter( new FileWriter( fxml ) );
- output.write( xml );
- output.close();
-
-// KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
-// kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
-// ResourceType.ChangeSet );
-// assertFalse( kbuilder.hasErrors() );
-
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- //kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
-
- ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
- sconf.setProperty( "drools.resource.scanner.interval",
- "2" );
- ResourceFactory.getResourceChangeScannerService().configure( sconf );
-
- KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
- aconf.setProperty( "drools.agent.scanDirectories",
- "true" );
- aconf.setProperty( "drools.agent.newInstance",
- "true" );
-
- KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
- kbase,
- aconf );
- kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
-
- Thread.sleep( 3000 ); // give it 2 seconds to detect and build the changes
- StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
- List list = new ArrayList();
- ksession.setGlobal( "list",
- list );
- ksession.fireAllRules();
- ksession.dispose();
-
- assertEquals( 2,
- list.size() );
- assertTrue( list.contains( "rule1" ) );
- assertTrue( list.contains( "rule2" ) );
-
- list.clear();
- String rule3 = "";
- rule3 += "package org.drools.test\n";
- rule3 += "global java.util.List list\n";
- rule3 += "rule rule3\n";
- rule3 += "when\n";
- rule3 += "then\n";
- rule3 += "list.add( drools.getRule().getName() );\n";
- rule3 += "end\n";
- File f3 = File.createTempFile( "rule3",
- ".drl",
- dir );
- f3.deleteOnExit();
- output = new BufferedWriter( new FileWriter( f3 ) );
- output.write( rule3 );
- output.close();
-
- assertTrue( f1.delete() );
-
-
- Thread.sleep( 3000 );
-
- ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
- list = new ArrayList();
- ksession.setGlobal( "list",
- list );
- ksession.fireAllRules();
- ksession.dispose();
-
- assertEquals( 2,
- list.size() );
- assertTrue( list.contains( "rule2" ) );
- assertTrue( list.contains( "rule3" ) );
-
- kagent.monitorResourceChangeEvents( false );
- }
-
- public static class FileManager {
- private Set<File> files;
- }
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-06 12:41:03 UTC (rev 24269)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -114,39 +114,63 @@
public void processChangeSet(ChangeSet changeSet,
ChangeSetState changeSetState) {
- for ( Resource child : changeSet.getResourcesAdded() ) {
- if ( ((InternalResource) child).getResourceType() == ResourceType.PKG ) {
- changeSetState.pkgs.add( child );
- }
-
- ResourceMapping mapping = this.resources.get( child );
- if ( mapping == null ) {
+ for ( Resource resource : changeSet.getResourcesAdded() ) {
+ if ( ((InternalResource)resource).isDirectory() ) {
+ this.resourceDirectories.add( resource );
this.notifier.subscribeResourceChangeListener( this,
- child );
- mapping = new ResourceMapping( child );
- this.resources.put( child,
- mapping );
- }
+ resource );
+ // if it's a dir, subscribe it's children first
+ for ( Resource child : ((InternalResource)resource).listResources() ) {
+ if ( ((InternalResource)child).isDirectory() ) {
+ continue; // ignore sub directories
+ }
+ ((InternalResource)child).setResourceType( ((InternalResource)resource).getResourceType() );
+ ResourceMapping mapping = this.resources.get( child );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ child );
+ mapping = new ResourceMapping( child );
+ this.resources.put( child,
+ mapping );
+ }
+ }
+ } else {
+ if ( ((InternalResource) resource).getResourceType() == ResourceType.PKG ) {
+ changeSetState.pkgs.add( resource );
+ } else if ( ((InternalResource) resource).getResourceType() == ResourceType.ChangeSet ) {
+ // @TODO
+ continue;
+ }
+
+ ResourceMapping mapping = this.resources.get( resource );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ resource );
+ mapping = new ResourceMapping( resource );
+ this.resources.put( resource,
+ mapping );
+ }
+ }
}
- for ( Resource child : changeSet.getResourcesRemoved() ) {
- if ( ((InternalResource) child).getResourceType() == ResourceType.ChangeSet ) {
- processChangeSet( child,
+ for ( Resource resource : changeSet.getResourcesRemoved() ) {
+ if ( ((InternalResource) resource).getResourceType() == ResourceType.ChangeSet ) {
+ processChangeSet( resource,
changeSetState );
- } else if ( changeSetState.scanDirectories && ((InternalResource) child).isDirectory() ) {
- this.resourceDirectories.remove( child );
+ } else if ( changeSetState.scanDirectories && ((InternalResource) resource).isDirectory() ) {
+ this.resourceDirectories.remove( resource );
this.notifier.unsubscribeResourceChangeListener( this,
- child );
+ resource );
} else {
- this.resources.remove( child );
+ this.resources.remove( resource );
this.notifier.unsubscribeResourceChangeListener( this,
- child );
+ resource );
}
}
// are we going to need kbuilder to build these resources?
for ( Resource resource : this.resources.keySet() ) {
- if ( ((InternalResource) resource).getResourceType() != ResourceType.ChangeSet && ((InternalResource) resource).getResourceType() != ResourceType.PKG || changeSetState.scanDirectories && !((InternalResource) resource).isDirectory() ) {
+ if ( ((InternalResource) resource).getResourceType() != ResourceType.ChangeSet && ((InternalResource) resource).getResourceType() != ResourceType.PKG ) {
changeSetState.needsKnowledgeBuilder = true;
break;
}
@@ -346,6 +370,8 @@
((InternalResource) resource).getResourceType() );
}
}
+
+ System.err.println( kbuilder.getErrors() );
this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
this.kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-06 12:41:03 UTC (rev 24269)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -91,6 +91,9 @@
// detect modified and added
for ( Resource resource : this.directories ) {
for ( Resource child : ((InternalResource) resource).listResources() ) {
+ if ( ((InternalResource) child).isDirectory() ) {
+ continue; // ignore sub directories
+ }
if ( !this.resources.containsKey( child ) ) {
System.out.println( "found new file : " + child );
// child is new
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FileManager.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FileManager.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FileManager.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -0,0 +1,94 @@
+/**
+ *
+ */
+package org.drools.util;
+
+import java.io.File;
+import java.util.UUID;
+
+public class FileManager {
+ //private Set<File> files;
+ private File root;
+
+ public void setUp() {
+ this.root = getRootDirectory();
+ }
+
+ public void tearDown() {
+ // GC and Sleep, to give OS maximum chance of allowing stuff to be deleted. Attempt 5 times
+ boolean result = false;
+ for ( int i = 0; i < 5 && !result; i++ ) {
+ System.gc();
+ try {
+ Thread.sleep( 250 );
+ } catch ( InterruptedException e ) {
+ throw new RuntimeException( "This should never happen" );
+ }
+
+ result = deleteDir( root );
+ }
+ }
+
+ public File newFile(String name) {
+ File file = new File( getRootDirectory(), name);
+ //files.add( file );
+ return file;
+ }
+
+ public File newFile(File dir, String name) {
+ File file = new File( dir, name);
+ //files.add( file );
+ return file;
+ }
+
+ public File getRootDirectory() {
+ if ( this.root != null ) {
+ return this.root;
+ }
+ File tmp = new File(System.getProperty( "java.io.tmpdir" ));
+ File f = new File(tmp, "__drools__" + UUID.randomUUID().toString() );
+ //files.add( f );
+ if (f.exists()) {
+ if (f.isFile()) {
+ throw new IllegalStateException("The temp directory exists as a file. Nuke it now !");
+ }
+ deleteDir( f );
+ f.mkdir();
+ } else {
+ f.mkdir();
+ }
+ this.root = f;
+ return this.root;
+ }
+
+
+ public boolean deleteDir(File dir) {
+
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (String child : children) {
+ File file = new File(dir, child);
+ boolean success = deleteDir( file );
+ if (!success) {
+ // this is a hack, but some time you need to wait for a file release to release
+ // Windows was having intermittent issues with DirectoryScannerTest with the dir not being empty
+ System.gc();
+ try {
+ Thread.sleep( 250 );
+ } catch ( InterruptedException e ) {
+ throw new RuntimeException( "This should never happen" );
+ }
+ success = deleteDir( file );
+ if ( !success) {
+ //ok now give up
+ //throw new RuntimeException("Unable to delete !");
+ return false;
+ }
+ }
+ }
+ }
+
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java 2008-12-06 12:41:03 UTC (rev 24269)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java 2008-12-07 04:03:33 UTC (rev 24270)
@@ -20,18 +20,24 @@
import org.drools.io.impl.ClassPathResource;
import org.drools.io.impl.KnowledgeResource;
import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.util.FileManager;
import org.drools.xml.XmlChangeSetReader;
import org.xml.sax.SAXException;
public class ChangeSetTest extends TestCase {
- protected void setUp() throws Exception {
+ FileManager fileManager;
+
+ protected void setUp() throws Exception {
+ fileManager = new FileManager();
+ fileManager.setUp();
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
}
protected void tearDown() throws Exception {
+ fileManager.tearDown();
ResourceFactory.getResourceChangeNotifierService().stop();
ResourceFactory.getResourceChangeScannerService().stop();
}
More information about the jboss-svn-commits
mailing list