[jboss-cvs] JBossAS SVN: r58920 - in projects/microcontainer/trunk: build container/src/main/org/jboss/net/protocol container/src/main/org/jboss/virtual container/src/main/org/jboss/virtual/plugins/context container/src/main/org/jboss/virtual/plugins/context/file container/src/main/org/jboss/virtual/plugins/context/jar container/src/main/org/jboss/virtual/plugins/vfs container/src/main/org/jboss/virtual/protocol container/src/main/org/jboss/virtual/protocol/vfsfile container/src/main/org/jboss/virtual/protocol/vfsjar container/src/main/org/jboss/virtual/spi container/src/tests/org/jboss/test/virtual/support container/src/tests/org/jboss/test/virtual/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Dec 7 20:43:22 EST 2006
Author: bill.burke at jboss.com
Date: 2006-12-07 20:43:14 -0500 (Thu, 07 Dec 2006)
New Revision: 58920
Added:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowser.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowserFactory.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsjar/
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsjar/Handler.java
Removed:
projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/VirtualFileURLConnection.java
Modified:
projects/microcontainer/trunk/build/build-thirdparty.xml
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVFSContextTest.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java
Log:
vfs based URL support
Modified: projects/microcontainer/trunk/build/build-thirdparty.xml
===================================================================
--- projects/microcontainer/trunk/build/build-thirdparty.xml 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/build/build-thirdparty.xml 2006-12-08 01:43:14 UTC (rev 58920)
@@ -46,7 +46,7 @@
<componentref name="apache-log4j" version="1.2.8"/>
<componentref name="apache-xerces" version="2.7.1"/>
<componentref name="javassist" version="3.4.GA"/>
- <componentref name="jboss/common-core" version="2.0.2.GA"/>
+ <componentref name="jboss/common-core" version="2.0.3.GA"/>
<componentref name="jboss/common-logging-log4j" version="2.0.2.GA"/>
<componentref name="jboss/common-logging-jdk" version="2.0.2.GA"/>
<componentref name="jboss/common-logging-spi" version="2.0.2.GA"/>
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -27,10 +27,12 @@
import java.util.List;
import org.jboss.virtual.plugins.vfs.helpers.WrappingVirtualFileHandlerVisitor;
+import org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VFSContextFactory;
import org.jboss.virtual.spi.VFSContextFactoryLocator;
import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.util.file.ArchiveBrowser;
/**
* Virtual File System
@@ -44,6 +46,23 @@
/** The VFS Context */
private final VFSContext context;
+ static
+ {
+ String pkgs = System.getProperty("java.protocol.handler.pkgs");
+ if (pkgs == null || pkgs.trim().length() == 0)
+ {
+ pkgs = "org.jboss.virtual.protocol";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ else if (!pkgs.contains("org.jboss.virtual.protocol"))
+ {
+ pkgs += "|org.jboss.virtual.protocol";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ // keep this until AOP and HEM uses VFS internally instead of the stupid ArchiveBrowser crap.
+ ArchiveBrowser.factoryFinder.put("vfsfile", new VfsArchiveBrowserFactory());
+ }
+
/**
* Get the virtual file system for a root uri
*
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -24,10 +24,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLEncoder;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -41,7 +43,7 @@
/**
* A virtual file as seen by the user
- *
+ *
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
* @version $Revision: 44334 $
@@ -54,14 +56,14 @@
private final VirtualFileHandler handler;
/** Whether we are closed */
- private AtomicBoolean closed = new AtomicBoolean(false);
-
+ private AtomicBoolean closed = new AtomicBoolean(false);
+
/** The open streams */
private transient final Set<InputStream> streams = Collections.synchronizedSet(new WeakSet());
-
+
/**
* Create a new VirtualFile.
- *
+ *
* @param handler the handler
* @throws IllegalArgumentException if the handler is null
*/
@@ -74,20 +76,20 @@
/**
* Get the virtual file handler
- *
+ *
* @return the handler
* @throws IllegalStateException if the file is closed
*/
- protected VirtualFileHandler getHandler()
+ public VirtualFileHandler getHandler()
{
if (closed.get())
throw new IllegalStateException("The virtual file is closed");
return handler;
}
-
+
/**
* Get the simple VF name (X.java)
- *
+ *
* @return the simple file name
* @throws IllegalStateException if the file is closed
*/
@@ -98,7 +100,7 @@
/**
* Get the VFS relative path name (org/jboss/X.java)
- *
+ *
* @return the VFS relative path name
* @throws IllegalStateException if the file is closed
*/
@@ -109,7 +111,7 @@
/**
* Get the VF URL (file://root/org/jboss/X.java)
- *
+ *
* @return the full URL to the VF in the VFS.
* @throws MalformedURLException if a url cannot be parsed
* @throws URISyntaxException if a uri cannot be parsed
@@ -117,24 +119,24 @@
*/
public URL toURL() throws MalformedURLException, URISyntaxException
{
- return getHandler().toURL();
+ return getHandler().toVfsUrl();
}
-
+
/**
* Get the VF URI (file://root/org/jboss/X.java)
- *
+ *
* @return the full URI to the VF in the VFS.
* @throws URISyntaxException if a uri cannot be parsed
* @throws IllegalStateException if the file is closed
*/
- public URI toURI() throws URISyntaxException
+ public URI toURI() throws MalformedURLException, URISyntaxException
{
- return getHandler().toURI();
+ return VFSUtils.toURI(toURL());
}
/**
* When the file was last modified
- *
+ *
* @return the last modified time
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -143,10 +145,10 @@
{
return getHandler().getLastModified();
}
-
+
/**
* Get the size
- *
+ *
* @return the size
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -159,7 +161,7 @@
/**
* Whether it is a simple leaf of the VFS,
* i.e. whether it can contain other files
- *
+ *
* @return true if a simple file.
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -168,10 +170,10 @@
{
return getHandler().isLeaf();
}
-
+
/**
* Whether it is hidden
- *
+ *
* @return true when hidden
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -183,9 +185,9 @@
/**
* Access the file contents.
- *
+ *
* @return an InputStream for the file contents.
- * @throws IOException for any error accessing the file system
+ * @throws IOException for any error accessing the file system
* @throws IllegalStateException if the file is closed
*/
public InputStream openStream() throws IOException
@@ -228,10 +230,10 @@
handler.close();
}
}
-
+
/**
* Get the VFS instance for this virtual file
- *
+ *
* @return the VFS
* @throws IllegalStateException if the file is closed
*/
@@ -240,10 +242,10 @@
VFSContext context = getHandler().getVFSContext();
return context.getVFS();
}
-
+
/**
* Get the parent
- *
+ *
* @return the parent or null if there is no parent
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -255,10 +257,10 @@
return parent.getVirtualFile();
return null;
}
-
+
/**
* Get the children
- *
+ *
* @return the children
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -270,7 +272,7 @@
/**
* Get the children
- *
+ *
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
@@ -287,12 +289,12 @@
visit(visitor);
return visitor.getMatched();
}
-
+
/**
* Get all the children recursively<p>
- *
+ *
* This always uses {@link VisitorAttributes#RECURSE}
- *
+ *
* @return the children
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
@@ -301,12 +303,12 @@
{
return getChildrenRecursively(null);
}
-
+
/**
* Get all the children recursively<p>
- *
+ *
* This always uses {@link VisitorAttributes#RECURSE}
- *
+ *
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
@@ -323,10 +325,10 @@
visit(visitor);
return visitor.getMatched();
}
-
+
/**
* Visit the virtual file system
- *
+ *
* @param visitor the visitor
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalArgumentException if the visitor is null
@@ -342,8 +344,8 @@
/**
* Find a child
- *
- * @param path the path
+ *
+ * @param path the path
* @return the child
* @throws IOException for any problem accessing the VFS (including the child does not exist)
* @throws IllegalArgumentException if the path is null
@@ -352,7 +354,7 @@
public VirtualFile findChild(String path) throws IOException
{
VirtualFileHandler handler = getHandler();
-
+
if (handler.isLeaf())
throw new IllegalStateException("File cannot contain children: " + this);
@@ -372,7 +374,7 @@
{
return handler.hashCode();
}
-
+
@Override
public boolean equals(Object obj)
{
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -60,7 +60,8 @@
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("rootURI", URI.class),
new ObjectStreamField("parent", VirtualFileHandler.class),
- new ObjectStreamField("name", String.class)
+ new ObjectStreamField("name", String.class),
+ new ObjectStreamField("vfsUrl", URL.class)
};
/** The VFS context
@@ -81,6 +82,8 @@
/** The vfsPath */
private transient String vfsPath;
+ protected URL vfsUrl;
+
/** The reference count */
private transient AtomicInteger references = new AtomicInteger(0);
@@ -124,6 +127,12 @@
return toURI().toURL();
}
+
+ public URL toVfsUrl() throws MalformedURLException, URISyntaxException
+ {
+ return vfsUrl;
+ }
+
/**
* Initialise the path into the path name
*
@@ -344,6 +353,7 @@
fields.put("rootURI", this.getVFSContext().getRootURI());
fields.put("parent", parent);
fields.put("name", name);
+ fields.put("vfsUrl", vfsUrl);
out.writeFields();
}
private void readObject(ObjectInputStream in)
@@ -357,6 +367,7 @@
VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
this.context = factory.getVFS(rootURI);
this.references = new AtomicInteger(0);
+ this.vfsUrl = (URL)fields.get("vfsUrl", null);
// Restore the log
log = Logger.getLogger(getClass());
}
Added: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowser.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowser.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowser.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -0,0 +1,107 @@
+/*
+* 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.virtual.plugins.context;
+
+import org.jboss.util.file.ArchiveBrowser;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
+import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+
+import java.util.Iterator;
+import java.util.List;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * This is a bridge to an older, crappier API written by myself.
+ *
+ * @deprecated
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class VfsArchiveBrowser implements Iterator
+{
+ private ArchiveBrowser.Filter filter;
+ private VirtualFile vf;
+ private Iterator<VirtualFile> it;
+
+
+ public VfsArchiveBrowser(final ArchiveBrowser.Filter filter, VirtualFile vf)
+ {
+ this.filter = filter;
+ this.vf = vf;
+ List<VirtualFile> classes = getResources(new VirtualFileFilter() {
+ public boolean accepts(VirtualFile file)
+ {
+ return filter.accept(file.getName());
+ }
+ });
+
+ it = classes.iterator();
+ }
+
+ public List<VirtualFile> getResources(VirtualFileFilter filter)
+ {
+ VisitorAttributes va = new VisitorAttributes();
+ va.setLeavesOnly(true);
+ SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
+ va.setRecurseFilter(noJars);
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
+
+ try
+ {
+ vf.visit(visitor);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return visitor.getMatched();
+ }
+
+
+ public boolean hasNext()
+ {
+ return it.hasNext();
+ }
+
+ public Object next()
+ {
+ try
+ {
+ return it.next().openStream();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void remove()
+ {
+ it.remove();
+ }
+}
Added: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowserFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowserFactory.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/VfsArchiveBrowserFactory.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -0,0 +1,57 @@
+/*
+* 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.virtual.plugins.context;
+
+import org.jboss.util.file.ArchiveBrowserFactory;
+import org.jboss.util.file.ArchiveBrowser;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+import java.util.Iterator;
+import java.net.URL;
+import java.io.IOException;
+
+/**
+ * This is a bridge to an older, crappier API written by myself.
+ *
+ * @deprecated
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class VfsArchiveBrowserFactory implements ArchiveBrowserFactory
+{
+ public Iterator create(URL url, ArchiveBrowser.Filter filter)
+ {
+ try
+ {
+ VirtualFileURLConnection conn = (VirtualFileURLConnection)url.openConnection();
+ VirtualFile vf = conn.getVirtualFile();
+ return new VfsArchiveBrowser(filter, vf);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to browse URL: " + url, e);
+ }
+ }
+}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -27,13 +27,18 @@
import java.io.ObjectInputStream;
import java.net.URI;
import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import org.jboss.virtual.plugins.context.AbstractURLHandler;
import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.VFS;
/**
* FileHandler.
@@ -49,6 +54,8 @@
/** The file */
private transient File file;
+ private transient Map<String, VirtualFileHandler> childCache = Collections.synchronizedMap(new HashMap<String, VirtualFileHandler>());
+
/**
* Create a new FileHandler.
*
@@ -66,6 +73,7 @@
this.file = file;
if (file.exists() == false)
throw new FileNotFoundException("File does not exist: " + file.getCanonicalPath());
+ this.vfsUrl = new URL("vfs" + url.toString());
}
/**
* Create a new FileHandler
@@ -82,6 +90,16 @@
this(context, parent, file, uri.toURL());
}
+
+ public URL toVfsUrl() throws MalformedURLException, URISyntaxException
+ {
+ if (vfsUrl == null)
+ {
+ vfsUrl = new URL("vfs" + getURL().toString());
+ }
+ return vfsUrl;
+ }
+
@Override
public FileSystemContext getVFSContext()
{
@@ -133,12 +151,24 @@
FileSystemContext context = getVFSContext();
List<VirtualFileHandler> result = new ArrayList<VirtualFileHandler>();
+ Map<String, VirtualFileHandler> newCache = Collections.synchronizedMap(new HashMap<String, VirtualFileHandler>());
+ Map<String, VirtualFileHandler> oldCache = childCache;
for (File file : files)
{
try
{
- VirtualFileHandler handler = context.createVirtualFileHandler(this, file);
+ VirtualFileHandler handler = null;
+ handler = oldCache.get(file.getName());
+ if (handler != null && file.lastModified() != handler.getLastModified())
+ {
+ handler = null;
+ }
+ if (handler == null)
+ {
+ handler = context.createVirtualFileHandler(this, file);
+ }
result.add(handler);
+ newCache.put(file.getName(), handler);
}
catch (IOException e)
{
@@ -148,6 +178,8 @@
throw e;
}
}
+ // cleanup old entries
+ childCache = newCache;
return result;
}
@@ -161,7 +193,17 @@
FileSystemContext context = getVFSContext();
File parentFile = getFile();
File child = new File(parentFile, name);
- return context.createVirtualFileHandler(this, child);
+ VirtualFileHandler handler = childCache.get(name);
+ if (handler != null)
+ {
+ if (handler.getLastModified() != child.lastModified()) handler = null;
+ }
+ if (handler == null)
+ {
+ handler = context.createVirtualFileHandler(this, child);
+ childCache.put(name, handler);
+ }
+ return handler;
}
private void readObject(ObjectInputStream in)
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -56,7 +56,7 @@
/**
* Get the file for a url
*
- * @param url the url
+ * @param uri the url
* @return the file
* @throws IOException for any error accessing the file system
* @throws IllegalArgumentException for a null url
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/LinkHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -26,6 +26,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -66,6 +67,14 @@
public ParentOfLink(VFSContext context, VirtualFileHandler parent, URL url, String name)
{
super(context, parent, url, name);
+ try
+ {
+ this.vfsUrl = new URL("vfs" + url.toString());
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
}
void addChild(VirtualFileHandler child, String name)
{
@@ -90,6 +99,8 @@
{
return false;
}
+
+
}
/**
@@ -111,7 +122,8 @@
// TODO: This URL is not consistent with the getName, but does point to the raw link file
super(context, parent, uri.toURL(), name);
this.links = links;
- // Create handlers for the links and add
+ this.vfsUrl = new URL("vfs" + uri.toURL().toString());
+ // Create handlers for the links and add
for(LinkInfo link : links)
{
String linkName = link.getName();
@@ -211,4 +223,5 @@
// TODO: if the factory caches contexts the root handler may not point to the link
return new DelegatingHandler(this.getVFSContext(), parent, name, rootHandler);
}
+
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -390,6 +390,44 @@
}
/**
+ * Convert a URL into a JarFIle
+ *
+ * @param url
+ * @return
+ * @throws IOException
+ */
+ public static JarFile fromURL(URL url) throws IOException
+ {
+ try
+ {
+ URLConnection connection = url.openConnection();
+ JarURLConnection jarConnection;
+ if (connection instanceof JarURLConnection)
+ {
+ jarConnection = (JarURLConnection)connection;
+ }
+ else
+ {
+ // try wrapping it in jar:
+ URL jarUrl = new URL("jar:" + url + "!/");
+ jarConnection = (JarURLConnection)jarUrl.openConnection();
+ }
+ jarConnection.setUseCaches(false);
+ return jarConnection.getJarFile();
+ }
+ catch (IOException original)
+ {
+ // Fix the context of the error message
+ IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
+ e.setStackTrace(original.getStackTrace());
+ throw e;
+
+ }
+
+ }
+
+
+ /**
* Restore the jar file from the jar URL
*
* @param in
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -24,7 +24,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.net.URL;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -76,6 +79,21 @@
throws IOException
{
super(context, parent, url, entryName);
+ try
+ {
+ URL parentVfsUrl = parent.toVfsUrl();
+ String vfsParentUrl = parentVfsUrl.toString();
+ String vfsUrlString = null;
+ if (vfsParentUrl.endsWith("/")) vfsUrlString = vfsParentUrl + entryName;
+ else vfsUrlString = vfsParentUrl + "/" + entryName;
+ if (entry.isDirectory()) vfsUrlString += "/";
+ vfsUrl = new URL(vfsUrlString);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
+
if (jar == null)
throw new IllegalArgumentException("Null jar");
@@ -128,12 +146,6 @@
return false;
}
- @Override
- public InputStream openStream() throws IOException
- {
- return jar.getInputStream(getEntry());
- }
-
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
checkClosed();
@@ -148,6 +160,14 @@
return super.structuredFindChild(path);
}
+ @Override
+ public InputStream openStream() throws IOException
+ {
+ return jar.getInputStream(getEntry());
+ }
+
+
+
/**
* TODO: synchronization on lazy entryMap creation
*/
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -55,6 +55,7 @@
public JarHandler(VFSContext context, VirtualFileHandler parent, URL url, String name) throws IOException
{
super(context, parent, url, name);
+ this.vfsUrl = new URL("vfs" + url.toString());
try
{
@@ -73,6 +74,7 @@
public JarHandler(VFSContext context, VirtualFileHandler parent, File file, URL url, String name) throws IOException
{
super(context, parent, url, name);
+ this.vfsUrl = new URL("vfs" + url.toString());
try
{
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -25,14 +25,16 @@
/**
* A nested jar implementation used to represent a jar within a jar.
- *
+ *
* @author Scott.Stark at jboss.org
* @version $Revision: 44334 $
*/
public class NestedJarFromStream
- extends AbstractVirtualFileHandler
+ extends AbstractVirtualFileHandler
{
- /** serialVersionUID */
+ /**
+ * serialVersionUID
+ */
private static final long serialVersionUID = 1L;
private ZipInputStream zis;
@@ -47,11 +49,12 @@
/**
* Create a nested jar from the parent zip inputstream/zip entry.
+ *
* @param context - the context containing the jar
- * @param parent - the jar handler for this nested jar
- * @param zis - the jar zip input stream
- * @param jarURL - the URL to use as the jar URL
- * @param entry - the parent jar ZipEntry for the nested jar
+ * @param parent - the jar handler for this nested jar
+ * @param zis - the jar zip input stream
+ * @param jarURL - the URL to use as the jar URL
+ * @param entry - the parent jar ZipEntry for the nested jar
*/
public NestedJarFromStream(VFSContext context, VirtualFileHandler parent, ZipInputStream zis, URL jarURL, ZipEntry entry)
{
@@ -61,19 +64,32 @@
this.lastModified = entry.getTime();
this.size = entry.getSize();
this.zis = zis;
+ try
+ {
+ if (parent != null)
+ {
+ String vfsParentUrl = parent.toVfsUrl().toString();
+ if (vfsParentUrl.endsWith("/")) vfsUrl = new URL(vfsParentUrl + this.name);
+ else vfsUrl = new URL(vfsParentUrl + "/" + this.name);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
public VirtualFileHandler findChild(String path) throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
return entries.get(name);
}
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
List<VirtualFileHandler> children = new ArrayList<VirtualFileHandler>();
children.addAll(entries.values());
@@ -102,31 +118,34 @@
public Iterator<JarEntryContents> getEntries()
- throws IOException
+ throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
return entries.values().iterator();
}
+
public JarEntryContents getEntry(String name)
- throws IOException
+ throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
return entries.get(name);
}
+
public ZipEntry getJarEntry(String name)
- throws IOException
+ throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
JarEntryContents jec = entries.get(name);
return (jec != null ? jec.getEntry() : null);
}
+
public byte[] getContents(String name)
- throws IOException
+ throws IOException
{
- if( inited == false )
+ if (inited == false)
init();
JarEntryContents jec = entries.get(name);
return (jec != null ? jec.getContents() : null);
@@ -136,6 +155,7 @@
{
return name;
}
+
public String getPathName()
{
return vfsPath;
@@ -150,13 +170,13 @@
public void close()
{
entries.clear();
- if( zis != null )
+ if (zis != null)
{
try
{
zis.close();
}
- catch(IOException e)
+ catch (IOException e)
{
log.error("close error", e);
}
@@ -168,10 +188,10 @@
{
try
{
- if( entryURL == null )
+ if (entryURL == null)
entryURL = new URL(jarURL, getName());
}
- catch(MalformedURLException e)
+ catch (MalformedURLException e)
{
throw new URISyntaxException("Failed to create relative jarURL", e.getMessage());
}
@@ -193,7 +213,7 @@
{
tmp.append(toURI());
}
- catch(URISyntaxException e)
+ catch (URISyntaxException e)
{
}
tmp.append(']');
@@ -201,21 +221,21 @@
}
protected void init()
- throws IOException
+ throws IOException
{
inited = true;
ZipEntry entry = zis.getNextEntry();
- while( entry != null )
+ while (entry != null)
{
try
{
- String url = toURI().toASCIIString() + "!/" + entry.getName();
+ String url = toURI().toASCIIString() + "!/" + entry.getName();
URL jecURL = new URL(url);
JarEntryContents jec = new JarEntryContents(getVFSContext(), this, entry, jecURL, zis, getPathName());
entries.put(entry.getName(), jec);
entry = zis.getNextEntry();
}
- catch(URISyntaxException e)
+ catch (URISyntaxException e)
{
e.printStackTrace();
}
@@ -225,9 +245,11 @@
}
public static class JarEntryContents
- extends AbstractVirtualFileHandler
+ extends AbstractVirtualFileHandler
{
- /** serialVersionUID */
+ /**
+ * serialVersionUID
+ */
private static final long serialVersionUID = 1L;
private ZipEntry entry;
private URL entryURL;
@@ -238,8 +260,8 @@
private InputStream openStream;
JarEntryContents(VFSContext context, VirtualFileHandler parent, ZipEntry entry, URL entryURL, InputStream zis,
- String parentVfsPath)
- throws IOException
+ String parentVfsPath)
+ throws IOException
{
super(context, parent, entry.getName());
this.entry = entry;
@@ -247,15 +269,15 @@
this.vfsPath = parentVfsPath + "/" + entry.getName();
this.isJar = JarUtils.isArchive(entry.getName());
int size = (int) entry.getSize();
- if( size <= 0 )
+ if (size <= 0)
return;
ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
byte[] tmp = new byte[1024];
- while( zis.available() > 0 )
+ while (zis.available() > 0)
{
int length = zis.read(tmp);
- if( length > 0 )
+ if (length > 0)
baos.write(tmp, 0, length);
}
contents = baos.toByteArray();
@@ -270,6 +292,7 @@
{
return entry;
}
+
public byte[] getContents()
{
return contents;
@@ -279,6 +302,7 @@
{
return entry.getName();
}
+
public String getPathName()
{
return vfsPath;
@@ -287,24 +311,25 @@
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
List<VirtualFileHandler> children = null;
- if( isJar )
+ if (isJar)
{
initNestedJar();
children = njar.getChildren(ignoreErrors);
}
return children;
}
+
public VirtualFileHandler findChild(String path) throws IOException
{
VirtualFileHandler child;
- if( isJar )
+ if (isJar)
{
initNestedJar();
child = njar.findChild(path);
}
else
{
- throw new FileNotFoundException("JarEntryContents("+entry.getName()+") has no children");
+ throw new FileNotFoundException("JarEntryContents(" + entry.getName() + ") has no children");
}
return child;
}
@@ -329,10 +354,10 @@
// Stream accessor
public synchronized InputStream openStream()
- throws IOException
+ throws IOException
{
initNestedJar();
- if( njar != null )
+ if (njar != null)
openStream = njar.openStream();
else
openStream = new ByteArrayInputStream(contents);
@@ -341,13 +366,13 @@
public synchronized void close()
{
- if( openStream != null )
+ if (openStream != null)
{
try
{
openStream.close();
}
- catch(IOException e)
+ catch (IOException e)
{
log.error("close error", e);
}
@@ -375,7 +400,7 @@
{
tmp.append(toURI());
}
- catch(URISyntaxException e)
+ catch (URISyntaxException e)
{
}
tmp.append(']');
@@ -383,9 +408,9 @@
}
private synchronized void initNestedJar()
- throws IOException
+ throws IOException
{
- if( isJar && njar == null )
+ if (isJar && njar == null)
{
ByteArrayInputStream bais = new ByteArrayInputStream(contents);
ZipInputStream zis = new ZipInputStream(bais);
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -28,6 +28,7 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.URL;
+import java.net.URISyntaxException;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -138,6 +139,17 @@
{
super(context, parent, temp.toURL(), entryName);
+ try
+ {
+ String vfsParentUrl = parent.toVfsUrl().toString();
+ if (vfsParentUrl.endsWith("/")) vfsUrl = new URL(vfsParentUrl + entryName);
+ else vfsUrl = new URL(vfsParentUrl + "/" + entryName);
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
+
this.temp = temp;
this.original = original;
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -69,6 +70,17 @@
throws IOException
{
super(context, parent, url, entryName);
+ try
+ {
+ URL parentVfsUrl = parent.toVfsUrl();
+ String vfsParentUrl = parentVfsUrl.toString();
+ if (vfsParentUrl.endsWith("/")) vfsUrl = new URL(vfsParentUrl + entryName);
+ else vfsUrl = new URL(vfsParentUrl + "/" + entryName + "/");
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
this.lastModified = lastModified;
}
Copied: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java (from rev 58701, projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java)
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java 2006-11-28 13:43:29 UTC (rev 58701)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -0,0 +1,100 @@
+/*
+* 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.virtual.plugins.vfs;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFS;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+
+/**
+ * Implements basic URLConnection for a VirtualFile
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class VirtualFileURLConnection extends URLConnection
+{
+ public static Map<URL, VFS> urlCache = Collections.synchronizedMap(new HashMap<URL, VFS>());
+
+ protected VirtualFile file;
+ protected URL vfsurl;
+ protected String relativePath;
+
+
+ public VirtualFileURLConnection(URL url, URL vfsurl, String relativePath)
+ {
+ super(url);
+ this.vfsurl = vfsurl;
+ this.relativePath = relativePath;
+ }
+
+ public void connect() throws IOException
+ {
+ }
+
+ public static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
+ {
+ VFS vfs = urlCache.get(vfsurl);
+ if (vfs == null)
+ {
+ vfs = VFS.getVFS(vfsurl);
+ urlCache.put(vfsurl, vfs);
+ }
+ return vfs.findChild(relativePath);
+
+ }
+
+ public static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
+ {
+ VFS vfs = VFS.getVFS(vfsurl);
+ return vfs.findChild(relativePath);
+ }
+
+ public synchronized VirtualFile getVirtualFile() throws IOException
+ {
+ if (file == null)
+ {
+ if (this.getUseCaches())
+ {
+ file = resolveCachedVirtualFile(vfsurl, relativePath);
+ }
+ else
+ {
+ file = resolveVirtualFile(vfsurl, relativePath);
+ }
+ }
+ return file;
+ }
+
+
+ public InputStream getInputStream() throws IOException
+ {
+ return getVirtualFile().openStream();
+ }
+}
Copied: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile (from rev 58907, projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile)
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/Handler.java 2006-12-07 19:26:38 UTC (rev 58907)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/Handler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -19,10 +19,10 @@
* 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.net.protocol.vfsfile;
+package org.jboss.virtual.protocol.vfsfile;
import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
import java.io.File;
import java.io.IOException;
@@ -30,6 +30,14 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.net.URLClassLoader;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.HashSet;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
/**
* URLStreamHandler for VFS
@@ -39,43 +47,81 @@
*/
public class Handler extends URLStreamHandler
{
-
protected URLConnection openConnection(URL u) throws IOException
{
String file = u.toString().substring(8); // strip out vfsfile:
+ URL vfsurl = null;
+ String relative;
File fp = new File(file);
-
- File parent = fp;
- File curr = fp;
- String relative = fp.getName();
- while ((curr = curr.getParentFile()) != null)
+ if (fp.exists())
{
- parent = curr;
- if (parent.getParentFile() != null) relative = parent.getName() + "/" + relative;
+ 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;
+ }
+ }
+ }
- URL url = parent.toURL();
-
- VFS vfs = VFS.getVFS(url);
- VirtualFile vf = vfs.findChild(relative);
-
-
- return new VirtualFileURLConnection(url, vf);
+ if (vfsurl == null) throw new IOException("vfsfile does not exist: " + u.toString());
+ return new VirtualFileURLConnection(u, vfsurl, relative);
}
-
public static void main(String[] args) throws Exception
{
- System.setProperty("java.protocol.handler.pkgs", "org.jboss.net.protocol");
+ System.setProperty("java.protocol.handler.pkgs", "org.jboss.virtual.protocol");
+
//URL url = new URL("vfsfile:/c:/tmp/urlstream.java");
//URL url = new URL("vfsfile:/C:\\jboss\\jboss-head\\build\\output\\jboss-5.0.0.Beta\\server\\default\\lib\\jboss.jar\\schema\\xml.xsd");
+ URL furl = new URL("file:/c:/tmp/parent.jar");
+ System.out.println("urlpath: " + furl.getPath());
URL url = new URL("vfsfile:/c:/tmp/parent.jar/foo.jar/urlstream.java");
InputStream is = url.openStream();
+ char curr = 0;
while (is.available() != 0)
{
- System.out.print((char)is.read());
+ curr = (char) is.read();
+ System.out.print(curr);
}
is.close();
+ // use a .jar file that would NEVER EVER be in my IDE's classpath
+ File fp = new File("c:/jboss/geronimo-1.1.1/lib/geronimo-kernel-1.1.1.jar");
+ JarFile jf = new JarFile(fp);
+ Enumeration<JarEntry> entries = jf.entries();
+ HashSet<String> set = new HashSet<String>();
+ while (entries.hasMoreElements())
+ {
+ String name = entries.nextElement().getName();
+ if (name.endsWith(".class")) set.add(name.replace('/', '.').substring(0, name.length() - 6));
+ }
+ jf.close();
+ /*
+URL[] urls = {new URL("vfsfile:/c:/tmp/webinf-classes.jar/classes/"),
+ new URL("file:/c:/jboss/geronimo-1.1.1/lib/xstream-1.1.3.jar")};
+ */
+ // use a .jar file that would NEVER EVER be in my IDE's classpath
+ URL[] urls = {new URL("vfsfile:/c:/tmp/wrap.jar/geronimo-kernel-1.1.1.jar"),
+ new URL("file:/c:/jboss/geronimo-1.1.1/lib/xstream-1.1.3.jar")};
+ URLClassLoader loader = new URLClassLoader(urls);
+ for (String name : set)
+ {
+ System.out.println("loading: " + name);
+ loader.loadClass(name);
+ }
}
+
}
Deleted: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/VirtualFileURLConnection.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/net/protocol/vfsfile/VirtualFileURLConnection.java 2006-12-07 19:26:38 UTC (rev 58907)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsfile/VirtualFileURLConnection.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -1,61 +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.net.protocol.vfsfile;
-
-import org.jboss.virtual.VirtualFile;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Implements basic URLConnection for a VirtualFile
- *
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @version $Revision: 1.1 $
- */
-public class VirtualFileURLConnection extends URLConnection
-{
- protected VirtualFile file;
-
- public VirtualFileURLConnection(URL url, VirtualFile file)
- {
- super(url);
- this.file = file;
- }
-
- public void connect() throws IOException
- {
- }
-
- public VirtualFile getVirtualFile()
- {
- return file;
- }
-
-
- public InputStream getInputStream() throws IOException
- {
- return file.openStream();
- }
-}
Added: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsjar/Handler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsjar/Handler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/protocol/vfsjar/Handler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -0,0 +1,67 @@
+/*
+* 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.virtual.protocol.vfsjar;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+
+import java.net.URLStreamHandler;
+import java.net.URLConnection;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+
+/**
+ * URLStreamHandler for VFS
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ */
+public class Handler extends URLStreamHandler
+{
+ protected URLConnection openConnection(URL u) throws IOException
+ {
+ String urlString = u.toString();
+ int index = urlString.indexOf("!/");
+ String file = urlString.substring(3, index + 2); // strip out vfs
+ String path = urlString.substring(index + 2);
+ URL url = new URL(file);
+ return new VirtualFileURLConnection(u, url, path);
+ }
+ public static void main(String[] args) throws Exception
+ {
+ System.setProperty("java.protocol.handler.pkgs", "org.jboss.virtual.protocol");
+ //URL url = new URL("vfsfile:/c:/tmp/urlstream.java");
+ //URL url = new URL("vfsfile:/C:\\jboss\\jboss-head\\build\\output\\jboss-5.0.0.Beta\\server\\default\\lib\\jboss.jar\\schema\\xml.xsd");
+ URL url = new URL("vfsjar:file:/c:/tmp/parent.jar!/foo.jar/urlstream.java");
+ InputStream is = url.openStream();
+ while (is.available() != 0)
+ {
+ System.out.print((char)is.read());
+ }
+ is.close();
+
+ }
+}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -39,6 +39,8 @@
import org.jboss.logging.Logger;
import org.jboss.virtual.plugins.context.file.FileSystemContextFactory;
import org.jboss.virtual.plugins.context.jar.JarContextFactory;
+import org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory;
+import org.jboss.util.file.ArchiveBrowser;
/**
* A singleton factory for locating VFSContextFactory instances given VFS root URIs.
@@ -64,6 +66,24 @@
/** Has the default initialzation been performed */
private static boolean initialized;
+ static
+ {
+ String pkgs = System.getProperty("java.protocol.handler.pkgs");
+ if (pkgs == null || pkgs.trim().length() == 0)
+ {
+ pkgs = "org.jboss.virtual.protocol";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ else if (!pkgs.contains("org.jboss.virtual.protocol"))
+ {
+ pkgs += "|org.jboss.virtual.protocol";
+ System.setProperty("java.protocol.handler.pkgs", pkgs);
+ }
+ // keep this until AOP and HEM uses VFS internally instead of the stupid ArchiveBrowser crap.
+ ArchiveBrowser.factoryFinder.put("vfsfile", new VfsArchiveBrowserFactory());
+ }
+
+
/**
* Register a new VFSContextFactory
*
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -56,6 +56,16 @@
String getPathName();
/**
+ * Get a VFS-based URL
+ *
+ * @return
+ * @throws MalformedURLException
+ * @throws URISyntaxException
+ */
+ URL toVfsUrl() throws MalformedURLException, URISyntaxException;
+
+
+ /**
* Get the VF URI (file://root/org/jboss/X.java)
*
* @return the full URI to the VF in the VFS.
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/support/AbstractMockVirtualFileHandler.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -244,6 +244,12 @@
return uri;
}
+
+ public URL toVfsUrl() throws MalformedURLException, URISyntaxException
+ {
+ return toURL();
+ }
+
@Override
public URL toURL() throws MalformedURLException, URISyntaxException
{
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVFSContextTest.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -61,7 +61,7 @@
VFS vfs = context.getVFS();
VirtualFile rootFile = vfs.getRoot();
- assertEquals(rootURI, rootFile.toURI());
+ assertEquals(new URI("vfs" + rootURI), rootFile.toURI());
}
public void testGetRoot() throws Exception
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/AbstractVirtualFileHandlerTest.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -587,8 +587,10 @@
assertEquals(handler.isLeaf(), file.isLeaf());
assertEquals(handler.getLastModified(), file.getLastModified());
assertEquals(handler.getSize(), file.getSize());
- assertEquals(handler.toURI(), file.toURI());
- assertEquals(handler.toURL(), file.toURL());
+
+ // can't do this anymore as VirtualFile.toURL() returns a vfs based url
+ //assertEquals(handler.toURI(), file.toURI());
+ //assertEquals(handler.toURL(), file.toURL());
VirtualFileHandler parent = handler.getParent();
if (parent == null)
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -625,7 +625,7 @@
String name = tmp.getName();
String vfsPath = tmp.getPath();
vfsPath = vfsPath.substring(tmpRoot.getPath().length()+1);
- URL url = tmp.toURL();
+ URL url = new URL("vfs" + tmp.toURL());
log.debug("name: "+name);
log.debug("vfsPath: "+vfsPath);
log.debug("url: "+url);
@@ -693,7 +693,7 @@
String name = tmpJar.getName();
String vfsPath = tmpJar.getPath();
vfsPath = vfsPath.substring(tmpRoot.getPath().length()+1);
- URL url = tmpJar.toURL();
+ URL url = new URL("vfs" + tmpJar.toURL());
//url = JarUtils.createJarURL(url);
log.debug("name: "+name);
log.debug("vfsPath: "+vfsPath);
@@ -1042,10 +1042,19 @@
VirtualFile tstjar = vfs.findChild("path with spaces/tst.jar");
assertNotNull("tstjar != null", tstjar);
URI uri = tstjar.toURI();
- URI expectedURI = new URI(rootURL.toString()+"/path%20with%20spaces/tst.jar");
+ URI expectedURI = new URI("vfs"+rootURL.toString()+"/path%20with%20spaces/tst.jar");
assertEquals(uri, expectedURI);
}
+ public static void main(String[] args) throws Exception
+ {
+ File file = new File("C:\\Documents and Settings");
+ System.out.println(file.toURI());
+ System.out.println(file.toURL().getHost());
+ URI uri = new URI("file", null, "/Document and Settings", null);
+ System.out.println(uri);
+ }
+
/**
* Validate accessing an unpacked jar vf and its uri when the vfs path
* contains spaces
@@ -1059,7 +1068,7 @@
VirtualFile tstjar = vfs.findChild("path with spaces/unpacked-tst.jar");
assertNotNull("tstjar != null", tstjar);
URI uri = tstjar.toURI();
- URI expectedURI = new URI(rootURL.toString()+"/path%20with%20spaces/unpacked-tst.jar/");
+ URI expectedURI = new URI("vfs" + rootURL.toString()+"/path%20with%20spaces/unpacked-tst.jar/");
assertEquals(uri, expectedURI);
}
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java 2006-12-07 22:33:10 UTC (rev 58919)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/virtual/test/TestClassLoading.java 2006-12-08 01:43:14 UTC (rev 58920)
@@ -29,8 +29,7 @@
log.info(mf);
URL expected = new URL(url, "jar1.jar");
- expected = JarUtils.createJarURL(expected);
- expected = new URL(expected, "META-INF/MANIFEST.MF");
+ expected = new URL("vfs" + expected + "/META-INF/MANIFEST.MF");
assertEquals(expected, mf);
Class c = cl.loadClass("org.jboss.test.vfs.support.jar1.ClassInJar1");
More information about the jboss-cvs-commits
mailing list