[richfaces-svn-commits] JBoss Rich Faces SVN: r18619 - in sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk: faces and 8 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Aug 13 09:56:19 EDT 2010


Author: nbelaevski
Date: 2010-08-13 09:56:18 -0400 (Fri, 13 Aug 2010)
New Revision: 18619

Added:
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/util/
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/util/ResourceUtil.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/ResourceProcessor.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CSSResourceProcessor.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CharResourceProcessor.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ResourceWriterImpl.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ThroughputResourceProcessor.java
Removed:
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
Modified:
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapper.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
   sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
Log:
Maven resources plugin:

- bug fixing
- resource compression

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapper.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapper.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/FileNameMapper.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -21,7 +21,6 @@
  */
 package org.richfaces.cdk;
 
-import javax.faces.application.Resource;
 
 /**
  * @author Nick Belaevski
@@ -29,6 +28,6 @@
  */
 public interface FileNameMapper {
 
-    public String createName(Resource resource);
+    public String createName(String resourcePath);
     
 }

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/ProcessMojo.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -31,6 +31,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -54,13 +55,16 @@
 import org.richfaces.cdk.concurrent.CountingExecutorCompletionService;
 import org.richfaces.cdk.faces.FacesImpl;
 import org.richfaces.cdk.naming.FileNameMapperImpl;
-import org.richfaces.cdk.resource.ResourceUtil;
-import org.richfaces.cdk.resource.ResourceWriterImpl;
 import org.richfaces.cdk.resource.handler.impl.DynamicResourceHandler;
 import org.richfaces.cdk.resource.handler.impl.StaticResourceHandler;
 import org.richfaces.cdk.resource.scan.ResourcesScanner;
 import org.richfaces.cdk.resource.scan.impl.DynamicResourcesScanner;
 import org.richfaces.cdk.resource.scan.impl.StaticResourcesScanner;
+import org.richfaces.cdk.resource.util.ResourceUtil;
+import org.richfaces.cdk.resource.writer.ResourceProcessor;
+import org.richfaces.cdk.resource.writer.impl.CSSResourceProcessor;
+import org.richfaces.cdk.resource.writer.impl.JavaScriptResourceProcessor;
+import org.richfaces.cdk.resource.writer.impl.ResourceWriterImpl;
 import org.richfaces.cdk.task.ResourceTaskFactoryImpl;
 import org.richfaces.cdk.util.MoreConstraints;
 import org.richfaces.cdk.util.MorePredicates;
@@ -162,6 +166,10 @@
     
     private Collection<ResourceKey> foundResources = Sets.newHashSet();
     
+    private Collection<ResourceProcessor> resourceProcessors = Arrays.<ResourceProcessor>asList(
+        new JavaScriptResourceProcessor(getLog()), 
+        new CSSResourceProcessor());
+    
     // TODO executor parameters
     private static ExecutorService createExecutorService() {
         return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@@ -221,30 +229,24 @@
         return fromUrls(Collections.singletonList(resolveWebRoot()));
     }
     
-    protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL) {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
+    protected URL[] getProjectClasspath() {
         try {
             List<String> classpath = Constraints.constrainedList(Lists.<String>newArrayList(), MoreConstraints.cast(String.class));
             classpath.addAll((List<String>) project.getCompileClasspathElements());
             classpath.add(project.getBuild().getOutputDirectory());
 
             URL[] urlClasspath = filter(transform(classpath, filePathToURL), notNull()).toArray(EMPTY_URL_ARRAY);            
-            if (useCCL) {
-                classLoader = new URLClassLoader(urlClasspath, classLoader);
-            } else {
-                classLoader = new URLClassLoader(urlClasspath);
-            }
+            return urlClasspath;
         } catch (DependencyResolutionRequiredException e) {
             getLog().error("Dependencies not resolved ", e);
         }
 
-        return classLoader;
+        return new URL[0];
     }
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
-        ClassLoader cCL = Thread.currentThread().getContextClassLoader();
+        ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
         Faces faces = null;
         ExecutorService executorService = null;
         
@@ -252,7 +254,8 @@
         Collection<VFSRoot> cpResources = null;
         
         try {
-            ClassLoader projectCL = createProjectClassLoader(project, true);
+            URL[] projectCP = getProjectClasspath();
+            ClassLoader projectCL = new URLClassLoader(projectCP, contextCL);
             Thread.currentThread().setContextClassLoader(projectCL);
 
             webResources = getWebrootVfs();
@@ -276,7 +279,7 @@
             faces = new FacesImpl(null, new FileNameMapperImpl(Maps.fromProperties(fileNameMappings)), resourceHandler);
             faces.start();
             
-            ResourceWriterImpl resourceWriter = new ResourceWriterImpl(resourceOutputDir, resourceMappingDir);
+            ResourceWriterImpl resourceWriter = new ResourceWriterImpl(resourceOutputDir, resourceMappingDir, resourceProcessors);
             ResourceTaskFactoryImpl taskFactory = new ResourceTaskFactoryImpl(faces);
             taskFactory.setResourceWriter(resourceWriter);
 
@@ -320,7 +323,7 @@
             }
             
             if (webResources != null) {
-                for (VFSRoot vfsRoot : cpResources) {
+                for (VFSRoot vfsRoot : webResources) {
                     try {
                         vfsRoot.close();
                     } catch (IOException e) {
@@ -337,7 +340,7 @@
             if (faces != null) {
                 faces.stop();
             }
-            Thread.currentThread().setContextClassLoader(cCL);
+            Thread.currentThread().setContextClassLoader(contextCL);
         }
     }
 }

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/faces/ResourceELResolver.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -37,9 +37,6 @@
 import javax.faces.application.ResourceHandler;
 import javax.faces.context.FacesContext;
 
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.cdk.FileNameMapper;
-
 import com.google.common.collect.Lists;
 
 /**
@@ -92,10 +89,6 @@
         return SLASH_JOINER.join(resultPathSegments);
     }
 
-    private FileNameMapper getFileNameMapper() {
-        return ServiceTracker.getService(FileNameMapper.class);
-    }
-    
     public Object getValue(ELContext context, Object base, Object property) {
         checkBaseAndProperty(base, property);
 
@@ -116,13 +109,11 @@
             context.setPropertyResolved(true);
 
             if (resource != null) {
-                FileNameMapper fileNameMapper = getFileNameMapper();
-                
-                String requestPath = fileNameMapper.createName(resource);
+                String requestPath = resource.getRequestPath();
                 FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
                 Resource contextResource = CurrentResourceContext.getInstance(facesContext).getResource();
                 if (contextResource != null) {
-                    requestPath = relativize(requestPath, fileNameMapper.createName(contextResource));
+                    requestPath = relativize(requestPath, contextResource.getRequestPath());
                 }
 
                 return requestPath;

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/naming/FileNameMapperImpl.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -27,8 +27,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.faces.application.Resource;
-
 import org.richfaces.cdk.FileNameMapper;
 
 import com.google.common.collect.Lists;
@@ -80,25 +78,20 @@
         return result;
     }
 
-    //TODO implement counter remapping
-    private String remapName(String name) {
-        if (name == null) {
-            return name;
+    @Override
+    public String createName(String resourcePath) {
+        if (resourcePath == null) {
+            return resourcePath;
         }
 
         for (Mapping mapping : fileNameMappings) {
-            Matcher matcher = mapping.getPattern().matcher(name);
+            Matcher matcher = mapping.getPattern().matcher(resourcePath);
             if (matcher.find()) {
                 return matcher.replaceAll(mapping.getReplacement());
             }
         }
 
-        return name;
-    } 
-
-    @Override
-    public String createName(Resource resource) {
-        return remapName(resource.getRequestPath());
+        return resourcePath;
     }
 
 }

Deleted: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -1,147 +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.resource;
-
-import static org.richfaces.cdk.strings.Constants.DOT_JOINER;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.richfaces.cdk.vfs.VFSRoot;
-import org.richfaces.cdk.vfs.VirtualFile;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Ordering;
-import com.google.common.primitives.Ints;
-
-/**
- * @author Nick Belaevski
- * 
- */
-public final class ResourceUtil {
-
-    private static final String CLASSPATH_RESOURCES_LOCATION = "META-INF/resources";
-
-    private static final String WEB_RESOURCES_LOCATION = "resources";
-
-    private static final Pattern LIBRARY_VERSION_PATTERN = Pattern.compile("^(\\d+)(_\\d+)+");
-    
-    private static final Pattern RESOURCE_VERSION_PATTERN = Pattern.compile("^((?:\\d+)(?:_\\d+)+)[\\.]?(\\w+)?");
-    
-    public static final class VersionKey {
-
-        static final Ordering<VersionKey> ORDERING = Ordering.from(new Comparator<VersionKey>() {
-
-            @Override
-            public int compare(VersionKey o1, VersionKey o2) {
-                return Ints.lexicographicalComparator().compare(o1.versionVector, o2.versionVector);
-            }
-        }).nullsFirst();
-        
-        private String version;
-        
-        private int[] versionVector;
-
-        private String extension;
-        
-        public VersionKey(String version, String extension) throws NumberFormatException {
-            this.version = version;
-            this.versionVector = parseVersionString(version);
-            this.extension = extension;
-        }
-        
-        private static int[] parseVersionString(String s) {
-            String[] split = s.split("_");
-            int[] result = new int[split.length];
-            for (int i = 0; i < result.length; i++) {
-                result[i] = Integer.parseInt(split[i]);
-            }
-            return result;
-        }
-       
-        public String toString() {
-            return DOT_JOINER.join(version, extension);
-        }
-    }
-    
-    private ResourceUtil() {}
-    
-    public static VirtualFile getLatestVersion(VirtualFile file, boolean library) {
-        VersionKey latestVersionKey = null;
-        
-        Collection<VirtualFile> children = file.getChildren();
-        for (VirtualFile child : children) {
-            if (library && child.isDirectory()) {
-                Matcher matcher = LIBRARY_VERSION_PATTERN.matcher(child.getName());
-                if (matcher.matches()) {
-                    latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new VersionKey(child.getName(), null));
-                }
-            } else if (!library && child.isFile()) {
-                Matcher matcher = RESOURCE_VERSION_PATTERN.matcher(child.getName());
-                if (matcher.matches()) {
-                    latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new VersionKey(matcher.group(1), matcher.group(2)));
-                }
-            }
-        }
-        
-        VirtualFile result;
-        
-        if (latestVersionKey != null) {
-            result = file.getChild(latestVersionKey.toString());
-        } else {
-            result = file;
-        }
-        
-        if (result != null && (library ^ result.isFile())) {
-            return result;
-        }
-        
-        return null;
-    }
-    
-    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 result;
-    }
-    
-    public static Collection<VirtualFile> getResourceRoots(Iterable<VFSRoot> cpRoots, Iterable<VFSRoot> webRoots) throws URISyntaxException, IOException {
-        List<VirtualFile> result = Lists.newArrayList();
-        
-        result.addAll(getExistingChildren(cpRoots, CLASSPATH_RESOURCES_LOCATION));
-        result.addAll(getExistingChildren(webRoots, WEB_RESOURCES_LOCATION));
-        
-        return result;
-    }
-}

Deleted: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -1,145 +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.resource;
-
-import static org.richfaces.cdk.strings.Constants.COLON_JOINER;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.faces.application.Resource;
-
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.cdk.FileNameMapper;
-import org.richfaces.cdk.ResourceWriter;
-import org.richfaces.resource.ResourceFactory;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Maps;
-import com.google.common.io.ByteStreams;
-
-/**
- * @author Nick Belaevski
- * 
- */
-public class ResourceWriterImpl implements ResourceWriter {
-
-    private File resourceContentsDir;
-    
-    private File resourceMappingDir;
-    
-    private Map<String, String> processedResources = Maps.newConcurrentMap();
-    
-    public ResourceWriterImpl(File resourceContentsDir, File resourceMappingDir) {
-        this.resourceContentsDir = resourceContentsDir;
-        this.resourceMappingDir = resourceMappingDir;
-        resourceContentsDir.mkdirs();
-    }
-
-    private String getResourceQualifier(Resource resource) {
-        return COLON_JOINER.join(resource.getLibraryName(), resource.getResourceName());
-    }
-    
-    private FileNameMapper getFileNameMapper() {
-        return ServiceTracker.getService(FileNameMapper.class);
-    }
-    
-    private File getRoot(String rootName) {
-        if (!Strings.isNullOrEmpty(rootName)) {
-            return new File(resourceContentsDir, rootName);
-        } else {
-            return resourceContentsDir;
-        }
-    }
-    
-    private String addSkinPrefix(String s) {
-        return "%skin%/" + s;
-    }
-    
-    public void writeResource(String skinName, Resource resource) throws IOException {
-        FileOutputStream fos = null;
-        InputStream is = null;
-        try {
-            is = resource.getInputStream();
-            String mappedName = getFileNameMapper().createName(resource);
-            File outFile = new File(getRoot(skinName), mappedName);
-            outFile.getParentFile().mkdirs();
-            outFile.createNewFile();
-            
-            fos = new FileOutputStream(outFile);
-            ByteStreams.copy(is, fos);
-            
-            if (!Strings.isNullOrEmpty(skinName)) {
-                mappedName = addSkinPrefix(mappedName);
-            }
-            
-            processedResources.put(getResourceQualifier(resource), mappedName);
-        } finally {
-            if (fos != null) {
-                try {
-                    fos.close();
-                } catch (IOException e) {
-                    // TODO: handle exception
-                    e.printStackTrace();
-                }
-            }
-            if (is != null) {
-                try {
-                    is.close();
-                } catch (IOException e) {
-                    // TODO: handle exception
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
-    @Override
-    public void writeProcessedResourceMappings() throws IOException {
-        //TODO separate mappings file location
-        FileOutputStream fos = null;
-        try {
-            File mappingsFile = new File(resourceMappingDir, ResourceFactory.STATIC_RESOURCE_MAPPINGS);
-            mappingsFile.delete();
-            mappingsFile.getParentFile().mkdirs();
-            mappingsFile.createNewFile();
-            
-            fos = new FileOutputStream(mappingsFile);
-            Properties properties = new Properties();
-            properties.putAll(processedResources);
-            properties.store(fos, null);
-        } finally {
-            try {
-                if (fos != null) {
-                    fos.close();
-                }
-            } catch (IOException e) {
-                // TODO: handle exception
-            }
-        }
-    }
-
-}

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/DynamicResourceWrapper.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -33,6 +33,9 @@
 import javax.faces.application.Resource;
 import javax.faces.context.FacesContext;
 
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.cdk.FileNameMapper;
+import org.richfaces.resource.ResourceFactory;
 import org.richfaces.resource.VersionedResource;
 
 import com.google.common.base.Strings;
@@ -121,6 +124,10 @@
         }
     }
     
+    private FileNameMapper getFileNameMapper() {
+        return ServiceTracker.getService(FileNameMapper.class);
+    }
+    
     private String getVersion() {
         String version = null;
         if (resource instanceof VersionedResource) {
@@ -136,8 +143,9 @@
         String resourceExtension = getResourceExtension();
         
         String resourceName = DOT_JOINER.join(DASH_JOINER.join(mangledResourceName, getVersion()), resourceExtension);
-        
-        return SLASH_JOINER.join(mangledLibraryName, resourceName);
+        String resourcePath = SLASH_JOINER.join(mangledLibraryName, resourceName);
+
+        return ResourceFactory.SKINNED_RESOURCE_PREFIX + getFileNameMapper().createName(resourcePath);
     }
 
     @Override

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/StaticResourceHandler.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -27,7 +27,7 @@
 import javax.activation.MimetypesFileTypeMap;
 import javax.faces.application.Resource;
 
-import org.richfaces.cdk.resource.ResourceUtil;
+import org.richfaces.cdk.resource.util.ResourceUtil;
 import org.richfaces.cdk.vfs.VirtualFile;
 
 import com.google.common.base.Strings;

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/handler/impl/VFSResource.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -29,6 +29,8 @@
 import javax.faces.application.Resource;
 import javax.faces.context.FacesContext;
 
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.cdk.FileNameMapper;
 import org.richfaces.cdk.vfs.VirtualFile;
 
 /**
@@ -51,6 +53,10 @@
         this.relativePath = relativePath;
     }
 
+    private FileNameMapper getFileNameMapper() {
+        return ServiceTracker.getService(FileNameMapper.class);
+    }
+    
     @Override
     public InputStream getInputStream() throws IOException {
         return file.getInputStream();
@@ -63,7 +69,7 @@
 
     @Override
     public String getRequestPath() {
-        return relativePath;
+        return getFileNameMapper().createName(relativePath);
     }
 
     @Override

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/StaticResourcesScanner.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -24,8 +24,8 @@
 import java.util.Collection;
 
 import org.richfaces.cdk.ResourceKey;
-import org.richfaces.cdk.resource.ResourceUtil;
 import org.richfaces.cdk.resource.scan.ResourcesScanner;
+import org.richfaces.cdk.resource.util.ResourceUtil;
 import org.richfaces.cdk.vfs.VirtualFile;
 
 import com.google.common.collect.Sets;

Copied: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/util/ResourceUtil.java (from rev 18609, sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceUtil.java)
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/util/ResourceUtil.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/util/ResourceUtil.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,147 @@
+/*
+ * 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.resource.util;
+
+import static org.richfaces.cdk.strings.Constants.DOT_JOINER;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.richfaces.cdk.vfs.VFSRoot;
+import org.richfaces.cdk.vfs.VirtualFile;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
+import com.google.common.primitives.Ints;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public final class ResourceUtil {
+
+    private static final String CLASSPATH_RESOURCES_LOCATION = "META-INF/resources";
+
+    private static final String WEB_RESOURCES_LOCATION = "resources";
+
+    private static final Pattern LIBRARY_VERSION_PATTERN = Pattern.compile("^(\\d+)(_\\d+)+");
+    
+    private static final Pattern RESOURCE_VERSION_PATTERN = Pattern.compile("^((?:\\d+)(?:_\\d+)+)[\\.]?(\\w+)?");
+    
+    public static final class VersionKey {
+
+        static final Ordering<VersionKey> ORDERING = Ordering.from(new Comparator<VersionKey>() {
+
+            @Override
+            public int compare(VersionKey o1, VersionKey o2) {
+                return Ints.lexicographicalComparator().compare(o1.versionVector, o2.versionVector);
+            }
+        }).nullsFirst();
+        
+        private String version;
+        
+        private int[] versionVector;
+
+        private String extension;
+        
+        public VersionKey(String version, String extension) throws NumberFormatException {
+            this.version = version;
+            this.versionVector = parseVersionString(version);
+            this.extension = extension;
+        }
+        
+        private static int[] parseVersionString(String s) {
+            String[] split = s.split("_");
+            int[] result = new int[split.length];
+            for (int i = 0; i < result.length; i++) {
+                result[i] = Integer.parseInt(split[i]);
+            }
+            return result;
+        }
+       
+        public String toString() {
+            return DOT_JOINER.join(version, extension);
+        }
+    }
+    
+    private ResourceUtil() {}
+    
+    public static VirtualFile getLatestVersion(VirtualFile file, boolean library) {
+        VersionKey latestVersionKey = null;
+        
+        Collection<VirtualFile> children = file.getChildren();
+        for (VirtualFile child : children) {
+            if (library && child.isDirectory()) {
+                Matcher matcher = LIBRARY_VERSION_PATTERN.matcher(child.getName());
+                if (matcher.matches()) {
+                    latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new VersionKey(child.getName(), null));
+                }
+            } else if (!library && child.isFile()) {
+                Matcher matcher = RESOURCE_VERSION_PATTERN.matcher(child.getName());
+                if (matcher.matches()) {
+                    latestVersionKey = VersionKey.ORDERING.max(latestVersionKey, new VersionKey(matcher.group(1), matcher.group(2)));
+                }
+            }
+        }
+        
+        VirtualFile result;
+        
+        if (latestVersionKey != null) {
+            result = file.getChild(latestVersionKey.toString());
+        } else {
+            result = file;
+        }
+        
+        if (result != null && (library ^ result.isFile())) {
+            return result;
+        }
+        
+        return null;
+    }
+    
+    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 result;
+    }
+    
+    public static Collection<VirtualFile> getResourceRoots(Iterable<VFSRoot> cpRoots, Iterable<VFSRoot> webRoots) throws URISyntaxException, IOException {
+        List<VirtualFile> result = Lists.newArrayList();
+        
+        result.addAll(getExistingChildren(cpRoots, CLASSPATH_RESOURCES_LOCATION));
+        result.addAll(getExistingChildren(webRoots, WEB_RESOURCES_LOCATION));
+        
+        return result;
+    }
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/ResourceProcessor.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/ResourceProcessor.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/ResourceProcessor.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,38 @@
+/*
+ * 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.resource.writer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public interface ResourceProcessor {
+
+    public boolean isSupportedFile(String name);
+    
+    public void process(String resourceName, InputStream in, OutputStream out) throws IOException;
+    
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CSSResourceProcessor.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CSSResourceProcessor.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CSSResourceProcessor.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,46 @@
+/*
+ * 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.resource.writer.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+import com.yahoo.platform.yui.compressor.CssCompressor;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class CSSResourceProcessor extends CharResourceProcessor {
+
+    @Override
+    public boolean isSupportedFile(String name) {
+        return name.endsWith(".css");
+    }
+
+    @Override
+    protected void doActualProcess(String resourceName, Reader in, Writer out) throws IOException {
+        new CssCompressor(in).compress(out, 0);
+    }
+    
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CharResourceProcessor.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CharResourceProcessor.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/CharResourceProcessor.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,62 @@
+/*
+ * 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.resource.writer.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.richfaces.cdk.resource.writer.ResourceProcessor;
+
+import com.google.common.io.Closeables;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public abstract class CharResourceProcessor implements ResourceProcessor {
+
+    protected abstract void doActualProcess(String resourceName, Reader in, Writer out) throws IOException;
+
+    @Override
+    public void process(String resourceName, InputStream in, OutputStream out) throws IOException {
+
+        boolean threw = true;
+        Reader reader = new InputStreamReader(in);
+        try {
+            Writer writer = new OutputStreamWriter(out);
+            try {
+                doActualProcess(resourceName, reader, writer);
+                threw = false;
+            } finally {
+                Closeables.close(writer, threw);
+            }
+        } finally {
+            Closeables.close(reader, threw);
+        }
+    }
+
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,56 @@
+/*
+ * 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.resource.writer.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.maven.plugin.logging.Log;
+
+import com.yahoo.platform.yui.compressor.JavaScriptCompressor;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class JavaScriptResourceProcessor extends CharResourceProcessor {
+
+    private Log log;
+    
+    public JavaScriptResourceProcessor(Log log) {
+        super();
+        this.log = log;
+    }
+
+    @Override
+    public boolean isSupportedFile(String name) {
+        return name.endsWith(".js");
+    }
+
+    @Override
+    protected void doActualProcess(String resourceName, Reader in, Writer out) throws IOException {
+        MavenLogErrorReporter reporter = new MavenLogErrorReporter(log, resourceName);
+        new JavaScriptCompressor(in, reporter).compress(out, 0, true, true, false, false);
+    }
+    
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,70 @@
+/*
+ * 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.resource.writer.impl;
+
+import java.text.MessageFormat;
+
+import org.apache.maven.plugin.logging.Log;
+import org.mozilla.javascript.ErrorReporter;
+import org.mozilla.javascript.EvaluatorException;
+
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+final class MavenLogErrorReporter implements ErrorReporter {
+    
+    private String resourceName;
+    
+    private Log log;
+    
+    public MavenLogErrorReporter(Log log, String resourceName) {
+        super();
+        this.log = log;
+        this.resourceName = resourceName;
+    }
+
+    private String formatMessage(String message, String sourceName, int line, String lineSource, int lineOffset) {
+        String location = MessageFormat.format("{0} (line {1}, col {2})", 
+            Strings.isNullOrEmpty(sourceName) ? resourceName : sourceName, lineSource, lineOffset);
+        
+        return MessageFormat.format("{0}: {1}\n{2}", location, message, lineSource);
+    }
+    
+    @Override
+    public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
+        log.warn(formatMessage(message, sourceName, line, lineSource, lineOffset));
+    }
+
+    @Override
+    public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) {
+        return new EvaluatorException(message, sourceName, line, lineSource, lineOffset); 
+    }
+
+    @Override
+    public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
+        log.error(formatMessage(message, sourceName, line, lineSource, lineOffset));
+    }
+}
\ No newline at end of file

Copied: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ResourceWriterImpl.java (from rev 18609, sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/ResourceWriterImpl.java)
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ResourceWriterImpl.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ResourceWriterImpl.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -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.resource.writer.impl;
+
+import static org.richfaces.cdk.strings.Constants.COLON_JOINER;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.faces.application.Resource;
+
+import org.richfaces.cdk.ResourceWriter;
+import org.richfaces.cdk.resource.writer.ResourceProcessor;
+import org.richfaces.cdk.strings.Constants;
+import org.richfaces.resource.ResourceFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class ResourceWriterImpl implements ResourceWriter {
+
+    private File resourceContentsDir;
+    
+    private File resourceMappingDir;
+    
+    private Map<String, String> processedResources = Maps.newConcurrentMap();
+    
+    private Iterable<ResourceProcessor> resourceProcessors;
+    
+    public ResourceWriterImpl(File resourceContentsDir, File resourceMappingDir, Iterable<ResourceProcessor> resourceProcessors) {
+        this.resourceContentsDir = resourceContentsDir;
+        this.resourceMappingDir = resourceMappingDir;
+        this.resourceProcessors = Iterables.concat(resourceProcessors, Collections.singleton(ThroughputResourceProcessor.INSTANCE));
+        resourceContentsDir.mkdirs();
+    }
+
+    private String getResourceQualifier(Resource resource) {
+        return COLON_JOINER.join(resource.getLibraryName(), resource.getResourceName());
+    }
+    
+    private File createOutputFile(String path) throws IOException {
+        File outFile = new File(resourceContentsDir, path);
+        outFile.getParentFile().mkdirs();
+        outFile.createNewFile();
+
+        return outFile;
+    }
+    
+    public void writeResource(String skinName, Resource resource) throws IOException {
+        String requestPath = resource.getRequestPath();
+        String requestPathWithSkin = requestPath;
+        
+        if (requestPath.startsWith(ResourceFactory.SKINNED_RESOURCE_PREFIX)) {
+            requestPathWithSkin = Constants.SLASH_JOINER.join(skinName, 
+                requestPath.substring(ResourceFactory.SKINNED_RESOURCE_PREFIX.length()));
+        }
+        
+        for (ResourceProcessor resourceProcessor : resourceProcessors) {
+            if (resourceProcessor.isSupportedFile(requestPath)) {
+                File outFile = createOutputFile(requestPathWithSkin); 
+                resourceProcessor.process(requestPathWithSkin, resource.getInputStream(), new FileOutputStream(outFile));
+                processedResources.put(getResourceQualifier(resource), requestPath);
+                return;
+            }
+        }
+    }
+
+    @Override
+    public void writeProcessedResourceMappings() throws IOException {
+        //TODO separate mappings file location
+        FileOutputStream fos = null;
+        try {
+            File mappingsFile = new File(resourceMappingDir, ResourceFactory.STATIC_RESOURCE_MAPPINGS);
+            //TODO merge properties
+            mappingsFile.delete();
+            mappingsFile.getParentFile().mkdirs();
+            mappingsFile.createNewFile();
+            
+            fos = new FileOutputStream(mappingsFile);
+            Properties properties = new Properties();
+            properties.putAll(processedResources);
+            properties.store(fos, null);
+        } finally {
+            try {
+                if (fos != null) {
+                    fos.close();
+                }
+            } catch (IOException e) {
+                // TODO: handle exception
+            }
+        }
+    }
+
+}

Added: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ThroughputResourceProcessor.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ThroughputResourceProcessor.java	                        (rev 0)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/ThroughputResourceProcessor.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -0,0 +1,58 @@
+/*
+ * 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.resource.writer.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.richfaces.cdk.resource.writer.ResourceProcessor;
+
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+final class ThroughputResourceProcessor implements ResourceProcessor {
+
+    public static final ResourceProcessor INSTANCE = new ThroughputResourceProcessor();
+
+    private ThroughputResourceProcessor() {}
+    
+    @Override
+    public boolean isSupportedFile(String name) {
+        return true;
+    }
+
+    @Override
+    public void process(String resourceName, InputStream in, OutputStream out) throws IOException {
+        try {
+            ByteStreams.copy(in, out);
+        } finally {
+            Closeables.close(in, true);
+            Closeables.close(out, true);
+        }
+    }
+
+}

Modified: sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java
===================================================================
--- sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java	2010-08-13 13:44:52 UTC (rev 18618)
+++ sandbox/trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/task/ResourceTaskFactoryImpl.java	2010-08-13 13:56:18 UTC (rev 18619)
@@ -35,7 +35,7 @@
 import org.richfaces.cdk.ResourceTaskFactory;
 import org.richfaces.cdk.ResourceWriter;
 import org.richfaces.cdk.faces.CurrentResourceContext;
-import org.richfaces.cdk.resource.handler.impl.DynamicResourceWrapper;
+import org.richfaces.resource.ResourceFactory;
 
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
@@ -111,8 +111,7 @@
                     return;
                 }
                 
-                //TODO hack
-                skinDependent = (resource instanceof DynamicResourceWrapper);
+                skinDependent = resource.getRequestPath().startsWith(ResourceFactory.SKINNED_RESOURCE_PREFIX);
             } finally {
                 faces.setSkin(null);
                 faces.stopRequest();



More information about the richfaces-svn-commits mailing list