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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | package Torello.Java.Build; import Torello.Java.Additional.Ret4; import Torello.Java.Additional.ByRef; import Torello.Java.ReadOnly.ReadOnlyList; import Torello.Java.ReadOnly.ROArrayListBuilder; import Torello.Java.ReadOnly.ROHashMapBuilder; import Apache.CLI.Option; import Apache.CLI.OptionGroup; import static Torello.Java.C.RESET; import static Torello.Java.C.BYELLOW; import static Torello.Java.C.BCYAN; import static Torello.Java.C.BGREEN; // This class does nothing more than: // // 1) Generate the Object-Instances of the Apache-CLI "Option" Class for the Command Line Main // Menu's Composite-Build Options. Composite-Stages include: // a. "Complete-Builds" - Steps 2 through 7 or 8 (everything) // b. "Partial-Builds" - Steps 2 & 3 and then maybe 5 or 8. // // 2) Generate the actual Main-Menu String-Text Data that is printed to the terminal for those // steps. // // These "Composite Steps" are called "Composite" because they are steps which simply invoke // at least 2 (more than 1) of the "Primary Build Steps". That's what the word "Composite" sort of // means. There are exactly two variants of the "Composite Build Options". They are: // // 1) "Complete Build" Options (and use the "-cbX" name at the Command-Line because they run ALL // OF THE Steps, specifically: #1 through #7 (or #1 through #8). // // 2) "Partial Build" Options (and are named "-pbX") These run some amalgam of the Primary-Build // Steps, BUT NOT ALL OF THEM! There are "Partial-Build" Options for Steps #2 & #3, for // instance. There is another Partial-Build Option for Steps #2, #3 & #5 too. class GenerateCompositeOpts { // Inserts all relevant "-pb" and "-cb" Options into the Apache-CLI Class "OptionGroup". // Each of these individual Options are associated with a certain / specific CloudSync // instance. static Ret4 <Integer, Integer, String, String> generate( // Apache.CLI "OptionGroup" instance. This is the Main-Menu Dispatch-Decision // thing-y. All Main-Menu (non-Auxiliary) Options are added into this group, and // the end user is expected to select precisely / exactly one of these options. final OptionGroup group, // Maps an Option to the Cloud-Sync that it is associated with. I'm not going to // explain this entire thing right here. I explained it elsewhere already. final ROHashMapBuilder<String, CloudSync> cloudSync_SwitchMapper_B, // This list-builder builds a list that maintains the names of all Menu-Options which // accept a list of Package Nick-Names at the Command-Line. final ROArrayListBuilder<String> optionsWhichAcceptPkgNickNames_B, // This maintains a list of Menu-Options where the "No Browser Cache" / Stage-8 // is part of the Composite-List of steps to be executed. It is easier to keep this // as a ReadOnlyList when the build starts because, well, that's how if-then-else // statements work! // // Inside the actual Stage_8 code, the ReadOnlyList<String> is queried whether or not // the user's selected Menu-Option implies that Stage-8 needs to run. final ROArrayListBuilder<String> sma_IsRequested_List_B, // This maintains a list of Menu-Options that are "-pb" options, and include // step 5 (and possibly 8). There are two versions of "-pb", one does only steps // #2 and #3, while the other variant does #2, #3 and #5 (and possibly #8) // // The String, itself, is the shortened-version of the Option-Name final ROArrayListBuilder<String> partialWithSync_List_B, // This is a "passed by reference" thing - the value that is currently contained in this // wrapper (upon invocation of this method) is COMPLETELY-IRRELEVANT. This method // actually computes the value needed for `compositeStep_RunStage2to4_OptionName`, and // that value is returned by assigning the correct Option-Name to the field: // // compositeStep_RunStage2to4_OptionName.f = "The-Correct-Option-Name for Stage 1 to 4" final ByRef<String> compositeStep_RunStage2to4_OptionName, // List of User-Provided Cloud-Sync Options. final ReadOnlyList<CloudSync> cloudSyncList ) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Composite-Step / Complete-Build Options // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** int cbCounter = 0; int pbCounter = 0; // This StringBuilder generates the Main-Menu Options-List that will be printed to // terminal whenever the user has entered error-case input. If / when an error occurs, the // Main-Menu is simply printed to the terminal, and the String that is printed is actually // generated, right here, in this class. // // Generating the Main-Menu Text inside the exact same class that generates the Apache-CLI // Object-References makes is more straight-forward that the output text is correct, and // that nothing is left out. // // The CLI/Terminal Main-Menu helps remind the user what the actual Menu-Options are. It // is smarter to generate this String here, where it is actually used - BECAUSE THESE // STRINGS ARE IDENTICAL to the description strings inserted into the Object-References, // (which are also generated right here). // // This particular StringBuilder, declared directly below, contains the Menu-Text for the // "Composite-Stage Options" of a "Complete-Build". final StringBuilder mainMenu_CompositeSteps_CompleteBuildOpts_SB = new StringBuilder(); // This is nearly the same as the previously declared field, except it shall hold the // Menu-Text for "Composite-Stage Options" of "Partial-Builds" final StringBuilder mainMenu_CompositeSteps_PartialBuildOpts_SB = new StringBuilder(); // This initializes the Title-String or Description-String that is placed directly above // the list of "-cb" (Complete-Build) options. mainMenu_CompositeSteps_CompleteBuildOpts_SB.append (BYELLOW + "\n\n\tComposite-Stage Complete-Build (-cb) Options:" + RESET); // This initializes the title-string for all "-pb" Partial-Build Options. mainMenu_CompositeSteps_PartialBuildOpts_SB.append (BYELLOW + "\n\n\tComposite-Stage Partial-Build (-pb) Options:" + RESET); String optShortName; // Temp-Variable, used over and over **BOTH** in the loop, and then once, at the very // end of the loop. // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Partial-Build Option: Steps 2 & 3 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** optShortName = "pb" + (++pbCounter); group.addOption( Option .builder (optShortName) .required (false) .desc ("Partial/Dev Build: STEPS 2 & 3.") .longOpt ("partial" + pbCounter) .hasArgs () .optionalArg (true) .valueSeparator (' ') .argName ("PackageNickNames") .build () ); mainMenu_CompositeSteps_PartialBuildOpts_SB.append( "\n\t\t-" + optShortName + " -> SETPS 2 and 3. [Doc Only, " + BGREEN + "Optional: " + RESET + "Pkg-Nicknames]" ); // This option also allows for the user providing a list of package nick-names. In this // case, only the packages which have been explicitly specified by name are put through // the Stage-3 Upgrader. Remember that Stage-2 JavaDoc *NEVER* skips any packages, no // matter what the user requested. Java-Doc generates thousands of URL Anchor-Links, so // packages cannot be skipped in Stage-2, only in Stage-3 optionsWhichAcceptPkgNickNames_B.add(optShortName); // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Complete-Build Option: Steps 2, 3 & 4 (With or Without Cloud-Sync !!) // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // // If the user has not provided any CloudSync instances, then this is the **ONLY** // Complete-Build Option. if (cloudSyncList.size() == 0) { optShortName = "cb" + (++cbCounter); group.addOption( Option .builder (optShortName) .required (false) .desc ("Complete Build: STEPS 2 to 4.") .longOpt ("complete" + cbCounter) .hasArg (false) .build() ); // Add the Description for the "-cb" option to the Main-Menu Text-String StringBuilder mainMenu_CompositeSteps_CompleteBuildOpts_SB.append ("\n\t\t-" + optShortName + " -> STEPS 2 through 4."); // Save this, it is used inside of "RunBuild". It is assigned to a boolean inside of // BuilderRecord and inside OptionsRecord. "Command-Line Options-Processing" is truly // awful to code. It **always** feels like Spaghetti-Code. compositeStep_RunStage2to4_OptionName.f = optShortName; } // If the user has provided "CloudSync" instances, then this is quietly filed under // the "Partial-Build" Menu-Option Category. Note, I never use this one when I do my // builds, but then again, I have **ALWAYS** synced to the Cloud. // // If I ever started using Package Torello.Java.Build to build things without messing // with my web-site, then this would probably become a lot more useful. else { optShortName = "pb" + (++pbCounter); group.addOption( Option .builder (optShortName) .required (false) .desc ("Partial Build: STEPS 2 to 4.") .longOpt ("partial" + pbCounter) .hasArg (false) .build() ); // Add the Description for the "-cb" option to the Main-Menu Text-String StringBuilder mainMenu_CompositeSteps_PartialBuildOpts_SB.append ("\n\t\t-" + optShortName + " -> STEPS 2 through 4."); // SEE ABOVE COMMENT - for the exact same line at the end of the above if-branch. compositeStep_RunStage2to4_OptionName.f = optShortName; } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Iterate the list of CloudSync instances provided by the User // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** for (CloudSync cs : cloudSyncList) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Primary / Main Complete Build-Option: Steps 2 to 7 (No Set-Max-Age) // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** optShortName = "cb" + (++cbCounter); group.addOption( Option .builder (optShortName) .required (false) .desc ("Complete Build: STEPS 2 to 7. Sync-To: " + cs.nickName) .longOpt ("complete" + cbCounter) .hasArg (false) .build() ); // The Mapper remembers which CloudSync option is assigned to which switch cloudSync_SwitchMapper_B.put(optShortName, cs); // Add the Description for the "-cb" option to the Main-Menu Text-String StringBuilder // instance. This is a "-cb, Steps #2 to #7" Option. mainMenu_CompositeSteps_CompleteBuildOpts_SB.append( "\n\t\t-" + optShortName + " -> STEPS 2 through 7. " + "[" + BCYAN + "Push-To: " + RESET + cs.nickName + "]" ); // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Complete Build Option: 2 to 8 (Includes Set-Max-Age) // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** if (cs.includeSetMaxAgeBuilds) { optShortName = "cb" + (++cbCounter); group.addOption( Option .builder (optShortName) .required (false) .desc ("Complete Build: STEPS 2 to 8. Sync-To: " + cs.nickName) .longOpt ("complete" + cbCounter) .hasArg (false) .build () ); // The Mapper remembers which CloudSync option is assigned to which switch cloudSync_SwitchMapper_B.put(optShortName, cs); mainMenu_CompositeSteps_CompleteBuildOpts_SB.append( "\n\t\t-" + optShortName + " -> STEPS 2 through 8. " + "[" + BCYAN + "Push-To: " + RESET + cs.nickName + "]" ); sma_IsRequested_List_B.add(optShortName); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Partial / Debugging Build-Options // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** if (cs.allowPartialBuilds) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Partial-Build Option: Steps 2, 3 & 5 (possibly 8, too) // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** optShortName = "pb" + (++pbCounter); final String desc = "Partial Build: Steps 2, 3 " + (cs.includeSetMaxAgeBuilds ? "5, and 8. " : "and 5. "); partialWithSync_List_B.add(optShortName); if (cs.includeSetMaxAgeBuilds) sma_IsRequested_List_B.add(optShortName); group.addOption( Option .builder (optShortName) .required (false) .desc (desc + "Sync-To: " + cs.nickName) .longOpt ("partial" + pbCounter) .hasArgs () .optionalArg (true) .valueSeparator (' ') .argName ("PackageNickNames") .build () ); cloudSync_SwitchMapper_B.put(optShortName, cs); // This particular Menu-Option is one where a user is allowed to enter a list of // of "Package Nicknames". When this is done (by the user), it asks this Build // Package to skip over any packages which haven't been explicity requested and // listed by the user. optionsWhichAcceptPkgNickNames_B.add(optShortName); mainMenu_CompositeSteps_PartialBuildOpts_SB.append ("\n\t\t-" + optShortName + " -> STEPS "); if (cs.includeSetMaxAgeBuilds) mainMenu_CompositeSteps_PartialBuildOpts_SB.append( "2, 3, 5 and 8. [" + BCYAN + "Push-To: " + RESET + cs.nickName + ", " + BGREEN + "Optional: " + RESET + "Pkg-Nicknames]" ); else mainMenu_CompositeSteps_PartialBuildOpts_SB.append( "2, 3 and 5. [" + BCYAN + "Push-To: " + RESET + cs.nickName + ", " + BGREEN + "Optional: " + RESET + "Pkg-Nicknames]" ); } } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Return the Ret4 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // // Note that the stuff that is returned is the stuff that goes directly into the // 'PrintHelpRecord'. All of the data the is needed by class 'CLI' in order to build the // data contained by 'CLI' (which is another giant data record, in and of it self) // is passed back to the class 'Generate' (which is the class that called this method) // using the object references listed as parameters at the top of this method. // // If you want to hear that translated into English - well - the stuff below that is // put into the "Return-Value" for this method are "datum" (or whatever the plural of // data actually is) that are used to generate the PrintHelpRecord. // // The datum that are used by class CLI to build a CLI instance is all passed by being // inserted into all of the `ROArrayListBuilder` inside this method's signature. return new Ret4<>( cbCounter, pbCounter, mainMenu_CompositeSteps_CompleteBuildOpts_SB.toString(), mainMenu_CompositeSteps_PartialBuildOpts_SB.toString() ); } } |