commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r232954 - in /jakarta/commons/sandbox/jci/trunk: .classpath project.xml src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
Date Tue, 16 Aug 2005 07:51:49 GMT
Author: tcurdt
Date: Tue Aug 16 00:51:41 2005
New Revision: 232954

URL: http://svn.apache.org/viewcvs?rev=232954&view=rev
Log:
a very rough outline how the groovy compilation could work


Modified:
    jakarta/commons/sandbox/jci/trunk/.classpath
    jakarta/commons/sandbox/jci/trunk/project.xml
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java

Modified: jakarta/commons/sandbox/jci/trunk/.classpath
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/.classpath?rev=232954&r1=232953&r2=232954&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/.classpath (original)
+++ jakarta/commons/sandbox/jci/trunk/.classpath Tue Aug 16 00:51:41 2005
@@ -11,5 +11,6 @@
 	<classpathentry kind="var" path="MAVEN_REPO/janino/jars/janino-2.3.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/eclipse/jars/jdtcore-3.1.0.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/groovy/jars/groovy-1.0-jsr-02.jar"/>
 	<classpathentry kind="output" path="eclipse"/>
 </classpath>

Modified: jakarta/commons/sandbox/jci/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/project.xml?rev=232954&r1=232953&r2=232954&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/project.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/project.xml Tue Aug 16 00:51:41 2005
@@ -116,6 +116,12 @@
       <version>2.3.0</version>
     </dependency>
 
+    <dependency>
+      <groupId>groovy</groupId>
+      <artifactId>groovy</artifactId>
+      <version>1.0-jsr-02</version>
+    </dependency>
+
   </dependencies>
 
 

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java?rev=232954&r1=232953&r2=232954&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
Tue Aug 16 00:51:41 2005
@@ -1,22 +1,79 @@
 package org.apache.commons.jci.compilers.groovy;
 
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
 import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilationUnit;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.ErrorCollector;
+import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.WarningMessage;
+import org.codehaus.groovy.tools.GroovyClass;
 
 public final class GroovyJavaCompiler implements JavaCompiler {
 
     private final static Log log = LogFactory.getLog(GroovyJavaCompiler.class);
-
+    
     public void compile(
             final String[] clazzNames,
             final ResourceReader reader,
             final ResourceStore store,
             final CompilationProblemHandler problemHandler
             ) {
-        throw new RuntimeException("NYI");
+     
+        final ClassLoader classloader = null;
+        final ErrorCollector collector = null;
+        final CompilerConfiguration configuration = null;
+        final CompilationUnit unit = null;
+        final SourceUnit[] source = new SourceUnit[clazzNames.length];
+        for (int i = 0; i < source.length; i++) {
+            source[i] = new SourceUnit(
+                    clazzNames[i],
+                    new String(reader.getContent(clazzNames[i])),
+                    configuration,
+                    classloader,
+                    collector
+                    );
+            unit.addSource(source[i]);
+        }
+        try {
+            unit.compile();
+            
+            final List classes = unit.getClasses();
+            for (final Iterator it = classes.iterator(); it.hasNext();) {
+                final GroovyClass clazz = (GroovyClass) it.next();
+                final String name = clazz.getName().replace('.', File.separatorChar) + ".class";
+                byte[] bytes = clazz.getBytes();
+                store.write(name, bytes);
+            }
+        } catch (final CompilationFailedException e) {
+            final ErrorCollector errorC = e.getUnit().getErrorCollector();
+            
+            final List warnings = errorC.getWarnings();
+            for (final Iterator it = warnings.iterator(); it.hasNext();) {
+                final WarningMessage warning = (WarningMessage) it.next();
+                problemHandler.handle(
+                        new CompilationProblem(0, "", warning.getMessage(), 0, 0, false)
+                        );
+            }
+
+            final List errors = errorC.getErrors();
+            for (final Iterator it = errors.iterator(); it.hasNext();) {
+                final Message message = (Message) it.next();
+                problemHandler.handle(
+                        new CompilationProblem(0, "", "", 0, 0, false)
+                        );                
+            }
+        }
+        
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message