1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package Torello.Java.Build;

import static Torello.Java.C.*;

import Torello.Java.StringParse;
import Torello.Java.OSResponse;
import java.io.IOException;

@Torello.JavaDoc.StaticFunctional
public class Util
{
    // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc
    private Util() { }

    /**
     * Simple Method for exiting with a consistent error message.
     * 
     * <BR /><BR /><B CLASS=JDDescLabel>Terminates the JVM</B>
     * 
     * <BR />This method invokes the Java-Command {@code 'System.exit'}
     * 
     * @param cmd The Command that was executed, leading to the error.
     */
    public static void ERROR_EXIT(String cmd)
    {
        final String s =
            BBLUE_BKGND + ' ' + RESET + " There was an error, and build is halting: " +
            BRED + cmd + RESET;

        final int len = s.length() - (BBLUE_BKGND + RESET + BRED + RESET).length();

        System.err.println(
            Printing.ERROR_EXIT_LINE + '\n' +

            s + StringParse.nChars(' ', Printing.LEN + 40 - len - 1) +
                BBLUE_BKGND + ' ' + RESET + '\n' +

            Printing.ERROR_EXIT_LINE + '\n'
        );

        System.exit(0);
    }

    /**
     * Checks a Command's Response for errors.  If Errors have occured, the response that was 
     * returned is printed, and an {@code Error} is thrown.
     * 
     * @param osr The Command's Response
     * @throws BuildError If an error has occured in executing an Operating System call.
     */
    public static void HALT_ON_ERROR(OSResponse osr)
    {
        if (    (osr.response != 0)
            // NOTE: You cannot do this check, because 'gsutil' literally writes all of its 
            //       output to standard-error.  It's quite madening.
            // ||  ((osr.stdErr != null) && (osr.stdErr.length() > 0))
        )
        {
            System.out.println('\n' + osr.toString() + '\n');

            throw new BuildError("OSResponse Had Errors, Look at StackTrace to See Where !");
        }
    }
}