incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1058553 - /sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java
Date Thu, 13 Jan 2011 13:44:06 GMT
Author: cziegeler
Date: Thu Jan 13 13:44:06 2011
New Revision: 1058553

URL: http://svn.apache.org/viewvc?rev=1058553&view=rev
Log:
SLING-1931 : Compiler message contain only class name but not resource path

Modified:
    sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java

Modified: sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java?rev=1058553&r1=1058552&r2=1058553&view=diff
==============================================================================
--- sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java
(original)
+++ sling/trunk/contrib/jcr/compiler/src/main/java/org/apache/sling/jcr/compiler/impl/JcrJavaCompilerImpl.java
Thu Jan 13 13:44:06 2011
@@ -24,6 +24,10 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.jcr.Item;
 import javax.jcr.Node;
@@ -37,6 +41,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.apache.sling.commons.compiler.CompilationResult;
 import org.apache.sling.commons.compiler.CompilationUnit;
+import org.apache.sling.commons.compiler.CompilerMessage;
 import org.apache.sling.commons.compiler.JavaCompiler;
 import org.apache.sling.commons.compiler.Options;
 import org.apache.sling.jcr.api.SlingRepository;
@@ -117,7 +122,7 @@ public class JcrJavaCompilerImpl impleme
             }
 
             // and compile
-            return compiler.compile(units, options);
+            return mapResult(compiler.compile(units, options), srcFiles, units);
         } finally {
             if ( session != null ) {
                 session.logout();
@@ -125,6 +130,56 @@ public class JcrJavaCompilerImpl impleme
         }
     }
 
+    /**
+     * Map the source information of the errors
+     */
+    private CompilationResult mapResult(final CompilationResult result,
+            final String[] srcFiles,
+            final CompilationUnit[] units) {
+        if ( result == null || (result.getErrors() == null && result.getWarnings()
== null ) ) {
+            return result;
+        }
+
+        final Map<String, String> mapping = new HashMap<String, String>();
+        for(int i=0;i<srcFiles.length;i++) {
+            mapping.put(units[i].getMainClassName() + ".java", srcFiles[i]);
+        }
+        return new CompilationResult() {
+
+            private List<CompilerMessage> mapMessages(final List<CompilerMessage>
msgs) {
+                if ( msgs == null || msgs.size() == 0 ) {
+                    return msgs;
+                }
+                final List<CompilerMessage> newMsgs = new ArrayList<CompilerMessage>();
+                for(final CompilerMessage msg : msgs) {
+                    final String mapped = mapping.get(msg.getFile());
+
+                    newMsgs.add(new CompilerMessage(
+                            mapped == null ? msg.getFile() : mapped,
+                            msg.getLine(), msg.getColumn(), msg.getMessage()));
+                }
+                return newMsgs;
+            }
+
+            public Class<?> loadCompiledClass(String className)
+                    throws ClassNotFoundException {
+                return result.loadCompiledClass(className);
+            }
+
+            public List<CompilerMessage> getWarnings() {
+                return mapMessages(result.getWarnings());
+            }
+
+            public List<CompilerMessage> getErrors() {
+                return mapMessages(result.getErrors());
+            }
+
+            public boolean didCompile() {
+                return result.didCompile();
+            }
+        };
+    }
+
     //--------------------------------------------------------< misc. helpers >
 
     private CompilationUnit createCompileUnit(final String sourceFile, final Session session)



Mime
View raw message