[jboss-cvs] jboss-seam/src/main/org/jboss/seam/deployment ...
Ales Justin
ajustin at redhat.com
Mon Dec 3 15:29:49 EST 2007
User: alesj
Date: 07/12/03 15:29:49
Modified: src/main/org/jboss/seam/deployment Scanner.java
Log:
JBoss VFS aware Scanner.
Transparent usage of VFS via URL protocol.
Revision Changes Path
1.30 +60 -15 jboss-seam/src/main/org/jboss/seam/deployment/Scanner.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Scanner.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/deployment/Scanner.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- Scanner.java 21 Jun 2007 05:27:27 -0000 1.29
+++ Scanner.java 3 Dec 2007 20:29:49 -0000 1.30
@@ -1,4 +1,4 @@
-//$Id: Scanner.java,v 1.29 2007/06/21 05:27:27 gavin Exp $
+//$Id: Scanner.java,v 1.30 2007/12/03 20:29:49 alesj Exp $
package org.jboss.seam.deployment;
import java.io.DataInputStream;
@@ -12,14 +12,13 @@
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
+import java.util.jar.JarInputStream;
import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import javassist.bytecode.annotation.MemberValue;
-
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
@@ -38,6 +37,7 @@
protected String resourceName;
protected ClassLoader classLoader;
+ protected static Boolean useVFS;
public Scanner(String resourceName)
{
@@ -51,6 +51,25 @@
ClassFile.class.getPackage(); //to force loading of javassist, throwing an exception if it is missing
}
+ protected static boolean useVFS()
+ {
+ if (useVFS == null)
+ {
+ try
+ {
+ Class.forName("org.jboss.virtual.VFS");
+ useVFS = true;
+ log.info("Using JBoss VFS for scanning.");
+ }
+ catch(Throwable t)
+ {
+ useVFS = false;
+ log.debug("Using default file utils for scanning.");
+ }
+ }
+ return useVFS;
+ }
+
public static String filenameToClassname(String filename)
{
return filename.substring( 0, filename.lastIndexOf(".class") )
@@ -89,8 +108,9 @@
urlPath = URLDecoder.decode(urlPath, "UTF-8");
if ( urlPath.startsWith("file:") )
{
- // On windows urlpath looks like file:/C: on Linux file:/home
- // substring(5) works for both
+ if (useVFS())
+ urlPath = "vfs" + urlPath;
+ else
urlPath = urlPath.substring(5);
}
if ( urlPath.indexOf('!')>0 )
@@ -127,9 +147,14 @@
{
handleDirectory(file, null);
}
+ else if (useVFS())
+ {
+ URL url = new URL(urlPath);
+ handleArchiveByURL(url);
+ }
else
{
- handleArchive(file);
+ handleArchiveByFile(file);
}
}
catch (IOException ioe)
@@ -145,7 +170,7 @@
}
- private void handleArchive(File file) throws ZipException, IOException
+ private void handleArchiveByFile(File file) throws IOException
{
log.debug("archive: " + file);
ZipFile zip = new ZipFile(file);
@@ -159,13 +184,33 @@
}
}
+ private void handleArchiveByURL(URL url) throws IOException
+ {
+ log.debug("archive: " + url);
+ JarInputStream inputStream = new JarInputStream(url.openStream());
+ try
+ {
+ ZipEntry entry = inputStream.getNextEntry();
+ while ( entry != null )
+ {
+ String name = entry.getName();
+ log.debug("found: " + name);
+ handleItem(name);
+ entry = inputStream.getNextEntry();
+ }
+ }
+ finally
+ {
+ inputStream.close();
+ }
+ }
+
private void handleDirectory(File file, String path)
{
log.debug("directory: " + file);
for ( File child: file.listFiles() )
{
- String newPath = path==null ?
- child.getName() : path + '/' + child.getName();
+ String newPath = path==null ? child.getName() : path + '/' + child.getName();
if ( child.isDirectory() )
{
handleDirectory(child, newPath);
More information about the jboss-cvs-commits
mailing list