Author: jboynes Date: Mon Apr 6 18:53:07 2015 New Revision: 1671635 URL: http://svn.apache.org/r1671635 Log: Separate mounting FileSystem from creating ClassLoader
Modified: tomcat/sandbox/niofs/src/niofs/ArchiveFileSystemProvider.java tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java Modified: tomcat/sandbox/niofs/src/niofs/ArchiveFileSystemProvider.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/niofs/src/niofs/ArchiveFileSystemProvider.java?rev=1671635&r1=1671634&r2=1671635&view=diff ============================================================================== --- tomcat/sandbox/niofs/src/niofs/ArchiveFileSystemProvider.java (original) +++ tomcat/sandbox/niofs/src/niofs/ArchiveFileSystemProvider.java Mon Apr 6 18:53:07 2015 @@ -52,6 +52,7 @@ import java.nio.file.attribute.FileTime; import java.nio.file.attribute.UserPrincipalLookupService; import java.nio.file.spi.FileSystemProvider; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; @@ -261,6 +262,7 @@ public class ArchiveFileSystemProvider e */ class ArchiveFileSystem extends FileSystem { private final URI baseURI; + private final Path root; private final Map<Path, DirectoryNode> directory; private volatile boolean open = true; @@ -271,6 +273,7 @@ public class ArchiveFileSystemProvider e throw new IllegalArgumentException(e); } directory = createIndex(path); + root = getPath("/"); } /** @@ -348,7 +351,7 @@ public class ArchiveFileSystemProvider e @Override public Iterable<Path> getRootDirectories() { - return null; + return Collections.singleton(root); } @Override Modified: tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java?rev=1671635&r1=1671634&r2=1671635&view=diff ============================================================================== --- tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java (original) +++ tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java Mon Apr 6 18:53:07 2015 @@ -20,7 +20,6 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -34,6 +33,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -41,7 +41,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static java.net.URLEncoder.encode; import static org.junit.Assert.assertEquals; /** @@ -89,30 +88,32 @@ public class ClassLoaderTest { private ClassLoader classLoader; @Before - public void initClassLoader() throws IOException { + public void initClassLoader() throws Exception { ArchiveFileSystemProvider provider = new ArchiveFileSystemProvider(); + String scheme = provider.getScheme(); Path war = FileSystems.getDefault().getPath("greenhouse-1.0.0.BUILD-SNAPSHOT.war"); - URI warURI = URI.create(provider.getScheme() + "://" + encode(war.toUri().toString(), "UTF8")); - FileSystem fileSystem = FileSystems.newFileSystem(warURI, Collections.emptyMap()); - URL[] urls = Files.list(fileSystem.getPath(fileSystem.getSeparator() + "WEB-INF", "lib")) + URI warURI = new URI(scheme, war.toUri().toString(), null, null, null); + FileSystem warFS = FileSystems.newFileSystem(warURI, Collections.emptyMap()); + List<FileSystem> fileSystems = Files.list(warFS.getPath("/WEB-INF/lib")) .filter(path -> path.getFileName().toString().matches(".*\\.(zip|jar)$")) .map(path -> { try { - return URI.create(provider.getScheme() + "://" + encode(path.toUri().toString(), "UTF8")); - } catch (UnsupportedEncodingException e) { + URI archiveURI = new URI(scheme, path.toUri().toString(), null, null, null); + return FileSystems.newFileSystem(archiveURI, Collections.emptyMap()); + } catch (URISyntaxException | IOException e) { throw new IllegalStateException(e); } }) - .peek(uri -> { + .collect(Collectors.toList()); + Path classes = warFS.getPath("/WEB-INF/classes"); + if (Files.isDirectory(classes)) { + fileSystems.add(FileSystems.newFileSystem(classes.toUri(), Collections.emptyMap())); + } + URL[] urls = fileSystems.stream() + .map(archiveFS -> { try { - FileSystems.newFileSystem(uri, Collections.emptyMap()); - } catch (IOException e) { - throw new IllegalStateException(e); - } - }) - .map(uri -> { - try { - return new URL(uri.toString() + '/'); + Path rootPath = archiveFS.getRootDirectories().iterator().next(); + return rootPath.toUri().toURL(); } catch (IOException e) { throw new IllegalStateException(e); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org