Index: antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java,v --- antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java 7 Mar 2009 00:59:06 -0000 1.68 +++ antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java 25 Apr 2010 20:09:44 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -107,63 +107,63 @@ */ cmd.createArgument().setValue("-noExit"); //$NON-NLS-1$ - if (this.bootclasspath != null) { + if (this.bootclasspath != null) { cmd.createArgument().setValue("-bootclasspath"); //$NON-NLS-1$ - if (this.bootclasspath.size() != 0) { - /* - * Set the bootclasspath for the Eclipse compiler. - */ - cmd.createArgument().setPath(this.bootclasspath); - } else { - cmd.createArgument().setValue(Util.EMPTY_STRING); - } - } - - Path classpath = new Path(this.project); - - /* - * Eclipse compiler doesn't support -extdirs. - * It is emulated using the classpath. We add extdirs entries after the - * bootclasspath. - */ - if (this.extdirs != null) { + if (this.bootclasspath.size() != 0) { + /* + * Set the bootclasspath for the Eclipse compiler. + */ + cmd.createArgument().setPath(this.bootclasspath); + } else { + cmd.createArgument().setValue(Util.EMPTY_STRING); + } + } + + Path classpath = new Path(this.project); + + /* + * Eclipse compiler doesn't support -extdirs. + * It is emulated using the classpath. We add extdirs entries after the + * bootclasspath. + */ + if (this.extdirs != null) { cmd.createArgument().setValue("-extdirs"); //$NON-NLS-1$ cmd.createArgument().setPath(this.extdirs); - } + } /* * The java runtime is already handled, so we simply want to retrieve the * ant runtime and the compile classpath. */ - classpath.append(getCompileClasspath()); + classpath.append(getCompileClasspath()); + + // For -sourcepath, use the "sourcepath" value if present. + // Otherwise default to the "srcdir" value. + Path sourcepath = null; - // For -sourcepath, use the "sourcepath" value if present. - // Otherwise default to the "srcdir" value. - Path sourcepath = null; - - // retrieve the method getSourcepath() using reflect - // This is done to improve the compatibility to ant 1.5 - Method getSourcepathMethod = null; - try { - getSourcepathMethod = javacClass.getMethod("getSourcepath", null); //$NON-NLS-1$ - } catch(NoSuchMethodException e) { - // if not found, then we cannot use this method (ant 1.5) - } - Path compileSourcePath = null; - if (getSourcepathMethod != null) { - try { + // retrieve the method getSourcepath() using reflect + // This is done to improve the compatibility to ant 1.5 + Method getSourcepathMethod = null; + try { + getSourcepathMethod = javacClass.getMethod("getSourcepath", null); //$NON-NLS-1$ + } catch(NoSuchMethodException e) { + // if not found, then we cannot use this method (ant 1.5) + } + Path compileSourcePath = null; + if (getSourcepathMethod != null) { + try { compileSourcePath = (Path) getSourcepathMethod.invoke(this.attributes, null); } catch (IllegalAccessException e) { // should never happen } catch (InvocationTargetException e) { // should never happen } - } - if (compileSourcePath != null) { - sourcepath = compileSourcePath; - } else { - sourcepath = this.src; - } + } + if (compileSourcePath != null) { + sourcepath = compileSourcePath; + } else { + sourcepath = this.src; + } classpath.append(sourcepath); /* * Set the classpath for the Eclipse compiler. @@ -171,38 +171,38 @@ cmd.createArgument().setValue("-classpath"); //$NON-NLS-1$ createClasspathArgument(cmd, classpath); - final String javaVersion = JavaEnvUtils.getJavaVersion(); + final String javaVersion = JavaEnvUtils.getJavaVersion(); String memoryParameterPrefix = javaVersion.equals(JavaEnvUtils.JAVA_1_1) ? "-J-" : "-J-X";//$NON-NLS-1$//$NON-NLS-2$ - if (this.memoryInitialSize != null) { - if (!this.attributes.isForkedJavac()) { - this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryInitialSize"), Project.MSG_WARN); //$NON-NLS-1$ - } else { - cmd.createArgument().setValue(memoryParameterPrefix - + "ms" + this.memoryInitialSize); //$NON-NLS-1$ - } - } - - if (this.memoryMaximumSize != null) { - if (!this.attributes.isForkedJavac()) { - this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryMaximumSize"), Project.MSG_WARN); //$NON-NLS-1$ - } else { - cmd.createArgument().setValue(memoryParameterPrefix - + "mx" + this.memoryMaximumSize); //$NON-NLS-1$ - } - } - - if (this.debug) { - // retrieve the method getSourcepath() using reflect - // This is done to improve the compatibility to ant 1.5 - Method getDebugLevelMethod = null; - try { - getDebugLevelMethod = javacClass.getMethod("getDebugLevel", null); //$NON-NLS-1$ - } catch(NoSuchMethodException e) { - // if not found, then we cannot use this method (ant 1.5) - // debug level is only available with ant 1.5.x - } - String debugLevel = null; - if (getDebugLevelMethod != null) { + if (this.memoryInitialSize != null) { + if (!this.attributes.isForkedJavac()) { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryInitialSize"), Project.MSG_WARN); //$NON-NLS-1$ + } else { + cmd.createArgument().setValue(memoryParameterPrefix + + "ms" + this.memoryInitialSize); //$NON-NLS-1$ + } + } + + if (this.memoryMaximumSize != null) { + if (!this.attributes.isForkedJavac()) { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryMaximumSize"), Project.MSG_WARN); //$NON-NLS-1$ + } else { + cmd.createArgument().setValue(memoryParameterPrefix + + "mx" + this.memoryMaximumSize); //$NON-NLS-1$ + } + } + + if (this.debug) { + // retrieve the method getSourcepath() using reflect + // This is done to improve the compatibility to ant 1.5 + Method getDebugLevelMethod = null; + try { + getDebugLevelMethod = javacClass.getMethod("getDebugLevel", null); //$NON-NLS-1$ + } catch(NoSuchMethodException e) { + // if not found, then we cannot use this method (ant 1.5) + // debug level is only available with ant 1.5.x + } + String debugLevel = null; + if (getDebugLevelMethod != null) { try { debugLevel = (String) getDebugLevelMethod.invoke(this.attributes, null); } catch (IllegalAccessException e) { @@ -210,7 +210,7 @@ } catch (InvocationTargetException e) { // should never happen } - } + } if (debugLevel != null) { this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); @@ -230,18 +230,18 @@ this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.GENERATE); - } - } else { + } + } else { this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.DO_NOT_GENERATE); - } + } /* * Handle the nowarn option. If none, then we generate all warnings. */ if (this.attributes.getNowarn()) { - // disable all warnings + // disable all warnings Object[] entries = this.customDefaultOptions.entrySet().toArray(); for (int i = 0, max = entries.length; i < max; i++) { Map.Entry entry = (Map.Entry) entries[i]; @@ -269,7 +269,7 @@ this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED); } - /* + /* * destDir option. */ if (this.destDir != null) { @@ -302,20 +302,12 @@ * source option */ String source = this.attributes.getSource(); - if (source != null) { + if (source != null) { this.customDefaultOptions.put(CompilerOptions.OPTION_Source, source); - } - - /* - * encoding option - */ - if (this.encoding != null) { - cmd.createArgument().setValue("-encoding"); //$NON-NLS-1$ - cmd.createArgument().setValue(this.encoding); - } + } if (compilerArgs != null) { - /* + /* * Add extra argument on the command line */ final int length = compilerArgs.length; @@ -325,17 +317,26 @@ if (this.logFileName == null && "-log".equals(arg) && ((i + 1) < max)) { //$NON-NLS-1$ this.logFileName = compilerArgs[i + 1]; } - cmd.createArgument().setValue(arg); + cmd.createArgument().setValue(arg); } } - } - /* + } + /* + * encoding option. javac task encoding property must be the last encoding on the command + * line as compiler arg might also specify an encoding. + */ + if (this.encoding != null) { + cmd.createArgument().setValue("-encoding"); //$NON-NLS-1$ + cmd.createArgument().setValue(this.encoding); + } + + /* * Eclipse compiler doesn't have a -sourcepath option. This is * handled through the javac task that collects all source files in * srcdir option. */ - logAndAddFilesToCompile(cmd); - return cmd; + logAndAddFilesToCompile(cmd); + return cmd; } /** Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 21 Apr 2010 19:04:24 -0000 1.352 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 25 Apr 2010 20:09:45 -0000 @@ -38,6 +38,7 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -105,6 +106,7 @@ public static final int EMACS = 2; private static final String ERROR = "ERROR"; //$NON-NLS-1$ private static final String ERROR_TAG = "error"; //$NON-NLS-1$ + private static final String WARNING_TAG = "warning"; //$NON-NLS-1$ private static final String EXCEPTION = "exception"; //$NON-NLS-1$ private static final String EXTRA_PROBLEM_TAG = "extra_problem"; //$NON-NLS-1$ private static final String EXTRA_PROBLEMS = "extra_problems"; //$NON-NLS-1$ @@ -151,7 +153,7 @@ private static final String VALUE = "value"; //$NON-NLS-1$ private static final String WARNING = "WARNING"; //$NON-NLS-1$ public static final int XML = 1; - private static final String XML_DTD_DECLARATION = ""; //$NON-NLS-1$ + private static final String XML_DTD_DECLARATION = ""; //$NON-NLS-1$ static { try { Class c = IProblem.class; @@ -723,6 +725,17 @@ this.printlnErr(error); } + /** + * @param message the given message + */ + public void logWarning(String message) { + if ((this.tagBits & Logger.XML) != 0) { + this.parameters.put(Logger.MESSAGE, message); + printTag(Logger.WARNING_TAG, this.parameters, true, true); + } + this.printlnOut(message); + } + private void logProblem(CategorizedProblem problem, int localErrorCount, int globalErrorCount, char[] unitSource) { if ((this.tagBits & Logger.EMACS) != 0) { @@ -1736,7 +1749,6 @@ String usageSection = null; boolean printVersionRequired = false; - boolean didSpecifyDefaultEncoding = false; boolean didSpecifyDeprecation = false; boolean didSpecifyCompliance = false; boolean didSpecifyDisabledAnnotationProcessing = false; @@ -1745,6 +1757,8 @@ String customDestinationPath = null; String currentSourceDirectory = null; String currentArg = Util.EMPTY_STRING; + + Set specifiedEncodings = null; // expand the command line if necessary boolean needExpansion = false; @@ -2456,9 +2470,23 @@ mode = DEFAULT; continue; case INSIDE_DEFAULT_ENCODING : - if (didSpecifyDefaultEncoding) { - throw new IllegalArgumentException( - this.bind("configure.duplicateDefaultEncoding", currentArg)); //$NON-NLS-1$ + if (specifiedEncodings != null) { + // check already defined encoding + if (!specifiedEncodings.contains(currentArg)) { + if (specifiedEncodings.size() > 1) { + this.logger.logWarning( + this.bind("configure.differentencodings", //$NON-NLS-1$ + currentArg, + getAllEncodings(specifiedEncodings))); + } else { + this.logger.logWarning( + this.bind("configure.differentencoding", //$NON-NLS-1$ + currentArg, + getAllEncodings(specifiedEncodings))); + } + } + } else { + specifiedEncodings = new HashSet(); } try { // ensure encoding is supported new InputStreamReader(new ByteArrayInputStream(new byte[0]), currentArg); @@ -2466,8 +2494,8 @@ throw new IllegalArgumentException( this.bind("configure.unsupportedEncoding", currentArg)); //$NON-NLS-1$ } + specifiedEncodings.add(currentArg); this.options.put(CompilerOptions.OPTION_Encoding, currentArg); - didSpecifyDefaultEncoding = true; mode = DEFAULT; continue; case INSIDE_DESTINATION_PATH : @@ -2724,6 +2752,11 @@ endorsedDirClasspaths, customEncoding); + if (specifiedEncodings != null && specifiedEncodings.size() > 1) { + this.logger.logWarning(this.bind("configure.multipleencodings", //$NON-NLS-1$ + (String) this.options.get(CompilerOptions.OPTION_Encoding), + getAllEncodings(specifiedEncodings))); + } if (this.pendingErrors != null) { for (Iterator iterator = this.pendingErrors.iterator(); iterator.hasNext(); ) { String message = (String) iterator.next(); @@ -2732,6 +2765,21 @@ this.pendingErrors = null; } } +private static String getAllEncodings(Set encodings) { + int size = encodings.size(); + String[] allEncodings = new String[size]; + encodings.toArray(allEncodings); + Arrays.sort(allEncodings); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < size; i++) { + if (i > 0) { + buffer.append(", "); //$NON-NLS-1$ + } + buffer.append(allEncodings[i]); + } + return String.valueOf(buffer); +} + private void initializeWarnings(String propertiesFile) { File file = new File(propertiesFile); if (!file.exists()) { Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v --- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 23 Apr 2010 13:12:35 -0000 1.893 +++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 25 Apr 2010 20:09:46 -0000 @@ -15,7 +15,7 @@ #Format: compiler.name = word1 word2 word3 compiler.name = Eclipse Compiler for Java(TM) #Format: compiler.version = 0.XXX[, other words (don't forget the comma if adding other words)] -compiler.version = 0.A47, 3.6.0 M7 +compiler.version = 0.A48, 3.6.0 M7 compiler.copyright = Copyright IBM Corp 2000, 2010. All rights reserved. ### progress @@ -97,6 +97,9 @@ configure.multipleClasspathSections = multiple Class-Path headers in manifest of jar file: {0} configure.missingwarningspropertiesfile=properties file {0} does not exist configure.ioexceptionwarningspropertiesfile=An IOException occurred while reading the properties file {0} +configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0} +configure.differentencodings=Found encoding {0}. Different encodings were specified: {1} +configure.differentencoding=Found encoding {0}. A different encoding was specified: {1} ### requestor requestor.error = {0}. ERROR in {1} @@ -155,9 +158,10 @@ \ created); this option can be overridden per source\n\ \ directory\n\ \ -d none generate no .class files\n\ -\ -encoding specify custom encoding for all sources. Each\n\ +\ -encoding specify custom encoding for all sources. If multiple \n\ +\ encodings are specified, the last one will be used. Each\n\ \ file/directory can override it when suffixed with\n\ -\ ''['''']'' (e.g. X.java[utf8])\n\ +\ ''['''']'' (e.g. X.java[utf8]).\n\ \ \n\ \ Compliance options:\n\ \ -1.3 use 1.3 compliance (-source 1.3 -target 1.1)\n\ Index: schema/compiler.dtd =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/schema/compiler.dtd,v --- schema/compiler.dtd 31 Jul 2007 18:28:02 -0000 1.17 +++ schema/compiler.dtd 25 Apr 2010 20:09:46 -0000 @@ -1,9 +1,10 @@ - + + @@ -68,6 +69,7 @@ > + destination directory (if omitted, no directory is\n" + " created); this option can be overridden per source\n" + - " directory\n" + - " -d none generate no .class files\n" + - " -encoding specify custom encoding for all sources. Each\n" + - " file/directory can override it when suffixed with\n" + - " ''['''']'' (e.g. X.java[utf8])\n" + + " directory\n" + + " -d none generate no .class files\n" + + " -encoding specify custom encoding for all sources. If multiple \n" + + " encodings are specified, the last one will be used. Each\n" + + " file/directory can override it when suffixed with\n" + + " ''['''']'' (e.g. X.java[utf8]).\n" + " \n" + " Compliance options:\n" + " -1.3 use 1.3 compliance (-source 1.3 -target 1.1)\n" + @@ -1774,7 +1775,7 @@ String logContents = Util.fileContent(logFileName); String expectedLogContents = "\n" + - "\n" + + "\n" + "\n" + " \n" + " \n" + @@ -11379,4 +11380,33 @@ "1 problem (1 error)", true); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=310330 +public void test305(){ + this.runConformTest( + new String[] { + "src/X.java", + "public class X {}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -encoding UTF-8 -1.5 -g -encoding ISO-8859-1", + "Found encoding ISO-8859-1. A different encoding was specified: UTF-8\n" + + "Multiple encoding specified: ISO-8859-1, UTF-8. The default encoding has been set to ISO-8859-1\n", + "", + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=310330 +public void test306(){ + this.runConformTest( + new String[] { + "src/X.java", + "public class X {}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -encoding UTF-8 -1.5 -encoding Cp1252 -g -encoding ISO-8859-1", + "Found encoding Cp1252. A different encoding was specified: UTF-8\n" + + "Found encoding ISO-8859-1. Different encodings were specified: Cp1252, UTF-8\n" + + "Multiple encoding specified: Cp1252, ISO-8859-1, UTF-8. The default encoding has been set to ISO-8859-1\n", + "", + true); +} } Index: guide/jdt_api_compile.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm,v --- guide/jdt_api_compile.htm 21 Apr 2010 19:04:26 -0000 1.79 +++ guide/jdt_api_compile.htm 25 Apr 2010 20:09:51 -0000 @@ -158,8 +158,8 @@ -encoding <encoding name> -Specify default source encoding format (custom encoding can also be specified on a per file basis by suffixing each input source file/folder name with [<encoding name>], - for example X.java[utf8]). +Specify default source encoding format. If multiple encodings are specified, the last one will be used. Custom encoding can also be specified on a per file basis by suffixing each input source file/folder name with [<encoding name>], + for example X.java[utf8]. Compliance options