[richfaces-svn-commits] JBoss Rich Faces SVN: r18495 - in root/sandbox/cdk/maven-resources-plugin: src/it/richfaces-application and 10 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Aug 6 14:31:30 EDT 2010


Author: nbelaevski
Date: 2010-08-06 14:31:28 -0400 (Fri, 06 Aug 2010)
New Revision: 18495

Added:
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/strings/
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/strings/Constants.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFS.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSRoot.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSType.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VirtualFile.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSFile.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSRoot.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipNode.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSFile.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSRoot.java
Removed:
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/ClasspathUtil.java
Modified:
   root/sandbox/cdk/maven-resources-plugin/pom.xml
   root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
   root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
Log:
Dynamic resources prerenderer: latest changes check-in

Modified: root/sandbox/cdk/maven-resources-plugin/pom.xml
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/pom.xml	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/pom.xml	2010-08-06 18:31:28 UTC (rev 18495)
@@ -104,19 +104,6 @@
             <artifactId>slf4j-simple</artifactId>
             <version>1.5.8</version>
         </dependency>
-        
-        <dependency>
-            <groupId>org.jboss</groupId>
-            <artifactId>jboss-vfs</artifactId>
-            <version>3.0.0.CR5</version>
-        </dependency>
-        
-        <!-- TODO use maven logging -->
-        <dependency>
-        	<groupId>org.jboss.logging</groupId>
-        	<artifactId>jboss-logging-log4j</artifactId>
-        	<version>2.2.0.CR1</version>
-        </dependency>
     </dependencies>
 
     <build>

Modified: root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/it/richfaces-application/pom.xml	2010-08-06 18:31:28 UTC (rev 18495)
@@ -36,16 +36,20 @@
                                 <include>text/css</include>
                                 <include>image/.+</include>
                             </includedContentTypes>
-                            <!-- fileNameMappings>
+                            <fileNameMappings>
                                 <property>
-                                    <name>^org\.richfaces\.renderkit\.html\.(images\.)?</name>
+                                    <name>^\Qorg.richfaces.renderkit.html\E</name>
                                     <value>org.richfaces/images/</value>
                                 </property>
                                 <property>
+                                    <name>^\Qorg.richfaces.renderkit.html.images\E</name>
+                                    <value>org.richfaces/images/</value>
+                                </property>
+                                <property>
                                     <name>^css/</name>
                                     <value>org.richfaces/css/</value>
                                 </property>
-                            </fileNameMappings -->
+                            </fileNameMappings>
                         </configuration>
                     </execution>
                 </executions>

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -26,10 +26,13 @@
 import static com.google.common.collect.Collections2.transform;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
@@ -47,7 +50,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.jboss.vfs.VirtualFile;
+import org.reflections.util.ClasspathHelper;
 import org.richfaces.cdk.concurrent.CountingExecutorCompletionService;
 import org.richfaces.cdk.faces.FacesImpl;
 import org.richfaces.cdk.naming.FileNameMapperImpl;
@@ -59,9 +62,11 @@
 import org.richfaces.cdk.resource.scan.impl.DynamicResourcesScanner;
 import org.richfaces.cdk.resource.scan.impl.StaticResourcesScanner;
 import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
-import org.richfaces.cdk.util.ClasspathUtil;
 import org.richfaces.cdk.util.MoreConstraints;
 import org.richfaces.cdk.util.MorePredicates;
+import org.richfaces.cdk.vfs.VFS;
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VirtualFile;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
@@ -159,7 +164,7 @@
     
     // TODO executor parameters
     private static ExecutorService createExecutorService() {
-        return Executors.newSingleThreadExecutor();
+        return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
     }
 
     private Predicate<Resource> createResourcesFilter() {
@@ -180,8 +185,8 @@
         return result.toURI().toURL();
     }
     
-    private void scanDynamicResources(Collection<URL> cpUrls) throws Exception {
-        ResourcesScanner scanner = new DynamicResourcesScanner(cpUrls);
+    private void scanDynamicResources(Collection<VFSRoot> cpFiles) throws Exception {
+        ResourcesScanner scanner = new DynamicResourcesScanner(cpFiles);
         scanner.scan();
         foundResources.addAll(scanner.getResources());
     }
@@ -192,6 +197,30 @@
         foundResources.addAll(scanner.getResources());
     }
 
+    private Collection<VFSRoot> fromUrls(Iterable<URL> urls) throws URISyntaxException, IOException {
+        Collection<VFSRoot> result = Lists.newArrayList();
+        
+        for (URL url : urls) {
+            if (url == null) {
+                continue;
+            }
+            
+            VFSRoot vfsRoot = VFS.getRoot(url);
+            vfsRoot.initialize();
+            result.add(vfsRoot);
+        }
+
+        return result;
+    }
+    
+    private Collection<VFSRoot> getClasspathVfs() throws URISyntaxException, IOException {
+        return fromUrls(ClasspathHelper.getUrlsForCurrentClasspath());
+    }
+    
+    private Collection<VFSRoot> getWebrootVfs() throws URISyntaxException, IOException {
+        return fromUrls(Collections.singletonList(resolveWebRoot()));
+    }
+    
     protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL) {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
@@ -215,23 +244,25 @@
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
-        
         ClassLoader cCL = Thread.currentThread().getContextClassLoader();
         Faces faces = null;
         ExecutorService executorService = null;
+        
+        Collection<VFSRoot> webResources = null;
+        Collection<VFSRoot> cpResources = null;
+        
+        try {
+            ClassLoader projectCL = createProjectClassLoader(project, true);
+            Thread.currentThread().setContextClassLoader(projectCL);
 
-        try {
-            URL webRootUrl = resolveWebRoot();
+            webResources = getWebrootVfs();
+            cpResources = getClasspathVfs();
+
+            Collection<VirtualFile> resourceRoots = ResourceUtil.getResourceRoots(cpResources, webResources);
             
-            Collection<URL> cpUrls = ClasspathUtil.getFacesClasspathUrls();
-            Collection<VirtualFile> resourceRoots = ResourceUtil.getResourceRoots(cpUrls, webRootUrl);
-
-            scanDynamicResources(cpUrls);
+            scanDynamicResources(cpResources);
             scanStaticResources(resourceRoots);
             
-            ClassLoader projectCL = createProjectClassLoader(project, true);
-            Thread.currentThread().setContextClassLoader(projectCL);
-
             File outputDirFile = new File(outputDir);
             if (!outputDirFile.exists()) {
                 outputDirFile = new File(project.getBuild().getDirectory(), outputDir);
@@ -274,6 +305,29 @@
         } catch (Exception e) {
             throw new MojoExecutionException(e.getMessage(), e);
         } finally {
+            
+            if (cpResources != null) {
+                for (VFSRoot vfsRoot : cpResources) {
+                    try {
+                        vfsRoot.close();
+                    } catch (IOException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+            }
+            
+            if (webResources != null) {
+                for (VFSRoot vfsRoot : cpResources) {
+                    try {
+                        vfsRoot.close();
+                    } catch (IOException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+            }
+            
             // TODO review finally block
             if (executorService != null) {
                 executorService.shutdown();

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ResourceTaskFactory.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -25,7 +25,6 @@
 
 import javax.faces.application.Resource;
 
-
 import com.google.common.base.Predicate;
 
 /**

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -21,6 +21,9 @@
  */
 package org.richfaces.cdk.faces;
 
+import static org.richfaces.cdk.strings.Constants.SLASH_JOINER;
+import static org.richfaces.cdk.strings.Constants.SLASH_SPLITTER;
+
 import java.beans.FeatureDescriptor;
 import java.text.MessageFormat;
 import java.util.Iterator;
@@ -34,8 +37,6 @@
 import javax.faces.application.ResourceHandler;
 import javax.faces.context.FacesContext;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
 import com.google.common.collect.Lists;
 
 /**
@@ -67,8 +68,8 @@
     }
     
     private String relativize(String path, String basePath) {
-        Iterator<String> pathItr = Splitter.on('/').split(path).iterator();
-        Iterator<String> basePathItr = Splitter.on('/').split(basePath).iterator();
+        Iterator<String> pathItr = SLASH_SPLITTER.split(path).iterator();
+        Iterator<String> basePathItr = SLASH_SPLITTER.split(basePath).iterator();
 
         List<String> resultPathSegments = Lists.newArrayList();
         String firstNonMatchedSegment = skipEqualPathSegments(pathItr, basePathItr);
@@ -85,7 +86,7 @@
             resultPathSegments.add(pathItr.next());
         }
         
-        return Joiner.on('/').join(resultPathSegments);
+        return SLASH_JOINER.join(resultPathSegments);
     }
 
     public Object getValue(ELContext context, Object base, Object property) {

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -21,22 +21,19 @@
  */
 package org.richfaces.cdk.resource;
 
+import static org.richfaces.cdk.strings.Constants.DOT_JOINER;
+
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.net.URL;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.util.automount.Automounter;
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VirtualFile;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Ordering;
 import com.google.common.primitives.Ints;
@@ -65,8 +62,6 @@
             }
         }).nullsFirst();
         
-        private static final Joiner DOT_JOINER = Joiner.on('.').skipNulls();
-
         private String version;
         
         private int[] versionVector;
@@ -98,7 +93,7 @@
     public static VirtualFile getLatestVersion(VirtualFile file, boolean library) {
         VersionKey latestVersionKey = null;
         
-        List<VirtualFile> children = file.getChildren();
+        Collection<VirtualFile> children = file.getChildren();
         for (VirtualFile child : children) {
             if (library && child.isDirectory()) {
                 Matcher matcher = LIBRARY_VERSION_PATTERN.matcher(child.getName());
@@ -121,38 +116,32 @@
             result = file;
         }
         
-        if (result.exists() && (library ^ result.isFile())) {
+        if (result != null && (library ^ result.isFile())) {
             return result;
         }
         
         return null;
     }
     
-    private static VirtualFile getExistingChild(URL rootUrl, String path) throws URISyntaxException, IOException {
-        VirtualFile root = VFS.getChild(rootUrl);
-        Automounter.mount(root);
-        VirtualFile child = root.getChild(path);
-        if (child.exists()) {
-            return child;
+    private static Collection<VirtualFile> getExistingChildren(Iterable<VFSRoot> files, String path) throws URISyntaxException, IOException {
+        Collection<VirtualFile> result = Lists.newArrayList();
+
+        for (VirtualFile file: files) {
+            VirtualFile child = file.getChild(path, true);
+            if (child != null) {
+                result.add(child);
+            }
         }
         
-        return null;
+        return result;
     }
     
-    public static Collection<VirtualFile> getResourceRoots(Iterable<URL> cpUrls, URL webrootUrl) throws URISyntaxException, IOException {
-        Collection<VirtualFile> result = Lists.newArrayList();
-
-        for (URL url : cpUrls) {
-            result.add(getExistingChild(url, CLASSPATH_RESOURCES_LOCATION));
-        }
+    public static Collection<VirtualFile> getResourceRoots(Iterable<VFSRoot> cpRoots, Iterable<VFSRoot> webRoots) throws URISyntaxException, IOException {
+        List<VirtualFile> result = Lists.newArrayList();
         
-        if (webrootUrl != null) {
-            result.add(getExistingChild(webrootUrl, WEB_RESOURCES_LOCATION));
-        }
+        result.addAll(getExistingChildren(cpRoots, CLASSPATH_RESOURCES_LOCATION));
+        result.addAll(getExistingChildren(webRoots, WEB_RESOURCES_LOCATION));
         
-        Iterables.removeIf(result, Predicates.isNull());
-        
         return result;
     }
-    
 }

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -21,6 +21,8 @@
  */
 package org.richfaces.cdk.resource;
 
+import static org.richfaces.cdk.strings.Constants.COLON_JOINER;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -35,7 +37,6 @@
 import org.richfaces.cdk.FileNameMapper;
 import org.richfaces.cdk.ResourceWriter;
 
-import com.google.common.base.Joiner;
 import com.google.common.base.Strings;
 import com.google.common.io.ByteStreams;
 
@@ -55,7 +56,7 @@
     }
 
     private String getResourceQualifier(Resource resource) {
-        return Joiner.on(':').skipNulls().join(resource.getLibraryName(), resource.getResourceName());
+        return COLON_JOINER.join(resource.getLibraryName(), resource.getResourceName());
     }
     
     private FileNameMapper getFileNameMapper() {

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -21,6 +21,10 @@
  */
 package org.richfaces.cdk.resource.handler.impl;
 
+import static org.richfaces.cdk.strings.Constants.DASH_JOINER;
+import static org.richfaces.cdk.strings.Constants.DOT_JOINER;
+import static org.richfaces.cdk.strings.Constants.SLASH_JOINER;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -31,7 +35,6 @@
 
 import org.richfaces.resource.VersionedResource;
 
-import com.google.common.base.Joiner;
 import com.google.common.base.Strings;
 
 /**
@@ -45,12 +48,6 @@
      */
     private static final String ECSS_EXTENSION = ".ecss";
 
-    private static final Joiner SLASH_JOINER = Joiner.on('/').skipNulls();
-
-    private static final Joiner DOT_JOINER = Joiner.on('.').skipNulls();
-
-    private static final Joiner DASH_JOINER = Joiner.on('-').skipNulls();
-
     private Resource resource;
 
     public DynamicResourceWrapper(Resource resource) {

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -27,8 +27,8 @@
 import javax.activation.MimetypesFileTypeMap;
 import javax.faces.application.Resource;
 
-import org.jboss.vfs.VirtualFile;
 import org.richfaces.cdk.resource.ResourceUtil;
+import org.richfaces.cdk.vfs.VirtualFile;
 
 import com.google.common.base.Strings;
 
@@ -48,7 +48,7 @@
     private VirtualFile findLibrary(String libraryName) {
         for (VirtualFile file : roots) {
             VirtualFile child = file.getChild(libraryName);
-            if (!child.exists()) {
+            if (child == null) {
                 continue;
             }
             
@@ -64,7 +64,7 @@
     private VirtualFile findResource(Collection<VirtualFile> libraryDirs, String resourceName) {
         for (VirtualFile libraryDir : libraryDirs) {
             VirtualFile child = libraryDir.getChild(resourceName);
-            if (child.exists()) {
+            if (child != null) {
                 VirtualFile resource = ResourceUtil.getLatestVersion(child, false);
                 if (resource != null) {
                     return resource;
@@ -89,7 +89,7 @@
         
         VirtualFile resource = findResource(libraryDirs, resourceName);
         if (resource != null) {
-            Resource result = new VFSResource(resource, getRelativePath(resource));
+            Resource result = new VFSResource(resource, resource.getRelativePath());
             
             result.setResourceName(resourceName);
             result.setLibraryName(libraryName);
@@ -107,14 +107,4 @@
         return null;
     }
 
-    private String getRelativePath(VirtualFile resource) {
-        String relativePath = null;
-        for (VirtualFile parent : resource.getParentFileList()) {
-            if (roots.contains(parent)) {
-                relativePath = resource.getPathNameRelativeTo(parent);
-                break;
-            }
-        }
-        return relativePath;
-    }
 }

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -29,7 +29,7 @@
 import javax.faces.application.Resource;
 import javax.faces.context.FacesContext;
 
-import org.jboss.vfs.VirtualFile;
+import org.richfaces.cdk.vfs.VirtualFile;
 
 /**
  * @author Nick Belaevski
@@ -53,7 +53,7 @@
 
     @Override
     public InputStream getInputStream() throws IOException {
-        return file.openStream();
+        return file.getInputStream();
     }
 
     @Override

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/DynamicResourcesScanner.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -21,6 +21,7 @@
  */
 package org.richfaces.cdk.resource.scan.impl;
 
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Set;
@@ -32,6 +33,8 @@
 import org.richfaces.cdk.resource.scan.ResourcesScanner;
 import org.richfaces.cdk.resource.scan.impl.reflections.MarkerResourcesScanner;
 import org.richfaces.cdk.resource.scan.impl.reflections.ReflectionsExt;
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VFSType;
 import org.richfaces.resource.DynamicResource;
 
 import com.google.common.base.Function;
@@ -55,17 +58,29 @@
     
     private Collection<ResourceKey> resources = Sets.newHashSet();
 
-    private Collection<URL> urls;
+    private Collection<VFSRoot> cpFiles;
     
-    public DynamicResourcesScanner(Collection<URL> urls) {
+    public DynamicResourcesScanner(Collection<VFSRoot> cpFiles) {
         super();
-        this.urls = urls;
+        this.cpFiles = cpFiles;
     }
 
-    public void scan() {
+    public void scan() throws IOException {
+        Collection<URL> urls = Sets.newHashSet();
+        for (VFSRoot cpFile : cpFiles) {
+            if (cpFile.getType() == VFSType.zip) {
+                if (cpFile.getChild("META-INF/faces-config.xml") == null) {
+                    continue;
+                }
+            }
+            
+            URL url = cpFile.toURL();
+            urls.add(url);
+        }
+        
         ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(urls);
         configurationBuilder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(),
-            new MarkerResourcesScanner());
+            new MarkerResourcesScanner()).useParallelExecutor();
 
         ReflectionsExt refl = new ReflectionsExt(configurationBuilder);
         Set<Class<?>> allClasses = Sets.newHashSet();

Modified: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -22,12 +22,11 @@
 package org.richfaces.cdk.resource.scan.impl;
 
 import java.util.Collection;
-import java.util.List;
 
-import org.jboss.vfs.VirtualFile;
 import org.richfaces.cdk.ResourceKey;
 import org.richfaces.cdk.resource.ResourceUtil;
 import org.richfaces.cdk.resource.scan.ResourcesScanner;
+import org.richfaces.cdk.vfs.VirtualFile;
 
 import com.google.common.collect.Sets;
 
@@ -50,7 +49,7 @@
             return;
         }
         
-        List<VirtualFile> children = file.getChildren();
+        Collection<VirtualFile> children = file.getChildren();
         for (VirtualFile child : children) {
             if (child.isFile()) {
                 resources.add(new ResourceKey(child.getName()));
@@ -65,7 +64,7 @@
     }
 
     private void scanLibrary(String libraryName, VirtualFile dir) {
-        List<VirtualFile> children = dir.getChildren();
+        Collection<VirtualFile> children = dir.getChildren();
         for (VirtualFile child : children) {
             if (child.isFile()) {
                 resources.add(new ResourceKey(child.getName(), libraryName));

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/strings/Constants.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/strings/Constants.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/strings/Constants.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.strings;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public final class Constants {
+
+    private Constants() {
+    }
+
+    public static final Joiner SLASH_JOINER = Joiner.on('/').skipNulls();
+
+    public static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
+    
+    public static final Joiner DOT_JOINER = Joiner.on('.').skipNulls();
+
+    public static final Joiner DASH_JOINER = Joiner.on('-').skipNulls();
+
+    public static final Joiner COLON_JOINER = Joiner.on(':').skipNulls();
+}

Deleted: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/ClasspathUtil.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/ClasspathUtil.java	2010-08-06 10:04:44 UTC (rev 18494)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/util/ClasspathUtil.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * 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.richfaces.cdk.util;
-
-import java.net.URL;
-import java.util.Collection;
-
-import org.reflections.util.ClasspathHelper;
-import org.reflections.vfs.Vfs;
-import org.reflections.vfs.Vfs.Dir;
-import org.reflections.vfs.Vfs.File;
-import org.reflections.vfs.ZipDir;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Iterators;
-
-/**
- * @author Nick Belaevski
- * 
- */
-public final class ClasspathUtil {
-
-    private static final Predicate<File> IS_FACES_CONFIG = new Predicate<File>() {
-
-        public boolean apply(File input) {
-            return input.getRelativePath().endsWith("META-INF/faces-config.xml");
-        }
-
-    };
-
-    private static final Predicate<URL> FACES_URL = new Predicate<URL>() {
-
-        public boolean apply(URL input) {
-            Dir dir = Vfs.fromURL(input);
-            if (dir instanceof ZipDir) {
-                return containsFacesConfig(dir);
-            } else {
-                return true;
-            }
-        }
-    };
-
-    private ClasspathUtil() {}
-
-    private static boolean containsFacesConfig(Dir dir) {
-        return Iterators.any(dir.getFiles().iterator(), IS_FACES_CONFIG);
-    }
-
-    public static Collection<URL> getFacesClasspathUrls() {
-        return Collections2.filter(ClasspathHelper.getUrlsForCurrentClasspath(), FACES_URL);
-    }
-
-}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFS.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFS.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFS.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.richfaces.cdk.vfs.file.FileVFSRoot;
+import org.richfaces.cdk.vfs.zip.ZipVFSRoot;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public final class VFS {
+
+    private VFS() {
+    }
+    
+    public static VFSRoot getRoot(URL url) throws URISyntaxException, IOException {
+        File file = new File(url.toURI());
+        if (file.isDirectory()) {
+            return new FileVFSRoot(file);
+        } else {
+            return new ZipVFSRoot(file);
+        }
+    }
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSRoot.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSRoot.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSRoot.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public interface VFSRoot extends Closeable, VirtualFile {
+
+    public void initialize() throws IOException;
+    
+    public VFSType getType();
+
+    public URL toURL() throws MalformedURLException;
+    
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSType.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSType.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VFSType.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public enum VFSType {
+
+    zip, file
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VirtualFile.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VirtualFile.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/VirtualFile.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public interface VirtualFile {
+
+    public boolean isFile();
+    
+    public boolean isDirectory();
+    
+    public InputStream getInputStream() throws IOException;
+    
+    public String getName();
+    
+    public String getRelativePath();
+    
+    public Collection<VirtualFile> getChildren();
+    
+    public VirtualFile getChild(String path);
+
+    public VirtualFile getChild(String path, boolean remounted);
+    
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSFile.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSFile.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSFile.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs.file;
+
+import static org.richfaces.cdk.strings.Constants.SLASH_JOINER;
+import static org.richfaces.cdk.strings.Constants.SLASH_SPLITTER;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+
+import org.richfaces.cdk.vfs.VirtualFile;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class FileVFSFile implements VirtualFile {
+
+    private File file;
+
+    private String relativePath;
+    
+    public FileVFSFile(File file, String relativePath) {
+        super();
+        this.file = file;
+        this.relativePath = relativePath;
+    }
+    
+    @Override
+    public boolean isFile() {
+        return file.isFile();
+    }
+
+    @Override
+    public boolean isDirectory() {
+        return file.isDirectory();
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        return new FileInputStream(file);
+    }
+
+    @Override
+    public String getName() {
+        return file.getName();
+    }
+
+    @Override
+    public String getRelativePath() {
+        return relativePath;
+    }
+
+    @Override
+    public Collection<VirtualFile> getChildren() {
+        List<VirtualFile> result = Lists.newArrayList();
+        
+        String[] list = file.list();
+        if (list != null) {
+            for (String childName : list) {
+                File child = new File(file, childName);
+                result.add(new FileVFSFile(child, SLASH_JOINER.join(relativePath, childName)));
+            }
+        }
+
+        return result;
+    }
+
+    @Override
+    public VirtualFile getChild(String path) {
+        return getChild(path, false);
+    }
+    
+    @Override
+    public VirtualFile getChild(String path, boolean isRemounted) {
+        Iterable<String> split = SLASH_SPLITTER.split(path);
+        File result = file;
+        for (String pathSeg : split) {
+            result = new File(result, pathSeg);
+            
+            if (!result.exists()) {
+                break;
+            }
+        }
+        
+        if (result.exists()) {
+            return new FileVFSFile(result, isRemounted ? null : SLASH_JOINER.join(relativePath, result.getName()));
+        }
+        
+        return null;
+    }
+
+    protected File getFile() {
+        return file;
+    }
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSRoot.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSRoot.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/file/FileVFSRoot.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs.file;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VFSType;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class FileVFSRoot extends FileVFSFile implements VFSRoot {
+
+    public FileVFSRoot(File dir) {
+        super(dir, null);
+        
+        assert dir.isDirectory() && dir.exists();
+    }
+
+    @Override
+    public VFSType getType() {
+        return VFSType.file;
+    }
+    
+    @Override
+    public void close() throws IOException {
+        //nothing to close
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        throw new IOException("Stream is not available");
+    }
+
+    @Override
+    public String getName() {
+        return null;
+    }
+
+    @Override
+    public void initialize() throws IOException {
+        //do nothing
+    }
+
+    @Override
+    public URL toURL() throws MalformedURLException {
+        return getFile().toURI().toURL();
+    }
+
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipNode.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipNode.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipNode.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs.zip;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+
+final class ZipNode {
+    
+    private Map<String, ZipNode> children; 
+
+    private String name;
+
+    private ZipEntry zipEntry;
+    
+    private boolean directory;
+    
+    public ZipNode(String name) {
+        super();
+        this.name = name;
+    }
+    
+    public ZipNode getOrCreateChild(String name) {
+        setDirectory(true);
+        
+        if (children == null) {
+            children = new LinkedHashMap<String, ZipNode>();
+        }
+        
+        String lcName = name.toLowerCase();
+        
+        ZipNode node = children.get(lcName);
+        if (node == null) {
+            node = new ZipNode(name);
+            children.put(lcName, node);
+        }
+        
+        return node;
+    }
+    
+    public ZipNode getChild(String name) {
+        if (children == null) {
+            return null;
+        }
+        
+        return children.get(name.toLowerCase());
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public Iterable<ZipNode> listChildren() {
+        if (children == null) {
+            return Collections.emptySet();
+        }
+        return children.values();
+    }
+    
+    private void setDirectory(boolean directory) {
+        this.directory = directory;
+    }
+    
+    public boolean isDirectory() {
+        return directory;
+    }
+    
+    public void setZipEntry(ZipEntry zipEntry) {
+        this.zipEntry = zipEntry;
+        setDirectory(zipEntry.isDirectory());
+    }
+    
+    public ZipEntry getZipEntry() {
+        return zipEntry;
+    }
+    
+}
\ No newline at end of file

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSFile.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSFile.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSFile.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs.zip;
+
+import static org.richfaces.cdk.strings.Constants.SLASH_JOINER;
+import static org.richfaces.cdk.strings.Constants.SLASH_SPLITTER;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.richfaces.cdk.vfs.VirtualFile;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class ZipVFSFile implements VirtualFile {
+
+    private ZipFile zipFile;
+    
+    private ZipNode zipNode;
+    
+    private String relativePath;
+    
+    public ZipVFSFile(ZipFile zipFile, ZipNode zipNode, String relativePath) {
+        super();
+        this.zipFile = zipFile;
+        this.zipNode = zipNode;
+        this.relativePath = relativePath;
+    }
+
+    @Override
+    public boolean isFile() {
+        return !isDirectory();
+    }
+
+    @Override
+    public boolean isDirectory() {
+        return zipNode.isDirectory();
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        ZipEntry entry = zipNode.getZipEntry();
+        if (entry != null) {
+            synchronized (zipFile) {
+                return zipFile.getInputStream(entry);
+            }
+        }
+
+        throw new IOException("Input stream isn't available!");
+    }
+
+    @Override
+    public Collection<VirtualFile> getChildren() {
+        Iterable<ZipNode> children = zipNode.listChildren();
+        
+        List<VirtualFile> result = Lists.newArrayList();
+        
+        for (ZipNode child: children) {
+            result.add(new ZipVFSFile(zipFile, child, SLASH_JOINER.join(getRelativePath(), child.getName())));
+        }
+        
+        return result;
+    }
+
+    @Override
+    public VirtualFile getChild(String path) {
+        return getChild(path, false);
+    }
+    
+    @Override
+    public VirtualFile getChild(String path, boolean remounted) {
+        Iterable<String> split = SLASH_SPLITTER.split(path);
+        ZipNode node = zipNode;
+        for (String pathSeg : split) {
+            node = node.getChild(pathSeg);
+            if (node == null) {
+                return null;
+            }
+        }
+        
+        String relativePath = null;
+        if (!remounted) {
+            relativePath = SLASH_JOINER.join(getRelativePath(), path);
+        }
+        
+        return new ZipVFSFile(zipFile, node, relativePath);
+    }
+
+    @Override
+    public String getName() {
+        return zipNode.getName();
+    }
+
+    @Override
+    public String getRelativePath() {
+        return relativePath;
+    }
+    
+    protected ZipFile getZipFile() {
+        return zipFile;
+    }
+    
+    protected ZipNode getZipNode() {
+        return zipNode;
+    }
+}

Added: root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSRoot.java
===================================================================
--- root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSRoot.java	                        (rev 0)
+++ root/sandbox/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/vfs/zip/ZipVFSRoot.java	2010-08-06 18:31:28 UTC (rev 18495)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * 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.richfaces.cdk.vfs.zip;
+
+import static org.richfaces.cdk.strings.Constants.SLASH_SPLITTER;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VFSType;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class ZipVFSRoot extends ZipVFSFile implements VFSRoot {
+
+    private File file;
+    
+    public ZipVFSRoot(File file) throws IOException {
+        super(new ZipFile(file), new ZipNode(null), null);
+
+        assert file.isFile() && file.exists();
+        this.file = file;
+    }
+
+    @Override
+    public void initialize() throws IOException {
+        Enumeration<? extends ZipEntry> entries = getZipFile().entries();
+        while (entries.hasMoreElements()) {
+            ZipEntry entry = entries.nextElement();
+            
+            String entryName = entry.getName();
+            Iterable<String> split = SLASH_SPLITTER.split(entryName);
+            ZipNode node = getZipNode();
+            for (String pathSeg : split) {
+                if (".".equals(pathSeg) || "..".equals(pathSeg)) {
+                    continue;
+                }
+                
+                node = node.getOrCreateChild(pathSeg);
+            }
+            
+            node.setZipEntry(entry);
+        }
+    }
+    
+    @Override
+    public void close() throws IOException {
+        getZipFile().close();
+    }
+
+    @Override
+    public VFSType getType() {
+        return VFSType.zip;
+    }
+
+    public URL toURL() throws MalformedURLException {
+        return file.toURI().toURL();
+    };
+    
+    @Override
+    public InputStream getInputStream() throws IOException {
+        throw new IOException("Stream is not available");
+    }
+
+}



More information about the richfaces-svn-commits mailing list