001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.tools.javac;
019:
020: import java.io.PrintWriter;
021: import java.io.File;
022: import org.apache.harmony.tools.toolutils.Util;
023:
024: /**
025: * This is the entry point for the javac tool.
026: */
027: public final class Main {
028:
029: /*
030: * Command-line tool invokes this method.
031: */
032: public static void main(String[] args) {
033: new Main().compile(args);
034: }
035:
036: /**
037: * Default constructor.
038: */
039: public Main() {
040: super ();
041: }
042:
043: /**
044: * Invokes the ECJ compiler with the given arguments.
045: *
046: * @param args
047: * the arguments passed through to the compiler
048: * @return true on compilation success, false on failure
049: */
050: public boolean compile(String[] args) {
051:
052: return compile(args, Util.getDefaultWriter(System.out), Util
053: .getDefaultWriter(System.err));
054: }
055:
056: /**
057: * Invokes the ECJ compiler with the given arguments.
058: *
059: * @param args
060: * the arguments passed through to the compiler
061: * @param out
062: * get the output from System.out
063: * @param err
064: * get the output from System.err
065: * @return true on compilation success, false on failure
066: */
067: public boolean compile(String[] args, PrintWriter out,
068: PrintWriter err) {
069:
070: /* Give me something to do */
071: if (args == null || args.length == 0) {
072: new Compiler(out, err).printUsage();
073: return false;
074: }
075:
076: /* Add in the base class library code to compile against */
077: String[] newArgs = addBootclasspath(args);
078:
079: /* Invoke the compiler */
080: return Compiler.main(newArgs, out, err);
081: }
082:
083: /*
084: * Set up the compiler option to compile against the running JRE class
085: * libraries.
086: */
087: private String[] addBootclasspath(String[] args) {
088: StringBuilder sb = new StringBuilder();
089: String[] result = new String[args.length + 2];
090:
091: System.arraycopy(args, 0, result, 0, args.length);
092: result[args.length] = "-classpath"; //$NON-NLS-1$
093: sb.append(System.getProperty(
094: "org.apache.harmony.boot.class.path", ".")); //$NON-NLS-1$ //$NON-NLS-2$
095: sb.append(File.pathSeparator);
096: sb.append(System.getProperty("sun.boot.class.path", ".")); //$NON-NLS-1$ //$NON-NLS-2$
097: sb.append(File.pathSeparator);
098: sb.append("."); //$NON-NLS-1$
099: result[args.length + 1] = sb.toString();
100: return result;
101: }
102: }
|