[seam-commits] Seam SVN: r8306 - in trunk: src/interop/jbas5/META-INF and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu May 29 12:14:32 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-05-29 12:14:32 -0400 (Thu, 29 May 2008)
New Revision: 8306
Added:
trunk/src/main/org/jboss/seam/deployment/VFSScanner.java
Removed:
trunk/src/interop/jbas5/META-INF/seam-deployment.properties
trunk/src/interop/jbas5/org/jboss/seam/as5/vfs/VFSScanner.java
Modified:
trunk/build/core.pom.xml
trunk/build/root.pom.xml
trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
Log:
JBSEAM-3050
Modified: trunk/build/core.pom.xml
===================================================================
--- trunk/build/core.pom.xml 2008-05-29 03:47:21 UTC (rev 8305)
+++ trunk/build/core.pom.xml 2008-05-29 16:14:32 UTC (rev 8306)
@@ -300,6 +300,11 @@
<artifactId>hsqldb</artifactId>
<optional>true</optional>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
</dependencies>
Modified: trunk/build/root.pom.xml
===================================================================
--- trunk/build/root.pom.xml 2008-05-29 03:47:21 UTC (rev 8305)
+++ trunk/build/root.pom.xml 2008-05-29 16:14:32 UTC (rev 8306)
@@ -782,7 +782,7 @@
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
- <version>2.0.0.Beta7</version>
+ <version>2.0.0.Beta11</version>
</dependency>
<dependency>
Deleted: trunk/src/interop/jbas5/META-INF/seam-deployment.properties
===================================================================
--- trunk/src/interop/jbas5/META-INF/seam-deployment.properties 2008-05-29 03:47:21 UTC (rev 8305)
+++ trunk/src/interop/jbas5/META-INF/seam-deployment.properties 2008-05-29 16:14:32 UTC (rev 8306)
@@ -1 +0,0 @@
-org.jboss.seam.deployment.scanners=org.jboss.seam.as5.vfs.VFSScanner
Deleted: trunk/src/interop/jbas5/org/jboss/seam/as5/vfs/VFSScanner.java
===================================================================
--- trunk/src/interop/jbas5/org/jboss/seam/as5/vfs/VFSScanner.java 2008-05-29 03:47:21 UTC (rev 8305)
+++ trunk/src/interop/jbas5/org/jboss/seam/as5/vfs/VFSScanner.java 2008-05-29 16:14:32 UTC (rev 8306)
@@ -1,191 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.jboss.seam.as5.vfs;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-
-import org.jboss.seam.deployment.AbstractScanner;
-import org.jboss.seam.deployment.DeploymentStrategy;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * JBoss VSF aware scanner.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class VFSScanner extends AbstractScanner
-{
- private static final LogProvider log = Logging.getLogProvider(VFSScanner.class);
-
- public VFSScanner(DeploymentStrategy deploymentStrategy)
- {
- super(deploymentStrategy);
- }
-
- /**
- * Get the virtual file root.
- *
- * @param url the root URL
- * @param parentDepth level of parent depth
- * @return actual virtual file from url param
- * @throws IOException for any error
- */
- protected static VirtualFile getRoot(URL url, int parentDepth) throws IOException
- {
-
- log.trace("Root url: " + url);
-
- String urlString = url.toString();
- // TODO - this should go away once we figure out why -exp.war is part of CL resources
- if (urlString.startsWith("vfs") == false)
- return null;
-
- int p = urlString.indexOf(":");
- String file = urlString.substring(p + 1);
- URL vfsurl = null;
- String relative;
- File fp = new File(file);
-
- log.trace("File: " + fp);
-
- if (fp.exists())
- {
- vfsurl = fp.getParentFile().toURL();
- relative = fp.getName();
- }
- else
- {
- File curr = fp;
- relative = fp.getName();
- while ((curr = curr.getParentFile()) != null)
- {
- if (curr.exists())
- {
- vfsurl = curr.toURL();
- break;
- }
- else
- {
- relative = curr.getName() + "/" + relative;
- }
- }
- }
-
- log.trace("URL: " + vfsurl + ", relative: " + relative);
-
- VirtualFile top = VFS.getRoot(vfsurl);
- top = top.getChild(relative);
- while(parentDepth > 0)
- {
- if (top == null)
- throw new IllegalArgumentException("Null parent: " + vfsurl + ", relative: " + relative);
- top = top.getParent();
- parentDepth--;
- }
-
- log.trace("Top: " + top);
-
- return top;
- }
-
- public void scanDirectories(File[] directories)
- {
- for (File dir : directories)
- {
- try
- {
- VirtualFile root = getRoot(dir.toURL(), 0);
- if (root != null)
- handleRoot(root);
- else
- log.trace("Null root: " + dir);
- }
- catch (IOException e)
- {
- log.warn("Cannot scan directory " + dir, e);
- }
- }
- }
-
- public void scanResources(String[] resources)
- {
- for (String resourceName : resources)
- {
- try
- {
- Enumeration<URL> urlEnum = getDeploymentStrategy().getClassLoader().getResources(resourceName);
- while (urlEnum.hasMoreElements())
- {
- URL url = urlEnum.nextElement();
- VirtualFile root = getRoot(url, resourceName.lastIndexOf('/') > 0 ? 2 : 1);
- if (root != null)
- handleRoot(root);
- else
- log.trace("Null root: " + url);
- }
- }
- catch (IOException ioe)
- {
- log.warn("Cannot read resource: " + resourceName, ioe);
- }
- }
- }
-
- /**
- * Handle virtual file root.
- *
- * @param root the virtual file root
- * @throws IOException for any error
- */
- protected void handleRoot(VirtualFile root) throws IOException
- {
- if (root.isLeaf())
- {
- getDeploymentStrategy().handle(root.getPathName());
- }
- else
- {
- String rootPathName = root.getPathName();
- int rootPathNameLength = rootPathName.length();
- List<VirtualFile> children = root.getChildrenRecursively();
- for (VirtualFile child : children)
- {
- if (child.isLeaf())
- {
- String name = child.getPathName();
- // move past '/'
- int length = rootPathNameLength;
- if (name.charAt(length) == '/')
- length++;
- getDeploymentStrategy().handle(name.substring(length));
- }
- }
- }
- }
-}
Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-05-29 03:47:21 UTC (rev 8305)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-05-29 16:14:32 UTC (rev 8306)
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -188,8 +189,17 @@
return;
}
}
- log.debug("Using default URLScanner");
- this.scanner = new URLScanner(this);
+ // Use VFS Scanner if on JBoss 5 and not on Embedded
+ if (isVFSAvailable() && !isEmbedded() && isJBoss5())
+ {
+ log.debug("Using VFS aware scanner on JBoss 5");
+ this.scanner = new VFSScanner(this);
+ }
+ else
+ {
+ log.debug("Using default URLScanner");
+ this.scanner = new URLScanner(this);
+ }
}
private Scanner instantiateScanner(String className)
@@ -283,4 +293,54 @@
return null;
}
+ private static boolean isVFSAvailable()
+ {
+ try
+ {
+ Class.forName("org.jboss.virtual.VFS");
+ log.trace("VFS detected");
+ return true;
+ }
+ catch (Throwable t)
+ {
+ return false;
+ }
+ }
+
+ private static boolean isJBoss5()
+ {
+ try
+ {
+ Class versionClass = Class.forName("org.jboss.Version");
+ Method getVersionInstance = versionClass.getMethod("getInstance");
+ Object versionInstance = getVersionInstance.invoke(null);
+ Method getMajor = versionClass.getMethod("getMajor");
+ Object major = getMajor.invoke(versionInstance);
+ boolean isJBoss5 = major != null && major.equals(5);
+ if (isJBoss5)
+ {
+ log.trace("JBoss 5 detected");
+ }
+ return isJBoss5;
+ }
+ catch (Throwable t)
+ {
+ return false;
+ }
+ }
+
+ private static boolean isEmbedded()
+ {
+ try
+ {
+ Class.forName("org.jboss.embedded.Bootstrap");
+ log.trace("JBoss Embedded detected");
+ return true;
+ }
+ catch (Throwable t)
+ {
+ return false;
+ }
+ }
+
}
Added: trunk/src/main/org/jboss/seam/deployment/VFSScanner.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/VFSScanner.java (rev 0)
+++ trunk/src/main/org/jboss/seam/deployment/VFSScanner.java 2008-05-29 16:14:32 UTC (rev 8306)
@@ -0,0 +1,191 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.jboss.seam.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.jboss.seam.deployment.AbstractScanner;
+import org.jboss.seam.deployment.DeploymentStrategy;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * JBoss VSF aware scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSScanner extends AbstractScanner
+{
+ private static final LogProvider log = Logging.getLogProvider(VFSScanner.class);
+
+ public VFSScanner(DeploymentStrategy deploymentStrategy)
+ {
+ super(deploymentStrategy);
+ }
+
+ /**
+ * Get the virtual file root.
+ *
+ * @param url the root URL
+ * @param parentDepth level of parent depth
+ * @return actual virtual file from url param
+ * @throws IOException for any error
+ */
+ protected static VirtualFile getRoot(URL url, int parentDepth) throws IOException
+ {
+
+ log.trace("Root url: " + url);
+
+ String urlString = url.toString();
+ // TODO - this should go away once we figure out why -exp.war is part of CL resources
+ if (urlString.startsWith("vfs") == false)
+ return null;
+
+ int p = urlString.indexOf(":");
+ String file = urlString.substring(p + 1);
+ URL vfsurl = null;
+ String relative;
+ File fp = new File(file);
+
+ log.trace("File: " + fp);
+
+ if (fp.exists())
+ {
+ vfsurl = fp.getParentFile().toURL();
+ relative = fp.getName();
+ }
+ else
+ {
+ File curr = fp;
+ relative = fp.getName();
+ while ((curr = curr.getParentFile()) != null)
+ {
+ if (curr.exists())
+ {
+ vfsurl = curr.toURL();
+ break;
+ }
+ else
+ {
+ relative = curr.getName() + "/" + relative;
+ }
+ }
+ }
+
+ log.trace("URL: " + vfsurl + ", relative: " + relative);
+
+ VirtualFile top = VFS.getRoot(vfsurl);
+ top = top.getChild(relative);
+ while(parentDepth > 0)
+ {
+ if (top == null)
+ throw new IllegalArgumentException("Null parent: " + vfsurl + ", relative: " + relative);
+ top = top.getParent();
+ parentDepth--;
+ }
+
+ log.trace("Top: " + top);
+
+ return top;
+ }
+
+ public void scanDirectories(File[] directories)
+ {
+ for (File dir : directories)
+ {
+ try
+ {
+ VirtualFile root = getRoot(dir.toURL(), 0);
+ if (root != null)
+ handleRoot(root);
+ else
+ log.trace("Null root: " + dir);
+ }
+ catch (IOException e)
+ {
+ log.warn("Cannot scan directory " + dir, e);
+ }
+ }
+ }
+
+ public void scanResources(String[] resources)
+ {
+ for (String resourceName : resources)
+ {
+ try
+ {
+ Enumeration<URL> urlEnum = getDeploymentStrategy().getClassLoader().getResources(resourceName);
+ while (urlEnum.hasMoreElements())
+ {
+ URL url = urlEnum.nextElement();
+ VirtualFile root = getRoot(url, resourceName.lastIndexOf('/') > 0 ? 2 : 1);
+ if (root != null)
+ handleRoot(root);
+ else
+ log.trace("Null root: " + url);
+ }
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Cannot read resource: " + resourceName, ioe);
+ }
+ }
+ }
+
+ /**
+ * Handle virtual file root.
+ *
+ * @param root the virtual file root
+ * @throws IOException for any error
+ */
+ protected void handleRoot(VirtualFile root) throws IOException
+ {
+ if (root.isLeaf())
+ {
+ getDeploymentStrategy().handle(root.getPathName());
+ }
+ else
+ {
+ String rootPathName = root.getPathName();
+ int rootPathNameLength = rootPathName.length();
+ List<VirtualFile> children = root.getChildrenRecursively();
+ for (VirtualFile child : children)
+ {
+ if (child.isLeaf())
+ {
+ String name = child.getPathName();
+ // move past '/'
+ int length = rootPathNameLength;
+ if (name.charAt(length) == '/')
+ length++;
+ getDeploymentStrategy().handle(name.substring(length));
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/src/main/org/jboss/seam/deployment/VFSScanner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the seam-commits
mailing list