[jboss-svn-commits] JBL Code SVN: r24403 - in labs/jbossrules/trunk: drools-container and 20 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 17 11:21:00 EST 2008
Author: alesj
Date: 2008-12-17 11:21:00 -0500 (Wed, 17 Dec 2008)
New Revision: 24403
Added:
labs/jbossrules/trunk/drools-container/
labs/jbossrules/trunk/drools-container/drools-mc/
labs/jbossrules/trunk/drools-container/drools-mc/pom.xml
labs/jbossrules/trunk/drools-container/drools-mc/src/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResourceProvider.java
labs/jbossrules/trunk/drools-container/drools-mc/src/main/resources/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/BaseTest.java
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/first.txt
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/second.xml
Modified:
labs/jbossrules/trunk/pom.xml
Log:
[JBRULES-1897]; initial MC int; Resource impl over VFS.
Added: labs/jbossrules/trunk/drools-container/drools-mc/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/pom.xml (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/pom.xml 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>drools</artifactId>
+ <groupId>org.drools</groupId>
+ <version>5.0.0.SNAPSHOT</version>
+ </parent>
+
+ <artifactId>drools-mc</artifactId>
+ <packaging>jar</packaging>
+ <name>Drools :: Microcontainer</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <aggregate>false</aggregate>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+ </links>
+ <minmemory>128m</minmemory>
+ <maxmemory>512</maxmemory>
+ <author>false</author>
+ <bottom>true</bottom>
+ <header>JBoss Drools</header>
+ <packagenames>org.drools.*</packagenames>
+ <use>true</use>
+ <version>true</version>
+ <windowtitle>${project.name} ${project.version} API</windowtitle>
+ <breakiterator>true</breakiterator>
+ <excludePackageNames>org.drools.asm*,org.drools.objenesis.*,org.drools.commons.jci.*
+ </excludePackageNames>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+
+</project>
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.drools.mc.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import java.util.Collections;
+import java.util.ArrayList;
+
+import org.drools.io.Resource;
+import org.drools.io.impl.BaseResource;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * JBoss VFS based Resource impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VFSResource extends BaseResource
+{
+ private URL url;
+ private VirtualFile file;
+ private long lastRead = -1;
+
+ public VFSResource(URL url)
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+ this.url = url;
+ }
+
+ public VFSResource(VirtualFile file)
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+ this.file = file;
+ }
+
+ /**
+ * Get file.
+ *
+ * @return virtual file instance
+ */
+ protected VirtualFile getFile()
+ {
+ if (file == null)
+ {
+ try
+ {
+ file = VFS.getCachedFile(url);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return file;
+ }
+
+ public URL getURL() throws IOException
+ {
+ try
+ {
+ return (url != null) ? url : getFile().toURL();
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ public boolean hasURL()
+ {
+ return true;
+ }
+
+ public boolean isDirectory()
+ {
+ try
+ {
+ // TODO - do you need to know if it's directory or if it has children, e.g. jar resource
+ return getFile().isLeaf() == false;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Collection<Resource> listResources()
+ {
+ try
+ {
+ List<VirtualFile> children = getFile().getChildren();
+ if (children == null || children.isEmpty())
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ List<Resource> resources = new ArrayList<Resource>(children.size());
+ for (VirtualFile child : children)
+ {
+ resources.add(new VFSResource(child));
+ }
+ return resources;
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public long getLastModified()
+ {
+ try
+ {
+ return getFile().getLastModified();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public long getLastRead()
+ {
+ return lastRead;
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ lastRead = System.currentTimeMillis();
+ return getFile().openStream();
+ }
+
+ public Reader getReader() throws IOException
+ {
+ return new InputStreamReader(getInputStream());
+ }
+}
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResourceProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResourceProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResourceProvider.java 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.drools.mc.io;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.drools.io.impl.ResourceProviderImpl;
+import org.drools.io.Resource;
+import org.drools.util.StringUtils;
+
+/**
+ * JBoss VFS based ResourceProvider impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VFSResourceProvider extends ResourceProviderImpl
+{
+ /**
+ * Determine a cleaned URL for the given original URL.
+ * @param originalUrl the original URL
+ * @param originalPath the original URL path
+ * @return the cleaned URL
+ * @see org.springframework.util.StringUtils#cleanPath
+ */
+ private static URL getCleanedUrl(URL originalUrl,
+ String originalPath) {
+ try {
+ return new URL( StringUtils.cleanPath( originalPath ) );
+ } catch ( MalformedURLException ex ) {
+ // Cleaned URL path cannot be converted to URL
+ // -> take original URL.
+ return originalUrl;
+ }
+ }
+
+ @Override
+ public Resource newUrlResource(URL url)
+ {
+ return new VFSResource(url);
+ }
+
+ @Override
+ public Resource newUrlResource(String path)
+ {
+ try
+ {
+ URL url = getCleanedUrl(new URL(path), path);
+ return new VFSResource(url);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/BaseTest.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/BaseTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/BaseTest.java 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.drools.test.mc;
+
+import java.net.URL;
+import java.security.PrivilegedAction;
+import java.security.AccessController;
+
+import junit.framework.TestCase;
+
+/**
+ * Base test class.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class BaseTest extends TestCase
+{
+ protected static URL findResource(final Class clazz, final String name)
+ {
+ PrivilegedAction<URL> action = new PrivilegedAction<URL>()
+ {
+ public URL run()
+ {
+ return clazz.getResource(name);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+
+ protected URL getResource(String name)
+ {
+ URL url = findResource(getClass(), name);
+ assertNotNull("Resource not found: " + name, url);
+ return url;
+ }
+}
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.drools.test.mc.io.test;
+
+import java.net.URL;
+import java.util.Collection;
+
+import org.drools.io.InternalResource;
+import org.drools.io.Resource;
+import org.drools.io.ResourceProvider;
+import org.drools.mc.io.VFSResourceProvider;
+import org.drools.test.mc.BaseTest;
+
+/**
+ * Resources test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ResourcesTest extends BaseTest
+{
+ private ResourceProvider provider;
+
+ protected ResourceProvider getResourceProvider()
+ {
+ if (provider == null)
+ provider = new VFSResourceProvider();
+
+ return provider;
+ }
+
+ protected Resource testResource(String name)
+ {
+ URL url = getResource(name);
+ ResourceProvider provider = getResourceProvider();
+ Resource root = provider.newUrlResource(url);
+ assertNotNull(root);
+ return root;
+ }
+
+ public void testResource() throws Exception
+ {
+ Resource resource = testResource("/mc/io/root");
+ assertNotNull(resource.getInputStream());
+ assertNotNull(resource.getReader());
+ }
+
+ public void testInternalResource() throws Exception
+ {
+ Resource root = testResource("/mc/io/root");
+ assertTrue(root instanceof InternalResource);
+ InternalResource resource = InternalResource.class.cast(root);
+
+ assertTrue(resource.isDirectory());
+ assertTrue(resource.hasURL());
+ assertNotNull(resource.getURL());
+
+ assertEquals(-1l, resource.getLastRead());
+ assertNotNull(resource.getInputStream());
+ assertFalse(-1l == resource.getLastRead());
+
+ Collection<Resource> resources = resource.listResources();
+ assertNotNull(resources);
+ assertEquals(2, resources.size());
+ for (Resource child : resources)
+ {
+ assertNotNull(child.getInputStream());
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/first.txt
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/first.txt (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/first.txt 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1 @@
+first
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/second.xml
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/second.xml (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/root/second.xml 2008-12-17 16:21:00 UTC (rev 24403)
@@ -0,0 +1,3 @@
+<snd>
+ <element/>
+</snd>
\ No newline at end of file
Modified: labs/jbossrules/trunk/pom.xml
===================================================================
--- labs/jbossrules/trunk/pom.xml 2008-12-17 15:51:25 UTC (rev 24402)
+++ labs/jbossrules/trunk/pom.xml 2008-12-17 16:21:00 UTC (rev 24403)
@@ -722,6 +722,7 @@
<module>drools-repository</module>
<module>drools-guvnor</module>
<module>drools-solver</module>
+ <module>drools-container/drools-mc</module>
</modules>
<dependencies>
@@ -1126,6 +1127,13 @@
<version>1.3.2</version>
</dependency>
+ <!-- drools-mc -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>2.0.0.GA</version>
+ </dependency>
+
<!--
TODO looks like jsr170:jcr:1.0 isn't used any more, remove it from /repository/jsr170/jcr/1.0
It's also in the central repo: http://www.mvnrepository.com/artifact/javax.jcr/jcr
More information about the jboss-svn-commits
mailing list