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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | package Torello.Java.Build; import Torello.HTML.HTMLPage; // needed for a JavaDoc '@link' import Torello.Java.ReadOnly.ReadOnlyList; import Torello.Java.ReadOnly.ReadOnlyArrayList; import Torello.Java.ReadOnly.ROArrayListBuilder; import Torello.Java.StrCSV; import Torello.Java.StringParse; import Torello.Java.StrCmpr; import static Torello.Java.C.*; import java.io.File; import java.util.TreeSet; import java.util.stream.Stream; /** * This User-Data class is used to describe the Java-Packages included inside of a Java Project. * * <BR /><BR /><B CLASS=JDDescLabel>Java-HTML JAR BuildPackage instances:</B> * * <BR />You may view the list of packages that are used to build the Java-HTML JAR-Library * here, in the link below: * * <BR /><BR /><A HREF='hilite-files/MyPackages.java.html'>MyPackages.java</A> */ public class BuildPackage { // ******************************************************************************************** // ******************************************************************************************** // Static Flag-Fields // ******************************************************************************************** // ******************************************************************************************** /** * This flag may be attached to one of your {@code BuildPackage} instances to signify that the * package being flagged should not ever be re-compiled when Build-Stage 1 ({@code 'javac'}) is * executing - <I>unless the package's nick-name has been explicity specified at the Command * Line Interface</I>. * * <BR /><BR />This flag can be an invaluable tool for speeding up build times be eliminating * the compilation for Source-Files whose code is not changing and is not dependent on the * Source-Files inside your project. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />In the Java-HTML {@code '.jar'} File, the external-imports that are included such as * the Glass-Fish JSON Processor, and the Apache CLI Tools have Source-Files that do not ever * need to be recompiled. Those packages are included in this {@code '.jar'} file's * documentation, but when this project is built, the Compiler Build-Stage will skip the * compilation of the Source-Files in those Packages. */ public static final byte DO_NOT_RECOMPILE = 1; /** * This flag may be attached to one of your {@code BuildPackage} instances to signify that the * package being flagged should not ever be documented when Build-Stage 2 ({@code 'javadoc'}) * is executing. * * <BR /><BR />When this flag is attached to a {@code BuildPackage}, there will simply be no * documentation generated for that package. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />This Project's {@code '.jar'} File includes several classes that act as Internal * Processors for the Java-Doc Upgrader Tool. Those classes are all part of a root package * known as {@code JDUInternal}. * * <BR /><BR />Because the Source-Code in these classes serves no purpose whatsoever as a part * of any kind of "External API", the methods and fields of those classes are not documented. * The {@code BuildPackage} instance for the {@code JDUInternal} Package has been flagged with * this flag {@code DO_NOT_DOCUMENT} */ public static final byte DO_NOT_DOCUMENT = DO_NOT_RECOMPILE << 1; /** * This is a special flag that may be used to signify that a particular {@code BuildPackage} * instance actually refers to a tree of packages, rather than just a single package. * * <BR /><BR />This flag works very well with the {@link #DO_NOT_DOCUMENT} Flag. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />Again, the internal Java-Doc Upgrader Classes, rooted in package {@code JDUInternal}, * actually form a tree of packages that are ultimately included in the {@code '.jar'} File. */ public static final byte HAS_SUB_PACKAGES = DO_NOT_DOCUMENT << 1; /** * This is a flag that can be used to boost Build-Times in a way quite similar to the * {@link #DO_NOT_RECOMPILE} flag. When a {@code BuildPackage} instance is flagged with * {@code QUICKER_BUILD_SKIP}, if a user is performing a "Partial Build" using one of the * Partial-Build Flags ({@code -pb1} and {@code -pb2}), then that package will simply be * eliminated from the Build. * * <BR /><BR />For packages that are not necessarily external and independent packages, but * are disjoint enough such that they do not need to be recompiled or documented in most * situations, then this flag can help boost Build-Speed during development. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />The Java-HTML {@code '.jar'} includes an Experimental Headless-Browser * Package. The {@code BuildPackage} instance that models that package is flagged with the * {@code QUICKER_BUILD_SKIP}. This means that during development, unless a Full Release * Build has been invoked (Build-Switch {@code '-cb1'}), the Browser-Package is simply ignored. * * <BR /><BR />It is not compiled by Stage 1; it is not documented by the {@code 'javadoc'} * stage, and its documentation pages are not upgraded. Because that package was generated by * a Code-Generator, and is extremely lengthy and doesn't change, it doesn't need to be * included in the Build-Process at all unless a Full-Release Build is being invoked. * * <BR /><BR />Note that the Build-Switch {@code '-NQB'} can override the elimination of * packages that have been flagged in this way. */ public static final byte QUICKER_BUILD_SKIP = HAS_SUB_PACKAGES << 1; /** * This can be used to request that the class files for a Java Package not be included in the * {@code '.jar'} File generated for that package. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />There is a proprietary, internal, Builder Package Hierarchy that is only used for * improving this particular package. The classes in package {@code Torello.BuildJAR} are, * therefore, flagged with the {@code 'DO_NOT_JAR'} flag. * * <BR /><BR />A cursory inspection of the Java-HTML {@code '.jar'} File will reveal that * there is not package named {@code Torello.BuildJAR} inside the {@code '.jar'} File. This is * because that package contains proprietary and internal classes that serve no purpose * whatsoever outside of the Build-Process. */ public static final byte DO_NOT_JAR = QUICKER_BUILD_SKIP << 1; /** * Can be used to flag a package as "Under Development." Packages flagged as such will not be * included in the Build unless explicity requested. * * <BR /><BR /><B CLASS=JDDescLabel>For Instance, Java-HTML:</B> * * <BR />The most recent addition to Java-HTML has been the package {@code Torello.CSS}. * It is currently under development and therefore wholly eliminated from the Build except * when it has been explicity requested. * * <BR /><BR />The elimination of packages flagged with the {@code 'EARLY_DEVELOPMENT'} flag * can be overriden using the Build Command-Line Switch {@code '-IEDP'}, which simply stands * for "Include Early Development Packages". */ public static final byte EARLY_DEVELOPMENT = DO_NOT_JAR << 1; // ******************************************************************************************** // ******************************************************************************************** // Static Fields // ******************************************************************************************** // ******************************************************************************************** // This can be important public static final boolean DEBUGGING = false; // This is ubiquitous in Build-Stuff private static final String FS = File.separator; // For (most) packages, which do not have "Helper Packages" private static final ReadOnlyList<String> EMPTY_LIST = ReadOnlyList.of(); // ******************************************************************************************** // ******************************************************************************************** // Instance Fields // ******************************************************************************************** // ******************************************************************************************** /** This package's full-name. */ public final String fullName; /** This package's class-path location within the File-System. */ public final String classPathLocation; /** This package's root-directory within the File-System. */ public final String pkgRootDirectory; /** A Nick-Name that may be used when trying to request this package at the CLI */ public final String nickName; /** * Indicates that this package's Source-Code Directory has an {@code 'upgrade-files/'} * sub-directory. The {@code 'upgrade-files/'} directory stores myriad configurations that are * utilized by the Java-Doc Upgrader Tool, which is executed in Build-Stage 3. * * <BR /><BR />This field is assigned as follows: * * <BR /><DIV CLASS=SNIP>{@code * File f = new File(this.pkgRootDirectory + "upgrade-files" + FS); * * this.hasUpgradeFilesDir = f.exists() && f.isDirectory(); * }</DIV> */ public final boolean hasUpgradeFilesDir; /** * Indicates that this package's Source-Code Directory has a {@code 'package-source/'} * sub-directory containing {@code '.java'} Files. The {@code 'package-source/'} directory * can be used to organize and categorize {@code '.java'} Files within a single Java Package * so that they are not all lumped together in a single Java-Package Directory. * * <BR /><BR />This field is assigned as follows: * * <BR /><DIV CLASS=SNIP>{@code * f = new File(this.pkgRootDirectory + "package-source" + FS); * * this.hasPackageSourceDir = f.exists() && f.isDirectory(); * }</DIV> */ public final boolean hasPackageSourceDir; /** * This field indicates whether or not the {@link #DO_NOT_RECOMPILE} flag was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.mustReCompile = (flags & DO_NOT_RECOMPILE) == 0; * }</DIV> * * @see #DO_NOT_RECOMPILE */ public final boolean mustReCompile; /** * This field simply indicates whether or not the {@link #DO_NOT_DOCUMENT} was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.mustDocument = (flags & DO_NOT_DOCUMENT) == 0; * }</DIV> * * @see #DO_NOT_DOCUMENT */ public final boolean mustDocument; /** * This field simply indicates whether or not the {@link #DO_NOT_JAR} was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.doNotJAR = (flags & DO_NOT_JAR) >= 1; * }</DIV> * * @see #DO_NOT_JAR */ public final boolean doNotJAR; /** * This field simply indicates whether or not the {@link #HAS_SUB_PACKAGES} was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.hasSubPackages = (flags & HAS_SUB_PACKAGES) >= 1; * }</DIV> * * @see #HAS_SUB_PACKAGES */ public final boolean hasSubPackages; /** * This field simply indicates whether or not the {@link #QUICKER_BUILD_SKIP} was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.skipIfQuickerBuild = (flags & QUICKER_BUILD_SKIP) >= 1; * }</DIV> * * @see #QUICKER_BUILD_SKIP */ public final boolean skipIfQuickerBuild; /** * This field simply indicates whether or not the {@link #EARLY_DEVELOPMENT} was assigned to * {@code 'this'} instance of {@code BuildPackage}. This field's value is assigned, in this * class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.earlyDevelopment = (flags & EARLY_DEVELOPMENT) >= 1; * }</DIV> * * @see #EARLY_DEVELOPMENT */ public final boolean earlyDevelopment; /** * Helper packages may be passed as parameters to the {@code BuildPackage} constructor. All a * "Helper Package" is is a sub-directory of the Package-Directory that contains additional * classes that are germaine to the classes in this package. * * <BR /><BR />The classes in a Helper-Package will not be documented by {@code 'javadoc'}, nor * will they be (obviously) be upgrader by the Stage 3 Build-Class performing the JavaDoc * Upgrade. * * <BR /><BR />Instead, these classes will be compiled by the {@code 'javac'}, and included, * quietly, in the final {@code '.jar'} File produced by this Build. This can be a great way * to add simple classes that are required for an API Class to fully function, but do not * actually need to be documented and included in the API themselves. * * <BR /><BR />A cursory inspection of the contents of the Java-HTML {@code '.jar'} * Distribution should reveal, for instance the HTML Helper-Package * {@code 'Torello.HTML.parse'}, which does the actual parsing for the HTML Parsing class * {@link HTMLPage}. This class is fundamental and necessary to the operation of the HTML * Package, but is largely useless in the API that's exported to the end user. * * <BR /><BR />This field's value is assigned by this class' constructor, as below: * * <BR /><DIV CLASS=SNIP>{@code * this.helperPackages = (helperPackages == null) || (helperPackages.length == 0) * ? EMPTY_LIST * : new ReadOnlyArrayList( * 0, * (String subDirName) -> this.pkgRootDirectory + * (subDirName.endsWith(FS) ? subDirName : (subDirName + FS)), * helperPackages * ); * }</DIV> */ public final ReadOnlyList<String> helperPackages; // ******************************************************************************************** // ******************************************************************************************** // Lone Constructor // ******************************************************************************************** // ******************************************************************************************** /** * Constructs an instance of this class. * * @param fullName The full name of the package. This package, for instance, is named * {@code Torello.Java.Build}. * * @param classPathLocation The root class-path location * * @param nickName A nick-name for this package that may be passed at the Command-Line * Interface when it is necessary to specify that this package be included in the Build-Proces. * * @param flags The <B>{@code Boolean-OR}</B> of all flags being assigned to this package. * * @param helperPackages A list of any and all sub-directory packages to be included in this * {@code '.jar'} upon which this package depends. This list must contain {@code String's} * that name actual sub-directories of the package-directory that contains the source-files * for this package. * * @throws IllegalArgumentException This exception throws under the following circumstances: * * <BR /><BR /><UL CLASS=JDUL> * <LI> If {@link #mustDocument} and {@link #hasSubPackages} are both, simultaneously, set</LI> * <LI> If any of the "Helper Packages" do not name valid sub-directories of the primary * package-directory * </LI> * </UL> */ public BuildPackage( final String fullName, final String classPathLocation, final String nickName, final int flags, final String... helperPackages ) { this.fullName = fullName; if (StrCmpr.equalsXOR(classPathLocation, ".", "")) this.classPathLocation = ""; else if (! classPathLocation.endsWith(FS)) this.classPathLocation = classPathLocation + FS; else this.classPathLocation = classPathLocation; this.nickName = nickName; this.earlyDevelopment = (flags & EARLY_DEVELOPMENT) >= 1; this.skipIfQuickerBuild = (flags & QUICKER_BUILD_SKIP) >= 1; this.mustReCompile = (flags & DO_NOT_RECOMPILE) == 0; // The "NOT" of the flag this.mustDocument = (flags & DO_NOT_DOCUMENT) == 0; // The "NOT" of the flag this.doNotJAR = (flags & DO_NOT_JAR) >= 1; this.hasSubPackages = (flags & HAS_SUB_PACKAGES) >= 1; this.pkgRootDirectory = classPathLocation + fullName.replace(".", FS) + FS; this.helperPackages = (helperPackages == null) || (helperPackages.length == 0) ? EMPTY_LIST : new ReadOnlyArrayList<>( 0, (String subDirName) -> this.pkgRootDirectory + (subDirName.endsWith(FS) ? subDirName : (subDirName + FS)), helperPackages ); File f = null; for (String pkgDirName : this.helperPackages) { f = new File(pkgDirName); if ((! f.exists()) || (! f.isDirectory())) throw new IllegalArgumentException( "Helper Package [" + pkgDirName + "] specifies a directory that either doesn't " + "exist or is a file, rather than a directory:\n" + f.toString() ); } f = new File(this.pkgRootDirectory + "upgrade-files" + FS); this.hasUpgradeFilesDir = f.exists() && f.isDirectory(); f = new File(this.pkgRootDirectory + "package-source" + FS); this.hasPackageSourceDir = f.exists() && f.isDirectory(); if (this.mustDocument && this.hasSubPackages) throw new IllegalArgumentException ("this.mustDocument AND this.hasSubPackages"); } // ******************************************************************************************** // ******************************************************************************************** // toString // ******************************************************************************************** // ******************************************************************************************** /** * Stringify an instance of this class. * @return a Java {@code String} representation of this class. */ public String toString() { final int LEN = 22; final String CPL = (classPathLocation.length() == 0) ? BGREEN + "Current Working Directory" + RESET : classPathLocation; return StringParse.rightSpacePad("fullName:", LEN) + fullName + '\n' + StringParse.rightSpacePad("classPathLocation:", LEN) + CPL + '\n' + StringParse.rightSpacePad("pkgRootDirectory:", LEN) + pkgRootDirectory + '\n' + StringParse.rightSpacePad("nickName:", LEN) + nickName + '\n' + StringParse.rightSpacePad("hasUpgradeFilesDir:", LEN) + hasUpgradeFilesDir + '\n' + StringParse.rightSpacePad("hasPackageSourceDir:", LEN) + hasPackageSourceDir + '\n' + StringParse.rightSpacePad("mustReCompile:", LEN) + mustReCompile + '\n' + StringParse.rightSpacePad("mustDocument:", LEN) + mustDocument + '\n' + StringParse.rightSpacePad("hasSubPackages:", LEN) + hasSubPackages + '\n' + StringParse.rightSpacePad("skipIfQuickerBuild:", LEN) + skipIfQuickerBuild + '\n' + StringParse.rightSpacePad("earlyDevelopment:", LEN) + earlyDevelopment + '\n' + StringParse.rightSpacePad("helperPackages:", LEN) + '[' + StrCSV.toCSV(helperPackages, true, true, null) + ']'; } // ******************************************************************************************** // ******************************************************************************************** // Static Helper // ******************************************************************************************** // ******************************************************************************************** static ReadOnlyList<BuildPackage> nickNameArgVPackages (BuildPackage[] allPackages, ReadOnlyList<String> packageNickNames) { // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Print it to terminal // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** if (DEBUGGING) { System.out.print("packageNickNames: "); for (String pnn : packageNickNames) System.out.print(pnn + ", "); System.out.println(); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Pkg Nick-Name Duplicate-Checker (typing the same name more than once - print & exit) // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** TreeSet<String> duplicateCheckerTS = new TreeSet<>(); for (String nickName : packageNickNames) if (duplicateCheckerTS.contains(nickName)) { System.err.println( "Duplicate Package Nick-Name Provided: " + BRED + nickName + RESET + '\n' + "Exiting..." ); System.exit(1); } else duplicateCheckerTS.add(nickName); // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Convert to a list of "BuildPackage" instances // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Keeps a list of the packages that matched a nick-name ROArrayListBuilder<BuildPackage> roab = new ROArrayListBuilder<>(packageNickNames.size()); // Keeps a list of any nick-names for which no matching package is found. This is needed // to ensure that if there is one un-matched, that the loop DOES NOT BREAK, and continues // to check for matches... So that when there is an unmatched nick-name, the error-message // that is ultimately printed to the user - CONTAINS THE LIST OF **ALL** unmatched // nick-names. Stream.Builder<String> unrecognized = Stream.builder(); // A flag indicating that there is at least one unmatched package boolean atLeastOneMismatch = false; TOP: for (int i=0; i < packageNickNames.size(); i++) { for (BuildPackage pkg : allPackages) if (pkg.nickName.equals(packageNickNames.get(i))) { roab.add(pkg); if (DEBUGGING) System.out.println ("argv[" + i + "]: " + packageNickNames.get(i) + " ==> " + pkg.fullName); continue TOP; } atLeastOneMismatch = true; unrecognized.accept(packageNickNames.get(i)); } if (atLeastOneMismatch) { System.err.println( "Unrecognized Package Nick-Name(s): " + "[" + BGREEN + String.join(", ", unrecognized.build().toArray(String[]::new)) + RESET + "]\n" + "This Name could not be mapped to any of your Java Packages to Compile\n" + "Exiting...\n" ); System.exit(1); } // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // DONE // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** return roab.build(); } } |