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