You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2014/05/02 17:56:33 UTC

svn commit: r1591962 - in /sling/trunk/bundles/scripting/jsp: ./ src/main/java/org/apache/sling/scripting/jsp/ src/main/java/org/apache/sling/scripting/jsp/jasper/ src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/

Author: cziegeler
Date: Fri May  2 15:56:33 2014
New Revision: 1591962

URL: http://svn.apache.org/r1591962
Log:
SLING-3542 : Use commons compiler (instead of embedding own jdt compiler)

Modified:
    sling/trunk/bundles/scripting/jsp/pom.xml
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IOProvider.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JDTCompiler.java

Modified: sling/trunk/bundles/scripting/jsp/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/pom.xml?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp/pom.xml Fri May  2 15:56:33 2014
@@ -71,13 +71,9 @@
                         <ScriptEngine-Name>${project.name}</ScriptEngine-Name>
                         <ScriptEngine-Version>${project.version}</ScriptEngine-Version>
 
-                        <Import-Package>
-                            !org.eclipse.*,
-                            !org.apache.tools.*,*
-                        </Import-Package>
-                        <!-- Embed Jasper completely -->
+                        <!-- Embed EL and JSP API -->
                         <Embed-Dependency>
-                            jasper-el,ecj,
+                            jasper-el,
                             el-api,
                             jsp-api,
                             org.apache.sling.commons.osgi;inline="org/apache/sling/commons/osgi/PropertiesUtil.*"
@@ -105,8 +101,16 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
@@ -117,7 +121,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.1.6</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -133,7 +137,6 @@
             <scope>provided</scope>
         </dependency>
         
-
         <dependency>
             <groupId>org.apache.tomcat</groupId>
             <artifactId>servlet-api</artifactId>
@@ -151,40 +154,15 @@
             <version>6.0.14</version>
         </dependency>
         <dependency>
-            <groupId>org.eclipse.jdt.core.compiler</groupId>
-            <artifactId>ecj</artifactId>
-            <version>P20140317-1600</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.tomcat</groupId>
             <artifactId>el-api</artifactId>
             <version>6.0.14</version>
         </dependency>
-
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>1.4</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-        </dependency>
         <dependency>
-            <groupId>commons-collections</groupId>
-            <artifactId>commons-collections</artifactId>
-            <version>3.2.1</version>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.compiler</artifactId>
+            <version>2.1.0</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java Fri May  2 15:56:33 2014
@@ -56,6 +56,7 @@ import org.apache.sling.api.scripting.Sl
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
+import org.apache.sling.commons.compiler.JavaCompiler;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
 import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
@@ -118,6 +119,9 @@ public class JspScriptEngineFactory
 
     private ClassLoader dynamicClassLoader;
 
+    @Reference
+    private JavaCompiler javaCompiler;
+
     /** The io provider for reading and writing. */
     private SlingIOProvider ioProvider;
 
@@ -328,7 +332,7 @@ public class JspScriptEngineFactory
             this.tldLocationsCache = new SlingTldLocationsCache(componentContext.getBundleContext());
 
             // prepare some classes
-            ioProvider = new SlingIOProvider(classLoaderWriter);
+            ioProvider = new SlingIOProvider(this.classLoaderWriter, this.javaCompiler);
 
             // return options which use the jspClassLoader
             options = new JspServletOptions(slingServletContext, ioProvider,

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java Fri May  2 15:56:33 2014
@@ -31,6 +31,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.commons.classloader.ClassLoaderWriter;
+import org.apache.sling.commons.compiler.JavaCompiler;
 import org.apache.sling.scripting.jsp.jasper.IOProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,9 +50,12 @@ class SlingIOProvider implements IOProvi
 
     private final ClassLoaderWriter classLoaderWriter;
 
-    SlingIOProvider(final ClassLoaderWriter classLoaderWriter) {
+    private final JavaCompiler javaCompiler;
+
+    SlingIOProvider(final ClassLoaderWriter classLoaderWriter, final JavaCompiler compiler) {
         this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
         this.classLoaderWriter = classLoaderWriter;
+        this.javaCompiler = compiler;
     }
 
     /**
@@ -227,4 +231,11 @@ class SlingIOProvider implements IOProvi
 
         return path;
     }
+
+    /**
+     * @see org.apache.sling.scripting.jsp.jasper.IOProvider#getJavaCompiler()
+     */
+    public JavaCompiler getJavaCompiler() {
+        return this.javaCompiler;
+    }
 }

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java Fri May  2 15:56:33 2014
@@ -19,11 +19,12 @@ package org.apache.sling.scripting.jsp;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.URL;
+import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Properties;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -60,11 +61,11 @@ public class SlingTldLocationsCache
                 addBundle(bundles[i]);
             }
         }
-        
-        Properties tldConfigPrinterProperties = new Properties();
-        tldConfigPrinterProperties.setProperty("felix.webconsole.label", "jsptaglibs");
-        tldConfigPrinterProperties.setProperty("felix.webconsole.title", "JSP Taglibs");
-        tldConfigPrinterProperties.setProperty("felix.webconsole.configprinter.modes", "always");
+
+        Dictionary<String, Object> tldConfigPrinterProperties = new Hashtable<String, Object>();
+        tldConfigPrinterProperties.put("felix.webconsole.label", "jsptaglibs");
+        tldConfigPrinterProperties.put("felix.webconsole.title", "JSP Taglibs");
+        tldConfigPrinterProperties.put("felix.webconsole.configprinter.modes", "always");
         this.serviceRegistration = context.registerService(Object.class.getName(),
             this, tldConfigPrinterProperties);
 
@@ -107,6 +108,7 @@ public class SlingTldLocationsCache
 
     // ---------- TldLocationsCache support ------------------------------------
 
+    @Override
     public String[] getLocation(final String uri) throws JasperException {
         synchronized (tldLocations) {
             if (tldLocations.containsKey(uri)) {
@@ -186,7 +188,7 @@ public class SlingTldLocationsCache
     public void printConfiguration(final PrintWriter pw) {
         pw.println("Currently available JSP Taglibs:");
         final SortedMap<String, String> taglibs = new TreeMap<String, String>();
-        
+
         for (final Map.Entry<String, TldLocationEntry> entry : tldLocations.entrySet()) {
             final long bundleId = entry.getValue().getBundleId();
             final Bundle bundle = bundleContext.getBundle(bundleId);
@@ -197,7 +199,7 @@ public class SlingTldLocationsCache
                 taglibs.put(entry.getKey(), String.format("INVALID BUNDLE ID: %s", bundleId));
             }
         }
-        
+
         for (final Map.Entry<String, String> entry : taglibs.entrySet()) {
             pw.printf("  %s - %s\n", entry.getKey(), entry.getValue());
         }

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IOProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IOProvider.java?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IOProvider.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IOProvider.java Fri May  2 15:56:33 2014
@@ -20,6 +20,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.sling.commons.compiler.JavaCompiler;
+
 /**
  * The <code>IOProvider</code> is an interface to provide more control of
  * sending output from JSP Java and Class generation phases as well as cleaning
@@ -106,4 +108,9 @@ public interface IOProvider {
      * Return the class loader to use
      */
     ClassLoader getClassLoader();
+
+    /**
+     * Return the Java Compiler
+     */
+    JavaCompiler getJavaCompiler();
 }

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JDTCompiler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JDTCompiler.java?rev=1591962&r1=1591961&r2=1591962&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JDTCompiler.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JDTCompiler.java Fri May  2 15:56:33 2014
@@ -17,44 +17,24 @@
 
 package org.apache.sling.scripting.jsp.jasper.compiler;
 
-import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.OutputStream;
 import java.io.Reader;
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
 
+import org.apache.sling.commons.compiler.CompilationResult;
+import org.apache.sling.commons.compiler.CompilationUnit;
+import org.apache.sling.commons.compiler.CompilationUnitWithSource;
+import org.apache.sling.commons.compiler.CompilerMessage;
+import org.apache.sling.commons.compiler.Options;
 import org.apache.sling.scripting.jsp.jasper.JasperException;
-import org.eclipse.jdt.core.compiler.IProblem;
-import org.eclipse.jdt.internal.compiler.ClassFile;
-import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.Compiler;
-import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
-import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
-import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
-import org.eclipse.jdt.internal.compiler.IProblemFactory;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
-import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
-import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
 /**
  * JDT class compiler. This compiler will load source dependencies from the
  * context classloader, reducing dramatically disk access during
  * the compilation process.
- *
- * @author Cocoon2
- * @author Remy Maucherat
  */
 public class JDTCompiler extends org.apache.sling.scripting.jsp.jasper.compiler.Compiler {
 
@@ -75,370 +55,75 @@ public class JDTCompiler extends org.apa
         }
 
         final String sourceFile = ctxt.getServletJavaFileName();
-        final String outputDir = ctxt.getOptions().getScratchDir();
-        String packageName = ctxt.getServletPackageName();
+        final String packageName = ctxt.getServletPackageName();
         final String targetClassName =
             ((packageName.length() != 0) ? (packageName + ".") : "")
                     + ctxt.getServletClassName();
-        String[] fileNames = new String[] {sourceFile};
-        String[] classNames = new String[] {targetClassName};
-        final ArrayList problemList = new ArrayList();
-
-        class CompilationUnit implements ICompilationUnit {
-
-            String className;
-            String sourceFile;
-
-            CompilationUnit(String sourceFile, String className) {
-                this.className = className;
-                this.sourceFile = sourceFile;
-            }
-
-            public char[] getFileName() {
-                return sourceFile.toCharArray();
-            }
+        final CompilationUnit unit = new CompilationUnitWithSource() {
 
-            public char[] getContents() {
-                char[] result = null;
-                InputStream is = null;
-                try {
-                    is = ctxt.getInputStream(sourceFile);
-                    Reader reader =
-                        new BufferedReader(new InputStreamReader(is, ctxt.getOptions().getJavaEncoding()));
-                    if (reader != null) {
-                        char[] chars = new char[8192];
-                        StringBuffer buf = new StringBuffer();
-                        int count;
-                        while ((count = reader.read(chars, 0,
-                                                    chars.length)) > 0) {
-                            buf.append(chars, 0, count);
-                        }
-                        result = new char[buf.length()];
-                        buf.getChars(0, result.length, result, 0);
-                    }
-                } catch (IOException e) {
-                    log.error("Compilation error", e);
-                } finally {
-                    if (is != null) {
-                        try {
-                            is.close();
-                        } catch (IOException exc) {
-                            // Ignore
-                        }
-                    }
-                }
-                return result;
+            /**
+             * @see org.apache.sling.commons.compiler.CompilationUnit#getLastModified()
+             */
+            public long getLastModified() {
+                return -1;
             }
 
-            public char[] getMainTypeName() {
-                int dot = className.lastIndexOf('.');
-                if (dot > 0) {
-                    return className.substring(dot + 1).toCharArray();
-                }
-                return className.toCharArray();
+            /**
+             * @see org.apache.sling.commons.compiler.CompilationUnit#getMainClassName()
+             */
+            public String getMainClassName() {
+                return targetClassName;
             }
 
-            public char[][] getPackageName() {
-                StringTokenizer izer =
-                    new StringTokenizer(className, ".");
-                char[][] result = new char[izer.countTokens()-1][];
-                for (int i = 0; i < result.length; i++) {
-                    String tok = izer.nextToken();
-                    result[i] = tok.toCharArray();
-                }
-                return result;
+            /**
+             * @see org.apache.sling.commons.compiler.CompilationUnit#getSource()
+             */
+            public Reader getSource() throws IOException {
+                return new BufferedReader(new InputStreamReader(ctxt.getInputStream(sourceFile),
+                                ctxt.getOptions().getJavaEncoding()));
             }
 
-            public boolean ignoreOptionalProblems() {
-                return false;
+            /**
+             * @see org.apache.sling.commons.compiler.CompilationUnitWithSource#getFileName()
+             */
+            public String getFileName() {
+                return sourceFile;
             }
-        }
-
-        final INameEnvironment env = new INameEnvironment() {
-
-                public NameEnvironmentAnswer
-                    findType(char[][] compoundTypeName) {
-                    String result = "";
-                    String sep = "";
-                    for (int i = 0; i < compoundTypeName.length; i++) {
-                        result += sep;
-                        result += new String(compoundTypeName[i]);
-                        sep = ".";
-                    }
-                    return findType(result);
-                }
-
-                public NameEnvironmentAnswer
-                    findType(char[] typeName,
-                             char[][] packageName) {
-                        String result = "";
-                        String sep = "";
-                        for (int i = 0; i < packageName.length; i++) {
-                            result += sep;
-                            result += new String(packageName[i]);
-                            sep = ".";
-                        }
-                        result += sep;
-                        result += new String(typeName);
-                        return findType(result);
-                }
-
-                private NameEnvironmentAnswer findType(String className) {
-
-                    InputStream is = null;
-                    try {
-                        if (className.equals(targetClassName)) {
-                            ICompilationUnit compilationUnit =
-                                new CompilationUnit(sourceFile, className);
-                            return
-                                new NameEnvironmentAnswer(compilationUnit, null);
-                        }
-                        String resourceName =
-                            className.replace('.', '/') + ".class";
-                        is = ctxt.getClassLoader().getResourceAsStream(resourceName);
-                        if (is != null) {
-                            byte[] classBytes;
-                            byte[] buf = new byte[8192];
-                            ByteArrayOutputStream baos =
-                                new ByteArrayOutputStream(buf.length);
-                            int count;
-                            while ((count = is.read(buf, 0, buf.length)) > 0) {
-                                baos.write(buf, 0, count);
-                            }
-                            baos.flush();
-                            classBytes = baos.toByteArray();
-                            char[] fileName = className.toCharArray();
-                            ClassFileReader classFileReader =
-                                new ClassFileReader(classBytes, fileName,
-                                                    true);
-                            return
-                                new NameEnvironmentAnswer(classFileReader, null);
-                        }
-                    } catch (IOException exc) {
-                        log.error("Compilation error", exc);
-                    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException exc) {
-                        log.error("Compilation error", exc);
-                    } finally {
-                        if (is != null) {
-                            try {
-                                is.close();
-                            } catch (IOException exc) {
-                                // Ignore
-                            }
-                        }
-                    }
-                    return null;
-                }
+        };
 
-                private boolean isPackage(String result) {
-                    if (result.equals(targetClassName)) {
-                        return false;
-                    }
-                    String resourceName = result.replace('.', '/') + ".class";
-                    InputStream is =
-                        ctxt.getClassLoader().getResourceAsStream(resourceName);
-                    return is == null;
-                }
-
-                public boolean isPackage(char[][] parentPackageName,
-                                         char[] packageName) {
-                    String result = "";
-                    String sep = "";
-                    if (parentPackageName != null) {
-                        for (int i = 0; i < parentPackageName.length; i++) {
-                            result += sep;
-                            String str = new String(parentPackageName[i]);
-                            result += str;
-                            sep = ".";
-                        }
-                    }
-                    String str = new String(packageName);
-                    if (Character.isUpperCase(str.charAt(0))) {
-                        if (!isPackage(result)) {
-                            return false;
-                        }
-                    }
-                    result += sep;
-                    result += str;
-                    return isPackage(result);
-                }
-
-                public void cleanup() {
-                }
-
-            };
-
-        final IErrorHandlingPolicy policy =
-            DefaultErrorHandlingPolicies.proceedWithAllProblems();
-
-        final Map settings = new HashMap();
-        settings.put(CompilerOptions.OPTION_LineNumberAttribute,
-                     CompilerOptions.GENERATE);
-        settings.put(CompilerOptions.OPTION_SourceFileAttribute,
-                     CompilerOptions.GENERATE);
-        settings.put(CompilerOptions.OPTION_ReportDeprecation,
-                     CompilerOptions.IGNORE);
-        if (ctxt.getOptions().getJavaEncoding() != null) {
-            settings.put(CompilerOptions.OPTION_Encoding,
-                    ctxt.getOptions().getJavaEncoding());
-        }
-        if (ctxt.getOptions().getClassDebugInfo()) {
-            settings.put(CompilerOptions.OPTION_LocalVariableAttribute,
-                         CompilerOptions.GENERATE);
-        }
+        final Options options = new Options();
+        options.put(Options.KEY_GENERATE_DEBUG_INFO, ctxt.getOptions().getClassDebugInfo());
 
         // Source JVM
-        if(ctxt.getOptions().getCompilerSourceVM() != null) {
-            String opt = ctxt.getOptions().getCompilerSourceVM();
-            if(opt.equals("1.1")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_1);
-            } else if(opt.equals("1.2")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_2);
-            } else if(opt.equals("1.3")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_3);
-            } else if(opt.equals("1.4")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_4);
-            } else if(opt.equals("1.5")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_5);
-            } else if(opt.equals("1.6")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_6);
-            } else if(opt.equals("1.7")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_7);
-            } else if(opt.equals("1.8")) {
-                settings.put(CompilerOptions.OPTION_Source,
-                             CompilerOptions.VERSION_1_8);
-            } else {
-                log.warn("Unknown source VM " + opt + " ignored.");
-                settings.put(CompilerOptions.OPTION_Source,
-                        CompilerOptions.VERSION_1_6);
-            }
+        if (ctxt.getOptions().getCompilerSourceVM() != null) {
+            options.put(Options.KEY_SOURCE_VERSION, ctxt.getOptions().getCompilerSourceVM());
         } else {
             // Default to 1.6
-            settings.put(CompilerOptions.OPTION_Source,
-                    CompilerOptions.VERSION_1_6);
+            options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_6);
         }
 
         // Target JVM
-        if(ctxt.getOptions().getCompilerTargetVM() != null) {
-            String opt = ctxt.getOptions().getCompilerTargetVM();
-            if(opt.equals("1.1")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_1);
-            } else if(opt.equals("1.2")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_2);
-            } else if(opt.equals("1.3")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_3);
-            } else if(opt.equals("1.4")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_4);
-            } else if(opt.equals("1.5")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_5);
-                settings.put(CompilerOptions.OPTION_Compliance,
-                        CompilerOptions.VERSION_1_5);
-            } else if(opt.equals("1.6")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_6);
-                settings.put(CompilerOptions.OPTION_Compliance,
-                        CompilerOptions.VERSION_1_6);
-            } else if(opt.equals("1.7")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_7);
-                settings.put(CompilerOptions.OPTION_Compliance,
-                        CompilerOptions.VERSION_1_7);
-            } else if(opt.equals("1.8")) {
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                             CompilerOptions.VERSION_1_8);
-                settings.put(CompilerOptions.OPTION_Compliance,
-                        CompilerOptions.VERSION_1_8);
-            } else {
-                log.warn("Unknown target VM " + opt + " ignored.");
-                settings.put(CompilerOptions.OPTION_TargetPlatform,
-                        CompilerOptions.VERSION_1_6);
-            }
+        if (ctxt.getOptions().getCompilerTargetVM() != null) {
+            options.put(Options.KEY_TARGET_VERSION, ctxt.getOptions().getCompilerTargetVM());
         } else {
             // Default to 1.6
-            settings.put(CompilerOptions.OPTION_TargetPlatform,
-                    CompilerOptions.VERSION_1_6);
-            settings.put(CompilerOptions.OPTION_Compliance,
-                    CompilerOptions.VERSION_1_6);
+            options.put(Options.KEY_TARGET_VERSION, Options.VERSION_1_6);
         }
 
-        final IProblemFactory problemFactory =
-            new DefaultProblemFactory(Locale.getDefault());
-
-        final ICompilerRequestor requestor = new ICompilerRequestor() {
-                public void acceptResult(CompilationResult result) {
-                    try {
-                        if (result.hasProblems()) {
-                            IProblem[] problems = result.getProblems();
-                            for (int i = 0; i < problems.length; i++) {
-                                IProblem problem = problems[i];
-                                if (problem.isError()) {
-                                    String name =
-                                        new String(problems[i].getOriginatingFileName());
-                                    try {
-                                        problemList.add(ErrorDispatcher.createJavacError
-                                                (name, pageNodes, new StringBuffer(problem.getMessage()),
-                                                        problem.getSourceLineNumber(), ctxt));
-                                    } catch (JasperException e) {
-                                        log.error("Error visiting node", e);
-                                    }
-                                }
-                            }
-                        }
-                        if (problemList.isEmpty()) {
-                            ClassFile[] classFiles = result.getClassFiles();
-                            for (int i = 0; i < classFiles.length; i++) {
-                                ClassFile classFile = classFiles[i];
-                                char[][] compoundName =
-                                    classFile.getCompoundName();
-                                String className = "";
-                                String sep = "";
-                                for (int j = 0;
-                                     j < compoundName.length; j++) {
-                                    className += sep;
-                                    className += new String(compoundName[j]);
-                                    sep = ".";
-                                }
-                                byte[] bytes = classFile.getBytes();
-                                String outFile = outputDir + "/" +
-                                    className.replace('.', '/') + ".class";
-                                OutputStream out = ctxt.getOutputStream(outFile);
-                                BufferedOutputStream bos =
-                                    new BufferedOutputStream(out);
-                                bos.write(bytes);
-                                bos.close();
-                            }
-                        }
-                    } catch (IOException exc) {
-                        log.error("Compilation error", exc);
-                    }
+        final ArrayList<JavacErrorDetail> problemList = new ArrayList<JavacErrorDetail>();
+        final CompilationResult result = this.ctxt.getRuntimeContext().getIOProvider().getJavaCompiler().compile(new CompilationUnit[] {unit}, options);
+        if ( result.getErrors() != null ) {
+            for(final CompilerMessage cm : result.getErrors() ) {
+                final String name = cm.getFile();
+                try {
+                    problemList.add(ErrorDispatcher.createJavacError
+                            (name, pageNodes, new StringBuffer(cm.getMessage()),
+                                    cm.getLine(), ctxt));
+                } catch (JasperException e) {
+                    log.error("Error visiting node", e);
                 }
-            };
-
-        ICompilationUnit[] compilationUnits =
-            new ICompilationUnit[classNames.length];
-        for (int i = 0; i < compilationUnits.length; i++) {
-            String className = classNames[i];
-            compilationUnits[i] = new CompilationUnit(fileNames[i], className);
+            }
         }
-        Compiler compiler = new Compiler(env,
-                                         policy,
-                                         settings,
-                                         requestor,
-                                         problemFactory,
-                                         true);
-        compiler.compile(compilationUnits);
 
         if (!ctxt.keepGenerated()) {
             ctxt.delete(ctxt.getServletJavaFileName());
@@ -446,7 +131,7 @@ public class JDTCompiler extends org.apa
 
         if (!problemList.isEmpty()) {
             JavacErrorDetail[] jeds =
-                (JavacErrorDetail[]) problemList.toArray(new JavacErrorDetail[0]);
+                problemList.toArray(new JavacErrorDetail[0]);
             errDispatcher.javacError(jeds);
         }
 
@@ -461,7 +146,7 @@ public class JDTCompiler extends org.apa
         }
 
         // JSR45 Support
-        if (! options.isSmapSuppressed()) {
+        if (! this.options.isSmapSuppressed()) {
             SmapUtil.installSmap(getCompilationContext(), smap);
         }