test/script/trusted/JDK-util.js

Wed, 05 Sep 2018 01:21:35 -0700

author
diazhou
date
Wed, 05 Sep 2018 01:21:35 -0700
changeset 2374
037913b52507
parent 1838
be4ef6af7d3d
permissions
-rw-r--r--

Added tag jdk8u192-b09 for changeset 456c0d45c43b

     1 /*
     2  * Copyright (c) 2016, 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.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * This file contains utility functions used by other tests.
    26  * @subtest
    27  */
    29 var Files = Java.type('java.nio.file.Files'),
    30     Paths = Java.type('java.nio.file.Paths'),
    31     System = Java.type('java.lang.System')
    33 var File = java.io.File
    34 var windows = System.getProperty("os.name").startsWith("Windows")
    35 var winCyg = false
    37 var outPath = {
    38     windows:0, //C:\dir
    39     mixed:1    //C:/dir
    40 }
    42 if (windows) {
    43     //Is there any better way to diffrentiate between cygwin/command prompt on windows
    44     var term = System.getenv("TERM")
    45     winCyg = term ? true:false
    46 }
    48 /**
    49  * Returns which command is selected from PATH
    50  * @param cmd name of the command searched from PATH
    51  */
    52 function which(cmd) {
    53     var path = System.getenv("PATH")
    54     var st = new java.util.StringTokenizer(path, File.pathSeparator)
    55     while (st.hasMoreTokens()) {
    56         var file = new File(st.nextToken(), cmd)
    57         if (file.exists()) {
    58             return (file.getAbsolutePath())
    59         }
    60     }
    61 }
    63 /**
    64  * Unix cygpath implementation
    65  * Supports only two outputs,windows(C:\dir\) and mixed(C:/dir/)
    66  */
    68 function cygpath(path,mode) {
    70     var newpath = path
    71     if(path.startsWith("/cygdrive/")){
    72         var str = path.substring(10)
    73         var index = str.indexOf('/',0)
    74         var drv = str.substring(0,index)
    75         var rstr = drv.toUpperCase() + ":"
    76         newpath = str.replaceFirst(drv,rstr)
    77     }
    78     if (mode == outPath.windows)
    79         return Paths.get(newpath).toString()
    80     else {
    81         newpath = newpath.replaceAll('\\\\','/')
    82         return newpath
    83     }                   
    85 }

mercurial