/* 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.harmony.tools.javac;

import java.io.PrintWriter;
import java.io.File;
import org.apache.harmony.tools.toolutils.Util;

/**
 * This is the entry point for the javac tool.
 */
public final class Main {

    /*
     * Command-line tool invokes this method.
     */
    public static void main(String[] args) {
        new Main().compile(args);
    }

    /**
     * Default constructor.
     */
    public Main() {
        super();
    }

    /**
     * Invokes the ECJ compiler with the given arguments.
     * 
     * @param args
     *            the arguments passed through to the compiler
     * @return true on compilation success, false on failure
     */
    public boolean compile(String[] args) {

        return compile(args,Util.getDefaultWriter(System.out), Util.getDefaultWriter(System.err));
    }

    /**
     * Invokes the ECJ compiler with the given arguments.
     * 
     * @param args
     *            the arguments passed through to the compiler
     * @param out
     *            get the output from System.out
     * @param err
     *            get the output from System.err
     * @return true on compilation success, false on failure
     */
    public boolean compile(String[] args, PrintWriter out, PrintWriter err) {

        /* Give me something to do */
        if (args == null || args.length == 0) {
            new Compiler(out, err).printUsage();
            return false;
        }

        /* Add in the base class library code to compile against */
        String[] newArgs = addBootclasspath(args);

        /* Invoke the compiler */
        return Compiler.main(newArgs, out, err);
    }

    /*
     * Set up the compiler option to compile against the running JRE class
     * libraries.
     */
    private String[] addBootclasspath(String[] args) {
        StringBuilder sb = new StringBuilder();
        String[] result = new String[args.length + 2];

        System.arraycopy(args, 0, result, 0, args.length);
        result[args.length] = "-classpath"; //$NON-NLS-1$
        sb.append(System.getProperty(
                 "org.apache.harmony.boot.class.path", ".")); //$NON-NLS-1$ //$NON-NLS-2$
        sb.append(File.pathSeparator);
        sb.append(System.getProperty(
                 "sun.boot.class.path", ".")); //$NON-NLS-1$ //$NON-NLS-2$
        sb.append(File.pathSeparator);
        sb.append("."); //$NON-NLS-1$
        result[args.length + 1] = sb.toString();
        return result;
    }
}

@@ -1016,24 +1016,198 @@
 ass Main %7B%0A%0A
+    // javac tool return codes%0A    public static final int RC_SUCCESS = 0;%0A    public static final int RC_COMPILE_ERROR = 1;%0A    public static final int RC_USAGE_ERROR = 2;%0A%0A
     /*%0A     
@@ -1303,24 +1303,33 @@
 s) %7B%0A       
+ int rc =
  new Main().
@@ -1343,16 +1343,41 @@
 (args);%0A
+        System.exit(rc);%0A
     %7D%0A%0A 
@@ -1638,53 +1638,46 @@
 urn 
-true on compilation success, false on failure
+a return code as defined by this class
 %0A   
@@ -1684,39 +1684,35 @@
   */%0A    public 
-boolean
+int
  compile(String%5B
@@ -2137,53 +2137,46 @@
 urn 
-true on compilation success, false on failure
+a return code as defined by this class
 %0A   
@@ -2195,15 +2195,11 @@
 lic 
-boolean
+int
  com
@@ -2413,13 +2413,22 @@
 urn 
-false
+RC_USAGE_ERROR
 ;%0A  
@@ -2598,22 +2598,33 @@
         
-return
+boolean success =
  Compile
@@ -2646,24 +2646,80 @@
  out, err);%0A
+        return success ? RC_SUCCESS : RC_COMPILE_ERROR;%0A
     %7D%0A%0A    /

Fix HARMONY-6079 ([jdktools] javac should exit with error code non-zero on compile errors)