Author: antonio Date: Mon Jan 10 01:36:58 2005 New Revision: 124779 URL: http://svn.apache.org/viewcvs?view=rev&rev=124779 Log: Add support for java 1.5: Allow define the compiler compliance level Added: cocoon/branches/BRANCH_2_1_X/src/mocks/com/ cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/ cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/ cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/javac/ cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/javac/Main.java Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java 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/EclipseJavaCompiler.java cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.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/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/conf/xsp-program-language.xconf&r2=124779 ============================================================================== --- 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 Mon Jan 10 01:36:58 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/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java&r2=124779 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/LanguageCompiler.java Mon Jan 10 01:36:58 2005 @@ -25,7 +25,7 @@ * (Java-based) compiled languages * * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id: LanguageCompiler.java,v 1.1 2004/03/10 12:58:07 stephan Exp $ + * @version CVS $Id$ * @since 2.0 */ public interface LanguageCompiler extends Component { @@ -68,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/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/AbstractJavaCompiler.java&r2=124779 ============================================================================== --- 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 Jan 10 01:36:58 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/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java&r2=124779 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/EclipseJavaCompiler.java Mon Jan 10 01:36:58 2005 @@ -60,27 +60,18 @@ */ 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 { @@ -175,23 +177,22 @@ 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()]; buf.getChars(0, result.length, result, 0); } } catch (IOException e) { - handleError(className, -1, -1, - e.getMessage()); - //e.printStackTrace(); + handleError(className, -1, -1, e.getMessage()); } return result; } @@ -205,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(); @@ -219,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) { @@ -297,36 +294,32 @@ 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); + final Map settings = new HashMap(9); settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); settings.put(CompilerOptions.OPTION_SourceFileAttribute, @@ -335,20 +328,33 @@ CompilerOptions.IGNORE); settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); if (sourceEncoding != null) { - settings.put(CompilerOptions.OPTION_Encoding, - sourceEncoding); + settings.put(CompilerOptions.OPTION_Encoding, sourceEncoding); } if (debug) { - settings.put(CompilerOptions.OPTION_LocalVariableAttribute, - CompilerOptions.GENERATE); + 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()); @@ -360,34 +366,27 @@ IProblem[] problems = result.getProblems(); for (int i = 0; i < problems.length; i++) { IProblem problem = problems[i]; - String name = - new String(problems[i].getOriginatingFileName()); - handleError(name, - problem.getSourceLineNumber(), - -1, - problem.getMessage()); + String name = new String(problems[i].getOriginatingFileName()); + handleError(name, problem.getSourceLineNumber(), -1, problem.getMessage()); } } else { ClassFile[] classFiles = result.getClassFiles(); for (int i = 0; i < classFiles.length; i++) { ClassFile classFile = classFiles[i]; - char[][] compoundName = - classFile.getCompoundName(); - String className = ""; + char[][] compoundName = classFile.getCompoundName(); + StringBuffer className = new StringBuffer(); String sep = ""; - for (int j = 0; - j < compoundName.length; j++) { - className += sep; - className += 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"; - FileOutputStream fout = - new FileOutputStream(outFile); - BufferedOutputStream bos = - new BufferedOutputStream(fout); + className.toString().replace('.', '/') + ".class"; + FileOutputStream fout = new FileOutputStream(outFile); + BufferedOutputStream bos = new BufferedOutputStream(fout); bos.write(bytes); bos.close(); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java&r2=124779 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java Mon Jan 10 01:36:58 2005 @@ -38,6 +38,7 @@ 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; /** * The Java programming language processor @@ -57,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. * @@ -88,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 { @@ -106,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); + } + } } /** @@ -121,8 +138,8 @@ // Initialize the classpath String systemBootClasspath = System.getProperty("sun.boot.class.path"); - String systemClasspath = System.getProperty("java.class.path"); - String systemExtDirs = System.getProperty("java.ext.dirs"); + String systemClasspath = SystemUtils.JAVA_CLASS_PATH; + String systemExtDirs = SystemUtils.JAVA_EXT_DIRS; String systemExtClasspath = null; try { @@ -169,7 +186,7 @@ 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()); @@ -182,19 +199,21 @@ String filename = name.substring(pos + 1); final String basePath = baseDirectory.getCanonicalPath(); - String filepath = basePath + File.separator - + name + "." + getSourceExtension(); + String filepath = basePath + File.separator + name + "." + getSourceExtension(); compiler.setFile(filepath); 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); @@ -264,7 +283,9 @@ File dir = new File(d); if (!dir.isDirectory()) { // The absence of a listed directory may not be an error. - if (getLogger().isWarnEnabled()) getLogger().warn("Attempted to retrieve directory listing of non-directory " + dir.toString()); + if (getLogger().isWarnEnabled()) { + getLogger().warn("Attempted to retrieve directory listing of non-directory " + dir.toString()); + } } else { File[] files = dir.listFiles(new JavaArchiveFilter()); for (int i = 0; i < files.length; i++) { @@ -272,7 +293,6 @@ } } } - return buffer.toString(); } 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/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Javac.java&r2=124779 ============================================================================== --- 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 Jan 10 01:36:58 2005 @@ -18,17 +18,15 @@ 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. @@ -40,33 +38,12 @@ 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; @@ -150,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); @@ -167,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; @@ -195,13 +183,14 @@ 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, ":"); @@ -232,7 +221,7 @@ return new CompilerError("could not parse error message: " + error); } } - +*/ public String toString() { return "Sun Javac Compiler"; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java&r2=124779 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/programming/java/Pizza.java Mon Jan 10 01:36:58 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/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/javac/Main.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/javac/Main.java?view=auto&rev=124779 ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/mocks/com/sun/tools/javac/Main.java Mon Jan 10 01:36:58 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/branches/BRANCH_2_1_X/status.xml Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=124779&p1=cocoon/branches/BRANCH_2_1_X/status.xml&r1=124778&p2=cocoon/branches/BRANCH_2_1_X/status.xml&r2=124779 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/status.xml (original) +++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Jan 10 01:36:58 2005 @@ -202,6 +202,22 @@ <changes> <release version="@version@" date="@date@"> + <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>