imario 2004/05/20 10:40:56 Modified: vfs/src/java/org/apache/commons/vfs/provider AbstractFileObject.java DefaultURLStreamHandler.java UriParser.java vfs/src/test/org/apache/commons AbstractVfsTestCase.java vfs/src/test/org/apache/commons/vfs/provider/test JunctionTests.java VirtualProviderTestCase.java vfs/src/test/org/apache/commons/vfs/provider/local/test LocalProviderTestCase.java vfs/src/test/org/apache/commons/vfs/cache NullFilesCacheTestCase.java vfs/src/java/org/apache/commons/vfs/impl providers.xml vfs/src/java/org/apache/commons/vfs Resources.properties vfs/src/test/org/apache/commons/vfs/provider/temp/test TemporaryProviderTestCase.java vfs/src/java/org/apache/commons/vfs/provider/url UrlFileObject.java UrlFileProvider.java UrlFileSystem.java vfs/src/test/org/apache/commons/vfs/provider/url/test UrlProviderTestCase.java Added: vfs/src/test/org/apache/commons/vfs/provider/res/test ResourceProviderTestCase.java vfs/src/java/org/apache/commons/vfs/provider/url UrlFileName.java UrlFileSystemConfigBuilder.java Log: "resolve Resource" aka ResourceFileProvider.
res:META-INF/LICENSE.txt Using its own FileProvider was not possible. Some internal tests failed and until i dont know better, i dont want to adjust the test-case. I treat them as a bible - what they say is fact :-) I found a solution by adding the scheme "res" to the UrlFileProvider too and explicity query this prefix during the resolveFile process. The con is, that now there exists a scheme-name which also "configures" a provider and could not be changed by editing providers.xml. Using UrlFileSystemConfigBuilder one could set the classloader to use. Revision Changes Path 1.40 +0 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java Index: AbstractFileObject.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 1.12 +0 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultURLStreamHandler.java Index: DefaultURLStreamHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultURLStreamHandler.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 1.20 +6 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java Index: UriParser.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- UriParser.java 10 May 2004 20:09:43 -0000 1.19 +++ UriParser.java 20 May 2004 17:40:55 -0000 1.20 @@ -342,11 +342,14 @@ { final char ch = buffer.charAt(index); boolean match = (ch == '%'); - for (int i = 0; !match && i < reserved.length; i++) + if (reserved != null) { - if (ch == reserved[i]) + for (int i = 0; !match && i < reserved.length; i++) { - match = true; + if (ch == reserved[i]) + { + match = true; + } } } if (match) 1.14 +17 -3 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java Index: AbstractVfsTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- AbstractVfsTestCase.java 10 May 2004 20:09:45 -0000 1.13 +++ AbstractVfsTestCase.java 20 May 2004 17:40:55 -0000 1.14 @@ -77,7 +77,7 @@ */ public static File getTestResource(final String name, final boolean mustExist) { - File file = new File(getTestDirectory(), name); + File file = new File(getTestDirectoryFile(), name); file = getCanonicalFile(file); if (mustExist) { @@ -94,14 +94,28 @@ /** * Locates the base directory for this test. */ - public static File getTestDirectory() + public static File getTestDirectoryFile() { if (baseDir == null) { + // final String baseDirProp = System.getProperty("test.basedir"); + final String baseDirProp = getTestDirectory(); + baseDir = getCanonicalFile(new File(baseDirProp)); + } + return baseDir; + } + + public static String getTestDirectory() + { + return System.getProperty("test.basedir"); + /* + if (baseDir == null) + { final String baseDirProp = System.getProperty("test.basedir"); baseDir = getCanonicalFile(new File(baseDirProp)); } return baseDir; + */ } /** @@ -111,7 +125,7 @@ */ public static File getTestDirectory(final String name) { - File file = new File(getTestDirectory(), name); + File file = new File(getTestDirectoryFile(), name); file = getCanonicalFile(file); assertTrue("Test directory \"" + file + "\" does not exist or is not a directory.", file.isDirectory() || file.mkdirs()); 1.10 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionTests.java Index: JunctionTests.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionTests.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JunctionTests.java 10 May 2004 20:09:49 -0000 1.9 +++ JunctionTests.java 20 May 2004 17:40:55 -0000 1.10 @@ -34,7 +34,7 @@ { private FileObject getBaseDir() throws FileSystemException { - final File file = AbstractVfsTestCase.getTestDirectory(); + final File file = AbstractVfsTestCase.getTestDirectoryFile(); assertTrue(file.exists()); return getManager().toFileObject(file); } 1.10 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/VirtualProviderTestCase.java Index: VirtualProviderTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/VirtualProviderTestCase.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- VirtualProviderTestCase.java 10 May 2004 20:09:49 -0000 1.9 +++ VirtualProviderTestCase.java 20 May 2004 17:40:55 -0000 1.10 @@ -45,7 +45,7 @@ */ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { - final File baseDir = AbstractVfsTestCase.getTestDirectory(); + final File baseDir = AbstractVfsTestCase.getTestDirectoryFile(); final FileObject baseFile = manager.toFileObject(baseDir); return manager.createVirtualFileSystem(baseFile); } 1.11 +1 -1 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalProviderTestCase.java Index: LocalProviderTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/local/test/LocalProviderTestCase.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- LocalProviderTestCase.java 10 May 2004 20:09:49 -0000 1.10 +++ LocalProviderTestCase.java 20 May 2004 17:40:55 -0000 1.11 @@ -49,7 +49,7 @@ */ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { - final File testDir = AbstractVfsTestCase.getTestDirectory(); + final File testDir = AbstractVfsTestCase.getTestDirectoryFile(); return manager.toFileObject(testDir); } } 1.2 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/cache/NullFilesCacheTestCase.java Index: NullFilesCacheTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/cache/NullFilesCacheTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NullFilesCacheTestCase.java 10 May 2004 20:09:51 -0000 1.1 +++ NullFilesCacheTestCase.java 20 May 2004 17:40:55 -0000 1.2 @@ -50,7 +50,7 @@ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { - final File testDir = AbstractVfsTestCase.getTestDirectory(); + final File testDir = AbstractVfsTestCase.getTestDirectoryFile(); return manager.toFileObject(testDir); } } 1.7 +3 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/providers.xml Index: providers.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/providers.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- providers.xml 17 May 2004 17:56:57 -0000 1.6 +++ providers.xml 20 May 2004 17:40:55 -0000 1.7 @@ -1,5 +1,7 @@ <providers> - <default-provider class-name="org.apache.commons.vfs.provider.url.UrlFileProvider"/> + <default-provider class-name="org.apache.commons.vfs.provider.url.UrlFileProvider"> + <scheme name="res"/> + </default-provider> <provider class-name="org.apache.commons.vfs.provider.local.DefaultLocalFileProvider"> <scheme name="file"/> </provider> 1.1 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/res/test/ResourceProviderTestCase.java Index: ResourceProviderTestCase.java =================================================================== /* * Copyright 2002, 2003,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.vfs.provider.res.test; import junit.framework.Test; import org.apache.commons.AbstractVfsTestCase; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystemManager; import org.apache.commons.vfs.impl.DefaultFileSystemManager; import org.apache.commons.vfs.provider.url.UrlFileProvider; import org.apache.commons.vfs.test.AbstractProviderTestConfig; import org.apache.commons.vfs.test.ProviderTestSuite; /** * Test cases for the resource provider. * * @author Emmanuel Bourg * @version $Revision: 1.1 $, $Date: 2004/05/20 17:40:55 $ */ public class ResourceProviderTestCase extends AbstractProviderTestConfig { public static Test suite() throws Exception { return new ProviderTestSuite(new ResourceProviderTestCase()); } /** * Prepares the file system manager. This implementation does nothing. */ public void prepare(DefaultFileSystemManager manager) throws Exception { manager.addProvider(new String[]{"res", "file"}, new UrlFileProvider()); } /** * Returns the base folder for tests. */ public FileObject getBaseTestFolder(FileSystemManager manager) throws Exception { String baseDir = AbstractVfsTestCase.getTestDirectory(); return manager.resolveFile("res:" + baseDir); } } 1.33 +0 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties Index: Resources.properties =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 1.10 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/temp/test/TemporaryProviderTestCase.java Index: TemporaryProviderTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/temp/test/TemporaryProviderTestCase.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TemporaryProviderTestCase.java 10 May 2004 20:09:53 -0000 1.9 +++ TemporaryProviderTestCase.java 20 May 2004 17:40:55 -0000 1.10 @@ -51,7 +51,7 @@ public void prepare(final DefaultFileSystemManager manager) throws Exception { - final File baseDir = AbstractVfsTestCase.getTestDirectory(); + final File baseDir = AbstractVfsTestCase.getTestDirectoryFile(); manager.addProvider("tmp", new TemporaryFileProvider(baseDir)); } 1.13 +9 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileObject.java Index: UrlFileObject.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileObject.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- UrlFileObject.java 10 May 2004 20:09:53 -0000 1.12 +++ UrlFileObject.java 20 May 2004 17:40:56 -0000 1.13 @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -56,8 +57,14 @@ { if (url == null) { - url = new URL(getName().getURI()); + // url = new URL(getName().getURI()); + url = createURL(getName()); } + } + + protected URL createURL(final FileName name) throws MalformedURLException + { + return new URL(getName().getURI()); } /** 1.21 +33 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java Index: UrlFileProvider.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- UrlFileProvider.java 19 May 2004 19:34:07 -0000 1.20 +++ UrlFileProvider.java 20 May 2004 17:40:56 -0000 1.21 @@ -19,10 +19,12 @@ import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystem; +import org.apache.commons.vfs.FileSystemConfigBuilder; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.provider.AbstractFileProvider; import org.apache.commons.vfs.provider.BasicFileName; +import org.apache.commons.vfs.provider.UriParser; import java.net.MalformedURLException; import java.net.URL; @@ -61,13 +63,37 @@ { try { - final URL url = new URL(uri); + StringBuffer buf = new StringBuffer(80); + String scheme = UriParser.extractScheme(uri, buf); + + final URL url; + if ("res".equals(scheme)) + { + String resourceName = buf.toString(); + + ClassLoader cl = UrlFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions); + if (cl == null) + { + cl = getClass().getClassLoader(); + } + url = cl.getResource(resourceName); + + if (url == null) + { + throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri); + } + } + else + { + url = new URL(uri); + } final URL rootUrl = new URL(url, "/"); final String key = this.getClass().getName() + rootUrl.toString(); FileSystem fs = findFileSystem(key, fileSystemOptions); if (fs == null) { final FileName rootName = + // new BasicFileName(scheme, rootUrl.toExternalForm(), FileName.ROOT_PATH); new BasicFileName(rootUrl, FileName.ROOT_PATH); fs = new UrlFileSystem(rootName, fileSystemOptions); addFileSystem(key, fs); @@ -78,6 +104,11 @@ { throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri, e); } + } + + public FileSystemConfigBuilder getConfigBuilder() + { + return UrlFileSystemConfigBuilder.getInstance(); } public Collection getCapabilities() 1.20 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileSystem.java Index: UrlFileSystem.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileSystem.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- UrlFileSystem.java 19 May 2004 19:34:07 -0000 1.19 +++ UrlFileSystem.java 20 May 2004 17:40:56 -0000 1.20 @@ -29,7 +29,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a> * @version $Revision$ $Date$ */ -class UrlFileSystem +public class UrlFileSystem extends AbstractFileSystem implements FileSystem { 1.1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java Index: UrlFileName.java =================================================================== /* * Copyright 2002, 2003,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.vfs.provider.url; import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.provider.LayeredFileName; import org.apache.commons.vfs.provider.UriParser; /** * A parser for Zip file names. * * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a> * @version $Revision: 1.1 $ $Date: 2004/05/20 17:40:56 $ */ public class UrlFileName extends LayeredFileName { public UrlFileName(final String scheme, final String zipFileUri, final String path) { super(scheme, zipFileUri, path); } /** * Builds the root URI for this file name. */ protected void appendRootUri(final StringBuffer buffer) { buffer.append(getScheme()); buffer.append(":"); // buffer.append("!"); UriParser.appendEncoded(buffer, getOuterUri(), null); } /** * Factory method for creating name instances. */ protected FileName createName(final String path) { return new UrlFileName(getScheme(), getOuterUri(), path); } /** * Parses a Zip URI. */ public static UrlFileName parseUri(final String uri) throws FileSystemException { final StringBuffer name = new StringBuffer(); // Extract the scheme final String scheme = UriParser.extractScheme(uri, name); // Extract the Zip file URI final String zipUri = extractZipName(name); // Decode and normalise the path UriParser.decode(name, 0, name.length()); UriParser.normalisePath(name); final String path = name.toString(); return new UrlFileName(scheme, zipUri, path); } /** * Pops the root prefix off a URI, which has had the scheme removed. */ private static String extractZipName(final StringBuffer uri) throws FileSystemException { return uri.substring(2); /* // Looking for <name>!<abspath> int maxlen = uri.length(); int pos = 0; for (; pos < maxlen && uri.charAt(pos) != '!'; pos++) { } // Extract the name String prefix = uri.substring(pos); if (pos < maxlen) { uri.delete(0, pos + 1); } else { uri.setLength(0); } // Decode the name return UriParser.decode(prefix); */ } } 1.1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileSystemConfigBuilder.java Index: UrlFileSystemConfigBuilder.java =================================================================== /* * Copyright 2002, 2003,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.vfs.provider.url; import org.apache.commons.vfs.FileSystemConfigBuilder; import org.apache.commons.vfs.FileSystemOptions; /** * The config builder for various ftp configuration options * * @author <a href="mailto:[EMAIL PROTECTED]">Mario Ivankovits</a> * @version $Revision: 1.1 $ $Date: 2004/05/20 17:40:56 $ */ public class UrlFileSystemConfigBuilder extends FileSystemConfigBuilder { private final static UrlFileSystemConfigBuilder builder = new UrlFileSystemConfigBuilder(); public static UrlFileSystemConfigBuilder getInstance() { return builder; } private UrlFileSystemConfigBuilder() { } public void setClassLoader(FileSystemOptions opts, ClassLoader classLoader) { setParam(opts, ClassLoader.class.getName(), classLoader); } public ClassLoader getClassLoader(FileSystemOptions opts) { return (ClassLoader) getParam(opts, ClassLoader.class.getName()); } protected Class getConfigClass() { return UrlFileSystem.class; } } 1.11 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/url/test/UrlProviderTestCase.java Index: UrlProviderTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/url/test/UrlProviderTestCase.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- UrlProviderTestCase.java 10 May 2004 20:09:53 -0000 1.10 +++ UrlProviderTestCase.java 20 May 2004 17:40:56 -0000 1.11 @@ -56,7 +56,7 @@ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { - final File baseDir = AbstractVfsTestCase.getTestDirectory(); + final File baseDir = AbstractVfsTestCase.getTestDirectoryFile(); final URL url = baseDir.toURL(); return manager.resolveFile(url.toExternalForm()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]