Ben Konrath d4e9e3
Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties
Ben Konrath d4e9e3
===================================================================
Ben Konrath d4e9e3
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v
Ben Konrath d4e9e3
retrieving revision 1.546.2.23
Ben Konrath d4e9e3
diff -u -r1.546.2.23 messages.properties
Ben Konrath d4e9e3
--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties	8 Feb 2007 15:04:43 -0000	1.546.2.23
Ben Konrath d4e9e3
+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties	26 Feb 2007 18:21:06 -0000
Ben Konrath d4e9e3
@@ -249,3 +249,8 @@
Ben Konrath d4e9e3
 template.restrictedAccess.constructor = The constructor {0} is not accessible due to restriction on classpath entry {1}
Ben Konrath d4e9e3
 template.restrictedAccess.field = The field {0} from the type {1} is not accessible due to restriction on classpath entry {2}
Ben Konrath d4e9e3
 template.restrictedAccess.method = The method {0} from the type {1} is not accessible due to restriction on classpath entry {2}
Ben Konrath d4e9e3
+
Ben Konrath d4e9e3
+# GCCMain messages.
Ben Konrath d4e9e3
+gcc.zipArg=-fzip-target requires argument
Ben Konrath d4e9e3
+gcc.zipDepArg=-fzip-dependency requires argument
Ben Konrath d4e9e3
+gcc.noClasspath=no classpath specified
Andrew Overholt 0e12cd
Index: batch/org/eclipse/jdt/internal/compiler/batch/GCCMain.java
Andrew Overholt 0e12cd
===================================================================
Andrew Overholt 0e12cd
RCS file: batch/org/eclipse/jdt/internal/compiler/batch/GCCMain.java
Andrew Overholt 0e12cd
diff -N batch/org/eclipse/jdt/internal/compiler/batch/GCCMain.java
Andrew Overholt 0e12cd
--- /dev/null	1 Jan 1970 00:00:00 -0000
Andrew Overholt 0e12cd
+++ batch/org/eclipse/jdt/internal/compiler/batch/GCCMain.java	1 Jan 1970 00:00:00 -0000
Ben Konrath 438277
@@ -0,0 +1,495 @@
Andrew Overholt 0e12cd
+/**
Andrew Overholt 0e12cd
+ * 
Andrew Overholt 0e12cd
+ */
Andrew Overholt 0e12cd
+package org.eclipse.jdt.internal.compiler.batch;
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+import java.io.BufferedOutputStream;
Andrew Overholt 0e12cd
+import java.io.BufferedReader;
Andrew Overholt 0e12cd
+import java.io.ByteArrayInputStream;
Andrew Overholt 0e12cd
+import java.io.File;
Andrew Overholt 0e12cd
+import java.io.FileOutputStream;
Andrew Overholt 0e12cd
+import java.io.FileReader;
Andrew Overholt 0e12cd
+import java.io.IOException;
Andrew Overholt 0e12cd
+import java.io.InputStreamReader;
Andrew Overholt 0e12cd
+import java.io.OutputStream;
Andrew Overholt 0e12cd
+import java.io.PrintWriter;
Andrew Overholt 0e12cd
+import java.io.UnsupportedEncodingException;
Andrew Overholt 0e12cd
+import java.util.ArrayList;
Andrew Overholt 0e12cd
+import java.util.HashSet;
Andrew Overholt 0e12cd
+import java.util.Iterator;
Andrew Overholt 0e12cd
+import java.util.Map;
Andrew Overholt 0e12cd
+import java.util.StringTokenizer;
Andrew Overholt 0e12cd
+import java.util.zip.CRC32;
Andrew Overholt 0e12cd
+import java.util.zip.ZipEntry;
Andrew Overholt 0e12cd
+import java.util.zip.ZipOutputStream;
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+import org.eclipse.jdt.core.compiler.InvalidInputException;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.ClassFile;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.CompilationResult;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.env.AccessRule;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.util.Messages;
Andrew Overholt 0e12cd
+import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+/**
Andrew Overholt 0e12cd
+ * This is an alternate entry point for the command-line compiler which
Andrew Overholt 0e12cd
+ * is simpler to integrate into GCC.  In particular the option processing
Andrew Overholt 0e12cd
+ * is more GNU-like and the recognized options are similar to those supported
Andrew Overholt 0e12cd
+ * by other GCC front ends.
Andrew Overholt 0e12cd
+ */
Andrew Overholt 0e12cd
+public class GCCMain extends Main {
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	// All the compilation units specified on the command line.
Andrew Overholt 0e12cd
+	private HashSet commandLineCompilationUnits = new HashSet();
Andrew Overholt 0e12cd
+	// True if we are only checking syntax.
Andrew Overholt 0e12cd
+	private boolean syntaxOnly;
Andrew Overholt 0e12cd
+	// If not null, the name of the output zip file.
Andrew Overholt 0e12cd
+	// If null, we are generating class files in the file system,
Andrew Overholt 0e12cd
+	// not a zip file.
Andrew Overholt 0e12cd
+	private String zipDestination;
Andrew Overholt 0e12cd
+	// The zip stream to which we're writing, or null if it hasn't been opened.
Andrew Overholt 0e12cd
+	private ZipOutputStream zipStream;
Andrew Overholt 0e12cd
+	
Andrew Overholt 0e12cd
+	// If not null, the name of the zip file to which dependency class files
Andrew Overholt 0e12cd
+	// should be written.
Andrew Overholt 0e12cd
+	private String zipDependencyDestination;
Andrew Overholt 0e12cd
+	// The zip stream to which dependency files should be written.
Andrew Overholt 0e12cd
+	private ZipOutputStream zipDependencyStream;
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public GCCMain(PrintWriter outWriter, PrintWriter errWriter,
Andrew Overholt 0e12cd
+			boolean systemExitWhenFinished) {
Andrew Overholt 0e12cd
+		super(outWriter, errWriter, systemExitWhenFinished);
Andrew Overholt 0e12cd
+		this.logger.setEmacs();
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public GCCMain(PrintWriter outWriter, PrintWriter errWriter,
Andrew Overholt 0e12cd
+			boolean systemExitWhenFinished, Map customDefaultOptions) {
Andrew Overholt 0e12cd
+		super(outWriter, errWriter, systemExitWhenFinished,
Andrew Overholt 0e12cd
+				customDefaultOptions);
Andrew Overholt 0e12cd
+		this.logger.setEmacs();
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private void fail(Exception t) {
Andrew Overholt 0e12cd
+		this.logger.logException(t);
Andrew Overholt 0e12cd
+		System.exit(1);
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public CompilationUnit[] getCompilationUnits() throws InvalidInputException {
Andrew Overholt 0e12cd
+		CompilationUnit[] units = super.getCompilationUnits();
Andrew Overholt 0e12cd
+		for (int i = 0; i < units.length; ++i)
Andrew Overholt 0e12cd
+			this.commandLineCompilationUnits.add(units[i]);
Andrew Overholt 0e12cd
+		return units;
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private String combine(char[] one, char[] two) {
Andrew Overholt 0e12cd
+		StringBuffer b = new StringBuffer();
Andrew Overholt 0e12cd
+		b.append(one);
Andrew Overholt 0e12cd
+		b.append(two);
Andrew Overholt 0e12cd
+		return b.toString();
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private ZipOutputStream getZipOutput() throws IOException {
Andrew Overholt 0e12cd
+		if (this.zipDestination != null && this.zipStream == null) {
Andrew Overholt 0e12cd
+			OutputStream os;
Andrew Overholt 0e12cd
+			if ("-".equals(this.zipDestination)) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				os = System.out;
Andrew Overholt 0e12cd
+			} else {
Andrew Overholt 0e12cd
+				os = new FileOutputStream(this.zipDestination);
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+			zipStream = new ZipOutputStream(new BufferedOutputStream(os));
Andrew Overholt 0e12cd
+			zipStream.setMethod(ZipOutputStream.STORED);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		return zipStream;
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private ZipOutputStream getDependencyOutput() throws IOException {
Andrew Overholt 0e12cd
+		if (this.zipDependencyDestination != null && this.zipDependencyStream == null) {
Andrew Overholt 0e12cd
+			OutputStream os = new FileOutputStream(zipDependencyDestination);
Andrew Overholt 0e12cd
+			zipDependencyStream = new ZipOutputStream(new BufferedOutputStream(os));
Andrew Overholt 0e12cd
+			zipDependencyStream.setMethod(ZipOutputStream.STORED);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		return zipDependencyStream;
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public void outputClassFiles(CompilationResult unitResult) {
Andrew Overholt 0e12cd
+		if (this.syntaxOnly) {
Andrew Overholt 0e12cd
+			return;
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		if (this.zipDestination == null) {
Andrew Overholt 0e12cd
+			// Nothing special to do here.
Andrew Overholt 0e12cd
+			super.outputClassFiles(unitResult);
Andrew Overholt 0e12cd
+			return;
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		if (unitResult == null || unitResult.hasErrors()) {
Andrew Overholt 0e12cd
+			return;
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		// If we are compiling with indirect dispatch, we don't need
Andrew Overholt 0e12cd
+		// any dependent classes.  If we are using the C++ ABI, then we
Andrew Overholt 0e12cd
+		// do need the dependencies in order to do proper layout.
Andrew Overholt 0e12cd
+		boolean gcjCompile = this.commandLineCompilationUnits.contains(unitResult.getCompilationUnit());
Andrew Overholt 0e12cd
+		if (this.zipDependencyDestination == null && !gcjCompile) {
Andrew Overholt 0e12cd
+			return;
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		try {
Andrew Overholt 0e12cd
+			ZipOutputStream dest = gcjCompile ? getZipOutput() : getDependencyOutput();
Andrew Overholt 0e12cd
+			ClassFile[] classFiles = unitResult.getClassFiles();
Andrew Overholt 0e12cd
+			for (int i = 0; i < classFiles.length; ++i) {
Andrew Overholt 0e12cd
+				ClassFile classFile = classFiles[i];
Andrew Overholt 0e12cd
+				String filename = combine(classFile.fileName(), SuffixConstants.SUFFIX_class);
Andrew Overholt 0e12cd
+				if (this.verbose)
Andrew Overholt 0e12cd
+					this.out.println(
Andrew Overholt 0e12cd
+							Messages.bind(
Andrew Overholt 0e12cd
+									Messages.compilation_write,
Andrew Overholt 0e12cd
+									new String[] {
Andrew Overholt 0e12cd
+								String.valueOf(this.exportedClassFilesCounter+1),
Andrew Overholt 0e12cd
+								filename
Andrew Overholt 0e12cd
+							}));
Andrew Overholt 0e12cd
+				ZipEntry entry = new ZipEntry(filename);
Andrew Overholt 0e12cd
+				byte[] contents = classFile.getBytes();
Andrew Overholt 0e12cd
+				CRC32 crc = new CRC32();
Andrew Overholt 0e12cd
+				crc.update(contents);
Andrew Overholt 0e12cd
+				entry.setSize(contents.length);
Andrew Overholt 0e12cd
+				entry.setCrc(crc.getValue());
Andrew Overholt 0e12cd
+				dest.putNextEntry(entry);
Andrew Overholt 0e12cd
+				dest.write(contents);
Andrew Overholt 0e12cd
+				dest.closeEntry();
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+		} catch (IOException err) {
Andrew Overholt 0e12cd
+			fail(err);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+	
Andrew Overholt 0e12cd
+	private String getArgument(String option) {
Andrew Overholt 0e12cd
+		int index = option.indexOf('=');
Andrew Overholt 0e12cd
+		return option.substring(index + 1);
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private void addPath(ArrayList result, String currentClasspathName) {
Andrew Overholt 0e12cd
+		String customEncoding = null;
Andrew Overholt 0e12cd
+		AccessRule[] accessRules = new AccessRule[0];
Andrew Overholt 0e12cd
+		String templates[] = new String[AccessRuleSet.MESSAGE_TEMPLATES_LENGTH];
Ben Konrath 438277
+		templates[0] = this.bind(
Andrew Overholt 0e12cd
+			"template.restrictedAccess.type", //$NON-NLS-1$
Andrew Overholt 0e12cd
+			new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ 
Ben Konrath 438277
+		templates[1] = this.bind(
Andrew Overholt 0e12cd
+			"template.restrictedAccess.constructor", //$NON-NLS-1$
Andrew Overholt 0e12cd
+			new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ 
Ben Konrath 438277
+		templates[2] = this.bind(
Andrew Overholt 0e12cd
+			"template.restrictedAccess.method", //$NON-NLS-1$
Andrew Overholt 0e12cd
+			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
Ben Konrath 438277
+		templates[3] = this.bind(
Andrew Overholt 0e12cd
+			"template.restrictedAccess.field", //$NON-NLS-1$
Andrew Overholt 0e12cd
+			new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ 
Andrew Overholt 0e12cd
+		AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates);
Andrew Overholt 0e12cd
+		FileSystem.Classpath currentClasspath = FileSystem
Andrew Overholt 0e12cd
+				.getClasspath(currentClasspathName,
Andrew Overholt 0e12cd
+						customEncoding, accessRuleSet);
Andrew Overholt 0e12cd
+		if (currentClasspath != null) {
Andrew Overholt 0e12cd
+			result.add(currentClasspath);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+	
Andrew Overholt 0e12cd
+	private void parsePath(ArrayList result, String path) {
Andrew Overholt 0e12cd
+		StringTokenizer iter = new StringTokenizer(path, File.pathSeparator);
Andrew Overholt 0e12cd
+		while (iter.hasMoreTokens()) {
Andrew Overholt 0e12cd
+			addPath(result, iter.nextToken());
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	protected void handleWarningToken(String token, boolean isEnabling,
Andrew Overholt 0e12cd
+			boolean useEnableJavadoc) throws InvalidInputException {
Andrew Overholt 0e12cd
+		// Recognize this for compatibility with older versions of gcj.
Andrew Overholt 0e12cd
+		if ("deprecated".equals(token)) //$NON-NLS-1$
Andrew Overholt 0e12cd
+			token = "deprecation"; //$NON-NLS-1$
Andrew Overholt 0e12cd
+		else if ("static-access".equals(token)   //$NON-NLS-1$
Andrew Overholt 0e12cd
+				|| "dep-ann".equals(token) //$NON-NLS-1$
Andrew Overholt 0e12cd
+				|| "over-ann".equals(token)) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+			// Some exceptions to the warning naming rule.
Andrew Overholt 0e12cd
+		} else if ("extraneous-semicolon".equals(token)) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+			// Compatibility with earlier versions of gcj.
Andrew Overholt 0e12cd
+			token = "semicolon"; //$NON-NLS-1$
Andrew Overholt 0e12cd
+		} else {
Andrew Overholt 0e12cd
+			// Turn "foo-bar-baz" into eclipse-style "fooBarBaz".
Andrew Overholt 0e12cd
+			StringBuffer newToken = new StringBuffer(token.length());
Andrew Overholt 0e12cd
+			StringTokenizer t = new StringTokenizer(token, "-"); //$NON-NLS-1$
Andrew Overholt 0e12cd
+			boolean first = true;
Andrew Overholt 0e12cd
+			while (t.hasMoreTokens()) {
Andrew Overholt 0e12cd
+				String next = t.nextToken();
Andrew Overholt 0e12cd
+				if (first) {
Andrew Overholt 0e12cd
+					newToken.append(next);
Andrew Overholt 0e12cd
+					first = false;
Andrew Overholt 0e12cd
+				} else {
Andrew Overholt 0e12cd
+					newToken.append(Character.toUpperCase(next.charAt(0)));
Andrew Overholt 0e12cd
+					newToken.append(next.substring(1));
Andrew Overholt 0e12cd
+				}
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+			token = newToken.toString();
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		super.handleWarningToken(token, isEnabling, useEnableJavadoc);
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Ben Konrath 438277
+	private void turnWarningsToErrors() {
Ben Konrath 438277
+		Object[] entries = this.options.entrySet().toArray();
Ben Konrath 438277
+		for (int i = 0, max = entries.length; i < max; i++) {
Ben Konrath 438277
+			Map.Entry entry = (Map.Entry) entries[i];
Ben Konrath 438277
+			if (!(entry.getKey() instanceof String))
Ben Konrath 438277
+				continue;
Ben Konrath 438277
+			if (!(entry.getValue() instanceof String))
Ben Konrath 438277
+				continue;
Ben Konrath 438277
+			if (((String) entry.getValue()).equals(CompilerOptions.WARNING)) {
Ben Konrath 438277
+				this.options.put(entry.getKey(), CompilerOptions.ERROR);
Ben Konrath 438277
+			}
Ben Konrath 438277
+		}
Ben Konrath 438277
+	}
Ben Konrath 438277
+
Andrew Overholt 0e12cd
+	/**
Andrew Overholt 0e12cd
+	 * Set the debug level to the indicated value.  The level should be
Andrew Overholt 0e12cd
+	 * between 0 and 2, inclusive, but this is not checked.
Andrew Overholt 0e12cd
+	 * @param level the debug level
Andrew Overholt 0e12cd
+	 */
Andrew Overholt 0e12cd
+	private void setDebugLevel(int level) {
Andrew Overholt 0e12cd
+		this.options.put(
Andrew Overholt 0e12cd
+				CompilerOptions.OPTION_LocalVariableAttribute,
Andrew Overholt 0e12cd
+				level > 1 ? CompilerOptions.GENERATE : CompilerOptions.DO_NOT_GENERATE);
Andrew Overholt 0e12cd
+		this.options.put(
Andrew Overholt 0e12cd
+				CompilerOptions.OPTION_LineNumberAttribute,
Andrew Overholt 0e12cd
+				level > 0 ? CompilerOptions.GENERATE : CompilerOptions.DO_NOT_GENERATE);
Andrew Overholt 0e12cd
+		this.options.put(
Andrew Overholt 0e12cd
+				CompilerOptions.OPTION_SourceFileAttribute,
Andrew Overholt 0e12cd
+				CompilerOptions.GENERATE);
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	private void readFileList(String file, ArrayList result) {
Andrew Overholt 0e12cd
+		try {
Andrew Overholt 0e12cd
+			BufferedReader b = new BufferedReader(new FileReader(file));
Andrew Overholt 0e12cd
+			String line;
Andrew Overholt 0e12cd
+			while ((line = b.readLine()) != null) {
Andrew Overholt 0e12cd
+				if (line.endsWith(SUFFIX_STRING_java))
Andrew Overholt 0e12cd
+					result.add(line);
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+			b.close();
Andrew Overholt 0e12cd
+		} catch (IOException err) {
Andrew Overholt 0e12cd
+			fail(err);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+	
Andrew Overholt 0e12cd
+	private void readAllFileListFiles(ArrayList fileList, ArrayList result) {
Andrew Overholt 0e12cd
+		Iterator it = fileList.iterator();
Andrew Overholt 0e12cd
+		while (it.hasNext()) {
Andrew Overholt 0e12cd
+			readFileList((String) it.next(), result);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Ben Konrath 438277
+	private void handleWall(boolean enable) throws InvalidInputException {
Ben Konrath 438277
+		// A somewhat arbitrary list.  We use the GCC names
Ben Konrath 438277
+		// here, and the local handleWarningToken translates
Ben Konrath 438277
+		// for us.
Ben Konrath 438277
+		handleWarningToken("constructor-name", enable, false);
Ben Konrath 438277
+		handleWarningToken("pkg-default-method", enable, false);
Ben Konrath 438277
+		handleWarningToken("masked-catch-block", enable, false);
Ben Konrath 438277
+		handleWarningToken("all-deprecation", enable, false);
Ben Konrath 438277
+		handleWarningToken("unused-local", enable, false);
Ben Konrath 438277
+		handleWarningToken("unused-label", enable, false);
Ben Konrath 438277
+		handleWarningToken("static-receiver", enable, false);
Ben Konrath 438277
+		handleWarningToken("indirect-static", enable, false);
Ben Konrath 438277
+		handleWarningToken("no-effect-assign", enable, false);
Ben Konrath 438277
+		handleWarningToken("char-concat", enable, false);
Ben Konrath 438277
+		handleWarningToken("useless-type-check", enable, false);
Ben Konrath 438277
+		handleWarningToken("final-bound", enable, false);
Ben Konrath 438277
+		handleWarningToken("assert-identifier", enable, false);
Ben Konrath 438277
+		handleWarningToken("enum-identifier", enable, false);
Ben Konrath 438277
+		handleWarningToken("finally", enable, false);
Ben Konrath 438277
+		handleWarningToken("varargs-cast", enable, false);
Ben Konrath 438277
+		handleWarningToken("unused", enable, false);
Ben Konrath 438277
+		handleWarningToken("forbidden", enable, false);
Ben Konrath 438277
+	}
Ben Konrath 438277
+
Andrew Overholt 0e12cd
+	public void configure(String[] argv) throws InvalidInputException {
Andrew Overholt 0e12cd
+		if ((argv == null) || (argv.length == 0)) {
Andrew Overholt 0e12cd
+			// This is a "can't happen".
Andrew Overholt 0e12cd
+			System.exit(1);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		ArrayList files = new ArrayList();
Andrew Overholt 0e12cd
+		ArrayList otherFiles = new ArrayList();
Andrew Overholt 0e12cd
+		String classpath = null;
Andrew Overholt 0e12cd
+		boolean haveFileList = false;
Ben Konrath 438277
+		boolean inhibitAllWarnings = false;
Ben Konrath 438277
+		boolean treatWarningsAsErrors = false;
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		for (int i = 0; i < argv.length; ++i) {
Andrew Overholt 0e12cd
+			String currentArg = argv[i];
Andrew Overholt 0e12cd
+			
Andrew Overholt 0e12cd
+			if (currentArg.startsWith("-fencoding=")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				// Simply accept the last one.
Andrew Overholt 0e12cd
+				String encoding = getArgument(currentArg);
Andrew Overholt 0e12cd
+				try { // ensure encoding is supported
Andrew Overholt 0e12cd
+					new InputStreamReader(new ByteArrayInputStream(new byte[0]), encoding);
Andrew Overholt 0e12cd
+				} catch (UnsupportedEncodingException e) {
Andrew Overholt 0e12cd
+					throw new InvalidInputException(
Ben Konrath 438277
+						this.bind("configure.unsupportedEncoding", encoding)); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				}
Andrew Overholt 0e12cd
+				this.options.put(CompilerOptions.OPTION_Encoding, encoding);
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-foutput-class-dir=")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				String arg = getArgument(currentArg);
Andrew Overholt 0e12cd
+				if (this.destinationPath != null) {
Andrew Overholt 0e12cd
+					StringBuffer errorMessage = new StringBuffer();
Andrew Overholt 0e12cd
+					errorMessage.append("-d"); //$NON-NLS-1$
Andrew Overholt 0e12cd
+					errorMessage.append(' ');
Andrew Overholt 0e12cd
+					errorMessage.append(arg);
Andrew Overholt 0e12cd
+					throw new InvalidInputException(
Ben Konrath 438277
+						this.bind("configure.duplicateOutputPath", errorMessage.toString())); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				}
Andrew Overholt 0e12cd
+				this.destinationPath = arg;
Ben Konrath 491b3a
+				// this.generatePackagesStructure = true;
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-fbootclasspath=")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				classpath = getArgument(currentArg);
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-fzip-target")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				++i;
Andrew Overholt 0e12cd
+				if (i >= argv.length)
Ben Konrath 438277
+					throw new InvalidInputException(this.bind("gcc.zipArg")); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				this.zipDestination = argv[i];
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-fzip-dependency")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				++i;
Andrew Overholt 0e12cd
+				if (i >= argv.length)
Ben Konrath 438277
+					throw new InvalidInputException(this.bind("gcc.zipDepArg")); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				this.zipDependencyDestination = argv[i];
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-g")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				if (currentArg.equals("-g0")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					setDebugLevel(0);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("-g2") || currentArg.equals("-g3") //$NON-NLS-1$ //$NON-NLS-2$
Andrew Overholt 0e12cd
+						|| currentArg.equals("-g")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					setDebugLevel(2);
Andrew Overholt 0e12cd
+				} else {
Andrew Overholt 0e12cd
+					// Handle -g1 but also things like -gstabs.
Andrew Overholt 0e12cd
+					setDebugLevel(1);
Andrew Overholt 0e12cd
+				}
Ben Konrath 438277
+			} else if (currentArg.equals("-Werror")) { //$NON-NLS-1$
Ben Konrath 438277
+				treatWarningsAsErrors = true;
Ben Konrath 438277
+			} else if (currentArg.equals("-Wno-error")) { //$NON-NLS-1$
Ben Konrath 438277
+				treatWarningsAsErrors = false;
Ben Konrath 438277
+			} else if (currentArg.equals("-Wall")) { //$NON-NLS-1$
Ben Konrath 438277
+				handleWall(true);
Ben Konrath 438277
+			} else if (currentArg.equals("-Wno-all")) { //$NON-NLS-1$
Ben Konrath 438277
+				handleWall(false);
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-Wno-")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				handleWarningToken(currentArg.substring(5), false, false);
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-W")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				handleWarningToken(currentArg.substring(2), true, false);
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-w")) { //$NON-NLS-1$
Ben Konrath 438277
+				inhibitAllWarnings = true;
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-O")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				// Ignore.
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-v")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				this.verbose = true;
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-fsyntax-only")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				this.syntaxOnly = true;
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-fsource=")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				currentArg = getArgument(currentArg);
Andrew Overholt 0e12cd
+				if (currentArg.equals("1.3")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
Andrew Overholt 0e12cd
+				} else {
Ben Konrath 438277
+					throw new InvalidInputException(this.bind("configure.source", currentArg)); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				}
Andrew Overholt 0e12cd
+			} else if (currentArg.startsWith("-ftarget=")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				currentArg = getArgument(currentArg);
Andrew Overholt 0e12cd
+				if (currentArg.equals("1.1")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.2")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.3")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.4")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
Andrew Overholt 0e12cd
+				} else if (currentArg.equals("jsr14")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+					this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14);
Andrew Overholt 0e12cd
+				} else {
Ben Konrath 438277
+					throw new InvalidInputException(this.bind("configure.targetJDK", currentArg)); //$NON-NLS-1$
Andrew Overholt 0e12cd
+				}
Andrew Overholt 0e12cd
+			} else if (currentArg.equals("-ffilelist-file")) { //$NON-NLS-1$
Andrew Overholt 0e12cd
+				haveFileList = true;
Andrew Overholt 0e12cd
+			} else if (currentArg.endsWith(SuffixConstants.SUFFIX_STRING_java)) {
Andrew Overholt 0e12cd
+				files.add(currentArg);
Andrew Overholt 0e12cd
+			} else if (currentArg.charAt(0) == '-'){
Andrew Overholt 0e12cd
+				// FIXME: error if not a file?
Andrew Overholt 0e12cd
+			} else {
Andrew Overholt 0e12cd
+				otherFiles.add(currentArg);
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		// Read the file list file.  We read them all, but really there
Andrew Overholt 0e12cd
+		// will only be one.
Andrew Overholt 0e12cd
+		if (haveFileList)
Andrew Overholt 0e12cd
+			readAllFileListFiles(otherFiles, files);
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		this.filenames = (String[]) files.toArray(new String[0]);
Andrew Overholt 0e12cd
+		this.encodings = new String[this.filenames.length];
Ben Konrath 438277
+		this.destinationPaths = new String[this.filenames.length];
Ben Konrath 438277
+		for (int i = 0; i < this.filenames.length; ++i)
Ben Konrath 438277
+			this.destinationPaths[i] = this.destinationPath;
Andrew Overholt 0e12cd
+		
Andrew Overholt 0e12cd
+		// Classpath processing.
Andrew Overholt 0e12cd
+		ArrayList result = new ArrayList();
Andrew Overholt 0e12cd
+		if (classpath == null)
Ben Konrath 438277
+			throw new InvalidInputException(this.bind("gcc.noClasspath")); //$NON-NLS-1$
Andrew Overholt 0e12cd
+		parsePath(result, classpath);
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		// We must always create both output files, even if one is not used.
Andrew Overholt 0e12cd
+		// That way we will always pass valid zip file on to jc1.
Andrew Overholt 0e12cd
+		try {
Andrew Overholt 0e12cd
+			getZipOutput();
Andrew Overholt 0e12cd
+			getDependencyOutput();
Andrew Overholt 0e12cd
+		} catch (IOException err) {
Andrew Overholt 0e12cd
+			fail(err);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+
Ben Konrath 438277
+		if (inhibitAllWarnings)
Ben Konrath 438277
+			disableWarnings();
Ben Konrath 438277
+		if (treatWarningsAsErrors)
Ben Konrath 438277
+			turnWarningsToErrors();
Ben Konrath 438277
+
Andrew Overholt 0e12cd
+		this.checkedClasspaths = new FileSystem.Classpath[result.size()];
Andrew Overholt 0e12cd
+		result.toArray(this.checkedClasspaths);
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+		this.logger.logCommandLineArguments(argv);
Andrew Overholt 0e12cd
+		this.logger.logOptions(this.options);
Andrew Overholt 0e12cd
+		this.logger.logClasspath(this.checkedClasspaths);
Andrew Overholt 0e12cd
+		
Andrew Overholt 0e12cd
+		this.repetitions = 1;
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public boolean compile(String[] argv) {
Andrew Overholt 0e12cd
+		boolean result = super.compile(argv);
Andrew Overholt 0e12cd
+		try {
Andrew Overholt 0e12cd
+			if (zipStream != null) {
Andrew Overholt 0e12cd
+				zipStream.finish();
Andrew Overholt 0e12cd
+				zipStream.close();
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+			if (zipDependencyStream != null) {
Andrew Overholt 0e12cd
+				zipDependencyStream.finish();
Andrew Overholt 0e12cd
+				zipDependencyStream.close();
Andrew Overholt 0e12cd
+			}
Andrew Overholt 0e12cd
+		} catch (IOException err) {
Andrew Overholt 0e12cd
+			fail(err);
Andrew Overholt 0e12cd
+		}
Andrew Overholt 0e12cd
+		return result;
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+
Andrew Overholt 0e12cd
+	public static void main(String[] argv) {
Andrew Overholt 0e12cd
+		boolean result = new GCCMain(new PrintWriter(System.out), new PrintWriter(System.err), false).compile(argv);
Andrew Overholt 0e12cd
+		System.exit(result ? 0 : 1);
Andrew Overholt 0e12cd
+	}
Andrew Overholt 0e12cd
+}