Author: antonio
Date: Sun Mar 6 21:24:07 2005
New Revision: 156393
URL: http://svn.apache.org/viewcvs?view=rev&rev=156393
Log:
Add support for java 1.5: Allow define the compiler compliance level.
Added:
cocoon/trunk/src/mocks/com/
cocoon/trunk/src/mocks/com/sun/
cocoon/trunk/src/mocks/com/sun/tools/
cocoon/trunk/src/mocks/com/sun/tools/javac/
cocoon/trunk/src/mocks/com/sun/tools/javac/Main.java
Modified:
cocoon/trunk/src/blocks/xsp/conf/xsp-program-language.xconf
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java
cocoon/trunk/status.xml
Modified: cocoon/trunk/src/blocks/xsp/conf/xsp-program-language.xconf
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/conf/xsp-program-language.xconf?view=diff&r1=156392&r2=156393
==============================================================================
--- cocoon/trunk/src/blocks/xsp/conf/xsp-program-language.xconf (original)
+++ cocoon/trunk/src/blocks/xsp/conf/xsp-program-language.xconf Sun Mar 6
21:24:07 2005
@@ -50,6 +50,21 @@
<!--parameter name="compiler"
value="org.apache.cocoon.components.language.programming.java.Jikes"/-->
<!--parameter name="compiler"
value="org.apache.cocoon.components.language.programming.java.Pizza"/-->
+ <!--+
+ | Specifies the java code source version used to compile the XSP
code.
+ |
+ | Posible values:
+ | 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).
+ |
+ | NOTE: The parameter is optional to keep backward compatibility.
+ | The parameter currently works only with Sun Javac compiler.
+ | The eclipse compiler version 3.0.1 currently does not
support java 1.5.
+ | The pizza compiler does not support java 1.5.
+ +-->
+ <!-- <parameter name="compiler-compliance-level" value="auto"/> -->
</java-language>
<!-- Interpreted JavaScript language -->
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java
Sun Mar 6 21:24:07 2005
@@ -15,6 +15,8 @@
*/
package org.apache.cocoon.components.language.programming;
+import org.apache.avalon.framework.component.Component;
+
import java.io.IOException;
import java.util.List;
@@ -26,7 +28,7 @@
* @version CVS $Id$
* @since 2.0
*/
-public interface LanguageCompiler {
+public interface LanguageCompiler extends Component {
/**
* Set the name of the file containing the source program
@@ -66,6 +68,17 @@
*/
void setEncoding(String encoding);
+ /**
+ * Set the version of the java source code to be compiled
+ *
+ * @param sourceCodeVersion The version of the JVM for wich the code was
written.
+ * i.e: Posible level's values are:
+ * 130 = for Java 1.3, 140 = for Java 1.4 and 150 = for Java 1.5
+ *
+ * @since 2.1.7
+ */
+ void setCompilerComplianceLevel(int level);
+
/**
* Compile a source file yielding a loadable program file.
*
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java
Sun Mar 6 21:24:07 2005
@@ -28,7 +28,7 @@
/**
* This class implements the functionality common to all Java compilers.
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Id: AbstractJavaCompiler.java,v 1.1 2004/03/10 12:58:07
stephan Exp $
+ * @version CVS $Id$
* @since 2.0
*/
public abstract class AbstractJavaCompiler extends AbstractLogEnabled
implements LanguageCompiler, Recyclable {
@@ -60,6 +60,12 @@
protected String encoding = null;
/**
+ * 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
+ */
+ protected int compilerComplianceLevel;
+
+ /**
* The input stream to output compilation errors
*/
protected InputStream errors;
@@ -113,6 +119,18 @@
}
/**
+ * Set the version of the java source code to be compiled
+ *
+ * @param sourceCodeVersion 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) {
+ this.compilerComplianceLevel = compilerComplianceLevel;
+ }
+
+ /**
* Return the list of errors generated by this compilation
*
* @return The list of errors generated by this compilation
@@ -139,7 +157,22 @@
* @param arguments The list of compilation arguments
* @return The prepared list of compilation arguments
*/
+
protected List fillArguments(List arguments) {
+ // add compiler compliance level
+ /*arguments.add("-source");
+ switch (compilerComplianceLevel) {
+ case 150:
+ arguments.add("5");
+ break;
+ case 140:
+ //arguments.add("-target");
+ arguments.add("1.4");
+ break;
+ default:
+ //arguments.add("-target");
+ arguments.add("1.3");
+ }*/
// destination directory
arguments.add("-d");
arguments.add(destDir);
@@ -154,13 +187,12 @@
// add optimization (for what is worth)
arguments.add("-O");
-
+
// add encoding if set
if (encoding != null) {
arguments.add("-encoding");
arguments.add(encoding);
}
-
return arguments;
}
@@ -175,7 +207,7 @@
String[] args = new String[arguments.size() + 1];
for (i = 0; i < arguments.size(); i++) {
- args[i] = (String) arguments.get(i);
+ args[i] = (String)arguments.get(i);
}
args[i] = file;
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java
Sun Mar 6 21:24:07 2005
@@ -56,31 +56,22 @@
/**
* Eclipse Java Compiler
*
- * @version CVS $Id: EclipseJavaCompiler.java,v 1.3 2004/07/11 23:45:50
antonio Exp $
+ * @version CVS $Id$
*/
public class EclipseJavaCompiler implements LanguageCompiler, Recyclable {
- static boolean target14;
- static boolean source14;
-
- static {
- // Detect JDK version we are running under
- source14 = target14 = SystemUtils.isJavaVersionAtLeast(140);
- }
-
boolean debug;
String sourceDir;
String sourceFile;
String destDir;
String sourceEncoding;
+ int compilerComplianceLevel;
List errors = new LinkedList();
-
public EclipseJavaCompiler() {
this.debug = true;
- source14 = true;
}
public void recycle() {
@@ -97,8 +88,7 @@
}
public void setSource(String srcDir) {
- // This is the "sourcepath" of the file to be
- // compiled
+ // This is the "sourcepath" of the file to be compiled
this.sourceDir = srcDir;
}
@@ -110,6 +100,18 @@
public void setEncoding(String encoding) {
this.sourceEncoding = encoding;
}
+
+ /**
+ * Set the version of the java source code to be compiled
+ *
+ * @param sourceCodeVersion 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) {
+ this.compilerComplianceLevel = compilerComplianceLevel;
+ }
/**
* Eclipse Java compiler ignores class path setting and uses current
@@ -117,7 +119,7 @@
* @param cp classpath to be ignored
*/
public void setClasspath(String cp) {
- // Not used
+ // Not used
}
private String makeClassName(String fileName) throws IOException {
@@ -129,10 +131,12 @@
String str = fileName;
str = str.replace('\\', '/');
if (sourceDir != null) {
- String prefix = new
File(sourceDir).getCanonicalPath().replace('\\', '/');
+ String prefix =
+ new File(sourceDir).getCanonicalPath().replace('\\', '/');
if (canonical != null) {
if (canonical.startsWith(prefix)) {
- String result = canonical.substring(prefix.length() + 1,
canonical.length() -5);
+ String result = canonical.substring(prefix.length() + 1,
+ canonical.length() -5);
result = result.replace('/', '.');
return result;
}
@@ -140,7 +144,8 @@
File t = new File(sourceDir, fileName);
if (t.exists()) {
str = t.getCanonicalPath().replace('\\', '/');
- String result = str.substring(prefix.length() + 1,
str.length() - 5).replace('/', '.');
+ String result = str.substring(prefix.length()+1,
+ str.length() -
5).replace('/', '.');
return result;
}
}
@@ -172,14 +177,15 @@
public char[] getContents() {
char[] result = null;
+ FileReader fr = null;
try {
- Reader reader = new BufferedReader(new
FileReader(sourceFile));
+ fr = new FileReader(sourceFile);
+ Reader reader = new BufferedReader(fr);
if (reader != null) {
char[] chars = new char[8192];
StringBuffer buf = new StringBuffer();
int count;
- while ((count = reader.read(chars, 0,
- chars.length)) > 0) {
+ while ((count = reader.read(chars, 0, chars.length)) >
0) {
buf.append(chars, 0, count);
}
result = new char[buf.length()];
@@ -187,7 +193,6 @@
}
} catch (IOException e) {
handleError(className, -1, -1, e.getMessage());
- //e.printStackTrace();
}
return result;
}
@@ -201,8 +206,7 @@
}
public char[][] getPackageName() {
- StringTokenizer izer =
- new StringTokenizer(className, ".");
+ StringTokenizer izer = new StringTokenizer(className, ".");
char[][] result = new char[izer.countTokens()-1][];
for (int i = 0; i < result.length; i++) {
String tok = izer.nextToken();
@@ -215,31 +219,28 @@
final INameEnvironment env = new INameEnvironment() {
- public NameEnvironmentAnswer
- findType(char[][] compoundTypeName) {
- String result = "";
- String sep = "";
+ public NameEnvironmentAnswer findType(char[][]
compoundTypeName) {
+ StringBuffer result = new StringBuffer();
for (int i = 0; i < compoundTypeName.length; i++) {
- result += sep;
- result += new String(compoundTypeName[i]);
- sep = ".";
+ if (i > 0) {
+ result.append(".");
+ }
+ result.append(compoundTypeName[i]);
}
- return findType(result);
+ return findType(result.toString());
}
- public NameEnvironmentAnswer
- findType(char[] typeName,
- char[][] packageName) {
- String result = "";
- String sep = "";
+ public NameEnvironmentAnswer findType(char[] typeName,
char[][] packageName) {
+ StringBuffer result = new StringBuffer();
for (int i = 0; i < packageName.length; i++) {
- result += sep;
- result += new String(packageName[i]);
- sep = ".";
+ if (i > 0) {
+ result.append(".");
+ }
+ result.append(packageName[i]);
}
- result += sep;
- result += new String(typeName);
- return findType(result);
+ result.append(".");
+ result.append(typeName);
+ return findType(result.toString());
}
private NameEnvironmentAnswer findType(String className) {
@@ -293,38 +294,38 @@
return is == null;
}
- public boolean isPackage(char[][] parentPackageName,
- char[] packageName) {
- String result = "";
- String sep = "";
+ public boolean isPackage(char[][] parentPackageName, char[]
packageName) {
+ StringBuffer result = new StringBuffer();
if (parentPackageName != null) {
for (int i = 0; i < parentPackageName.length; i++) {
- result += sep;
- String str = new String(parentPackageName[i]);
- result += str;
- sep = ".";
+ if (i > 0) {
+ result.append(".");
+ }
+ result.append(parentPackageName[i]);
}
}
String str = new String(packageName);
- if (Character.isUpperCase(str.charAt(0))) {
- if (!isPackage(result)) {
+ if (Character.isUpperCase(str.charAt(0)) &&
!isPackage(result.toString())) {
return false;
- }
}
- result += sep;
- result += str;
- return isPackage(result);
+ result.append(".");
+ result.append(str);
+ return isPackage(result.toString());
}
public void cleanup() {
+ // EMPTY
}
-
};
- final IErrorHandlingPolicy policy =
DefaultErrorHandlingPolicies.proceedWithAllProblems();
- final Map settings = new HashMap(8);
- settings.put(CompilerOptions.OPTION_LineNumberAttribute,
CompilerOptions.GENERATE);
- settings.put(CompilerOptions.OPTION_SourceFileAttribute,
CompilerOptions.GENERATE);
- settings.put(CompilerOptions.OPTION_ReportDeprecation,
CompilerOptions.IGNORE);
+ final IErrorHandlingPolicy policy =
+ DefaultErrorHandlingPolicies.proceedWithAllProblems();
+ final Map settings = new HashMap(9);
+ settings.put(CompilerOptions.OPTION_LineNumberAttribute,
+ CompilerOptions.GENERATE);
+ settings.put(CompilerOptions.OPTION_SourceFileAttribute,
+ CompilerOptions.GENERATE);
+ settings.put(CompilerOptions.OPTION_ReportDeprecation,
+ CompilerOptions.IGNORE);
settings.put(CompilerOptions.OPTION_ReportUnusedImport,
CompilerOptions.IGNORE);
if (sourceEncoding != null) {
settings.put(CompilerOptions.OPTION_Encoding, sourceEncoding);
@@ -332,13 +333,31 @@
if (debug) {
settings.put(CompilerOptions.OPTION_LocalVariableAttribute,
CompilerOptions.GENERATE);
}
- if (source14) {
- settings.put(CompilerOptions.OPTION_Source,
CompilerOptions.VERSION_1_4);
+ // Set the sourceCodeVersion
+ switch (this.compilerComplianceLevel) {
+ case 150:
+ settings.put(CompilerOptions.OPTION_Source,
CompilerOptions.VERSION_1_5);
+ settings.put(CompilerOptions.OPTION_Compliance,
CompilerOptions.VERSION_1_5);
+ break;
+ case 140:
+ settings.put(CompilerOptions.OPTION_Source,
CompilerOptions.VERSION_1_4);
+ break;
+ default:
+ settings.put(CompilerOptions.OPTION_Source,
CompilerOptions.VERSION_1_3);
}
- if (target14) {
- settings.put(CompilerOptions.OPTION_TargetPlatform,
CompilerOptions.VERSION_1_4);
+ // Set the target platform
+ switch (SystemUtils.JAVA_VERSION_INT) {
+ case 150:
+ settings.put(CompilerOptions.OPTION_TargetPlatform,
CompilerOptions.VERSION_1_5);
+ break;
+ case 140:
+ settings.put(CompilerOptions.OPTION_TargetPlatform,
CompilerOptions.VERSION_1_4);
+ break;
+ default:
+ settings.put(CompilerOptions.OPTION_TargetPlatform,
CompilerOptions.VERSION_1_3);
}
- final IProblemFactory problemFactory = new
DefaultProblemFactory(Locale.getDefault());
+ final IProblemFactory problemFactory =
+ new DefaultProblemFactory(Locale.getDefault());
final ICompilerRequestor requestor = new ICompilerRequestor() {
public void acceptResult(CompilationResult result) {
@@ -355,14 +374,17 @@
for (int i = 0; i < classFiles.length; i++) {
ClassFile classFile = classFiles[i];
char[][] compoundName =
classFile.getCompoundName();
- String className = "";
+ StringBuffer className = new StringBuffer();
String sep = "";
- for (int j = 0; j < compoundName.length; j++) {
- className += sep + new
String(compoundName[j]);
- sep = ".";
+ for (int j = 0; j < compoundName.length; j++)
{
+ if (j > 0) {
+ className.append(".");
+ }
+ className.append(compoundName[j]);
}
byte[] bytes = classFile.getBytes();
- String outFile = destDir + "/" +
className.replace('.', '/') + ".class";
+ String outFile = destDir + "/" +
+ className.toString().replace('.', '/') +
".class";
FileOutputStream fout = new
FileOutputStream(outFile);
BufferedOutputStream bos = new
BufferedOutputStream(fout);
bos.write(bytes);
@@ -374,20 +396,32 @@
}
}
};
- ICompilationUnit[] compilationUnits = new
ICompilationUnit[classNames.length];
+ 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);
+ Compiler compiler = new Compiler(env,
+ policy,
+ settings,
+ requestor,
+ problemFactory);
compiler.compile(compilationUnits);
return errors.size() == 0;
}
void handleError(String className, int line, int column, Object
errorMessage) {
- String fileName = className.replace('.', File.separatorChar) + ".java";
+ String fileName =
+ className.replace('.', File.separatorChar) + ".java";
if (column < 0) column = 0;
- errors.add(new CompilerError(fileName, true, line, column, line,
column, errorMessage.toString()));
+ errors.add(new CompilerError(fileName,
+ true,
+ line,
+ column,
+ line,
+ column,
+ errorMessage.toString()));
}
public List getErrors() throws IOException {
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
Sun Mar 6 21:24:07 2005
@@ -16,7 +16,6 @@
package org.apache.cocoon.components.language.programming.java;
import java.io.File;
-import java.io.FileFilter;
import java.io.IOException;
import java.util.List;
import java.util.StringTokenizer;
@@ -38,6 +37,7 @@
import org.apache.cocoon.components.language.programming.CompilerError;
import org.apache.cocoon.components.language.programming.LanguageCompiler;
import org.apache.cocoon.util.ClassUtils;
+import org.apache.cocoon.util.JavaArchiveFilter;
import org.apache.commons.lang.SystemUtils;
/**
@@ -58,8 +58,12 @@
/** Classpath */
private String classpath;
+ /** The Class Loader Class Name */
private String classLoaderClass;
+ /** Source code version */
+ private int compilerComplianceLevel;
+
/**
* Return the language's canonical source file extension.
*
@@ -89,6 +93,7 @@
public void parameterize(Parameters params) throws ParameterException {
super.parameterize(params);
+
this.classLoaderClass = params.getParameter("class-loader", null);
if (this.classLoaderClass != null) {
try {
@@ -107,6 +112,17 @@
throw new ParameterException("Lookup of ClassLoaderManager
failed", e);
}
}
+ // Get the compiler compliance level (source Code version)
+ String sourceVer = params.getParameter("compiler-compliance-level",
"auto");
+ if (sourceVer.equalsIgnoreCase("auto")) {
+ this.compilerComplianceLevel = SystemUtils.JAVA_VERSION_INT;
+ } else {
+ try {
+ compilerComplianceLevel = new
Float(Float.parseFloat(sourceVer) * 100).intValue();
+ } catch (NumberFormatException e) {
+ throw new ParameterException("XSP: compiler-compliance-level
parameter value not valid!", e);
+ }
+ }
}
/**
@@ -124,12 +140,11 @@
String systemBootClasspath = System.getProperty("sun.boot.class.path");
String systemClasspath = SystemUtils.JAVA_CLASS_PATH;
String systemExtDirs = SystemUtils.JAVA_EXT_DIRS;
- String systemExtClasspath;
+ String systemExtClasspath = null;
try {
systemExtClasspath = expandDirs(systemExtDirs);
} catch (Exception e) {
- systemExtClasspath = null;
getLogger().warn("Could not expand Directory:" + systemExtDirs, e);
}
@@ -171,12 +186,11 @@
throws LanguageException {
try {
- LanguageCompiler compiler = (LanguageCompiler)
this.compilerClass.newInstance();
+ LanguageCompiler compiler =
(LanguageCompiler)this.compilerClass.newInstance();
// AbstractJavaCompiler is LogEnabled
if (compiler instanceof LogEnabled) {
((LogEnabled)compiler).enableLogging(getLogger());
}
- // some may be Serviceable
if (compiler instanceof Serviceable) {
((Serviceable)compiler).service(this.manager);
}
@@ -191,12 +205,15 @@
compiler.setSource(basePath);
compiler.setDestination(basePath);
compiler.setClasspath(basePath + this.classpath);
+ compiler.setCompilerComplianceLevel(compilerComplianceLevel);
if (encoding != null) {
compiler.setEncoding(encoding);
}
- getLogger().debug("Compiling " + filepath);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Compiling " + filepath);
+ }
if (!compiler.compile()) {
StringBuffer message = new StringBuffer("Error compiling ");
message.append(filename);
@@ -270,13 +287,7 @@
getLogger().warn("Attempted to retrieve directory listing
of non-directory " + dir.toString());
}
} else {
- File[] files = dir.listFiles(new FileFilter() {
- public boolean accept(File file) {
- String name = file.getName().toLowerCase();
- return (name.endsWith(".jar") ||
name.endsWith(".zip"));
- }
- }
- );
+ File[] files = dir.listFiles(new JavaArchiveFilter());
for (int i = 0; i < files.length; i++) {
buffer.append(files[i]).append(File.pathSeparator);
}
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java
Sun Mar 6 21:24:07 2005
@@ -18,55 +18,32 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
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.avalon.framework.CascadingRuntimeException;
import org.apache.cocoon.components.language.programming.CompilerError;
-import org.apache.cocoon.util.ClassUtils;
-import org.apache.log.Hierarchy;
+import org.apache.commons.lang.SystemUtils;
/**
* This class wraps the Sun's Javac Compiler.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Id: Javac.java,v 1.1 2004/03/10 12:58:07 stephan Exp $
+ * @version CVS $Id$
* @since 2.0
*/
public class Javac extends AbstractJavaCompiler {
- public final static String CLASSIC_CLASS = "sun.tools.javac.Main";
- public final static String MODERN_CLASS = "com.sun.tools.javac.Main";
-
- private boolean modern = false;
+ //private boolean modern = false;
public Javac() {
-
- // Use reflection to be able to build on all JDKs
- try {
- ClassUtils.loadClass(MODERN_CLASS);
- modern = true;
- } catch (ClassNotFoundException e) {
- Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").debug("Javac
connector could not find modern compiler -- falling back to classic.");
- try {
- ClassUtils.loadClass(CLASSIC_CLASS);
- modern = false;
- } catch (Exception ex) {
- Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").error("No
compiler found in your classpath. Make sure you added 'tools.jar'", ex);
- throw new CascadingRuntimeException("No compiler found in your
classpath. Make sure you added 'tools.jar'", ex);
- }
- }
+ //modern = true;
}
- protected Javac(boolean modern) {
- this.modern = modern;
- }
-
/**
* Compile a source file yielding a loadable class file.
*
@@ -74,9 +51,17 @@
* @exception IOException If an error occurs during compilation
*/
public boolean compile() throws IOException {
+
ByteArrayOutputStream err = new ByteArrayOutputStream();
- sun.tools.javac.Main compiler = new sun.tools.javac.Main(err, "javac");
- boolean result = compiler.compile(toStringArray(fillArguments(new
ArrayList())));
+
+ 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())));
+ }
this.errors = new ByteArrayInputStream(err.toByteArray());
return result;
}
@@ -89,13 +74,13 @@
* @return The list of compiler error messages
* @exception IOException If an error occurs during message collection
*/
- protected List parseStream(BufferedReader input) throws IOException {
+/* protected List parseStream(BufferedReader input) throws IOException {
if (modern) {
return parseModernStream(input);
} else {
return parseClassicStream(input);
}
- }
+ }*/
/**
* Parse the compiler error stream to produce a list of
@@ -105,7 +90,7 @@
* @return The list of compiler error messages
* @exception IOException If an error occurs during message collection
*/
- protected List parseModernStream(BufferedReader input) throws IOException {
+ protected List parseStream(BufferedReader input) throws IOException {
List errors = new ArrayList();
String line = null;
StringBuffer buffer = null;
@@ -116,8 +101,7 @@
// most errors terminate with the '^' char
do {
- if ((line = input.readLine()) == null)
- {
+ 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()));
@@ -151,7 +135,9 @@
String pointer = tokens.nextToken("\n");
int startcolumn = pointer.indexOf("^");
int endcolumn = context.indexOf(" ", startcolumn);
- if (endcolumn == -1) endcolumn = context.length();
+ 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);
@@ -168,6 +154,7 @@
* @return The list of compiler error messages
* @exception IOException If an error occurs during message collection
*/
+ /*
protected List parseClassicStream(BufferedReader input) throws IOException {
List errors = null;
@@ -180,39 +167,46 @@
// each error has 3 lines
for (int i = 0; i < 3 ; i++) {
- if ((line = input.readLine()) == null) return errors;
+ if ((line = input.readLine()) == null) {
+ return errors;
+ }
buffer.append(line);
buffer.append('\n');
}
// if error is found create the vector
- if (errors == null) errors = new ArrayList();
+ if (errors == null) {
+ errors = new ArrayList();
+ }
// add the error bean
errors.add(parseClassicError(buffer.toString()));
}
}
-
+*/
/**
* Parse an individual compiler error message with classic style.
*
* @param error The error text
* @return A messaged <code>CompilerError</code>
*/
+ /*
private CompilerError parseClassicError(String error) {
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 = new
StringBuffer(file).append(":").append(tokens.nextToken()).toString();
+ }
int line = Integer.parseInt(tokens.nextToken());
- String last = tokens.nextToken();
+ StringBuffer last = new StringBuffer(tokens.nextToken());
// In case the message contains ':', it should be reassembled
while (tokens.hasMoreElements()) {
- last += tokens.nextToken();
+ last.append(tokens.nextToken());
}
- tokens = new StringTokenizer(last.trim(), "\n");
+ tokens = new StringTokenizer(last.toString().trim(), "\n");
String message = tokens.nextToken();
String context = tokens.nextToken();
String pointer = tokens.nextToken();
@@ -227,7 +221,7 @@
return new CompilerError("could not parse error message: " + error);
}
}
-
+*/
public String toString() {
return "Sun Javac Compiler";
}
Modified:
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java?view=diff&r1=156392&r2=156393
==============================================================================
---
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java
(original)
+++
cocoon/trunk/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java
Sun Mar 6 21:24:07 2005
@@ -32,22 +32,19 @@
* This class wraps the Pizza Java Compiler.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
- * @version CVS $Id: Pizza.java,v 1.1 2004/03/10 12:58:07 stephan Exp $
+ * @version CVS $Id$
*/
public class Pizza extends Javac {
public final static String PIZZA_CLASS =
"net.sf.pizzacompiler.compiler.Main";
public Pizza() {
- super(true);
-
try {
ClassUtils.loadClass(PIZZA_CLASS);
} catch (ClassNotFoundException e) {
Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").error("No
Pizza Java compiler found in your classpath. Make sure you added 'pizza.jar'",
e);
throw new RuntimeException("No Pizza Java compiler found in your
classpath. Make sure you added 'pizza.jar'");
}
-
net.sf.pizzacompiler.compiler.Main.init();
}
Added: cocoon/trunk/src/mocks/com/sun/tools/javac/Main.java
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/src/mocks/com/sun/tools/javac/Main.java?view=auto&rev=156393
==============================================================================
--- cocoon/trunk/src/mocks/com/sun/tools/javac/Main.java (added)
+++ cocoon/trunk/src/mocks/com/sun/tools/javac/Main.java Sun Mar 6 21:24:07
2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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 com.sun.tools.javac;
+
+import java.io.PrintWriter;
+
+/**
+ * Mock class providing the declarations required to compile the Cocoon code
when
+ * the actual library is not present.
+ *
+ * @version CVS $Id: Main.java 30932 2004-07-29 17:35:38Z vgritsenko $
+ */
+public class Main {
+
+ public Main() {
+ throw new UnsupportedOperationException("This is a mock object");
+ }
+
+ public static int compile(String[] strings, PrintWriter p) {
+ throw new UnsupportedOperationException("This is a mock object");
+ }
+}
Modified: cocoon/trunk/status.xml
URL:
http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?view=diff&r1=156392&r2=156393
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Sun Mar 6 21:24:07 2005
@@ -520,6 +520,21 @@
Refreshing a page with a JSR-168 portlet in it could cause unexpected
results. JSR-168 urls can
now be configured to contain the data required to generated the required
events.
</action>
+ <action dev="AG" type="add">
+ Add <compiler-compliance-level> parameter for java XSP compiler.
+ This new parameter allow to specify the java code source version used to
compile the XSP code.
+ It is useful to run cocoon using java 1.5 while using source code for 1.4.
+ Posible values:
+ 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).
+
+ NOTE: The parameter is optional to keep backward compatibility.
+ The parameter currently works only with Sun Javac compiler.
+ The eclipse compiler version 3.0.1 currently does not support java
1.5.
+ The pizza compiler does not support java 1.5.
+ </action>
<action dev="RG" type="fix" fixes-bug="32838" due-to="Roy Huang"
due-to-email="[EMAIL PROTECTED]">
PageLabel url's were not properly encoded.
</action>