Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 166022 Details for
Bug 310330
Add multiple encoding support for the batch compiler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_310330.txt (text/plain), 15.76 KB, created by
Olivier Thomann
on 2010-04-25 14:24:33 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-04-25 14:24:33 EDT
Size:
15.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java,v >retrieving revision 1.68 >diff -u -r1.68 JDTCompilerAdapter.java >--- 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 18:24:13 -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 >retrieving revision 1.352 >diff -u -r1.352 Main.java >--- 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 18:24:14 -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; >@@ -1736,7 +1737,6 @@ > String usageSection = null; > boolean printVersionRequired = false; > >- boolean didSpecifyDefaultEncoding = false; > boolean didSpecifyDeprecation = false; > boolean didSpecifyCompliance = false; > boolean didSpecifyDisabledAnnotationProcessing = false; >@@ -1745,6 +1745,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 +2458,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.logPendingError( >+ this.bind("configure.differentencodings", //$NON-NLS-1$ >+ currentArg, >+ getAllEncodings(specifiedEncodings))); >+ } else { >+ this.logger.logPendingError( >+ 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 +2482,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 +2740,11 @@ > endorsedDirClasspaths, > customEncoding); > >+ if (specifiedEncodings != null && specifiedEncodings.size() > 1) { >+ this.logger.logPendingError(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 +2753,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 >retrieving revision 1.893 >diff -u -r1.893 messages.properties >--- 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 18:24:14 -0000 >@@ -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}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 310330
:
166022
|
166033