You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2019/02/18 14:03:25 UTC

svn commit: r1853801 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/

Author: anathaniel
Date: Mon Feb 18 14:03:25 2019
New Revision: 1853801

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

Modified:
    cocoon/branches/BRANCH_2_1_X/README.txt
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/README.txt
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/README.txt?rev=1853801&r1=1853800&r2=1853801&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/README.txt (original)
+++ cocoon/branches/BRANCH_2_1_X/README.txt Mon Feb 18 14:03:25 2019
@@ -31,9 +31,9 @@
   Cocoon is implemented both as a Java servlet and a Java command line
   application. The following requirements exist for installing it:
 
-   o  A Java 1.5.0 or later compatible virtual machine for your operating system.
+   o  A Java 1.6.0 or later compatible virtual machine for your operating system.
 
-   o  A Servlet API 2.2 compatible Servlet Engine or J2EE Application Server. 
+   o  A Servlet API 2.3 compatible Servlet Engine or J2EE Application Server.
       [not required for command line operation]
 
   Installation Instructions and Documentation
@@ -46,7 +46,7 @@
 
   If you are updating from a previous release of Cocoon, make sure
   that you read the installation instructions on updating first.
-  
+
   Look for the most updated documentation on the Apache Cocoon web site
   (http://cocoon.apache.org/).
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java?rev=1853801&r1=1853800&r2=1853801&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java Mon Feb 18 14:03:25 2019
@@ -5,9 +5,9 @@
  * 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.
@@ -18,6 +18,7 @@ package org.apache.cocoon.components.lan
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.cocoon.components.language.programming.CompilerError;
 import org.apache.cocoon.components.language.programming.LanguageCompiler;
 
 import java.io.BufferedReader;
@@ -124,7 +125,7 @@ public abstract class AbstractJavaCompil
      *
      * @param compilerComplianceLevel The version of the JVM for wich the code was written.
      * i.e: 130 = Java 1.3, 140 = Java 1.4 and 150 = Java 1.5
-     * 
+     *
      * @since 2.1.7
      */
     public void setCompilerComplianceLevel(int compilerComplianceLevel) {
@@ -137,7 +138,7 @@ public abstract class AbstractJavaCompil
      * @return The list of errors generated by this compilation
      * @exception IOException If an error occurs during message collection
      */
-    public List getErrors() throws IOException {
+    public List<CompilerError> getErrors() throws IOException {
         return parseStream(new BufferedReader(new InputStreamReader(errors)));
     }
 
@@ -149,7 +150,7 @@ public abstract class AbstractJavaCompil
      * @return The list of compiler error messages
      * @exception IOException If an error occurs during message collection
      */
-    protected abstract List parseStream(BufferedReader errors)
+    protected abstract List<CompilerError> parseStream(BufferedReader errors)
             throws IOException;
 
     /**
@@ -159,7 +160,7 @@ public abstract class AbstractJavaCompil
      * @return The prepared list of compilation arguments
      */
 
-    protected List fillArguments(List arguments) {
+    protected List<String> fillArguments(List<String> arguments) {
         // add compiler compliance level
         /*arguments.add("-source");
         switch (compilerComplianceLevel) {
@@ -188,7 +189,7 @@ public abstract class AbstractJavaCompil
 
         // add optimization (for what is worth)
         arguments.add("-O");
-        
+
         // add encoding if set
         if (encoding != null) {
             arguments.add("-encoding");
@@ -203,12 +204,12 @@ public abstract class AbstractJavaCompil
      * @param arguments The compiler arguments
      * @return A string array containing compilation arguments
      */
-    protected String[] toStringArray(List arguments) {
+    protected String[] toStringArray(List<String> arguments) {
         int i;
         String[] args = new String[arguments.size() + 1];
 
         for (i = 0; i < arguments.size(); i++) {
-            args[i] = (String)arguments.get(i);
+            args[i] = arguments.get(i);
         }
 
         args[i] = file;

Modified: 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=1853801&r1=1853800&r2=1853801&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java Mon Feb 18 14:03:25 2019
@@ -5,9 +5,9 @@
  * 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.
@@ -20,14 +20,15 @@ import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.PrintWriter;
 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 org.apache.commons.lang.SystemUtils;
+
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
 
 /**
  * This class wraps the Sun's Javac Compiler.
@@ -50,17 +51,13 @@ public class Javac extends AbstractJavaC
    * @exception IOException If an error occurs during compilation
    */
   public boolean compile() throws IOException {
-      
+
     ByteArrayOutputStream err = new ByteArrayOutputStream();
-    
-    boolean result;
-    if (!SystemUtils.IS_JAVA_1_3) { // For Java 1.4 and 1.5
-        PrintWriter pw = new PrintWriter(err);
-        result = com.sun.tools.javac.Main.compile(toStringArray(fillArguments(new ArrayList())), pw) == 0;
-    } else {
-        sun.tools.javac.Main compiler = new sun.tools.javac.Main(err, "javac");
-        result = compiler.compile(toStringArray(fillArguments(new ArrayList())));
-    }
+    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;
   }
@@ -73,16 +70,14 @@ public class Javac extends AbstractJavaC
    * @return The list of compiler error messages
    * @exception IOException If an error occurs during message collection
    */
-  protected List parseStream(BufferedReader input) throws IOException {
-    List errors = new ArrayList();
-    String line = null;
-    StringBuffer buffer = null;
+  protected List<CompilerError> parseStream(BufferedReader input) throws IOException {
+    List<CompilerError> errors = new ArrayList<CompilerError>();
 
     while (true) {
-      // cleanup the buffer
-      buffer = new StringBuffer(); // this is quicker than clearing it
+      StringBuilder buffer = new StringBuilder();
 
       // most errors terminate with the '^' char
+      String line;
       do {
         if ((line = input.readLine()) == null) {
             if (buffer.length() > 0) {
@@ -110,7 +105,8 @@ public class Javac extends AbstractJavaC
     StringTokenizer tokens = new StringTokenizer(error, ":");
     try {
       String file = tokens.nextToken();
-      if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
+      if (file.length() == 1)
+        file = file + ":" + tokens.nextToken();
       int line = Integer.parseInt(tokens.nextToken());
 
       String message = tokens.nextToken("\n").substring(1);

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?rev=1853801&r1=1853800&r2=1853801&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Feb 18 14:03:25 2019
@@ -185,6 +185,9 @@
   <changes>
   <release version="2.1.13" date="TBD">
     <action dev="AN" type="update">
+      Use javax.tools.JavaCompiler interface (available since Java 6).
+    </action>
+    <action dev="AN" type="update">
       Core: Update to xalan-2.7.2 and add serializer-2.7.2
     </action>
     <action dev="DC" type="fix">