1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * This file defines build profiles for the JIB tool and others.
  28  *
  29  * A build profile defines a set of configuration options and external
  30  * dependencies that we for some reason or other care about specifically.
  31  * Typically, build profiles are defined for the build configurations we
  32  * build regularly.
  33  *
  34  * Contract against this file from the tools that use it, is to provide
  35  * a function on the form:
  36  *
  37  * getJibProfiles(input)
  38  *
  39  * which returns an object graph describing the profiles and their
  40  * dependencies. The name of the function is based on the name of this
  41  * file, minus the extension and the '-', camel cased and prefixed with
  42  * 'get'.
  43  *
  44  *
  45  * The parameter 'input' is an object that optionally contains  some data.
  46  * Optionally because a tool may read the configuration for different purposes.
  47  * To initially get a list of available profiles, the active profile may not
  48  * yet be known for instance.
  49  *
  50  * Data that may be set on the input object:
  51  *
  52  * input.profile = <name of active profile>
  53  *
  54  * If the active profile is set, the following data from it must also
  55  * be provided:
  56  *
  57  * input.profile
  58  * input.build_id
  59  * input.target_os
  60  * input.target_cpu
  61  * input.build_os
  62  * input.build_cpu
  63  * input.target_platform
  64  * input.build_platform
  65  * // The build_osenv_* variables describe the unix layer on Windows systems,
  66  * // i.e. Cygwin, which may also be 32 or 64 bit.
  67  * input.build_osenv
  68  * input.build_osenv_cpu
  69  * input.build_osenv_platform
  70  *
  71  * For more complex nested attributes, there is a method "get":
  72  *
  73  * input.get("<dependency>", "<attribute>")
  74  *
  75  * Valid attributes are:
  76  * install_path
  77  * download_path
  78  * download_dir
  79  *
  80  *
  81  * The output data generated by this configuration file has the following
  82  * format:
  83  *
  84  * data: {
  85  *   // Identifies the version of this format to the tool reading it
  86  *   format_version: "1.0",
  87  *
  88  *   // Name of base outputdir. JIB assumes the actual output dir is formed
  89  *   // by adding the configuration name: <output_basedir>/<config-name>
  90  *   output_basedir: "build",
  91  *   // Configure argument to use to specify configuration name
  92  *   configuration_configure_arg:
  93  *   // Make argument to use to specify configuration name
  94  *   configuration_make_arg:
  95  *
  96  *   profiles: {
  97  *     <profile-name>: {
  98  *       // Name of os the profile is built to run on
  99  *       target_os; <string>
 100  *       // Name of cpu the profile is built to run on
 101  *       target_cpu; <string>
 102  *       // Combination of target_os and target_cpu for convenience
 103  *       target_platform; <string>
 104  *       // Name of os the profile is built on
 105  *       build_os; <string>
 106  *       // Name of cpu the profile is built on
 107  *       build_cpu; <string>
 108  *       // Combination of build_os and build_cpu for convenience
 109  *       build_platform; <string>
 110  *
 111  *       // List of dependencies needed to build this profile
 112  *       dependencies: <Array of strings>
 113  *
 114  *       // List of configure args to use for this profile
 115  *       configure_args: <Array of strings>
 116  *
 117  *       // List of free form labels describing aspects of this profile
 118  *       labels: <Array of strings>
 119  *     }
 120  *   }
 121  *
 122  *   // Dependencies use a Maven like deployment structure
 123  *   dependencies: {
 124  *     <dependency-name>: {
 125  *       // Organization part of path defining this dependency
 126  *       organization: <string>
 127  *       // File extension for this dependency
 128  *       ext: <string>
 129  *       // Module part of path for defining this dependency,
 130  *       // defaults to <dependency-name>
 131  *       module: <string>
 132  *       // Revision part of path for defining this dependency
 133  *       revision: <string>
 134  *
 135  *       // List of configure args to add when using this dependency,
 136  *       // defaults to
 137  *       // "--with-<dependency-name>=input.get("<dependency-name", "install_path")"
 138  *       configure_args: <array of strings>
 139  *
 140  *       // Name of environment variable to set when using this dependency
 141  *       // when running make
 142  *       environment_name: <string>
 143  *       // Value of environment variable to set when using this dependency
 144  *       // when running make
 145  *       environment_value: <string>
 146  *
 147  *       // Value to add to the PATH variable when using this dependency,
 148  *       // applies to both make and configure
 149  *       environment_path: <string>
 150  *     }
 151  *
 152  *     <dependency-name>: {
 153  *       // For certain dependencies where a legacy distribution mechanism is
 154  *       // already in place, the "javare" server layout is also supported
 155  *       // Indicate that an alternate server source and layout should be used
 156  *       server: "javare"
 157  *
 158  *       // For "javare", a combination of module, revision,
 159  *       // build number (optional), files and checksum file is possible for
 160  *       // artifacts following the standard layout.
 161  *       module: <string>
 162  *       revision: <string>
 163  *       build_number: <string>
 164  *       checksum_file: <string>
 165  *       file: <string>
 166  *
 167  *       // For other files, use checksum path and path instead
 168  *       checksum_path: <string>
 169  *       path: <string>
 170  *     }
 171  *   }
 172  * }
 173  */
 174 
 175 /**
 176  * Main entry to generate the profile configuration
 177  *
 178  * @param input External data to use for generating the configuration
 179  * @returns {{}} Profile configuration
 180  */
 181 var getJibProfiles = function (input) {
 182 
 183     var data = {};
 184 
 185     // Identifies the version of this format to the tool reading it.
 186     // 1.1 signifies that the publish, publish-src and get-src features are usable.
 187     data.format_version = "1.1";
 188 
 189     // Organization, product and version are used when uploading/publishing build results
 190     data.organization = "";
 191     data.product = "jdk";
 192     data.version = getVersion();
 193 
 194     // The base directory for the build output. JIB will assume that the
 195     // actual build directory will be <output_basedir>/<configuration>
 196     data.output_basedir = "build";
 197     // The configure argument to use to specify the name of the configuration
 198     data.configuration_configure_arg = "--with-conf-name=";
 199     // The make argument to use to specify the name of the configuration
 200     data.configuration_make_arg = "CONF_NAME=";
 201 
 202     // Exclude list to use when Jib creates a source bundle
 203     data.src_bundle_excludes = "./build webrev* */webrev* */*/webrev* */*/*/webrev* .hg */.hg */*/.hg */*/*/.hg";
 204     // Include list to use when creating a minimal jib source bundle which
 205     // contains just the jib configuration files.
 206     data.conf_bundle_includes = "*/conf/jib-profiles.* common/autoconf/version-numbers"
 207 
 208     // Define some common values
 209     var common = getJibProfilesCommon(input, data);
 210     // Generate the profiles part of the configuration
 211     data.profiles = getJibProfilesProfiles(input, common, data);
 212     // Generate the dependencies part of the configuration
 213     data.dependencies = getJibProfilesDependencies(input, common, data);
 214 
 215     return data;
 216 };
 217 
 218 /**
 219  * Generates some common values
 220  *
 221  * @param input External data to use for generating the configuration
 222  * @returns Common values
 223  */
 224 var getJibProfilesCommon = function (input, data) {
 225     var common = {};
 226 
 227     common.organization = "jpg.infra.builddeps";
 228     common.build_id = getBuildId(input);
 229     common.build_number = input.build_number != null ? input.build_number : "0";
 230 
 231     // List of the main profile names used for iteration
 232     common.main_profile_names = [
 233         "linux-x64", "linux-x86", "macosx-x64", "solaris-x64",
 234         "solaris-sparcv9", "windows-x64", "windows-x86",
 235         "linux-arm64", "linux-arm-vfp-hflt", "linux-arm-vfp-hflt-dyn"
 236     ];
 237 
 238     // These are the base setttings for all the main build profiles.
 239     common.main_profile_base = {
 240         dependencies: ["boot_jdk", "gnumake", "jtreg", "jib"],
 241         default_make_targets: ["product-bundles", "test-bundles"],
 242         configure_args: concat(["--enable-jtreg-failure-handler"],
 243                                versionArgs(input, common))
 244     };
 245     // Extra settings for debug profiles
 246     common.debug_suffix = "-debug";
 247     common.debug_profile_base = {
 248         configure_args: ["--enable-debug"],
 249         labels: "debug"
 250     };
 251     // Extra settings for slowdebug profiles
 252     common.slowdebug_suffix = "-slowdebug";
 253     common.slowdebug_profile_base = {
 254         configure_args: ["--with-debug-level=slowdebug"],
 255         labels: "slowdebug"
 256     };
 257     // Extra settings for openjdk only profiles
 258     common.open_suffix = "-open";
 259     common.open_profile_base = {
 260         configure_args: ["--enable-openjdk-only"],
 261         labels: "open"
 262     };
 263 
 264     common.configure_args_64bit = ["--with-target-bits=64"];
 265     common.configure_args_32bit = ["--with-target-bits=32"];
 266 
 267     /**
 268      * Define common artifacts template for all main profiles
 269      * @param o - Object containing data for artifacts
 270      */
 271     common.main_profile_artifacts = function (o) {
 272         var jdk_subdir = (o.jdk_subdir != null ? o.jdk_subdir : "jdk-" + data.version);
 273         var jre_subdir = (o.jre_subdir != null ? o.jre_subdir : "jre-" + data.version);
 274         var pf = o.platform
 275         return {
 276             artifacts: {
 277                 jdk: {
 278                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 279                     remote: [
 280                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin.tar.gz",
 281                         "bundles/" + pf + "/\\1"
 282                     ],
 283                     subdir: jdk_subdir,
 284                     exploded: "images/jdk"
 285                 },
 286                 jre: {
 287                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 288                     remote: [
 289                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin.tar.gz",
 290                         "bundles/" + pf + "/\\1"
 291                     ],
 292                     subdir: jre_subdir,
 293                     exploded: "images/jre"
 294                 },
 295                 test: {
 296                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 297                     remote: [
 298                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests.tar.gz",
 299                         "bundles/" + pf + "/\\1"
 300                     ],
 301                     exploded: "images/test"
 302                 },
 303                 test_demos: {
 304                     local: "bundles/\\(jdk.*bin-tests-demos.tar.gz\\)",
 305                     remote: [
 306                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-demos.tar.gz",
 307                         "bundles/" + pf + "/\\1"
 308                     ],
 309                     exploded: "images/test"
 310                 },
 311                 jdk_symbols: {
 312                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 313                     remote: [
 314                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 315                         "bundles/" + pf + "/\\1"
 316                     ],
 317                     subdir: jdk_subdir,
 318                     exploded: "images/jdk"
 319                 },
 320                 jre_symbols: {
 321                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 322                     remote: [
 323                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 324                         "bundles/" + pf + "/\\1"
 325                     ],
 326                     subdir: jre_subdir,
 327                     exploded: "images/jre"
 328                 }
 329             }
 330         };
 331     };
 332 
 333 
 334     /**
 335      * Define common artifacts template for all debug profiles
 336      * @param o - Object containing data for artifacts
 337      */
 338     common.debug_profile_artifacts = function (o) {
 339         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 340         var jre_subdir = "jre-" + data.version + "/fastdebug";
 341         var pf = o.platform
 342         return {
 343             artifacts: {
 344                 jdk: {
 345                     local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
 346                     remote: [
 347                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 348                         "bundles/" + pf + "/\\1"
 349                     ],
 350                     subdir: jdk_subdir,
 351                     exploded: "images/jdk"
 352                 },
 353                 jre: {
 354                     local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
 355                     remote: [
 356                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 357                         "bundles/" + pf + "/\\1"
 358                     ],
 359                     subdir: jre_subdir,
 360                     exploded: "images/jre"
 361                 },
 362                 test: {
 363                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 364                     remote: [
 365                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 366                         "bundles/" + pf + "/\\1"
 367                     ],
 368                     exploded: "images/test"
 369                 },
 370                 jdk_symbols: {
 371                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 372                     remote: [
 373                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 374                         "bundles/" + pf + "/\\1"
 375                     ],
 376                     subdir: jdk_subdir,
 377                     exploded: "images/jdk"
 378                 },
 379                 jre_symbols: {
 380                     local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
 381                     remote: [
 382                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 383                         "bundles/" + pf + "/\\1"
 384                     ],
 385                     subdir: jre_subdir,
 386                     exploded: "images/jre"
 387                 }
 388             }
 389         };
 390     };
 391 
 392     common.boot_jdk_version = "9";
 393     common.boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk-"
 394         + common.boot_jdk_version
 395         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
 396 
 397     return common;
 398 };
 399 
 400 /**
 401  * Generates the profiles part of the configuration.
 402  *
 403  * @param input External data to use for generating the configuration
 404  * @param common The common values
 405  * @returns {{}} Profiles part of the configuration
 406  */
 407 var getJibProfilesProfiles = function (input, common, data) {
 408     // Main SE profiles
 409     var profiles = {
 410 
 411         "linux-x64": {
 412             target_os: "linux",
 413             target_cpu: "x64",
 414             dependencies: ["devkit", "graphviz", "pandoc"],
 415             configure_args: concat(common.configure_args_64bit,
 416                 "--enable-full-docs", "--with-zlib=system"),
 417             default_make_targets: ["docs-bundles"],
 418         },
 419 
 420         "linux-x86": {
 421             target_os: "linux",
 422             target_cpu: "x86",
 423             build_cpu: "x64",
 424             dependencies: ["devkit"],
 425             configure_args: concat(common.configure_args_32bit,
 426                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 427         },
 428 
 429         "macosx-x64": {
 430             target_os: "macosx",
 431             target_cpu: "x64",
 432             dependencies: ["devkit"],
 433             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 434                 "--with-macosx-version-max=10.7.0"),
 435         },
 436 
 437         "solaris-x64": {
 438             target_os: "solaris",
 439             target_cpu: "x64",
 440             dependencies: ["devkit", "cups"],
 441             configure_args: concat(common.configure_args_64bit,
 442                 "--with-zlib=system", "--enable-dtrace"),
 443         },
 444 
 445         "solaris-sparcv9": {
 446             target_os: "solaris",
 447             target_cpu: "sparcv9",
 448             dependencies: ["devkit", "cups"],
 449             configure_args: concat(common.configure_args_64bit,
 450                 "--with-zlib=system", "--enable-dtrace"),
 451         },
 452 
 453         "windows-x64": {
 454             target_os: "windows",
 455             target_cpu: "x64",
 456             dependencies: ["devkit", "freetype"],
 457             configure_args: concat(common.configure_args_64bit),
 458         },
 459 
 460         "windows-x86": {
 461             target_os: "windows",
 462             target_cpu: "x86",
 463             build_cpu: "x64",
 464             dependencies: ["devkit", "freetype"],
 465             configure_args: concat(common.configure_args_32bit),
 466         },
 467 
 468         "linux-arm64": {
 469             target_os: "linux",
 470             target_cpu: "aarch64",
 471             build_cpu: "x64",
 472             dependencies: ["devkit", "build_devkit", "cups", "headless_stubs"],
 473             configure_args: [
 474                 "--with-cpu-port=arm64",
 475                 "--with-jvm-variants=server",
 476                 "--openjdk-target=aarch64-linux-gnu",
 477                 "--enable-headless-only"
 478             ],
 479         },
 480 
 481         "linux-arm-vfp-hflt": {
 482             target_os: "linux",
 483             target_cpu: "arm",
 484             build_cpu: "x64",
 485             dependencies: ["devkit", "build_devkit", "cups"],
 486             configure_args: [
 487                 "--with-jvm-variants=minimal1,client",
 488                 "--with-x=" + input.get("devkit", "install_path") + "/arm-linux-gnueabihf/libc/usr/X11R6-PI",
 489                 "--openjdk-target=arm-linux-gnueabihf",
 490                 "--with-abi-profile=arm-vfp-hflt"
 491             ],
 492         },
 493 
 494         // Special version of the SE profile adjusted to be testable on arm64 hardware.
 495         "linux-arm-vfp-hflt-dyn": {
 496             configure_args: "--with-stdc++lib=dynamic"
 497         }
 498     };
 499     // Let linux-arm-vfp-hflt-dyn inherit everything from linux-arm-vfp-hflt
 500     profiles["linux-arm-vfp-hflt-dyn"] = concatObjects(
 501         profiles["linux-arm-vfp-hflt-dyn"], profiles["linux-arm-vfp-hflt"]);
 502 
 503     // Add the base settings to all the main profiles
 504     common.main_profile_names.forEach(function (name) {
 505         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 506     });
 507 
 508     // Generate debug versions of all the main profiles
 509     common.main_profile_names.forEach(function (name) {
 510         var debugName = name + common.debug_suffix;
 511         profiles[debugName] = concatObjects(profiles[name],
 512                                             common.debug_profile_base);
 513     });
 514     // Generate slowdebug versions of all the main profiles
 515     common.main_profile_names.forEach(function (name) {
 516         var debugName = name + common.slowdebug_suffix;
 517         profiles[debugName] = concatObjects(profiles[name],
 518                                             common.slowdebug_profile_base);
 519     });
 520 
 521     // Generate open only profiles for all the main profiles for JPRT and reference
 522     // implementation builds.
 523     common.main_profile_names.forEach(function (name) {
 524         var openName = name + common.open_suffix;
 525         profiles[openName] = concatObjects(profiles[name],
 526                                            common.open_profile_base);
 527     });
 528     // The open only profiles on linux are used for reference builds and should
 529     // produce the compact profile images by default. This adds "profiles" as an
 530     // extra default target.
 531     var openOnlyProfilesExtra = {
 532         "linux-x86-open": {
 533             default_make_targets: "profiles-bundles",
 534             configure_args: "--with-jvm-variants=client,server"
 535         }
 536     };
 537     profiles = concatObjects(profiles, openOnlyProfilesExtra);
 538 
 539     // Generate debug profiles for the open only profiles
 540     common.main_profile_names.forEach(function (name) {
 541         var openName = name + common.open_suffix;
 542         var openDebugName = openName + common.debug_suffix;
 543         profiles[openDebugName] = concatObjects(profiles[openName],
 544                                                 common.debug_profile_base);
 545     });
 546 
 547     // Profiles for building the zero jvm variant. These are used for verification
 548     // in JPRT.
 549     var zeroProfiles = {
 550         "linux-x64-zero": {
 551             target_os: "linux",
 552             target_cpu: "x64",
 553             dependencies: ["devkit"],
 554             configure_args: concat(common.configure_args_64bit, [
 555                 "--with-zlib=system",
 556                 "--with-jvm-variants=zero",
 557                 "--enable-libffi-bundling"
 558             ])
 559         },
 560 
 561         "linux-x86-zero": {
 562             target_os: "linux",
 563             target_cpu: "x86",
 564             build_cpu: "x64",
 565             dependencies: ["devkit"],
 566             configure_args:  concat(common.configure_args_32bit, [
 567                 "--with-zlib=system",
 568                 "--with-jvm-variants=zero",
 569                 "--enable-libffi-bundling"
 570             ])
 571         }
 572     }
 573     profiles = concatObjects(profiles, zeroProfiles);
 574 
 575     // Add the base settings to the zero profiles and generate debug profiles
 576     Object.keys(zeroProfiles).forEach(function (name) {
 577         var debugName = name + common.debug_suffix;
 578         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 579         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 580     });
 581 
 582     // Profiles used to run tests. Used in JPRT and Mach 5.
 583     var testOnlyProfiles = {
 584         "run-test-jprt": {
 585             target_os: input.build_os,
 586             target_cpu: input.build_cpu,
 587             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 588             labels: "test",
 589             environment: {
 590                 "JT_JAVA": common.boot_jdk_home
 591             }
 592         },
 593 
 594         "run-test": {
 595             target_os: input.build_os,
 596             target_cpu: input.build_cpu,
 597             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 598             labels: "test",
 599             environment: {
 600                 "JT_JAVA": common.boot_jdk_home
 601             }
 602         }
 603     };
 604     profiles = concatObjects(profiles, testOnlyProfiles);
 605 
 606     // Profiles used to run tests using Jib for internal dependencies.
 607     var testedProfile = input.testedProfile;
 608     if (testedProfile == null) {
 609         testedProfile = input.build_os + "-" + input.build_cpu;
 610     }
 611     var testOnlyProfilesPrebuilt = {
 612         "run-test-prebuilt": {
 613             target_os: input.build_os,
 614             target_cpu: input.build_cpu,
 615             src: "src.conf",
 616             dependencies: [ "jtreg", "gnumake", "boot_jdk", "jib", testedProfile + ".jdk",
 617                 testedProfile + ".test", "src.full"
 618             ],
 619             work_dir: input.get("src.full", "install_path") + "/test",
 620             environment: {
 621                 "JT_JAVA": common.boot_jdk_home,
 622                 "PRODUCT_HOME": input.get(testedProfile + ".jdk", "home_path"),
 623                 "TEST_IMAGE_DIR": input.get(testedProfile + ".test", "home_path"),
 624                 "TEST_OUTPUT_DIR": input.src_top_dir
 625             },
 626             labels: "test"
 627         }
 628     };
 629     // If actually running the run-test-prebuilt profile, verify that the input
 630     // variable is valid and if so, add the appropriate target_* values from
 631     // the tested profile.
 632     if (input.profile == "run-test-prebuilt") {
 633         if (profiles[testedProfile] == null) {
 634             error("testedProfile is not defined: " + testedProfile);
 635         }
 636     }
 637     if (profiles[testedProfile] != null) {
 638         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 639             = profiles[testedProfile]["target_os"];
 640         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 641             = profiles[testedProfile]["target_cpu"];
 642     }
 643     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 644 
 645     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 646     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 647     if (input.build_os == "macosx") {
 648         macosxRunTestExtra = {
 649             dependencies: [ "devkit" ],
 650             environment_path: input.get("devkit", "install_path")
 651                 + "/Xcode.app/Contents/Developer/usr/bin"
 652         }
 653         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 654         profiles["run-test-jprt"] = concatObjects(profiles["run-test-jprt"], macosxRunTestExtra);
 655         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 656     }
 657 
 658     //
 659     // Define artifacts for profiles
 660     //
 661     // Macosx bundles are named osx
 662     // tar.gz.
 663     var artifactData = {
 664         "linux-x64": {
 665             platform: "linux-x64",
 666         },
 667         "linux-x86": {
 668             platform: "linux-x86",
 669         },
 670         "macosx-x64": {
 671             platform: "osx-x64",
 672             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 673             jre_subdir: "jre-" + data.version +  ".jre/Contents/Home"
 674         },
 675         "solaris-x64": {
 676             platform: "solaris-x64",
 677         },
 678         "solaris-sparcv9": {
 679             platform: "solaris-sparcv9",
 680         },
 681         "windows-x64": {
 682             platform: "windows-x64",
 683         },
 684         "windows-x86": {
 685             platform: "windows-x86",
 686         },
 687        "linux-arm64": {
 688             platform: "linux-arm64-vfp-hflt",
 689         },
 690         "linux-arm-vfp-hflt": {
 691             platform: "linux-arm32-vfp-hflt",
 692         },
 693         "linux-arm-vfp-hflt-dyn": {
 694             platform: "linux-arm32-vfp-hflt-dyn",
 695         }
 696     }
 697     // Generate common artifacts for all main profiles
 698     Object.keys(artifactData).forEach(function (name) {
 699         profiles[name] = concatObjects(profiles[name],
 700             common.main_profile_artifacts(artifactData[name]));
 701     });
 702 
 703     // Generate common artifacts for all debug profiles
 704     Object.keys(artifactData).forEach(function (name) {
 705         var debugName = name + common.debug_suffix;
 706         profiles[debugName] = concatObjects(profiles[debugName],
 707             common.debug_profile_artifacts(artifactData[name]));
 708     });
 709 
 710     // Extra profile specific artifacts
 711     profilesArtifacts = {
 712         "linux-x64": {
 713             artifacts: {
 714                 doc_api_spec: {
 715                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 716                     remote: [
 717                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 718                         "bundles/linux-x64/\\1"
 719                     ],
 720                 },
 721             }
 722         },
 723 
 724         "linux-x64-open": {
 725             artifacts: {
 726                 jdk: {
 727                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 728                     remote: [
 729                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 730                             + "_linux-x64_bin.tar.gz",
 731                         "bundles/openjdk/GPL/linux-x64/\\1"
 732                     ],
 733                     subdir: "jdk-" + data.version
 734                 },
 735                 jre: {
 736                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 737                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 738                 },
 739                 test: {
 740                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 741                     remote: [
 742                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 743                             + "_linux-x64_bin-tests.tar.gz",
 744                         "bundles/openjdk/GPL/linux-x64/\\1"
 745                     ]
 746                 },
 747                 jdk_symbols: {
 748                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 749                     remote: [
 750                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 751                             + "_linux-x64_bin-symbols.tar.gz",
 752                         "bundles/openjdk/GPL/linux-x64/\\1"
 753                     ],
 754                     subdir: "jdk-" + data.version
 755                 },
 756                 jre_symbols: {
 757                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 758                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 759                 },
 760                 doc_api_spec: {
 761                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 762                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 763                 },
 764             }
 765         },
 766 
 767         "linux-x86-open": {
 768             artifacts: {
 769                 jdk: {
 770                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 771                     remote: [
 772                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 773                             + "_linux-x86_bin.tar.gz",
 774                         "bundles/openjdk/GPL/linux-x86/\\1"
 775                     ],
 776                     subdir: "jdk-" + data.version
 777                 },
 778                 jdk_symbols: {
 779                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 780                     remote: [
 781                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 782                             + "_linux-x86_bin-symbols.tar.gz",
 783                         "bundles/openjdk/GPL/linux-x86/\\1"
 784                     ],
 785                     subdir: "jdk-" + data.version
 786                 },
 787                 test: {
 788                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 789                     remote: [
 790                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 791                             + "_linux-x86_bin-tests.tar.gz",
 792                         "bundles/openjdk/GPL/linux-x86/\\1"
 793                     ]
 794                 },
 795                 jre: {
 796                     // This regexp needs to not match the compact* files below
 797                     local: "bundles/\\(jre.*[+][0-9]\\{1,\\}_linux-x86_bin.tar.gz\\)",
 798                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 799                 },
 800                 jre_compact1: {
 801                     local: "bundles/\\(jre.*-compact1_linux-x86_bin.tar.gz\\)",
 802                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 803                 },
 804                 jre_compact2: {
 805                     local: "bundles/\\(jre.*-compact2_linux-x86_bin.tar.gz\\)",
 806                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 807                 },
 808                 jre_compact3: {
 809                     local: "bundles/\\(jre.*-compact3_linux-x86_bin.tar.gz\\)",
 810                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 811                 },
 812             }
 813         },
 814 
 815         "macosx-x64-open": {
 816             artifacts: {
 817                 jdk: {
 818                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 819                     remote: [
 820                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 821                             + "_osx-x64_bin.tar.gz",
 822                         "bundles/openjdk/GPL/osx-x64/\\1"
 823                     ],
 824                     subdir: "jdk-" + data.version
 825                 },
 826                 jre: {
 827                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 828                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 829                 },
 830                 test: {
 831                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 832                     remote: [
 833                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 834                             + "_osx-x64_bin-tests.tar.gz",
 835                         "bundles/openjdk/GPL/osx-x64/\\1"
 836                     ]
 837                 },
 838                 jdk_symbols: {
 839                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 840                     remote: [
 841                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 842                             + "_osx-x64_bin-symbols.tar.gz",
 843                         "bundles/openjdk/GPL/osx-x64/\\1"
 844                     ],
 845                     subdir: "jdk-" + data.version
 846                 },
 847                 jre_symbols: {
 848                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 849                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 850                 },
 851                 doc_api_spec: {
 852                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 853                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 854                 },
 855             }
 856         },
 857 
 858         "windows-x86-open": {
 859             artifacts: {
 860                 jdk: {
 861                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 862                     remote: [
 863                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 864                             + "_windows-x86_bin.tar.gz",
 865                         "bundles/openjdk/GPL/windows-x86/\\1"
 866                     ],
 867                     subdir: "jdk-" + data.version
 868                 },
 869                 jre: {
 870                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 871                     remote: "bundles/openjdk/GPL/windows-x86/\\1"
 872                 },
 873                 test: {
 874                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 875                     remote: [
 876                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 877                             + "_windows-x86_bin-tests.tar.gz",
 878                         "bundles/openjdk/GPL/windows-x86/\\1"
 879                     ]
 880                 },
 881                 jdk_symbols: {
 882                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 883                     remote: [
 884                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 885                             + "_windows-x86_bin-symbols.tar.gz",
 886                         "bundles/openjdk/GPL/windows-x86/\\1"
 887                     ],
 888                     subdir: "jdk-" + data.version
 889                 },
 890                 jre_symbols: {
 891                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 892                     remote: "bundles/openjdk/GPL/windows-x86/\\1",
 893                 }
 894             }
 895         },
 896 
 897         "windows-x64-open": {
 898             artifacts: {
 899                 jdk: {
 900                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 901                     remote: [
 902                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 903                             + "_windows-x64_bin.tar.gz",
 904                         "bundles/openjdk/GPL/windows-x64/\\1"
 905                     ],
 906                     subdir: "jdk-" + data.version
 907                 },
 908                 jre: {
 909                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 910                     remote: "bundles/openjdk/GPL/windows-x64/\\1"
 911                 },
 912                 test: {
 913                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 914                     remote: [
 915                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 916                             + "_windows-x64_bin-tests.tar.gz",
 917                         "bundles/openjdk/GPL/windows-x64/\\1"
 918                     ]
 919                 },
 920                 jdk_symbols: {
 921                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 922                     remote: [
 923                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 924                             + "_windows-x64_bin-symbols.tar.gz",
 925                         "bundles/openjdk/GPL/windows-x64/\\1"
 926                     ],
 927                     subdir: "jdk-" + data.version
 928                 },
 929                 jre_symbols: {
 930                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 931                     remote: "bundles/openjdk/GPL/windows-x64/\\1",
 932                 }
 933             }
 934         },
 935 
 936         "linux-x86-open-debug": {
 937             artifacts: {
 938                 jdk: {
 939                     local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
 940                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 941                 },
 942                 jre: {
 943                     local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
 944                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 945                 },
 946                 jdk_symbols: {
 947                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 948                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 949                 },
 950             }
 951         },
 952 
 953     };
 954     profiles = concatObjects(profiles, profilesArtifacts);
 955 
 956 
 957     // Define the reference implementation profiles. These are basically the same
 958     // as the open profiles, but upload artifacts to a different location and
 959     // are only defined for specific platforms.
 960     profiles["linux-x64-ri"] = clone(profiles["linux-x64-open"]);
 961     profiles["linux-x86-ri"] = clone(profiles["linux-x86-open"]);
 962     profiles["linux-x86-ri-debug"] = clone(profiles["linux-x86-open-debug"]);
 963     profiles["macosx-x64-ri"] = clone(profiles["macosx-x64-open"]);
 964     profiles["windows-x86-ri"] = clone(profiles["windows-x86-open"]);
 965     profiles["windows-x64-ri"] = clone(profiles["windows-x64-open"]);
 966 
 967     // Generate artifacts for ri profiles
 968     [ "linux-x64-ri", "linux-x86-ri", "linux-x86-ri-debug", "macosx-x64-ri", "windows-x86-ri", "windows-x64-ri" ]
 969         .forEach(function (name) {
 970             // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 971             for (artifactName in profiles[name].artifacts) {
 972                 var artifact = profiles[name].artifacts[artifactName];
 973                 artifact.remote = replaceAll("\/GPL\/", "/BCL/",
 974                     (artifact.remote != null ? artifact.remote : artifact.local));
 975             }
 976         });
 977 
 978     // The windows ri profile needs to add the freetype license file
 979     profilesRiFreetype = {
 980         "windows-x86-ri": {
 981             configure_args: "--with-freetype-license="
 982                 + input.get("freetype", "install_path")
 983                 + "/freetype-2.7.1-v120-x86/freetype.md"
 984         },
 985         "windows-x64-ri": {
 986             configure_args: "--with-freetype-license="
 987                 + input.get("freetype", "install_path")
 988                 + "/freetype-2.7.1-v120-x64/freetype.md"
 989         }
 990     };
 991     profiles = concatObjects(profiles, profilesRiFreetype);
 992 
 993     // Generate the missing platform attributes
 994     profiles = generatePlatformAttributes(profiles);
 995     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
 996     return profiles;
 997 };
 998 
 999 /**
1000  * Generate the dependencies part of the configuration
1001  *
1002  * @param input External data to use for generating the configuration
1003  * @param common The common values
1004  * @returns {{}} Dependencies part of configuration
1005  */
1006 var getJibProfilesDependencies = function (input, common) {
1007 
1008     var devkit_platform_revisions = {
1009         linux_x64: "gcc4.9.2-OEL6.4+1.1",
1010         macosx_x64: "Xcode6.3-MacOSX10.9+1.0",
1011         solaris_x64: "SS12u4-Solaris11u1+1.0",
1012         solaris_sparcv9: "SS12u4-Solaris11u1+1.0",
1013         windows_x64: "VS2013SP4+1.0",
1014         linux_aarch64: "gcc-linaro-aarch64-linux-gnu-4.8-2013.11_linux+1.0",
1015         linux_arm: (input.profile != null && input.profile.indexOf("hflt") >= 0
1016                     ? "gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux+1.0"
1017                     : "arm-linaro-4.7+1.0")
1018     };
1019 
1020     var devkit_platform = (input.target_cpu == "x86"
1021         ? input.target_os + "_x64"
1022         : input.target_platform);
1023 
1024     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
1025         + "-" + input.build_cpu;
1026 
1027     var dependencies = {
1028 
1029         boot_jdk: {
1030             server: "jpg",
1031             product: "jdk",
1032             version: common.boot_jdk_version,
1033             build_number: "181",
1034             file: "bundles/" + boot_jdk_platform + "/jdk-" + common.boot_jdk_version + "_"
1035                 + boot_jdk_platform + "_bin.tar.gz",
1036             configure_args: "--with-boot-jdk=" + common.boot_jdk_home,
1037             environment_path: common.boot_jdk_home + "/bin"
1038         },
1039 
1040         devkit: {
1041             organization: common.organization,
1042             ext: "tar.gz",
1043             module: "devkit-" + devkit_platform,
1044             revision: devkit_platform_revisions[devkit_platform]
1045         },
1046 
1047         build_devkit: {
1048             organization: common.organization,
1049             ext: "tar.gz",
1050             module: "devkit-" + input.build_platform,
1051             revision: devkit_platform_revisions[input.build_platform]
1052         },
1053 
1054         cups: {
1055             organization: common.organization,
1056             ext: "tar.gz",
1057             revision: "1.0118+1.0"
1058         },
1059 
1060         jtreg: {
1061             server: "javare",
1062             revision: "4.2",
1063             build_number: "b08",
1064             checksum_file: "MD5_VALUES",
1065             file: "jtreg_bin-4.2.zip",
1066             environment_name: "JT_HOME",
1067             environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
1068         },
1069 
1070         gnumake: {
1071             organization: common.organization,
1072             ext: "tar.gz",
1073             revision: "4.0+1.0",
1074 
1075             module: (input.build_os == "windows"
1076                 ? "gnumake-" + input.build_osenv_platform
1077                 : "gnumake-" + input.build_platform),
1078 
1079             configure_args: (input.build_os == "windows"
1080                 ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make"
1081                 : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"),
1082 
1083             environment_path: (input.build_os == "windows"
1084                 ? input.get("gnumake", "install_path") + "/cygwin/bin"
1085                 : input.get("gnumake", "install_path") + "/bin")
1086         },
1087 
1088         freetype: {
1089             organization: common.organization,
1090             ext: "tar.gz",
1091             revision: "2.7.1-v120+1.0",
1092             module: "freetype-" + input.target_platform
1093         },
1094 
1095         graphviz: {
1096             organization: common.organization,
1097             ext: "tar.gz",
1098             revision: "2.38.0-1+1.1",
1099             module: "graphviz-" + input.target_platform,
1100             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
1101             environment_path: input.get("graphviz", "install_path")
1102         },
1103 
1104         pandoc: {
1105             organization: common.organization,
1106             ext: "tar.gz",
1107             revision: "1.17.2+1.0",
1108             module: "pandoc-" + input.target_platform,
1109             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
1110             environment_path: input.get("pandoc", "install_path") + "/pandoc"
1111         },
1112         // This adds java jib as a dependency for the test artifacts resolver
1113         jib: {
1114             organization: "com.oracle.java.jib",
1115             ext: "zip",
1116             classifier: "distribution",
1117             revision: "3.0-SNAPSHOT",
1118             environment_name: "JIB_JAR",
1119             environment_value: input.get("jib", "install_path")
1120                 + "/jib-3.0-SNAPSHOT-distribution/lib/jib-3.0-SNAPSHOT.jar"
1121        }
1122     };
1123 
1124     // Need to add a value for the Visual Studio tools variable to make
1125     // jaot be able to pick up the Visual Studio linker in testing.
1126     if (input.target_os == "windows") {
1127         dependencies.devkit.environment = {
1128             VS120COMNTOOLS: input.get("devkit", "install_path") + "/Common7/Tools"
1129         };
1130     }
1131 
1132     return dependencies;
1133 };
1134 
1135 /**
1136  * Generate the missing platform attributes for profiles
1137  *
1138  * @param profiles Profiles map to generate attributes on
1139  * @returns {{}} New profiles map with platform attributes fully filled in
1140  */
1141 var generatePlatformAttributes = function (profiles) {
1142     var ret = concatObjects(profiles, {});
1143     for (var profile in profiles) {
1144         if (ret[profile].build_os == null) {
1145             ret[profile].build_os = ret[profile].target_os;
1146         }
1147         if (ret[profile].build_cpu == null) {
1148             ret[profile].build_cpu = ret[profile].target_cpu;
1149         }
1150         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1151         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1152     }
1153     return ret;
1154 };
1155 
1156 /**
1157  * The default_make_targets attribute on a profile is not a real Jib attribute.
1158  * This function rewrites that attribute into the corresponding configure arg.
1159  * Calling this function multiple times on the same profiles object is safe.
1160  *
1161  * @param common Common values
1162  * @param profiles Profiles map to rewrite profiles for
1163  * @returns {{}} New map of profiles with the make targets converted
1164  */
1165 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1166     var ret = concatObjects(profiles, {});
1167     for (var profile in ret) {
1168         if (ret[profile]["default_make_targets"] != null) {
1169             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1170             // Iterate over all configure args and see if --with-default-make-target
1171             // is already there and change it, otherwise add it.
1172             var found = false;
1173             for (var i in ret[profile].configure_args) {
1174                 var arg = ret[profile].configure_args[i];
1175                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1176                     found = true;
1177                     ret[profile].configure_args[i]
1178                         = "--with-default-make-target=" + targetsString;
1179                 }
1180             }
1181             if (!found) {
1182                 ret[profile].configure_args = concat(
1183                     ret[profile].configure_args,
1184                     "--with-default-make-target=" + targetsString);
1185             }
1186         }
1187     }
1188     return ret;
1189 }
1190 
1191 var getBuildId = function (input) {
1192     if (input.build_id != null) {
1193         return input.build_id;
1194     } else {
1195         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1196         var userName = java.lang.System.getProperty("user.name");
1197         return userName + "." + topdir;
1198     }
1199 }
1200 
1201 /**
1202  * Deep clones an object tree.
1203  *
1204  * @param o Object to clone
1205  * @returns {{}} Clone of o
1206  */
1207 var clone = function (o) {
1208     return JSON.parse(JSON.stringify(o));
1209 };
1210 
1211 /**
1212  * Concatenates all arguments into a new array
1213  *
1214  * @returns {Array.<T>} New array containing all arguments
1215  */
1216 var concat = function () {
1217     return Array.prototype.concat.apply([], arguments);
1218 };
1219 
1220 /**
1221  * Takes a String or Array of Strings and does a replace operation on each
1222  * of them.
1223  *
1224  * @param pattern Pattern to look for
1225  * @param replacement Replacement text to insert
1226  * @param a String or Array of Strings to replace
1227  * @returns {Array} Either a new array or a new string depending on the input
1228  */
1229 var replaceAll = function (pattern, replacement, a) {
1230     // If a is an array
1231     if (Array === a.constructor) {
1232     var newA = [];
1233     for (var i in a) {
1234             newA.push(a[i].replace(pattern, replacement));
1235         }
1236         return newA;
1237         } else {
1238         return a.replace(pattern, replacement);
1239     }
1240 };
1241 
1242 /**
1243  * Deep concatenation of two objects. For each node encountered, merge
1244  * the contents with the corresponding node in the other object tree,
1245  * treating all strings as array elements.
1246  *
1247  * @param o1 Object to concatenate
1248  * @param o2 Object to concatenate
1249  * @returns {{}} New object tree containing the concatenation of o1 and o2
1250  */
1251 var concatObjects = function (o1, o2) {
1252     if (o1 == null) {
1253         return clone(o2);
1254     }
1255     if (o2 == null) {
1256         return clone(o1);
1257     }
1258     var ret = {};
1259     for (var a in o1) {
1260         if (o2[a] == null) {
1261             ret[a] = clone(o1[a]);
1262         }
1263     }
1264     for (var a in o2) {
1265         if (o1[a] == null) {
1266             ret[a] = clone(o2[a]);
1267         } else {
1268             if (typeof o1[a] == 'string') {
1269                 ret[a] = clone([o1[a]].concat(o2[a]));
1270             } else if (Array.isArray(o1[a])) {
1271                 ret[a] = clone(o1[a].concat(o2[a]));
1272             } else if (typeof o1[a] == 'object') {
1273                 ret[a] = concatObjects(o1[a], o2[a]);
1274             }
1275         }
1276     }
1277     return ret;
1278 };
1279 
1280 /**
1281  * Constructs the numeric version string from reading the
1282  * common/autoconf/version-numbers file and removing all trailing ".0".
1283  *
1284  * @param major Override major version
1285  * @param minor Override minor version
1286  * @param security Override security version
1287  * @param patch Override patch version
1288  * @returns {String} The numeric version string
1289  */
1290 var getVersion = function (major, minor, security, patch) {
1291     var version_numbers = getVersionNumbers();
1292     var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1293         + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1294         + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1295         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1296     while (version.match(".*\\.0$")) {
1297         version = version.substring(0, version.length - 2);
1298     }
1299     return version;
1300 };
1301 
1302 /**
1303  * Constructs the common version configure args based on build type and
1304  * other version inputs
1305  */
1306 var versionArgs = function(input, common) {
1307     var args = ["--with-version-build=" + common.build_number];
1308     if (input.build_type == "promoted") {
1309         args = concat(args,
1310                       // This needs to be changed when we start building release candidates
1311                       "--with-version-pre=ea",
1312                       "--without-version-opt");
1313     } else {
1314         args = concat(args, "--with-version-opt=" + common.build_id);
1315     }
1316     return args;
1317 }
1318 
1319 // Properties representation of the common/autoconf/version-numbers file. Lazily
1320 // initiated by the function below.
1321 var version_numbers;
1322 
1323 /**
1324  * Read the common/autoconf/version-numbers file into a Properties object.
1325  *
1326  * @returns {java.utilProperties}
1327  */
1328 var getVersionNumbers = function () {
1329     // Read version information from common/autoconf/version-numbers
1330     if (version_numbers == null) {
1331         version_numbers = new java.util.Properties();
1332         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
1333         version_numbers.load(stream);
1334         stream.close();
1335     }
1336     return version_numbers;
1337 }