You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/05/23 18:37:13 UTC

git commit: Simplify how ResourcePreProcessors are contributed

Updated Branches:
  refs/heads/master 74dcf0bd0 -> 56240a832


Simplify how ResourcePreProcessors are contributed


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/56240a83
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/56240a83
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/56240a83

Branch: refs/heads/master
Commit: 56240a83299ccc6e09f5262676622fc0c66adb07
Parents: 74dcf0b
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu May 23 09:37:07 2013 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu May 23 09:37:07 2013 -0700

----------------------------------------------------------------------
 .../wro4j/ResourceProcessorSourceImpl.java         |   14 +--
 .../tapestry5/wro4j/modules/WRO4JModule.java       |   60 ++++----------
 2 files changed, 22 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56240a83/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/ResourceProcessorSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/ResourceProcessorSourceImpl.java b/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/ResourceProcessorSourceImpl.java
index cb94760..5afe0f5 100644
--- a/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/ResourceProcessorSourceImpl.java
+++ b/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/ResourceProcessorSourceImpl.java
@@ -15,8 +15,6 @@
 package org.apache.tapestry5.internal.wro4j;
 
 import org.apache.tapestry5.internal.services.assets.BytestreamCache;
-import org.apache.tapestry5.ioc.ObjectCreator;
-import org.apache.tapestry5.ioc.internal.services.CachingObjectCreator;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.util.AvailableValues;
 import org.apache.tapestry5.ioc.util.UnknownValueException;
@@ -31,14 +29,14 @@ import java.util.Map;
 
 public class ResourceProcessorSourceImpl implements ResourceProcessorSource
 {
-    private final Map<String, ObjectCreator> configuration;
+    private final Map<String, ResourcePreProcessor> configuration;
 
     private final Map<String, ResourceProcessor> cache = CollectionFactory.newCaseInsensitiveMap();
 
     private final Map<String, ResourceType> contentType2resourceType = CollectionFactory.newMap();
 
 
-    public ResourceProcessorSourceImpl(Map<String, ObjectCreator> configuration)
+    public ResourceProcessorSourceImpl(Map<String, ResourcePreProcessor> configuration)
     {
         this.configuration = configuration;
 
@@ -62,15 +60,13 @@ public class ResourceProcessorSourceImpl implements ResourceProcessorSource
 
     private ResourceProcessor create(String name)
     {
-        ObjectCreator<ResourcePreProcessor> creator = configuration.get(name);
+        final ResourcePreProcessor preProcessor = configuration.get(name);
 
-        if (creator == null)
+        if (preProcessor == null)
         {
             throw new UnknownValueException(String.format("Unknown resource processor '%s'.", name), new AvailableValues("configured processors", configuration));
         }
 
-        final ObjectCreator<ResourcePreProcessor> lazyCreator = new CachingObjectCreator<ResourcePreProcessor>(creator);
-
         return new ResourceProcessor()
         {
             public InputStream process(String operationDescription, String inputURL, InputStream input, String contentType) throws IOException
@@ -81,7 +77,7 @@ public class ResourceProcessorSourceImpl implements ResourceProcessorSource
 
                 OutputStreamWriter writer = new OutputStreamWriter(outputStream);
 
-                lazyCreator.createObject().process(resource, new InputStreamReader(input), writer);
+                preProcessor.process(resource, new InputStreamReader(input), writer);
 
                 // close the writer to flush content into the outputStream
                 writer.close();

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56240a83/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java
----------------------------------------------------------------------
diff --git a/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java b/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java
index 499ae88..073d3aa 100644
--- a/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java
+++ b/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java
@@ -18,8 +18,6 @@ import com.github.sommeri.less4j.core.parser.AntlrException;
 import org.apache.tapestry5.MarkupWriter;
 import org.apache.tapestry5.internal.wro4j.*;
 import org.apache.tapestry5.ioc.MappedConfiguration;
-import org.apache.tapestry5.ioc.ObjectCreator;
-import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.ServiceBinder;
 import org.apache.tapestry5.ioc.annotations.Contribute;
 import org.apache.tapestry5.ioc.annotations.Primary;
@@ -34,12 +32,13 @@ import ro.isdc.wro.extensions.processor.css.Less4jProcessor;
 import ro.isdc.wro.extensions.processor.js.GoogleClosureCompressorProcessor;
 import ro.isdc.wro.extensions.processor.js.RhinoCoffeeScriptProcessor;
 import ro.isdc.wro.extensions.processor.support.coffeescript.CoffeeScript;
+import ro.isdc.wro.model.resource.processor.ResourcePreProcessor;
 import ro.isdc.wro.model.resource.processor.impl.css.CssCompressorProcessor;
 
 import java.util.List;
 
 /**
- * Configures CoffeeScript-to-JavaScript compilation.
+ * Configures use of various WRO4J processors.
  *
  * @since 5.4
  */
@@ -61,59 +60,29 @@ public class WRO4JModule
      * in a single bundle, not a given for Tapestry.</dd>
      * <dt>LessCompiler</dt> <dd>Compiles Less source files into CSS.</dd>
      * </dl>
-     *
-     * @param configuration
-     * @param locator
      */
     @Contribute(ResourceProcessorSource.class)
-    public static void provideDefaultProcessors(MappedConfiguration<String, ObjectCreator> configuration, final ObjectLocator locator)
+    public static void provideDefaultProcessors(MappedConfiguration<String, ResourcePreProcessor> configuration)
     {
         configuration.add("CoffeeScriptCompiler",
-                new ObjectCreator()
+                new RhinoCoffeeScriptProcessor()
                 {
-                    public Object createObject()
+                    @Override
+                    protected CoffeeScript newCoffeeScript()
                     {
-                        return new RhinoCoffeeScriptProcessor()
-                        {
-                            @Override
-                            protected CoffeeScript newCoffeeScript()
-                            {
-                                return new CoffeeScript().setOptions("bare");
-                            }
-                        };
+                        return new CoffeeScript().setOptions("bare");
                     }
                 }
         );
 
 
-        configuration.add("CSSMinimizer", new ObjectCreator()
-        {
-            public Object createObject()
-            {
-                return new CssCompressorProcessor();
-            }
-        });
-
-        configuration.add("JavaScriptMinimizer", new ObjectCreator()
-        {
-            public Object createObject()
-            {
-                return new GoogleClosureCompressorProcessor();
-            }
-        });
-
-        configuration.add("LessCompiler", new ObjectCreator()
-        {
-            public Object createObject()
-            {
-                return new Less4jProcessor();
-            }
-        });
+        configuration.addInstance("CSSMinimizer", CssCompressorProcessor.class);
+        configuration.add("JavaScriptMinimizer", new GoogleClosureCompressorProcessor());
+        configuration.addInstance("LessCompiler", Less4jProcessor.class);
     }
 
     @Contribute(StreamableResourceSource.class)
-    public static void provideCompilations
-            (MappedConfiguration<String, ResourceTransformer> configuration, ResourceTransformerFactory factory)
+    public static void provideCompilers(MappedConfiguration<String, ResourceTransformer> configuration, ResourceTransformerFactory factory)
     {
         configuration.add("coffee",
                 factory.createCompiler("text/javascript", "CoffeeScriptCompiler", "CoffeeScript", "JavaScript"));
@@ -129,9 +98,14 @@ public class WRO4JModule
         configuration.addInstance("text/javascript", JavaScriptMinimizer.class);
     }
 
+    /**
+     * Alas {@link AntlrException}s do not have a useful toString() which makes them useless in the exception report;
+     * here we provide an {@link ObjectRenderer} that breaks them apart into useful strings. Eventually we may be
+     * able to synthesize a {@link org.apache.tapestry5.ioc.Location} from them as well and show some of the source .less file.
+     */
     @Contribute(ObjectRenderer.class)
     @Primary
-    public static void decodeLessErrors(MappedConfiguration<Class, ObjectRenderer> configuration)
+    public static void provideLessErrorRenderers(MappedConfiguration<Class, ObjectRenderer> configuration)
     {
         configuration.add(AntlrException.class, new ObjectRenderer<AntlrException>()
         {