[jboss-cvs] JBossAS SVN: r72283 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/context and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 16 09:15:19 EDT 2008
Author: alesj
Date: 2008-04-16 09:15:19 -0400 (Wed, 16 Apr 2008)
New Revision: 72283
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/AssembledDirectory.java
Removed:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectory.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContext.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/Assembled.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContextFactory.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledFileHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledUrlStreamHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathQueryTestCase.java
Log:
Making VirtualFile::getHandler protected.
Moving AssembledDirectory to spi/api.
Removing the obsolete code in assembled plugins.
Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/AssembledDirectory.java (from rev 72209, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectory.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/AssembledDirectory.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/AssembledDirectory.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -0,0 +1,535 @@
+/*
+* 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;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.context.vfs.AssembledDirectoryHandler;
+import org.jboss.virtual.plugins.context.vfs.AssembledFileHandler;
+import org.jboss.virtual.plugins.context.vfs.ByteArrayHandler;
+import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
+
+/**
+ * Extension of VirtualFile that represents a virtual directory that can be composed of arbitrary files and resources
+ * spread throughout the file system or embedded in jar files.
+ *
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @version $Revision: 1.1 $
+ */
+public class AssembledDirectory extends VirtualFile
+{
+ private AssembledDirectoryHandler directory;
+
+ public AssembledDirectory(AssembledDirectoryHandler handler)
+ {
+ super(handler);
+ directory = handler;
+ }
+
+ /**
+ * Find the underlying .class file representing this class and create it within this directory, along with
+ * its packages.
+ *
+ * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
+ * and an entry in the acme directory would be the .class file.
+ *
+ * @param clazz the class
+ */
+ public void addClass(Class clazz)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null clazz");
+ addClass(clazz.getName(), clazz.getClassLoader());
+ }
+
+ /**
+ * Find the underlying .class file representing this class and create it within this directory, along with
+ * its packages.
+ *
+ * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
+ * and an entry in the acme directory would be the .class file.
+ *
+ * @param className
+ */
+ public void addClass(String className)
+ {
+ addClass(className, Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Find the underlying .class file representing this class and create it within this directory, along with
+ * its packages.
+ *
+ * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
+ * and an entry in the acme directory would be the .class file.
+ *
+ * @param className
+ * @param loader ClassLoader to look for class resource
+ */
+ public void addClass(String className, ClassLoader loader)
+ {
+ if (className == null)
+ throw new IllegalArgumentException("Null className");
+ if (loader == null)
+ throw new IllegalArgumentException("Null loader");
+
+ String resource = className.replace('.', '/') + ".class";
+ URL url = loader.getResource(resource);
+ if (url == null)
+ throw new RuntimeException("Could not find resource: " + resource);
+
+ AssembledDirectory p = mkdirs(resource);
+ p.addResource(resource, loader);
+ }
+
+ /**
+ * Make any directories for the give path to a file.
+ *
+ * @param path must be a path to a file as last element in path does not have a directory created
+ * @return directory file will live in
+ */
+ public AssembledDirectory mkdirs(String path)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+
+ String[] pkgs = path.split("/");
+ AssembledDirectoryHandler dir = directory;
+ for (int i = 0; i < pkgs.length - 1; i++)
+ {
+ AssembledDirectoryHandler next = (AssembledDirectoryHandler) dir.findChild(pkgs[i]);
+ if (next == null)
+ {
+ try
+ {
+ next = new AssembledDirectoryHandler(dir.getVFSContext(), dir, pkgs[i]);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ dir.addChild(next);
+ }
+ dir = next;
+ }
+ return (AssembledDirectory) dir.getVirtualFile();
+ }
+
+ /**
+ * Locate the .class resource of baseResource. From this resource, determine the base of the resource
+ * i.e. what jar or classpath directory it lives in.
+ *
+ * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
+ * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
+ * want to create a virtual jar that contains a subset of .class files in your classpath.
+ *
+ * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
+ *
+ * @param baseResource the base resource
+ * @param includes the includes
+ * @param excludes the excludes
+ */
+ public void addResources(Class baseResource, String[] includes, String[] excludes)
+ {
+ if (baseResource == null)
+ throw new IllegalArgumentException("Null base resource");
+
+ String resource = baseResource.getName().replace('.', '/') + ".class";
+ addResources(resource, includes, excludes, baseResource.getClassLoader());
+ }
+
+ /**
+ * From the baseResource, determine the base of that resource
+ * i.e. what jar or classpath directory it lives in. The Thread.currentThread().getContextClassloader() will be used
+ *
+ * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
+ * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
+ * want to create a virtual jar that contains a subset of .class files in your classpath.
+ *
+ * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
+ *
+ * @param baseResource the base resource
+ * @param includes the includes
+ * @param excludes the excludes
+ */
+ public void addResources(String baseResource, final String[] includes, final String[] excludes)
+ {
+ if (baseResource == null)
+ throw new IllegalArgumentException("Null base resource");
+ addResources(baseResource, includes, excludes, Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * From the baseResource, determine the base of that resource
+ * i.e. what jar or classpath directory it lives in. The loader parameter will be used to find the resource.
+ *
+ * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
+ * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
+ * want to create a virtual jar that contains a subset of .class files in your classpath.
+ *
+ * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
+ *
+ * @param baseResource the base resource
+ * @param includes the includes
+ * @param excludes the excludes
+ * @param loader the loader
+ */
+ public void addResources(String baseResource, final String[] includes, final String[] excludes, ClassLoader loader)
+ {
+ if (baseResource == null)
+ throw new IllegalArgumentException("Null baseResource");
+ if (loader == null)
+ throw new IllegalArgumentException("Null loader");
+
+ URL url = loader.getResource(baseResource);
+ if (url == null)
+ throw new RuntimeException("Could not find baseResource: " + baseResource);
+
+ String urlString = url.toString();
+ int idx = urlString.lastIndexOf(baseResource);
+ urlString = urlString.substring(0, idx);
+ try
+ {
+ url = new URL(urlString);
+ VirtualFile parent = VFS.getRoot(url);
+
+ VisitorAttributes va = new VisitorAttributes();
+ va.setLeavesOnly(true);
+ SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
+ va.setRecurseFilter(noJars);
+
+ VirtualFileFilter filter = new VirtualFileFilter()
+ {
+
+ public boolean accepts(VirtualFile file)
+ {
+ boolean matched = false;
+ String path = file.getPathName();
+ for (String include : includes)
+ {
+ if (antMatch(path, include))
+ {
+ matched = true;
+ break;
+ }
+ }
+ if (matched == false)
+ return false;
+ if (excludes != null)
+ {
+ for (String exclude : excludes)
+ {
+ if (antMatch(path, exclude))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ };
+
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
+ parent.visit(visitor);
+ List<VirtualFile> files = visitor.getMatched();
+ for (VirtualFile vf : files)
+ {
+ mkdirs(vf.getPathName()).addChild(vf);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a regular expression pattern from an Ant file matching pattern
+ *
+ * @param matcher the matcher pattern
+ * @return the pattern instance
+ */
+ public static Pattern getPattern(String matcher)
+ {
+ if (matcher == null)
+ throw new IllegalArgumentException("Null matcher");
+
+ matcher = matcher.replace(".", "\\.");
+ matcher = matcher.replace("*", ".*");
+ matcher = matcher.replace("?", ".{1}");
+ return Pattern.compile(matcher);
+ }
+
+ /**
+ * Determine whether a given file path matches an Ant pattern.
+ *
+ * @param path the path
+ * @param expression the expression
+ * @return true if we match
+ */
+ public static boolean antMatch(String path, String expression)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+ if (expression == null)
+ throw new IllegalArgumentException("Null expression");
+ if (path.startsWith("/")) path = path.substring(1);
+ if (expression.endsWith("/")) expression += "**";
+ String[] paths = path.split("/");
+ String[] expressions = expression.split("/");
+
+ int x = 0, p = 0;
+ Pattern pattern = getPattern(expressions[0]);
+
+ for (p = 0; p < paths.length && x < expressions.length; p++)
+ {
+ if (expressions[x].equals("**"))
+ {
+ do
+ {
+ x++;
+ } while (x < expressions.length && expressions[x].equals("**"));
+ if (x == expressions.length)
+ return true; // "**" with nothing after it
+ pattern = getPattern(expressions[x]);
+ }
+ String element = paths[p];
+ if (pattern.matcher(element).matches())
+ {
+ x++;
+ if (x < expressions.length)
+ {
+ pattern = getPattern(expressions[x]);
+ }
+ }
+ else if (!(x > 0 && expressions[x - 1].equals("**"))) // our previous isn't "**"
+ {
+ return false;
+ }
+ }
+ if (p < paths.length)
+ return false;
+ if (x < expressions.length)
+ return false;
+ return true;
+ }
+
+ /**
+ * Add a VirtualFile as a child to this AssembledDirectory.
+ *
+ * @param vf the virtual file
+ * @return the file
+ */
+ public VirtualFile addChild(VirtualFile vf)
+ {
+ if (vf == null)
+ throw new IllegalArgumentException("Null virtual file");
+
+ return directory.addChild(vf.getHandler()).getVirtualFile();
+ }
+
+ /**
+ * Add a VirtualFile as a child to this AssembledDirectory. This file will be added
+ * under a new aliased name.
+ *
+ * @param vf the virtual file
+ * @param newName the new name
+ * @return new file
+ */
+ public VirtualFile addChild(VirtualFile vf, String newName)
+ {
+ try
+ {
+ AssembledFileHandler handler = new AssembledFileHandler(directory.getVFSContext(), directory, newName, vf.getHandler());
+ directory.addChild(handler);
+ return handler.getVirtualFile();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the
+ * resource will be used as the child's name.
+ *
+ * Thread.currentThread.getCOntextClassLoader() will be used to load the resource.
+ *
+ * @param resource the resource
+ * @return the file
+ */
+ public VirtualFile addResource(String resource)
+ {
+ return addResource(resource, Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used
+ * as the name of the child.
+ *
+ * Thread.currentThread.getCOntextClassLoader() will be used to load the resource.
+ *
+ * @param resource the resource
+ * @param newName the new name
+ * @return the file
+ */
+ public VirtualFile addResource(String resource, String newName)
+ {
+ return addResource(resource, Thread.currentThread().getContextClassLoader(), newName);
+ }
+
+ /**
+ * Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the
+ * resource will be used as the child's name.
+ *
+ * The loader parameter will be used to load the resource.
+ *
+ * @param resource the resource
+ * @param loader the loader
+ * @return the file
+ */
+ public VirtualFile addResource(String resource, ClassLoader loader)
+ {
+ if (resource == null)
+ throw new IllegalArgumentException("Null resource");
+ if (loader == null)
+ throw new IllegalArgumentException("Null loader");
+ URL url = loader.getResource(resource);
+ if (url == null)
+ throw new RuntimeException("Could not find resource: " + resource);
+
+ return addResource(url);
+ }
+
+ /**
+ * Add a resource identified by the URL as a child to this AssembledDirectory.
+ *
+ * @param url the url
+ * @return the file
+ */
+ public VirtualFile addResource(URL url)
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Null url");
+
+ try
+ {
+ VirtualFile vf = VFS.getRoot(url);
+ return addChild(vf);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used
+ * as the name of the child.
+ *
+ * The loader parameter will be used to load the resource.
+ *
+ * @param resource the resource
+ * @param loader the loader
+ * @param newName the new name
+ * @return the file
+ */
+ public VirtualFile addResource(String resource, ClassLoader loader, String newName)
+ {
+ if (resource == null)
+ throw new IllegalArgumentException("Null resource");
+ if (loader == null)
+ throw new IllegalArgumentException("Null loader");
+ if (newName == null)
+ throw new IllegalArgumentException("Null newName");
+
+ URL url = loader.getResource(resource);
+ if (url == null)
+ throw new RuntimeException("Could not find resource: " + resource);
+
+ try
+ {
+ VirtualFile vf = VFS.getRoot(url);
+ return addChild(vf, newName);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Add raw bytes as a file to this assembled directory
+ *
+ * @param bytes the bytes
+ * @param name the name
+ * @return the file
+ */
+ public VirtualFile addBytes(byte[] bytes, String name)
+ {
+ if (bytes == null)
+ throw new IllegalArgumentException("Null bytes");
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+
+ ByteArrayHandler handler;
+ try
+ {
+ handler = new ByteArrayHandler(directory.getVFSContext(), directory, name, bytes);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ directory.addChild(handler);
+ return handler.getVirtualFile();
+ }
+
+ /**
+ * Create a directory within this directory.
+ *
+ * @param name the name
+ * @return the directory
+ */
+ public AssembledDirectory mkdir(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+
+ try
+ {
+ AssembledDirectoryHandler handler = new AssembledDirectoryHandler(directory.getVFSContext(), directory, name);
+ directory.addChild(handler);
+ return new AssembledDirectory(handler);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -41,6 +41,8 @@
import org.jboss.logging.Logger;
import org.jboss.util.StringPropertyReplacer;
import org.jboss.virtual.spi.LinkInfo;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
/**
* VFS Utilities
@@ -158,6 +160,7 @@
// TODO, this occurs for inner jars. Doubtful that such a mf cp is valid
if( rootPathLength > libPath.length() )
throw new IOException("Invalid rootPath: "+vfsRootURL+", libPath: "+libPath);
+
String vfsLibPath = libPath.substring(rootPathLength);
VirtualFile vf = file.getVFS().getChild(vfsLibPath);
if(vf != null)
@@ -268,8 +271,9 @@
}
/**
- *
- * @param uri
+ * Get the name.
+ *
+ * @param uri the uri
* @return name from uri's path
*/
public static String getName(URI uri)
@@ -385,4 +389,58 @@
urispec = urispec.replaceAll(" ", "%20");
return new URI(urispec);
}
+
+ /**
+ * Get the options for this file.
+ *
+ * @param file the file
+ * @return options map
+ */
+ private static Map<String, String> getOptions(VirtualFile file)
+ {
+ VirtualFileHandler handler = file.getHandler();
+ VFSContext context = handler.getVFSContext();
+ return context.getOptions();
+ }
+
+ /**
+ * Get the option.
+ *
+ * @param file the file
+ * @param key the option key
+ * @return key's option
+ */
+ public static String getOption(VirtualFile file, String key)
+ {
+ Map<String, String> options = getOptions(file);
+ return options != null ? options.get(key) : null;
+ }
+
+ /**
+ * Enable copy for file param.
+ *
+ * @param file the file
+ */
+ public static void enableCopy(VirtualFile file)
+ {
+ Map<String, String> options = getOptions(file);
+ if (options == null)
+ throw new IllegalArgumentException("Cannot enable copy on null options: " + file);
+
+ options.put(USE_COPY_QUERY, Boolean.TRUE.toString());
+ }
+
+ /**
+ * Disable copy for file param.
+ *
+ * @param file the file
+ */
+ public static void disableCopy(VirtualFile file)
+ {
+ Map<String, String> options = getOptions(file);
+ if (options == null)
+ throw new IllegalArgumentException("Cannot disable copy on null options: " + file);
+
+ options.remove(USE_COPY_QUERY);
+ }
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -78,7 +78,7 @@
* @return the handler
* @throws IllegalStateException if the file is closed
*/
- public VirtualFileHandler getHandler()
+ VirtualFileHandler getHandler()
{
if (closed.get())
throw new IllegalStateException("The virtual file is closed");
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -25,16 +25,15 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.jboss.logging.Logger;
import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
-import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
import org.jboss.virtual.spi.VirtualFileHandlerVisitor;
@@ -106,7 +105,7 @@
public Map<String, String> getOptions()
{
- return Collections.unmodifiableMap(rootOptions);
+ return rootOptions;
}
public List<VirtualFileHandler> getChildren(VirtualFileHandler parent, boolean ignoreErrors) throws IOException
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -155,9 +155,17 @@
{
super(rootURI);
root = createVirtualFileHandler(null, file);
+ if (root == null)
+ throw new IllegalArgumentException("Null root, rootURI: " + rootURI + ", file: " + file);
+
rootFile = root.getVirtualFile();
}
+ public String getName()
+ {
+ return root.getName();
+ }
+
public VirtualFileHandler getRoot() throws IOException
{
return root;
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -92,7 +92,7 @@
}
/**
- * Initialise the jar file
+ * Initialize the jar file
*
* @throws java.io.IOException for any error reading the jar file
* @throws IllegalArgumentException for a null jarFile
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -59,6 +59,11 @@
rootFile = root.getVirtualFile();
}
+ public String getName()
+ {
+ return root.getName();
+ }
+
public VirtualFileHandler getRoot() throws IOException
{
return root;
@@ -88,6 +93,9 @@
// todo This is a hack until we can fix http://jira.jboss.com/jira/browse/JBMICROCONT-164
AbstractVirtualFileHandler result = (AbstractVirtualFileHandler)jar.getChild(entryPath);
+ if (result == null)
+ throw new IllegalArgumentException("Null child, entryPath: " + entryPath);
+
result.setPathName("");
return result;
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -322,7 +322,7 @@
{
PutField fields = out.putFields();
- byte[] zisBytes = null;
+ byte[] zisBytes;
ZipInputStream jarStream = zis;
if(jarStream == null)
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -56,6 +56,11 @@
rootFile = root.getVirtualFile();
}
+ public String getName()
+ {
+ return root.getName();
+ }
+
public VirtualFileHandler getRoot() throws IOException
{
return root;
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/Assembled.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/Assembled.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/Assembled.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -32,7 +32,8 @@
* @author <a href="bill at jboss.com">Bill Burke</a>
* @version $Revision: 1.1 $
*/
- at Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
public @interface Assembled
{
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContextFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContextFactory.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledContextFactory.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -25,6 +25,8 @@
import java.net.URISyntaxException;
import java.io.IOException;
+import org.jboss.virtual.AssembledDirectory;
+
/**
* Factory for creating AssembledDirectory.
*
@@ -33,9 +35,10 @@
*/
public class AssembledContextFactory
{
+ private static AssembledContextFactory instance = new AssembledContextFactory();
+
private ConcurrentHashMap<String, AssembledDirectory> registry = new ConcurrentHashMap<String, AssembledDirectory>();
private volatile int count;
- private static AssembledContextFactory instance = new AssembledContextFactory();
/**
* Creates an assembly returning the root AssembledDirectory .
@@ -49,6 +52,7 @@
{
if (registry.containsKey(name))
throw new RuntimeException("Assembled context already exists for name: " + name);
+
try
{
AssembledContext context = new AssembledContext(name, rootName);
@@ -94,28 +98,29 @@
/**
* Remove an assembly
*
- * @param directory
+ * @param directory the directory
*/
public void remove(AssembledDirectory directory)
{
try
{
- if (directory.getParent() != null) throw new RuntimeException("This is not the root of assembly");
+ if (directory.getParent() != null)
+ throw new RuntimeException("This is not the root of assembly");
}
catch (IOException e)
{
throw new RuntimeException(e);
}
- registry.remove(((AssembledContext)directory.getHandler().getVFSContext()).getName());
+ registry.remove(directory.getName());
}
+ /**
+ * Get the instance.
+ *
+ * @return the instance
+ */
public static AssembledContextFactory getInstance()
{
return instance;
}
-
- public static void setInstance(AssembledContextFactory instance)
- {
- AssembledContextFactory.instance = instance;
- }
}
Deleted: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectory.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectory.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -1,519 +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.virtual.plugins.context.vfs;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VisitorAttributes;
-import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
-import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
-
-/**
- * Extension of VirtualFile that represents a virtual directory that can be composed of arbitrary files and resources
- * spread throughout the file system or embedded in jar files.
- *
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @version $Revision: 1.1 $
- */
-public class AssembledDirectory extends VirtualFile
-{
- private AssembledDirectoryHandler directory;
-
- public AssembledDirectory(AssembledDirectoryHandler handler)
- {
- super(handler);
- directory = handler;
- }
-
- /**
- * Find the underlying .class file representing this class and create it within this directory, along with
- * its packages.
- *
- * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
- * and an entry in the acme directory would be the .class file.
- *
- * @param clazz the class
- */
- public void addClass(Class clazz)
- {
- if (clazz == null)
- throw new IllegalArgumentException("Null clazz");
- addClass(clazz.getName(), clazz.getClassLoader());
- }
-
- /**
- * Find the underlying .class file representing this class and create it within this directory, along with
- * its packages.
- *
- * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
- * and an entry in the acme directory would be the .class file.
- *
- * @param className
- */
- public void addClass(String className)
- {
- addClass(className, Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * Find the underlying .class file representing this class and create it within this directory, along with
- * its packages.
- *
- * So, if you added com.acme.Customer class, then a directory structure com/acme would be created
- * and an entry in the acme directory would be the .class file.
- *
- * @param className
- * @param loader ClassLoader to look for class resource
- */
- public void addClass(String className, ClassLoader loader)
- {
- if (className == null)
- throw new IllegalArgumentException("Null className");
- if (loader == null)
- throw new IllegalArgumentException("Null loader");
- String resource = className.replace('.', '/') + ".class";
- URL url = loader.getResource(resource);
- if (url == null) throw new RuntimeException("Could not find resource: " + resource);
- AssembledDirectory p = mkdirs(resource);
- p.addResource(resource, loader);
- }
-
- /**
- * Make any directories for the give path to a file.
- *
- * @param path must be a path to a file as last element in path does not have a directory created
- * @return directory file will live in
- */
- public AssembledDirectory mkdirs(String path)
- {
- if (path == null)
- throw new IllegalArgumentException("Null path");
- String[] pkgs = path.split("/");
- AssembledDirectoryHandler dir = directory;
- for (int i = 0; i < pkgs.length - 1; i++)
- {
- AssembledDirectoryHandler next = (AssembledDirectoryHandler) dir.findChild(pkgs[i]);
- if (next == null)
- {
- try
- {
- next = new AssembledDirectoryHandler((AssembledContext) dir.getVFSContext(), dir, pkgs[i]);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- dir.addChild(next);
- }
- dir = next;
- }
- return (AssembledDirectory) dir.getVirtualFile();
- }
-
- /**
- * Locate the .class resource of baseResource. From this resource, determine the base of the resource
- * i.e. what jar or classpath directory it lives in.
- *
- * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
- * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
- * want to create a virtual jar that contains a subset of .class files in your classpath.
- *
- * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
- *
- * @param baseResource
- * @param includes
- * @param excludes
- */
- public void addResources(Class baseResource, String[] includes, String[] excludes)
- {
- if (baseResource == null)
- throw new IllegalArgumentException("Null base resource");
- String resource = baseResource.getName().replace('.', '/') + ".class";
- addResources(resource, includes, excludes, baseResource.getClassLoader());
- }
-
- /**
- * From the baseResource, determine the base of that resource
- * i.e. what jar or classpath directory it lives in. The Thread.currentThread().getContextClassloader() will be used
- *
- * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
- * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
- * want to create a virtual jar that contains a subset of .class files in your classpath.
- *
- * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
- *
- * @param baseResource
- * @param includes
- * @param excludes
- */
- public void addResources(String baseResource, final String[] includes, final String[] excludes)
- {
- if (baseResource == null)
- throw new IllegalArgumentException("Null base resource");
- addResources(baseResource, includes, excludes, Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * From the baseResource, determine the base of that resource
- * i.e. what jar or classpath directory it lives in. The loader parameter will be used to find the resource.
- *
- * Once the base of the resource is found, scan all files recursively within the base using the include and exclude
- * patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you
- * want to create a virtual jar that contains a subset of .class files in your classpath.
- *
- * The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.
- *
- * @param baseResource
- * @param includes
- * @param excludes
- * @param loader
- */
- public void addResources(String baseResource, final String[] includes, final String[] excludes, ClassLoader loader)
- {
- if (baseResource == null)
- throw new IllegalArgumentException("Null baseResource");
- if (loader == null)
- throw new IllegalArgumentException("Null loader");
- URL url = loader.getResource(baseResource);
- if (url == null) throw new RuntimeException("Could not find baseResource: " + baseResource);
- String urlString = url.toString();
- int idx = urlString.lastIndexOf(baseResource);
- urlString = urlString.substring(0, idx);
- try
- {
- url = new URL(urlString);
- VirtualFile parent = VFS.getRoot(url);
-
- VisitorAttributes va = new VisitorAttributes();
- va.setLeavesOnly(true);
- SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
- va.setRecurseFilter(noJars);
-
- VirtualFileFilter filter = new VirtualFileFilter()
- {
-
- public boolean accepts(VirtualFile file)
- {
- boolean matched = false;
- String path = file.getPathName();
- for (String include : includes)
- {
- if (antMatch(path, include))
- {
- matched = true;
- break;
- }
- }
- if (matched == false)
- return false;
- if (excludes != null)
- {
- for (String exclude : excludes)
- {
- if (antMatch(path, exclude))
- return false;
- }
- }
- return true;
- }
-
- };
-
- FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
- parent.visit(visitor);
- List<VirtualFile> files = visitor.getMatched();
- for (VirtualFile vf : files)
- {
- mkdirs(vf.getPathName()).addChild(vf);
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Create a regular expression pattern from an Ant file matching pattern
- *
- * @param matcher
- * @return
- */
- public static Pattern getPattern(String matcher)
- {
- if (matcher == null)
- throw new IllegalArgumentException("Null matcher");
- matcher = matcher.replace(".", "\\.");
- matcher = matcher.replace("*", ".*");
- matcher = matcher.replace("?", ".{1}");
- return Pattern.compile(matcher);
-
- }
-
- /**
- * Determine whether a given file path matches an Ant pattern.
- *
- * @param path
- * @param expression
- * @return
- */
- public static boolean antMatch(String path, String expression)
- {
- if (path == null)
- throw new IllegalArgumentException("Null path");
- if (expression == null)
- throw new IllegalArgumentException("Null expression");
- if (path.startsWith("/")) path = path.substring(1);
- if (expression.endsWith("/")) expression += "**";
- String[] paths = path.split("/");
- String[] expressions = expression.split("/");
-
- int x = 0, p = 0;
- Pattern pattern = getPattern(expressions[0]);
-
- for (p = 0; p < paths.length && x < expressions.length; p++)
- {
- if (expressions[x].equals("**"))
- {
- do
- {
- x++;
- } while (x < expressions.length && expressions[x].equals("**"));
- if (x == expressions.length)
- return true; // "**" with nothing after it
- pattern = getPattern(expressions[x]);
- }
- String element = paths[p];
- if (pattern.matcher(element).matches())
- {
- x++;
- if (x < expressions.length)
- {
- pattern = getPattern(expressions[x]);
- }
- }
- else if (!(x > 0 && expressions[x - 1].equals("**"))) // our previous isn't "**"
- {
- return false;
- }
- }
- if (p < paths.length)
- return false;
- if (x < expressions.length)
- return false;
- return true;
- }
-
- /**
- * Add a VirtualFile as a child to this AssembledDirectory.
- *
- * @param vf
- */
- public VirtualFile addChild(VirtualFile vf)
- {
- if (vf == null)
- throw new IllegalArgumentException("Null virtual file");
- return directory.addChild(vf.getHandler()).getVirtualFile();
- }
-
- /**
- * Add a VirtualFile as a child to this AssembledDirectory. This file will be added
- * under a new aliased name.
- *
- * @param vf
- * @param newName
- */
- public VirtualFile addChild(VirtualFile vf, String newName)
- {
- try
- {
- AssembledFileHandler handler = new AssembledFileHandler((AssembledContext) directory.getVFSContext(), directory, newName, vf.getHandler());
- directory.addChild(handler);
- return handler.getVirtualFile();
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the
- * resource will be used as the child's name.
- *
- * Thread.currentThread.getCOntextClassLoader() will be used to load the resource.
- *
- * @param resource
- */
- public VirtualFile addResource(String resource)
- {
- return addResource(resource, Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used
- * as the name of the child.
- *
- * Thread.currentThread.getCOntextClassLoader() will be used to load the resource.
- *
- * @param resource
- * @param newName
- */
- public VirtualFile addResource(String resource, String newName)
- {
- return addResource(resource, Thread.currentThread().getContextClassLoader(), newName);
- }
-
- /**
- * Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the
- * resource will be used as the child's name.
- *
- * The loader parameter will be used to load the resource.
- *
- * @param resource
- * @param loader
- */
- public VirtualFile addResource(String resource, ClassLoader loader)
- {
- if (resource == null)
- throw new IllegalArgumentException("Null resource");
- if (loader == null)
- throw new IllegalArgumentException("Null loader");
- URL url = loader.getResource(resource);
- if (url == null)
- throw new RuntimeException("Could not find resource: " + resource);
-
- return addResource(url);
- }
-
- /**
- * Add a resource identified by the URL as a child to this AssembledDirectory.
- *
- * @param url
- */
- public VirtualFile addResource(URL url)
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
-
- try
- {
- VirtualFile vf = VFS.getRoot(url);
- return addChild(vf);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used
- * as the name of the child.
- *
- * The loader parameter will be used to load the resource.
- *
- * @param resource
- * @param loader
- * @param newName
- */
- public VirtualFile addResource(String resource, ClassLoader loader, String newName)
- {
- if (resource == null)
- throw new IllegalArgumentException("Null resource");
- if (loader == null)
- throw new IllegalArgumentException("Null loader");
- if (newName == null)
- throw new IllegalArgumentException("Null newName");
-
- URL url = loader.getResource(resource);
- if (url == null)
- throw new RuntimeException("Could not find resource: " + resource);
- try
- {
- VirtualFile vf = VFS.getRoot(url);
- return addChild(vf, newName);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Add raw bytes as a file to this assembled directory
- *
- *
- * @param bytes
- * @param name
- * @return
- */
- public VirtualFile addBytes(byte[] bytes, String name)
- {
- if (bytes == null)
- throw new IllegalArgumentException("Null bytes");
- if (name == null)
- throw new IllegalArgumentException("Null name");
- ByteArrayHandler handler = null;
- try
- {
- handler = new ByteArrayHandler((AssembledContext) directory.getVFSContext(), directory, name, bytes);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- directory.addChild(handler);
- return handler.getVirtualFile();
- }
-
- /**
- * Create a directory within this directory.
- *
- * @param name
- * @return
- */
- public AssembledDirectory mkdir(String name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
- AssembledDirectoryHandler handler = null;
- try
- {
- handler = new AssembledDirectoryHandler((AssembledContext) directory.getVFSContext(), directory, name);
- directory.addChild(handler);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- return new AssembledDirectory(handler);
- }
-
-}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -33,8 +33,10 @@
import java.util.Map;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
+import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
@@ -50,7 +52,7 @@
private List<VirtualFileHandler> children = new ArrayList<VirtualFileHandler>();
private Map<String, VirtualFileHandler> childrenMap = new HashMap<String, VirtualFileHandler>();
- public AssembledDirectoryHandler(AssembledContext context, AssembledDirectoryHandler parent, String name) throws IOException
+ public AssembledDirectoryHandler(VFSContext context, AssembledDirectoryHandler parent, String name) throws IOException
{
super(context, parent, name);
String path = getPathName();
@@ -65,7 +67,7 @@
{
try
{
- handler = new AssembledFileHandler((AssembledContext)getVFSContext(), this, handler.getName(), handler);
+ handler = new AssembledFileHandler(getVFSContext(), this, handler.getName(), handler);
}
catch (IOException e)
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledFileHandler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledFileHandler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -26,6 +26,7 @@
import java.util.List;
import org.jboss.virtual.plugins.context.DelegatingHandler;
+import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
@@ -38,7 +39,7 @@
@Assembled
public class AssembledFileHandler extends DelegatingHandler
{
- public AssembledFileHandler(AssembledContext context, AssembledDirectoryHandler parent, String name, VirtualFileHandler delegate) throws IOException
+ public AssembledFileHandler(VFSContext context, AssembledDirectoryHandler parent, String name, VirtualFileHandler delegate) throws IOException
{
super(context, parent, name, delegate);
setVfsUrl(new URL("vfs", context.getName(), -1, getPathName(), new AssembledUrlStreamHandler(context)));
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledUrlStreamHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledUrlStreamHandler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledUrlStreamHandler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -27,19 +27,21 @@
import java.net.URLStreamHandler;
import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
* Used when creating VFS urls so we don't have to go through the handlers all the time
*
* @author <a href="bill at jboss.com">Bill Burke</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class AssembledUrlStreamHandler extends URLStreamHandler
{
- private final AssembledContext context;
+ private final VFSContext context;
- public AssembledUrlStreamHandler(AssembledContext context)
+ public AssembledUrlStreamHandler(VFSContext context)
{
this.context = context;
}
@@ -49,7 +51,7 @@
String path = url.getPath();
VirtualFileHandler vf = context.getRoot().getChild(path);
if (vf == null)
- throw new IOException(path + " was not found in Assembled VFS context " + context.getName());
+ throw new IOException(path + " was not found in Assembled VFS context " + context);
return new VirtualFileURLConnection(url, vf.getVirtualFile());
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -31,12 +31,14 @@
import java.util.List;
import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
* comment
*
* @author <a href="bill at jboss.com">Bill Burke</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
@Assembled
@@ -45,7 +47,7 @@
private byte[] bytes;
private final long lastModified;
- public ByteArrayHandler(AssembledContext context, VirtualFileHandler parent, String name, byte[] bytes) throws IOException
+ public ByteArrayHandler(VFSContext context, VirtualFileHandler parent, String name, byte[] bytes) throws IOException
{
super(context, parent, name);
this.bytes = bytes;
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -28,7 +28,7 @@
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.context.vfs.AssembledContextFactory;
-import org.jboss.virtual.plugins.context.vfs.AssembledDirectory;
+import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
/**
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -33,11 +33,19 @@
*
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
+ * @author ales.justin at jboss.org
* @version $Revision: 55466 $
*/
public interface VFSContext
{
/**
+ * Get the name.
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
* Get the root uri
*
* @return the root uri
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockVFSContext.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -89,6 +89,11 @@
super(createRootMockURI(name));
}
+ public String getName()
+ {
+ return root.getName();
+ }
+
/**
* Set the ioException.
*
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -21,22 +21,17 @@
*/
package org.jboss.test.virtual.test;
-import java.io.IOException;
import java.net.URL;
-import java.util.Map;
import junit.framework.AssertionFailedError;
import org.jboss.test.BaseTestCase;
-import org.jboss.test.virtual.support.OptionsAwareURI;
import org.jboss.test.virtual.support.FileOAContextFactory;
import org.jboss.test.virtual.support.JarOAContextFactory;
-import org.jboss.virtual.VFS;
+import org.jboss.test.virtual.support.OptionsAwareURI;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.spi.VFSContextFactoryLocator;
import org.jboss.virtual.spi.VFSContextFactory;
+import org.jboss.virtual.spi.VFSContextFactoryLocator;
/**
* AbstractVFSTest.
@@ -120,41 +115,12 @@
/**
* Do we force copy handling of jars.
*
- * @param vfs the vfs
+ * @param file the virtual file
* @return true if we force copy handling
- * @throws IOException for any error
*/
- protected boolean isForceCopyEnabled(VFS vfs) throws IOException
- {
- return isForceCopyEnabled(vfs.getRoot());
- }
-
- /**
- * Do we force copy handling of jars.
- *
- * @param file the file
- * @return true if we force copy handling
- */
protected boolean isForceCopyEnabled(VirtualFile file)
{
- return isForceCopyEnabled(file.getHandler());
- }
-
- /**
- * Do we force copy handling of jars.
- *
- * @param handler the virtual file handler
- * @return true if we force copy handling
- */
- protected boolean isForceCopyEnabled(VirtualFileHandler handler)
- {
boolean systemProperty = Boolean.parseBoolean(System.getProperty(VFSUtils.FORCE_COPY_KEY, "false"));
- if (systemProperty == false)
- {
- VFSContext context = handler.getVFSContext();
- Map<String, String> map = context.getOptions();
- return (map != null && map.get(VFSUtils.USE_COPY_QUERY) != null);
- }
- return true;
+ return systemProperty || VFSUtils.getOption(file, VFSUtils.FORCE_COPY_KEY) != null;
}
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AssembledContextTestCase.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -27,8 +27,8 @@
import junit.framework.Test;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.plugins.context.vfs.AssembledContextFactory;
-import org.jboss.virtual.plugins.context.vfs.AssembledDirectory;
/**
* comment
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -1428,7 +1428,7 @@
URL rootURL = tmpRoot.toURL();
VFS vfs = VFS.getVFS(rootURL);
VirtualFile tmpVF = vfs.findChild(tmp.getName());
- log.info(tmpVF.getHandler());
+ log.info(tmpVF);
assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
assertFalse(tmpVF.getPathName()+".isLeaf()", tmpVF.isLeaf());
assertTrue(tmp+".delete()", tmp.delete());
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -200,7 +200,7 @@
assertNotNull(file2);
VirtualFile test = file2.findChild("/acme/test/Test.class");
assertNotNull(test);
- assertSame(file.getHandler(), test.getHandler());
+ assertEquals(file, test);
//acme
List<VirtualFile> children = file2.getChildren();
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathQueryTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathQueryTestCase.java 2008-04-16 13:09:19 UTC (rev 72282)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathQueryTestCase.java 2008-04-16 13:15:19 UTC (rev 72283)
@@ -23,12 +23,11 @@
import java.net.URI;
import java.net.URL;
-import java.util.Map;
import junit.framework.Test;
import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.spi.VFSContext;
/**
* Test the query in url/uri.
@@ -58,11 +57,7 @@
protected void assertOption(VirtualFile vf, String key, String value)
{
- VFSContext context = vf.getHandler().getVFSContext();
- assertNotNull(context);
- Map<String, String> options = context.getOptions();
- assertNotNull(options);
- assertEquals(value, options.get(key));
+ assertEquals(value, VFSUtils.getOption(vf, key));
}
public void testURL() throws Throwable
More information about the jboss-cvs-commits
mailing list