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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | package Torello.Java.Build; import Torello.Java.StrCmpr; import static Torello.Java.C.BRED; import static Torello.Java.C.RESET; /** * * This class does error checking on the User's CLI-Input. Specifically, it does error checking * on the "Auxiliary Options" that he has entered. The types of errors that this class is looking * for are errors where the user has attempted to enter an Auxiliary-Option which simply does not * apply to a Main-Menu Option Selection. * * <BR /><BR /> * If, for instance, the user requested Main-Menu Option #4 - Tar & Jar Files - then also * provided the switch {@code '-SRG'} ==> this User-Input would simply be an error, and need to be * handled as an such. * * <BR /><BR /> * The value of these error-checks is that, when they are more rigorous, the error/help * explanations that are spit-out in their faces make explaining what any of this doing * (at all), just that much more helpful to the end user. * * <BR /><BR /> * CLI Interfaces are very difficult to code. I never really thought about this stuff much * until my Build-Package truly "went live". (It stopped being some cute little thing in the * background, and was formalized into this Publicly-Visible Package). * * <BR /><BR /> * I've typed hundreds of comments everywhere, and tried to document everything as tenaciously * as I can, and it doesn't even feel like 1% of this whole package has been explained at all. * I'm going to have to go back and write some kind of "really high-level description" for all of * this, eventually. * * @see AuxiliaryOptRecord */ class ErrorCheckAuxOpts { private ErrorCheckAuxOpts() { } public static void check( // This Data-Record contains TRUE/FALSE values for each of the available Auxiliary // Menu-Optiosn that are offered by this Build-Tool. This Record is constructed by the // Package-Private Internal-Class named "Generate". It is passed as an // Object-Reference, here, so that it's boolean-flag (all 'final' constants), can be // verified/checked to see that they "agree" with the User's Main-Menu Option-selection final AuxiliaryOptRecord aor, // This data-record contains the Main-Menu Itself (as java.lang.String's). It is // passed here, simply, so that if the user has messed up using an Auxiliary-Option, // the Main-Menu / Help-Menu can be printed to terminal, quicly-and-easily (at which // point 'System.exit' is called, and the program exits) final PrintHelpRecord phr, // This is simply the Main-Menu User-Selected Option-Name (as a java.lang.String). // When this class' "check" method is called (this method you are reading right now), // This choice has already been computed and extracted by the Apache-CLI stuff. // // It is passed as a parameter here because it is used to verify each and every one // one of the Auxiliary-Options that user (may or may not) has provided. Specifically, // each of the 'final' boolean-fields present in parameter 'aor' is checked to see if // it is consistent with this String-Parameter "MENU_CHOICE". // // This is not rocket-science, but it is quite difficult to make this look // intelligible. final String MENU_CHOICE, // The Auxiliary-Option "-JFO", which is an ancronym that stands for "Jar-File-Only" // is checked against a "Menu-Choice" that is not guaranteed to always have the same // name in the Build. Essentially, as of the writing of this comment, the "-JFO" // Auxiliary-Option can be used with the Composite-Step Menu-Choice that performs the // Build-Steps #1 to #4. // // That particular Menu-Option is sometimes named "-pb1", but on the off-chance that // the User's class 'Config' instance did not contain any 'CloudSync' instances, this // choice would be named "cb1". // // So it needs to be passed as a separate parameter here. final String compositeStep_RunStage2to4_OptionName ) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Some Error-Checking // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // // These simple error-checks are simply trying to inform the user when particular flags // may or may not be applied. if (aor.INCLUDE_JAR_IN_CP_SWITCH) if (! MENU_CHOICE.equals("1")) { phr.print_MainMenu_Options(); System.out.println( "The " + BRED + "--putJarInCP" + RESET + " (-JCP) may only be used " + "alongside Main-Menu Option " + BRED + "--javac" + RESET + " (-1)" ); System.exit(1); throw null; } // For -NQB, ONLY Main-Menu Options: Only Partial-Builds employ the "Quick-Build" thing. // // Partial-Build is, essentially, the same as Developer-Build, which means that I'm in the // middle of doing something, and I want to recompile and publish my docs to the Web-Site. // Please skip the giant Browser-Package completely, so that I don't have to sit and watch // the lines go by and wait. // // Complete-Build's are never "Quick Bulds", only Partial-Builds, so this Main-Menu // Auxiliary-Switch cannot be applied to the other Main-Menu Options. If it is, then the // User needs to be politely reminded that he has made a mistake. if (aor.NO_QUICK_BUILD_SWITCH) if ((! MENU_CHOICE.startsWith("pb")) && (! MENU_CHOICE.equals("1"))) { phr.print_MainMenu_Options(); System.out.println(phr.messageNQB()); System.exit(1); throw null; } // -SRG may only be used with -cbXX where the XX is associated with a Developer-CloudSync // not a release CloudSync if (aor.SKIP_REMOVE_GCS_FILES_SWITCH) if (! MENU_CHOICE.startsWith("cb")) { phr.print_MainMenu_Options(); System.out.println(phr.messageSRG()); System.exit(1); throw null; } // The Extra / Auxiliary Menu-Option for "Toggle whatever the default setting is" // (as defined in the User-Provided class 'Config' instance) for the application of // the -XLint switch to the 'javac' Step/Stage... // // well... // // Indeed, can only be applied if the user has requested the Stage-1 / Step-1 // Menu-Option - which is the 'javac' / Java-Copiler Stage. // // So if they passed this Auxilliary Menu-Option along with some other Main-Menu // switch, it's an error-scenario, and the user needs to learn about the error of // his ways. if (aor.OVERRIDE_TOGGLE_USE_XLINT_SWITCH || aor.OVERRIDE_TOGGLE_USE_XDIAGS_SWITCH) if (! MENU_CHOICE.equals("1")) { phr.print_MainMenu_Options(); System.out.println( "Switches " + BRED + "--toggleDefaultXlint" + RESET + " (-TXL) and " + BRED + "--toggleDefaultXdiags" + RESET + " (-TXD) may only be used in combination with " + "Main-Menu Option " + BRED + "`--javac`" + RESET + " (-1)" ); System.exit(1); throw null; } // The "Early Development" Switch requests that Early-Develoment packages be included // in the build process. This request is completely impertinent to Stage-4 (archive // step/stage). Stage-4 archives whatever is there. // // Stage-6 is "Synchronize Archive Files", and those cannot be changed once they are // build, so this switch is also impertinent to those Menu-Choices. // // Stage-7 is the "Log Stage", and (it is hopefully obvious) that log-files cannot be // changed in any way shape or form by some silly User-Provided Menu-Option Switch. // So if they have entered "stage-7" as their Menu-Choice, and also entered the // "Include Early Development" switch, they messed up. if (aor.INCLUDE_EARLY_DEV_PACKAGES_SWITCH) if (StrCmpr.equalsXOR(MENU_CHOICE, "4", "6", "7")) { phr.print_MainMenu_Options(); System.out.println( "The Command-Switch " + BRED + "--includeEarlyDev" + RESET + " (-IEDP) may " + "only be used in combination with some of the Main-Menu Options:\n" + "-1, -2, -3, -5, -8 and all cbX and pbX switches" ); System.exit(1); throw null; } // Must be a Stage-4 Request, or a Composite-Step #2 to #4 request. // // That giant-ugly variable-name contains the Composite-Stage Menu-Option Name that // provides the User with a Composite-Step "#1 to #4" Option. The reason it is a variable // name (of such a wonderful calliber), is that it is not guaranteed to be a "Partial" or // a "Complete" (-pbX or -cbX) switch. // // If the user has provided exactly ZERO CloudSync instances, then the "#1 to #4" choice // is a Complete-Build Composite-Step Choice. If there is even a single CloudSync provided // to the User's class 'Config' instance / Object-Reference, then this will be a "-pbX" // instance. // // So it is a variable name that is passed to this method at the top in the method // parameter list. It is retrieve out of the OptionsRecord where it is stored... // // HAVE A NICE DAY!!! if (aor.JAR_FILE_ONLY_SWITCH) if (StrCmpr.equalsNAND(MENU_CHOICE, "4", compositeStep_RunStage2to4_OptionName)) { phr.print_MainMenu_Options(); System.out.println( "The Command-Switch " + BRED + "--jarFileOnly" + RESET + " (-JFO) may only " + "be used in combination with Main-Menu Option: " + BRED + "-tarjar" + RESET + " (-4) or Menu-Option -" + BRED + compositeStep_RunStage2to4_OptionName + RESET ); System.exit(1); throw null; } // Requesting that all '.class'-Files be wiped, first, is a feature offered by this // Build-Tool. This feature is requested by passing the CLI Switch "-WCFF", and that // switch may only be passed when used in conjunction with switch "-1" (javac) if (aor.WIPE_CLASS_FILES_FIRST) if (! MENU_CHOICE.equals("1")) { phr.print_MainMenu_Options(); System.out.println( "The Command-Switch " + BRED + "--wipeClassFilesFirst" + RESET + " (-WCFF) " + "may only be used in combination with Main-Menu Option: " + BRED + "-javac" + RESET + " (-1)" ); System.exit(1); throw null; } } } |