[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xml-cocoon-cvs
Subject:    svn commit: r1853873 - in /cocoon/branches/BRANCH_2_1_X: build.properties src/blocks/xsp/conf/xsp-pr
From:       anathaniel () apache ! org
Date:       2019-02-19 11:49:05
Message-ID: 20190219114906.13C8F3A0222 () svn01-us-west ! apache ! org
[Download RAW message or body]

Author: anathaniel
Date: Tue Feb 19 11:49:05 2019
New Revision: 1853873

URL: http://svn.apache.org/viewvc?rev=1853873&view=rev
Log:
Use javax.tools.JavaCompiler interface for Javac (available since Java 6)

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
 Modified:
    cocoon/branches/BRANCH_2_1_X/build.properties
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/build.properties
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/build.properties?rev=1853873&r1=1853872&r2=1853873&view=diff
 ==============================================================================
--- cocoon/branches/BRANCH_2_1_X/build.properties (original)
+++ cocoon/branches/BRANCH_2_1_X/build.properties Tue Feb 19 11:49:05 2019
@@ -133,8 +133,8 @@ compiler.debug=on
 compiler.optimize=on
 compiler.deprecation=off
 compiler.nowarn=on
-source.vm=1.5
-target.vm=1.5
+source.vm=1.6
+target.vm=1.6
 
 # ---- System Properties -------------------------------------------------------
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf?rev=1853873&r1=1853872&r2=1853873&view=diff
 ==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf \
                (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf Tue \
Feb 19 11:49:05 2019 @@ -35,6 +35,7 @@
           | Specifies which Java compiler to use. Possible variants are:
           |
           |  - EclipseJavaCompiler: the Eclipse JDT java compiler
+          |  - Javac: the java compiler that comes with JDK
           |  - Jikes: the Jikes java compiler
           |  - Pizza: the Pizza java compiler (deprecated. Support will be removed \
in 2.2)  |
@@ -46,6 +47,7 @@
           |       or you might experience problems in some servlet containers.
           +-->
       <parameter name="compiler" \
value="org.apache.cocoon.components.language.programming.java.EclipseJavaCompiler"/> \
+      <!--parameter name="compiler" \
                value="org.apache.cocoon.components.language.programming.java.Javac"/-->
                
       <!--parameter name="compiler" \
                value="org.apache.cocoon.components.language.programming.java.Jikes"/-->
                
       <!--parameter name="compiler" \
value="org.apache.cocoon.components.language.programming.java.Pizza"/--> <!-- \
deprecated-->  
@@ -53,7 +55,7 @@
           | Specifies the java code source version used to compile the XSP code.
           |
           | Posible values:
-          | 1.3 = Java version 1.3
+          | 1.3 = Java version 1.3 
           | 1.4 = Java version 1.4
           | 1.5 = Java version 1.5
           | auto = The version of the JVM where cocoon is running. (Default value).

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
                
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org \
/apache/cocoon/components/language/programming/java/Javac.java?rev=1853873&view=auto \
                ==============================================================================
                
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java \
                (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java \
Tue Feb 19 11:49:05 2019 @@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.language.programming.java;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+import org.apache.cocoon.components.language.programming.CompilerError;
+
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
+/**
+ * This class wraps the Sun's Javac Compiler.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: Javac.java 1853801 2019-02-18 14:03:25Z anathaniel $
+ * @since 2.0
+ */
+
+public class Javac extends AbstractJavaCompiler {
+
+  public Javac() {
+      // EMPTY
+  }
+
+  /**
+   * Compile a source file yielding a loadable class file.
+   *
+   * <code>null</code> if it is the platform's default encoding
+   * @exception IOException If an error occurs during compilation
+   */
+  public boolean compile() throws IOException {
+
+    ByteArrayOutputStream err = new ByteArrayOutputStream();
+    String[] args = toStringArray(fillArguments(new ArrayList<String>()));
+
+    JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
+    int rc = javac.run(null, null, err, args);
+    boolean result = rc == 0;
+    this.errors = new ByteArrayInputStream(err.toByteArray());
+    return result;
+  }
+
+  /**
+   * Parse the compiler error stream to produce a list of
+   * <code>CompilerError</code>s
+   *
+   * @param input The error stream
+   * @return The list of compiler error messages
+   * @exception IOException If an error occurs during message collection
+   */
+  protected List<CompilerError> parseStream(BufferedReader input) throws IOException \
{ +    List<CompilerError> errors = new ArrayList<CompilerError>();
+
+    while (true) {
+      StringBuilder buffer = new StringBuilder();
+
+      // most errors terminate with the '^' char
+      String line;
+      do {
+        if ((line = input.readLine()) == null) {
+            if (buffer.length() > 0) {
+                // There's an error which doesn't end with a '^'
+                errors.add(new CompilerError("\n" + buffer.toString()));
+            }
+            return errors;
+        }
+        buffer.append(line);
+        buffer.append('\n');
+      } while (!line.endsWith("^"));
+
+      // add the error bean
+      errors.add(parseModernError(buffer.toString()));
+    }
+  }
+
+  /**
+   * Parse an individual compiler error message with modern style.
+   *
+   * @param error The error text
+   * @return A messaged <code>CompilerError</code>
+   */
+  private CompilerError parseModernError(String error) {
+    StringTokenizer tokens = new StringTokenizer(error, ":");
+    try {
+      String file = tokens.nextToken();
+      if (file.length() == 1)
+        file = file + ":" + tokens.nextToken();
+      int line = Integer.parseInt(tokens.nextToken());
+
+      String message = tokens.nextToken("\n").substring(1);
+      String context = tokens.nextToken("\n");
+      String pointer = tokens.nextToken("\n");
+      int startcolumn = pointer.indexOf("^");
+      int endcolumn = context.indexOf(" ", startcolumn);
+      if (endcolumn == -1) {
+          endcolumn = context.length();
+      }
+      return new CompilerError(file, false, line, startcolumn, line, endcolumn, \
message); +    } catch(NoSuchElementException nse) {
+      return new CompilerError("no more tokens - could not parse error message: " + \
error); +    } catch(Exception nse) {
+      return new CompilerError("could not parse error message: " + error);
+    }
+  }
+
+  public String toString() {
+    return "Sun Javac Compiler";
+  }
+}

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=1853873&r1=1853872&r2=1853873&view=diff
 ==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Tue Feb 19 11:49:05 2019
@@ -184,6 +184,10 @@
 
   <changes>
   <release version="2.1.13" date="TBD">
+    <!-- Leave this entry about raising minimum Java to 1.6 at the top for 2.1.13! \
--> +    <action dev="all" type="update">
+      Starting with 2.1.13 the minimum required Java version will be 1.6.
+    </action>
     <action dev="AN" type="fix">
       Unsynchronized HashMap.put in ResourceReader and GeneratorSelector may lead to \
infinite loop.  </action>
@@ -197,7 +201,7 @@
       Update to commons-httpclient-3.1
     </action>
     <action dev="AN" type="update">
-      XSP: Remove alternative Javac because there is no common API for Java 5 to 8.
+      XSP: Use javax.tools.JavaCompiler interface for Javac (available since Java \
6).  </action>
     <action dev="AN" type="update">
       Core: Update to xalan-2.7.2 and add serializer-2.7.2


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic