001package Torello.Java.Build; 002 003import static Torello.Java.C.*; 004 005import Torello.Java.StringParse; 006import Torello.Java.OSResponse; 007import java.io.IOException; 008 009@Torello.JavaDoc.StaticFunctional 010public class Util 011{ 012 // Completely irrelevant, and the 'private' modifier keeps it off of JavaDoc 013 private Util() { } 014 015 /** 016 * Simple Method for exiting with a consistent error message. 017 * 018 * <BR /><BR /><B CLASS=JDDescLabel>Terminates the JVM</B> 019 * 020 * <BR />This method invokes the Java-Command {@code 'System.exit'} 021 * 022 * @param cmd The Command that was executed, leading to the error. 023 */ 024 public static void ERROR_EXIT(String cmd) 025 { 026 final String s = 027 BBLUE_BKGND + ' ' + RESET + " There was an error, and build is halting: " + 028 BRED + cmd + RESET; 029 030 final int len = s.length() - (BBLUE_BKGND + RESET + BRED + RESET).length(); 031 032 System.err.println( 033 Printing.ERROR_EXIT_LINE + '\n' + 034 035 s + StringParse.nChars(' ', Printing.LEN + 40 - len - 1) + 036 BBLUE_BKGND + ' ' + RESET + '\n' + 037 038 Printing.ERROR_EXIT_LINE + '\n' 039 ); 040 041 System.exit(0); 042 } 043 044 /** 045 * Checks a Command's Response for errors. If Errors have occured, the response that was 046 * returned is printed, and an {@code Error} is thrown. 047 * 048 * @param osr The Command's Response 049 * @throws BuildError If an error has occured in executing an Operating System call. 050 */ 051 public static void HALT_ON_ERROR(OSResponse osr) 052 { 053 if ( (osr.response != 0) 054 // NOTE: You cannot do this check, because 'gsutil' literally writes all of its 055 // output to standard-error. It's quite madening. 056 // || ((osr.stdErr != null) && (osr.stdErr.length() > 0)) 057 ) 058 { 059 System.out.println('\n' + osr.toString() + '\n'); 060 061 throw new BuildError("OSResponse Had Errors, Look at StackTrace to See Where !"); 062 } 063 } 064}