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                 jdk_symbols: {
 304                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 305                     remote: [
 306                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 307                         "bundles/" + pf + "/\\1"
 308                     ],
 309                     subdir: jdk_subdir,
 310                     exploded: "images/jdk"
 311                 },
 312                 jre_symbols: {
 313                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 314                     remote: [
 315                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-symbols.tar.gz",
 316                         "bundles/" + pf + "/\\1"
 317                     ],
 318                     subdir: jre_subdir,
 319                     exploded: "images/jre"
 320                 }
 321             }
 322         };
 323     };
 324 
 325 
 326     /**
 327      * Define common artifacts template for all debug profiles
 328      * @param o - Object containing data for artifacts
 329      */
 330     common.debug_profile_artifacts = function (o) {
 331         var jdk_subdir = "jdk-" + data.version + "/fastdebug";
 332         var jre_subdir = "jre-" + data.version + "/fastdebug";
 333         var pf = o.platform
 334         return {
 335             artifacts: {
 336                 jdk: {
 337                     local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
 338                     remote: [
 339                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 340                         "bundles/" + pf + "/\\1"
 341                     ],
 342                     subdir: jdk_subdir,
 343                     exploded: "images/jdk"
 344                 },
 345                 jre: {
 346                     local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
 347                     remote: [
 348                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug.tar.gz",
 349                         "bundles/" + pf + "/\\1"
 350                     ],
 351                     subdir: jre_subdir,
 352                     exploded: "images/jre"
 353                 },
 354                 test: {
 355                     local: "bundles/\\(jdk.*bin-tests-debug.tar.gz\\)",
 356                     remote: [
 357                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-tests-debug.tar.gz",
 358                         "bundles/" + pf + "/\\1"
 359                     ],
 360                     exploded: "images/test"
 361                 },
 362                 jdk_symbols: {
 363                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 364                     remote: [
 365                         "bundles/" + pf + "/jdk-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 366                         "bundles/" + pf + "/\\1"
 367                     ],
 368                     subdir: jdk_subdir,
 369                     exploded: "images/jdk"
 370                 },
 371                 jre_symbols: {
 372                     local: "bundles/\\(jre.*bin-debug-symbols.tar.gz\\)",
 373                     remote: [
 374                         "bundles/" + pf + "/jre-" + data.version + "_" + pf + "_bin-debug-symbols.tar.gz",
 375                         "bundles/" + pf + "/\\1"
 376                     ],
 377                     subdir: jre_subdir,
 378                     exploded: "images/jre"
 379                 }
 380             }
 381         };
 382     };
 383 
 384     return common;
 385 };
 386 
 387 /**
 388  * Generates the profiles part of the configuration.
 389  *
 390  * @param input External data to use for generating the configuration
 391  * @param common The common values
 392  * @returns {{}} Profiles part of the configuration
 393  */
 394 var getJibProfilesProfiles = function (input, common, data) {
 395     // Main SE profiles
 396     var profiles = {
 397 
 398         "linux-x64": {
 399             target_os: "linux",
 400             target_cpu: "x64",
 401             dependencies: ["devkit", "graphviz", "pandoc"],
 402             configure_args: concat(common.configure_args_64bit,
 403                 "--enable-full-docs", "--with-zlib=system"),
 404             default_make_targets: ["docs-bundles"],
 405         },
 406 
 407         "linux-x86": {
 408             target_os: "linux",
 409             target_cpu: "x86",
 410             build_cpu: "x64",
 411             dependencies: ["devkit"],
 412             configure_args: concat(common.configure_args_32bit,
 413                 "--with-jvm-variants=minimal,server", "--with-zlib=system"),
 414         },
 415 
 416         "macosx-x64": {
 417             target_os: "macosx",
 418             target_cpu: "x64",
 419             dependencies: ["devkit"],
 420             configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
 421                 "--with-macosx-version-max=10.7.0"),
 422         },
 423 
 424         "solaris-x64": {
 425             target_os: "solaris",
 426             target_cpu: "x64",
 427             dependencies: ["devkit", "cups"],
 428             configure_args: concat(common.configure_args_64bit,
 429                 "--with-zlib=system", "--enable-dtrace"),
 430         },
 431 
 432         "solaris-sparcv9": {
 433             target_os: "solaris",
 434             target_cpu: "sparcv9",
 435             dependencies: ["devkit", "cups"],
 436             configure_args: concat(common.configure_args_64bit,
 437                 "--with-zlib=system", "--enable-dtrace"),
 438         },
 439 
 440         "windows-x64": {
 441             target_os: "windows",
 442             target_cpu: "x64",
 443             dependencies: ["devkit", "freetype"],
 444             configure_args: concat(common.configure_args_64bit),
 445         },
 446 
 447         "windows-x86": {
 448             target_os: "windows",
 449             target_cpu: "x86",
 450             build_cpu: "x64",
 451             dependencies: ["devkit", "freetype"],
 452             configure_args: concat(common.configure_args_32bit),
 453         },
 454 
 455         "linux-arm64": {
 456             target_os: "linux",
 457             target_cpu: "aarch64",
 458             build_cpu: "x64",
 459             dependencies: ["devkit", "build_devkit", "cups", "headless_stubs"],
 460             configure_args: [
 461                 "--with-cpu-port=arm64",
 462                 "--with-jvm-variants=server",
 463                 "--openjdk-target=aarch64-linux-gnu",
 464                 "--enable-headless-only"
 465             ],
 466         },
 467 
 468         "linux-arm-vfp-hflt": {
 469             target_os: "linux",
 470             target_cpu: "arm",
 471             build_cpu: "x64",
 472             dependencies: ["devkit", "build_devkit", "cups"],
 473             configure_args: [
 474                 "--with-jvm-variants=minimal1,client",
 475                 "--with-x=" + input.get("devkit", "install_path") + "/arm-linux-gnueabihf/libc/usr/X11R6-PI",
 476                 "--openjdk-target=arm-linux-gnueabihf",
 477                 "--with-abi-profile=arm-vfp-hflt"
 478             ],
 479         },
 480 
 481         // Special version of the SE profile adjusted to be testable on arm64 hardware.
 482         "linux-arm-vfp-hflt-dyn": {
 483             configure_args: "--with-stdc++lib=dynamic"
 484         }
 485     };
 486     // Let linux-arm-vfp-hflt-dyn inherit everything from linux-arm-vfp-hflt
 487     profiles["linux-arm-vfp-hflt-dyn"] = concatObjects(
 488         profiles["linux-arm-vfp-hflt-dyn"], profiles["linux-arm-vfp-hflt"]);
 489 
 490     // Add the base settings to all the main profiles
 491     common.main_profile_names.forEach(function (name) {
 492         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 493     });
 494 
 495     // Generate debug versions of all the main profiles
 496     common.main_profile_names.forEach(function (name) {
 497         var debugName = name + common.debug_suffix;
 498         profiles[debugName] = concatObjects(profiles[name],
 499                                             common.debug_profile_base);
 500     });
 501     // Generate slowdebug versions of all the main profiles
 502     common.main_profile_names.forEach(function (name) {
 503         var debugName = name + common.slowdebug_suffix;
 504         profiles[debugName] = concatObjects(profiles[name],
 505                                             common.slowdebug_profile_base);
 506     });
 507 
 508     // Generate open only profiles for all the main profiles for JPRT and reference
 509     // implementation builds.
 510     common.main_profile_names.forEach(function (name) {
 511         var openName = name + common.open_suffix;
 512         profiles[openName] = concatObjects(profiles[name],
 513                                            common.open_profile_base);
 514     });
 515     // The open only profiles on linux are used for reference builds and should
 516     // produce the compact profile images by default. This adds "profiles" as an
 517     // extra default target.
 518     var openOnlyProfilesExtra = {
 519         "linux-x86-open": {
 520             default_make_targets: "profiles-bundles",
 521             configure_args: "--with-jvm-variants=client,server"
 522         }
 523     };
 524     profiles = concatObjects(profiles, openOnlyProfilesExtra);
 525 
 526     // Generate debug profiles for the open only profiles
 527     common.main_profile_names.forEach(function (name) {
 528         var openName = name + common.open_suffix;
 529         var openDebugName = openName + common.debug_suffix;
 530         profiles[openDebugName] = concatObjects(profiles[openName],
 531                                                 common.debug_profile_base);
 532     });
 533 
 534     // Profiles for building the zero jvm variant. These are used for verification
 535     // in JPRT.
 536     var zeroProfiles = {
 537         "linux-x64-zero": {
 538             target_os: "linux",
 539             target_cpu: "x64",
 540             dependencies: ["devkit"],
 541             configure_args: concat(common.configure_args_64bit, [
 542                 "--with-zlib=system",
 543                 "--with-jvm-variants=zero",
 544                 "--enable-libffi-bundling"
 545             ])
 546         },
 547 
 548         "linux-x86-zero": {
 549             target_os: "linux",
 550             target_cpu: "x86",
 551             build_cpu: "x64",
 552             dependencies: ["devkit"],
 553             configure_args:  concat(common.configure_args_32bit, [
 554                 "--with-zlib=system",
 555                 "--with-jvm-variants=zero",
 556                 "--enable-libffi-bundling"
 557             ])
 558         }
 559     }
 560     profiles = concatObjects(profiles, zeroProfiles);
 561 
 562     // Add the base settings to the zero profiles and generate debug profiles
 563     Object.keys(zeroProfiles).forEach(function (name) {
 564         var debugName = name + common.debug_suffix;
 565         profiles[name] = concatObjects(common.main_profile_base, profiles[name]);
 566         profiles[debugName] = concatObjects(profiles[name], common.debug_profile_base);
 567     });
 568 
 569     // Profiles used to run tests. Used in JPRT and Mach 5.
 570     var testOnlyProfiles = {
 571         "run-test-jprt": {
 572             target_os: input.build_os,
 573             target_cpu: input.build_cpu,
 574             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 575             labels: "test",
 576             environment: {
 577                 "JT_JAVA": common.boot_jdk_home
 578             }
 579         },
 580 
 581         "run-test": {
 582             target_os: input.build_os,
 583             target_cpu: input.build_cpu,
 584             dependencies: [ "jtreg", "gnumake", "boot_jdk", "devkit", "jib" ],
 585             labels: "test",
 586             environment: {
 587                 "JT_JAVA": common.boot_jdk_home
 588             }
 589         }
 590     };
 591     profiles = concatObjects(profiles, testOnlyProfiles);
 592 
 593     // Profiles used to run tests using Jib for internal dependencies.
 594     var testedProfile = input.testedProfile;
 595     if (testedProfile == null) {
 596         testedProfile = input.build_os + "-" + input.build_cpu;
 597     }
 598     var testOnlyProfilesPrebuilt = {
 599         "run-test-prebuilt": {
 600             target_os: input.build_os,
 601             target_cpu: input.build_cpu,
 602             src: "src.conf",
 603             dependencies: [ "jtreg", "gnumake", "boot_jdk", "jib", testedProfile + ".jdk",
 604                 testedProfile + ".test", "src.full"
 605             ],
 606             work_dir: input.get("src.full", "install_path") + "/test",
 607             environment: {
 608                 "JT_JAVA": common.boot_jdk_home,
 609                 "PRODUCT_HOME": input.get(testedProfile + ".jdk", "home_path"),
 610                 "TEST_IMAGE_DIR": input.get(testedProfile + ".test", "home_path"),
 611                 "TEST_OUTPUT_DIR": input.src_top_dir
 612             },
 613             labels: "test"
 614         }
 615     };
 616     // If actually running the run-test-prebuilt profile, verify that the input
 617     // variable is valid and if so, add the appropriate target_* values from
 618     // the tested profile.
 619     if (input.profile == "run-test-prebuilt") {
 620         if (profiles[testedProfile] == null) {
 621             error("testedProfile is not defined: " + testedProfile);
 622         }
 623     }
 624     if (profiles[testedProfile] != null) {
 625         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_os"]
 626             = profiles[testedProfile]["target_os"];
 627         testOnlyProfilesPrebuilt["run-test-prebuilt"]["target_cpu"]
 628             = profiles[testedProfile]["target_cpu"];
 629     }
 630     profiles = concatObjects(profiles, testOnlyProfilesPrebuilt);
 631 
 632     // On macosx add the devkit bin dir to the path in all the run-test profiles.
 633     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
 634     if (input.build_os == "macosx") {
 635         macosxRunTestExtra = {
 636             dependencies: [ "devkit" ],
 637             environment_path: input.get("devkit", "install_path")
 638                 + "/Xcode.app/Contents/Developer/usr/bin"
 639         }
 640         profiles["run-test"] = concatObjects(profiles["run-test"], macosxRunTestExtra);
 641         profiles["run-test-jprt"] = concatObjects(profiles["run-test-jprt"], macosxRunTestExtra);
 642         profiles["run-test-prebuilt"] = concatObjects(profiles["run-test-prebuilt"], macosxRunTestExtra);
 643     }
 644 
 645     //
 646     // Define artifacts for profiles
 647     //
 648     // Macosx bundles are named osx
 649     // tar.gz.
 650     var artifactData = {
 651         "linux-x64": {
 652             platform: "linux-x64",
 653         },
 654         "linux-x86": {
 655             platform: "linux-x86",
 656         },
 657         "macosx-x64": {
 658             platform: "osx-x64",
 659             jdk_subdir: "jdk-" + data.version +  ".jdk/Contents/Home",
 660             jre_subdir: "jre-" + data.version +  ".jre/Contents/Home"
 661         },
 662         "solaris-x64": {
 663             platform: "solaris-x64",
 664         },
 665         "solaris-sparcv9": {
 666             platform: "solaris-sparcv9",
 667         },
 668         "windows-x64": {
 669             platform: "windows-x64",
 670         },
 671         "windows-x86": {
 672             platform: "windows-x86",
 673         },
 674        "linux-arm64": {
 675             platform: "linux-arm64-vfp-hflt",
 676         },
 677         "linux-arm-vfp-hflt": {
 678             platform: "linux-arm32-vfp-hflt",
 679         },
 680         "linux-arm-vfp-hflt-dyn": {
 681             platform: "linux-arm32-vfp-hflt-dyn",
 682         }
 683     }
 684     // Generate common artifacts for all main profiles
 685     Object.keys(artifactData).forEach(function (name) {
 686         profiles[name] = concatObjects(profiles[name],
 687             common.main_profile_artifacts(artifactData[name]));
 688     });
 689 
 690     // Generate common artifacts for all debug profiles
 691     Object.keys(artifactData).forEach(function (name) {
 692         var debugName = name + common.debug_suffix;
 693         profiles[debugName] = concatObjects(profiles[debugName],
 694             common.debug_profile_artifacts(artifactData[name]));
 695     });
 696 
 697     // Extra profile specific artifacts
 698     profilesArtifacts = {
 699         "linux-x64": {
 700             artifacts: {
 701                 doc_api_spec: {
 702                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 703                     remote: [
 704                         "bundles/common/jdk-" + data.version + "_doc-api-spec.tar.gz",
 705                         "bundles/linux-x64/\\1"
 706                     ],
 707                 },
 708             }
 709         },
 710 
 711         "linux-x64-open": {
 712             artifacts: {
 713                 jdk: {
 714                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 715                     remote: [
 716                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 717                             + "_linux-x64_bin.tar.gz",
 718                         "bundles/openjdk/GPL/linux-x64/\\1"
 719                     ],
 720                     subdir: "jdk-" + data.version
 721                 },
 722                 jre: {
 723                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 724                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 725                 },
 726                 test: {
 727                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 728                     remote: [
 729                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 730                             + "_linux-x64_bin-tests.tar.gz",
 731                         "bundles/openjdk/GPL/linux-x64/\\1"
 732                     ]
 733                 },
 734                 jdk_symbols: {
 735                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 736                     remote: [
 737                         "bundles/openjdk/GPL/linux-x64/jdk-" + data.version
 738                             + "_linux-x64_bin-symbols.tar.gz",
 739                         "bundles/openjdk/GPL/linux-x64/\\1"
 740                     ],
 741                     subdir: "jdk-" + data.version
 742                 },
 743                 jre_symbols: {
 744                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 745                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 746                 },
 747                 doc_api_spec: {
 748                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 749                     remote: "bundles/openjdk/GPL/linux-x64/\\1",
 750                 },
 751             }
 752         },
 753 
 754         "linux-x86-open": {
 755             artifacts: {
 756                 jdk: {
 757                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 758                     remote: [
 759                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 760                             + "_linux-x86_bin.tar.gz",
 761                         "bundles/openjdk/GPL/linux-x86/\\1"
 762                     ],
 763                     subdir: "jdk-" + data.version
 764                 },
 765                 jdk_symbols: {
 766                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 767                     remote: [
 768                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 769                             + "_linux-x86_bin-symbols.tar.gz",
 770                         "bundles/openjdk/GPL/linux-x86/\\1"
 771                     ],
 772                     subdir: "jdk-" + data.version
 773                 },
 774                 test: {
 775                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 776                     remote: [
 777                         "bundles/openjdk/GPL/linux-x86/jdk-" + data.version
 778                             + "_linux-x86_bin-tests.tar.gz",
 779                         "bundles/openjdk/GPL/linux-x86/\\1"
 780                     ]
 781                 },
 782                 jre: {
 783                     // This regexp needs to not match the compact* files below
 784                     local: "bundles/\\(jre.*[+][0-9]\\{1,\\}_linux-x86_bin.tar.gz\\)",
 785                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 786                 },
 787                 jre_compact1: {
 788                     local: "bundles/\\(jre.*-compact1_linux-x86_bin.tar.gz\\)",
 789                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 790                 },
 791                 jre_compact2: {
 792                     local: "bundles/\\(jre.*-compact2_linux-x86_bin.tar.gz\\)",
 793                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 794                 },
 795                 jre_compact3: {
 796                     local: "bundles/\\(jre.*-compact3_linux-x86_bin.tar.gz\\)",
 797                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 798                 },
 799             }
 800         },
 801 
 802         "macosx-x64-open": {
 803             artifacts: {
 804                 jdk: {
 805                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 806                     remote: [
 807                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 808                             + "_osx-x64_bin.tar.gz",
 809                         "bundles/openjdk/GPL/osx-x64/\\1"
 810                     ],
 811                     subdir: "jdk-" + data.version
 812                 },
 813                 jre: {
 814                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 815                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 816                 },
 817                 test: {
 818                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 819                     remote: [
 820                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 821                             + "_osx-x64_bin-tests.tar.gz",
 822                         "bundles/openjdk/GPL/osx-x64/\\1"
 823                     ]
 824                 },
 825                 jdk_symbols: {
 826                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 827                     remote: [
 828                         "bundles/openjdk/GPL/osx-x64/jdk-" + data.version
 829                             + "_osx-x64_bin-symbols.tar.gz",
 830                         "bundles/openjdk/GPL/osx-x64/\\1"
 831                     ],
 832                     subdir: "jdk-" + data.version
 833                 },
 834                 jre_symbols: {
 835                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 836                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 837                 },
 838                 doc_api_spec: {
 839                     local: "bundles/\\(jdk.*doc-api-spec.tar.gz\\)",
 840                     remote: "bundles/openjdk/GPL/osx-x64/\\1",
 841                 },
 842             }
 843         },
 844 
 845         "windows-x86-open": {
 846             artifacts: {
 847                 jdk: {
 848                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 849                     remote: [
 850                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 851                             + "_windows-x86_bin.tar.gz",
 852                         "bundles/openjdk/GPL/windows-x86/\\1"
 853                     ],
 854                     subdir: "jdk-" + data.version
 855                 },
 856                 jre: {
 857                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 858                     remote: "bundles/openjdk/GPL/windows-x86/\\1"
 859                 },
 860                 test: {
 861                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 862                     remote: [
 863                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 864                             + "_windows-x86_bin-tests.tar.gz",
 865                         "bundles/openjdk/GPL/windows-x86/\\1"
 866                     ]
 867                 },
 868                 jdk_symbols: {
 869                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 870                     remote: [
 871                         "bundles/openjdk/GPL/windows-x86/jdk-" + data.version
 872                             + "_windows-x86_bin-symbols.tar.gz",
 873                         "bundles/openjdk/GPL/windows-x86/\\1"
 874                     ],
 875                     subdir: "jdk-" + data.version
 876                 },
 877                 jre_symbols: {
 878                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 879                     remote: "bundles/openjdk/GPL/windows-x86/\\1",
 880                 }
 881             }
 882         },
 883 
 884         "windows-x64-open": {
 885             artifacts: {
 886                 jdk: {
 887                     local: "bundles/\\(jdk.*bin.tar.gz\\)",
 888                     remote: [
 889                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 890                             + "_windows-x64_bin.tar.gz",
 891                         "bundles/openjdk/GPL/windows-x64/\\1"
 892                     ],
 893                     subdir: "jdk-" + data.version
 894                 },
 895                 jre: {
 896                     local: "bundles/\\(jre.*bin.tar.gz\\)",
 897                     remote: "bundles/openjdk/GPL/windows-x64/\\1"
 898                 },
 899                 test: {
 900                     local: "bundles/\\(jdk.*bin-tests.tar.gz\\)",
 901                     remote: [
 902                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 903                             + "_windows-x64_bin-tests.tar.gz",
 904                         "bundles/openjdk/GPL/windows-x64/\\1"
 905                     ]
 906                 },
 907                 jdk_symbols: {
 908                     local: "bundles/\\(jdk.*bin-symbols.tar.gz\\)",
 909                     remote: [
 910                         "bundles/openjdk/GPL/windows-x64/jdk-" + data.version
 911                             + "_windows-x64_bin-symbols.tar.gz",
 912                         "bundles/openjdk/GPL/windows-x64/\\1"
 913                     ],
 914                     subdir: "jdk-" + data.version
 915                 },
 916                 jre_symbols: {
 917                     local: "bundles/\\(jre.*bin-symbols.tar.gz\\)",
 918                     remote: "bundles/openjdk/GPL/windows-x64/\\1",
 919                 }
 920             }
 921         },
 922 
 923         "linux-x86-open-debug": {
 924             artifacts: {
 925                 jdk: {
 926                     local: "bundles/\\(jdk.*bin-debug.tar.gz\\)",
 927                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 928                 },
 929                 jre: {
 930                     local: "bundles/\\(jre.*bin-debug.tar.gz\\)",
 931                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 932                 },
 933                 jdk_symbols: {
 934                     local: "bundles/\\(jdk.*bin-debug-symbols.tar.gz\\)",
 935                     remote: "bundles/openjdk/GPL/profile/linux-x86/\\1",
 936                 },
 937             }
 938         },
 939 
 940     };
 941     profiles = concatObjects(profiles, profilesArtifacts);
 942 
 943 
 944     // Define the reference implementation profiles. These are basically the same
 945     // as the open profiles, but upload artifacts to a different location and
 946     // are only defined for specific platforms.
 947     profiles["linux-x64-ri"] = clone(profiles["linux-x64-open"]);
 948     profiles["linux-x86-ri"] = clone(profiles["linux-x86-open"]);
 949     profiles["linux-x86-ri-debug"] = clone(profiles["linux-x86-open-debug"]);
 950     profiles["macosx-x64-ri"] = clone(profiles["macosx-x64-open"]);
 951     profiles["windows-x86-ri"] = clone(profiles["windows-x86-open"]);
 952     profiles["windows-x64-ri"] = clone(profiles["windows-x64-open"]);
 953 
 954     // Generate artifacts for ri profiles
 955     [ "linux-x64-ri", "linux-x86-ri", "linux-x86-ri-debug", "macosx-x64-ri", "windows-x86-ri", "windows-x64-ri" ]
 956         .forEach(function (name) {
 957             // Rewrite all remote dirs to "bundles/openjdk/BCL/..."
 958             for (artifactName in profiles[name].artifacts) {
 959                 var artifact = profiles[name].artifacts[artifactName];
 960                 artifact.remote = replaceAll("\/GPL\/", "/BCL/",
 961                     (artifact.remote != null ? artifact.remote : artifact.local));
 962             }
 963         });
 964 
 965     // The windows ri profile needs to add the freetype license file
 966     profilesRiFreetype = {
 967         "windows-x86-ri": {
 968             configure_args: "--with-freetype-license="
 969                 + input.get("freetype", "install_path")
 970                 + "/freetype-2.7.1-v120-x86/freetype.md"
 971         },
 972         "windows-x64-ri": {
 973             configure_args: "--with-freetype-license="
 974                 + input.get("freetype", "install_path")
 975                 + "/freetype-2.7.1-v120-x64/freetype.md"
 976         }
 977     };
 978     profiles = concatObjects(profiles, profilesRiFreetype);
 979 
 980     // Generate the missing platform attributes
 981     profiles = generatePlatformAttributes(profiles);
 982     profiles = generateDefaultMakeTargetsConfigureArg(common, profiles);
 983     return profiles;
 984 };
 985 
 986 /**
 987  * Generate the dependencies part of the configuration
 988  *
 989  * @param input External data to use for generating the configuration
 990  * @param common The common values
 991  * @returns {{}} Dependencies part of configuration
 992  */
 993 var getJibProfilesDependencies = function (input, common) {
 994 
 995     var devkit_platform_revisions = {
 996         linux_x64: "gcc4.9.2-OEL6.4+1.1",
 997         macosx_x64: "Xcode6.3-MacOSX10.9+1.0",
 998         solaris_x64: "SS12u4-Solaris11u1+1.0",
 999         solaris_sparcv9: "SS12u4-Solaris11u1+1.0",
1000         windows_x64: "VS2013SP4+1.0",
1001         linux_aarch64: "gcc-linaro-aarch64-linux-gnu-4.8-2013.11_linux+1.0",
1002         linux_arm: (input.profile != null && input.profile.indexOf("hflt") >= 0
1003                     ? "gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux+1.0"
1004                     : "arm-linaro-4.7+1.0")
1005     };
1006 
1007     var devkit_platform = (input.target_cpu == "x86"
1008         ? input.target_os + "_x64"
1009         : input.target_platform);
1010 
1011     var boot_jdk_version = "9";
1012     var boot_jdk_home = input.get("boot_jdk", "home_path") + "/jdk-"
1013         + boot_jdk_version
1014         + (input.build_os == "macosx" ? ".jdk/Contents/Home" : "");
1015     var boot_jdk_platform = (input.build_os == "macosx" ? "osx" : input.build_os)
1016         + "-" + input.build_cpu;
1017 
1018     var dependencies = {
1019 
1020         boot_jdk: {
1021             server: "jpg",
1022             product: "jdk",
1023             version: boot_jdk_version,
1024             build_number: "181",
1025             file: "bundles/" + boot_jdk_platform + "/jdk-" + boot_jdk_version + "_"
1026                 + boot_jdk_platform + "_bin.tar.gz",
1027             configure_args: "--with-boot-jdk=" + boot_jdk_home,
1028             environment_path: boot_jdk_home + "/bin"
1029         },
1030 
1031         devkit: {
1032             organization: common.organization,
1033             ext: "tar.gz",
1034             module: "devkit-" + devkit_platform,
1035             revision: devkit_platform_revisions[devkit_platform]
1036         },
1037 
1038         build_devkit: {
1039             organization: common.organization,
1040             ext: "tar.gz",
1041             module: "devkit-" + input.build_platform,
1042             revision: devkit_platform_revisions[input.build_platform]
1043         },
1044 
1045         cups: {
1046             organization: common.organization,
1047             ext: "tar.gz",
1048             revision: "1.0118+1.0"
1049         },
1050 
1051         jtreg: {
1052             server: "javare",
1053             revision: "4.2",
1054             build_number: "b08",
1055             checksum_file: "MD5_VALUES",
1056             file: "jtreg_bin-4.2.zip",
1057             environment_name: "JT_HOME",
1058             environment_path: input.get("jtreg", "install_path") + "/jtreg/bin"
1059         },
1060 
1061         gnumake: {
1062             organization: common.organization,
1063             ext: "tar.gz",
1064             revision: "4.0+1.0",
1065 
1066             module: (input.build_os == "windows"
1067                 ? "gnumake-" + input.build_osenv_platform
1068                 : "gnumake-" + input.build_platform),
1069 
1070             configure_args: (input.build_os == "windows"
1071                 ? "MAKE=" + input.get("gnumake", "install_path") + "/cygwin/bin/make"
1072                 : "MAKE=" + input.get("gnumake", "install_path") + "/bin/make"),
1073 
1074             environment_path: (input.build_os == "windows"
1075                 ? input.get("gnumake", "install_path") + "/cygwin/bin"
1076                 : input.get("gnumake", "install_path") + "/bin")
1077         },
1078 
1079         freetype: {
1080             organization: common.organization,
1081             ext: "tar.gz",
1082             revision: "2.7.1-v120+1.0",
1083             module: "freetype-" + input.target_platform
1084         },
1085 
1086         graphviz: {
1087             organization: common.organization,
1088             ext: "tar.gz",
1089             revision: "2.38.0-1+1.1",
1090             module: "graphviz-" + input.target_platform,
1091             configure_args: "DOT=" + input.get("graphviz", "install_path") + "/dot",
1092             environment_path: input.get("graphviz", "install_path")
1093         },
1094 
1095         pandoc: {
1096             organization: common.organization,
1097             ext: "tar.gz",
1098             revision: "1.17.2+1.0",
1099             module: "pandoc-" + input.target_platform,
1100             configure_args: "PANDOC=" + input.get("pandoc", "install_path") + "/pandoc/pandoc",
1101             environment_path: input.get("pandoc", "install_path") + "/pandoc"
1102         },
1103         // This adds java jib as a dependency for the test artifacts resolver
1104         jib: {
1105             organization: "com.oracle.java.jib",
1106             ext: "zip",
1107             classifier: "distribution",
1108             revision: "3.0-SNAPSHOT",
1109             environment_name: "JIB_JAR",
1110             environment_value: input.get("jib", "install_path")
1111                 + "/jib-3.0-SNAPSHOT-distribution/lib/jib-3.0-SNAPSHOT.jar"
1112        }
1113     };
1114 
1115     // Need to add a value for the Visual Studio tools variable to make
1116     // jaot be able to pick up the Visual Studio linker in testing.
1117     if (input.target_os == "windows") {
1118         dependencies.devkit.environment = {
1119             VS120COMNTOOLS: input.get("devkit", "install_path") + "/Common7/Tools"
1120         };
1121     }
1122 
1123     return dependencies;
1124 };
1125 
1126 /**
1127  * Generate the missing platform attributes for profiles
1128  *
1129  * @param profiles Profiles map to generate attributes on
1130  * @returns {{}} New profiles map with platform attributes fully filled in
1131  */
1132 var generatePlatformAttributes = function (profiles) {
1133     var ret = concatObjects(profiles, {});
1134     for (var profile in profiles) {
1135         if (ret[profile].build_os == null) {
1136             ret[profile].build_os = ret[profile].target_os;
1137         }
1138         if (ret[profile].build_cpu == null) {
1139             ret[profile].build_cpu = ret[profile].target_cpu;
1140         }
1141         ret[profile].target_platform = ret[profile].target_os + "_" + ret[profile].target_cpu;
1142         ret[profile].build_platform = ret[profile].build_os + "_" + ret[profile].build_cpu;
1143     }
1144     return ret;
1145 };
1146 
1147 /**
1148  * The default_make_targets attribute on a profile is not a real Jib attribute.
1149  * This function rewrites that attribute into the corresponding configure arg.
1150  * Calling this function multiple times on the same profiles object is safe.
1151  *
1152  * @param common Common values
1153  * @param profiles Profiles map to rewrite profiles for
1154  * @returns {{}} New map of profiles with the make targets converted
1155  */
1156 var generateDefaultMakeTargetsConfigureArg = function (common, profiles) {
1157     var ret = concatObjects(profiles, {});
1158     for (var profile in ret) {
1159         if (ret[profile]["default_make_targets"] != null) {
1160             var targetsString = concat(ret[profile].default_make_targets).join(" ");
1161             // Iterate over all configure args and see if --with-default-make-target
1162             // is already there and change it, otherwise add it.
1163             var found = false;
1164             for (var i in ret[profile].configure_args) {
1165                 var arg = ret[profile].configure_args[i];
1166                 if (arg != null && arg.startsWith("--with-default-make-target=")) {
1167                     found = true;
1168                     ret[profile].configure_args[i]
1169                         = "--with-default-make-target=" + targetsString;
1170                 }
1171             }
1172             if (!found) {
1173                 ret[profile].configure_args = concat(
1174                     ret[profile].configure_args,
1175                     "--with-default-make-target=" + targetsString);
1176             }
1177         }
1178     }
1179     return ret;
1180 }
1181 
1182 var getBuildId = function (input) {
1183     if (input.build_id != null) {
1184         return input.build_id;
1185     } else {
1186         var topdir = new java.io.File(__DIR__, "../..").getCanonicalFile().getName();
1187         var userName = java.lang.System.getProperty("user.name");
1188         return userName + "." + topdir;
1189     }
1190 }
1191 
1192 /**
1193  * Deep clones an object tree.
1194  *
1195  * @param o Object to clone
1196  * @returns {{}} Clone of o
1197  */
1198 var clone = function (o) {
1199     return JSON.parse(JSON.stringify(o));
1200 };
1201 
1202 /**
1203  * Concatenates all arguments into a new array
1204  *
1205  * @returns {Array.<T>} New array containing all arguments
1206  */
1207 var concat = function () {
1208     return Array.prototype.concat.apply([], arguments);
1209 };
1210 
1211 /**
1212  * Takes a String or Array of Strings and does a replace operation on each
1213  * of them.
1214  *
1215  * @param pattern Pattern to look for
1216  * @param replacement Replacement text to insert
1217  * @param a String or Array of Strings to replace
1218  * @returns {Array} Either a new array or a new string depending on the input
1219  */
1220 var replaceAll = function (pattern, replacement, a) {
1221     // If a is an array
1222     if (Array === a.constructor) {
1223     var newA = [];
1224     for (var i in a) {
1225             newA.push(a[i].replace(pattern, replacement));
1226         }
1227         return newA;
1228         } else {
1229         return a.replace(pattern, replacement);
1230     }
1231 };
1232 
1233 /**
1234  * Deep concatenation of two objects. For each node encountered, merge
1235  * the contents with the corresponding node in the other object tree,
1236  * treating all strings as array elements.
1237  *
1238  * @param o1 Object to concatenate
1239  * @param o2 Object to concatenate
1240  * @returns {{}} New object tree containing the concatenation of o1 and o2
1241  */
1242 var concatObjects = function (o1, o2) {
1243     if (o1 == null) {
1244         return clone(o2);
1245     }
1246     if (o2 == null) {
1247         return clone(o1);
1248     }
1249     var ret = {};
1250     for (var a in o1) {
1251         if (o2[a] == null) {
1252             ret[a] = clone(o1[a]);
1253         }
1254     }
1255     for (var a in o2) {
1256         if (o1[a] == null) {
1257             ret[a] = clone(o2[a]);
1258         } else {
1259             if (typeof o1[a] == 'string') {
1260                 ret[a] = clone([o1[a]].concat(o2[a]));
1261             } else if (Array.isArray(o1[a])) {
1262                 ret[a] = clone(o1[a].concat(o2[a]));
1263             } else if (typeof o1[a] == 'object') {
1264                 ret[a] = concatObjects(o1[a], o2[a]);
1265             }
1266         }
1267     }
1268     return ret;
1269 };
1270 
1271 /**
1272  * Constructs the numeric version string from reading the
1273  * common/autoconf/version-numbers file and removing all trailing ".0".
1274  *
1275  * @param major Override major version
1276  * @param minor Override minor version
1277  * @param security Override security version
1278  * @param patch Override patch version
1279  * @returns {String} The numeric version string
1280  */
1281 var getVersion = function (major, minor, security, patch) {
1282     var version_numbers = getVersionNumbers();
1283     var version = (major != null ? major : version_numbers.get("DEFAULT_VERSION_MAJOR"))
1284         + "." + (minor != null ? minor : version_numbers.get("DEFAULT_VERSION_MINOR"))
1285         + "." + (security != null ? security :  version_numbers.get("DEFAULT_VERSION_SECURITY"))
1286         + "." + (patch != null ? patch : version_numbers.get("DEFAULT_VERSION_PATCH"));
1287     while (version.match(".*\\.0$")) {
1288         version = version.substring(0, version.length - 2);
1289     }
1290     return version;
1291 };
1292 
1293 /**
1294  * Constructs the common version configure args based on build type and
1295  * other version inputs
1296  */
1297 var versionArgs = function(input, common) {
1298     var args = ["--with-version-build=" + common.build_number];
1299     if (input.build_type == "promoted") {
1300         args = concat(args,
1301                       // This needs to be changed when we start building release candidates
1302                       "--with-version-pre=ea",
1303                       "--without-version-opt");
1304     } else {
1305         args = concat(args, "--with-version-opt=" + common.build_id);
1306     }
1307     return args;
1308 }
1309 
1310 // Properties representation of the common/autoconf/version-numbers file. Lazily
1311 // initiated by the function below.
1312 var version_numbers;
1313 
1314 /**
1315  * Read the common/autoconf/version-numbers file into a Properties object.
1316  *
1317  * @returns {java.utilProperties}
1318  */
1319 var getVersionNumbers = function () {
1320     // Read version information from common/autoconf/version-numbers
1321     if (version_numbers == null) {
1322         version_numbers = new java.util.Properties();
1323         var stream = new java.io.FileInputStream(__DIR__ + "/../autoconf/version-numbers");
1324         version_numbers.load(stream);
1325         stream.close();
1326     }
1327     return version_numbers;
1328 }