[richfaces-svn-commits] JBoss Rich Faces SVN: r18795 - in trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource: writer/impl and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Aug 19 05:14:24 EDT 2010


Author: nbelaevski
Date: 2010-08-19 05:14:23 -0400 (Thu, 19 Aug 2010)
New Revision: 18795

Modified:
   trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java
   trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java
   trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java
Log:
Maven resources plugin:
- fixed CNFE
- improved JavaScript compressor logging better in multi-threded envs.

Modified: trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java
===================================================================
--- trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java	2010-08-19 07:44:52 UTC (rev 18794)
+++ trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/scan/impl/reflections/ReflectionsExt.java	2010-08-19 09:14:23 UTC (rev 18795)
@@ -30,6 +30,9 @@
 import org.reflections.scanners.Scanner;
 import org.reflections.util.Utils;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.Multimap;
 
 /**
@@ -38,6 +41,22 @@
  */
 public class ReflectionsExt extends Reflections {
 
+    private static final Function<String, Class<?>> CLASS_FOR_NAME = new Function<String, Class<?>>() {
+        public java.lang.Class<?> apply(String from) {
+            try {
+                return Class.forName(from, true, Utils.getContextClassLoader());
+            } catch (ClassNotFoundException e) {
+                // TODO: handle exception
+                e.printStackTrace();
+            } catch (LinkageError e) {
+                // TODO: handle exception
+                e.printStackTrace();
+            }
+            
+            return null;
+        };
+    };
+
     public ReflectionsExt() {
         super();
     }
@@ -56,7 +75,9 @@
         if (scannerMMap == null) {
             return Collections.emptySet();
         }
-        return Utils.forNames(scannerMMap.get(MarkerResourcesScanner.STORE_KEY));
+
+        return Collections2.filter(Collections2.transform(scannerMMap.get(MarkerResourcesScanner.STORE_KEY), CLASS_FOR_NAME), 
+            Predicates.notNull());
     }
 
 }

Modified: trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java
===================================================================
--- trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java	2010-08-19 07:44:52 UTC (rev 18794)
+++ trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/JavaScriptResourceProcessor.java	2010-08-19 09:14:23 UTC (rev 18795)
@@ -49,8 +49,16 @@
 
     @Override
     protected void doActualProcess(String resourceName, Reader in, Writer out) throws IOException {
-        MavenLogErrorReporter reporter = new MavenLogErrorReporter(log, resourceName);
+        MavenLogErrorReporter reporter = new MavenLogErrorReporter(resourceName);
         new JavaScriptCompressor(in, reporter).compress(out, 0, true, true, false, false);
+        
+        if (reporter.hasErrors()) {
+            log.error(reporter.getErrorsLog());
+        }
+        
+        if (reporter.hasWarnings()) {
+            log.warn(reporter.getWarningsLog());
+        }
     }
     
 }

Modified: trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java
===================================================================
--- trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java	2010-08-19 07:44:52 UTC (rev 18794)
+++ trunk/cdk/maven-resources-plugin/src/main/java/org/richfaces/cdk/resource/writer/impl/MavenLogErrorReporter.java	2010-08-19 09:14:23 UTC (rev 18795)
@@ -24,7 +24,6 @@
 
 import java.text.MessageFormat;
 
-import org.apache.maven.plugin.logging.Log;
 import org.mozilla.javascript.ErrorReporter;
 import org.mozilla.javascript.EvaluatorException;
 
@@ -38,11 +37,12 @@
     
     private String resourceName;
     
-    private Log log;
+    private StringBuilder errorMessages = new StringBuilder();
     
-    public MavenLogErrorReporter(Log log, String resourceName) {
+    private StringBuilder warningMessages = new StringBuilder();
+    
+    public MavenLogErrorReporter(String resourceName) {
         super();
-        this.log = log;
         this.resourceName = resourceName;
     }
 
@@ -55,7 +55,8 @@
     
     @Override
     public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
-        log.warn(formatMessage(message, sourceName, line, lineSource, lineOffset));
+        warningMessages.append(formatMessage(message, sourceName, line, lineSource, lineOffset));
+        warningMessages.append('\n');
     }
 
     @Override
@@ -65,6 +66,23 @@
 
     @Override
     public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
-        log.error(formatMessage(message, sourceName, line, lineSource, lineOffset));
+        errorMessages.append(formatMessage(message, sourceName, line, lineSource, lineOffset));
+        errorMessages.append('\n');
     }
+    
+    public boolean hasErrors() {
+        return errorMessages.length() > 0;
+    }
+    
+    public String getErrorsLog() {
+        return errorMessages.toString();
+    }
+    
+    public boolean hasWarnings() {
+        return warningMessages.length() > 0;
+    }
+    
+    public String getWarningsLog() {
+        return warningMessages.toString();
+    }
 }
\ No newline at end of file



More information about the richfaces-svn-commits mailing list