test/script/trusted/JDK-util.js

Fri, 06 Sep 2019 03:21:30 +0100

author
andrew
date
Fri, 06 Sep 2019 03:21:30 +0100
changeset 2516
ad8af81cc28b
parent 1838
be4ef6af7d3d
permissions
-rw-r--r--

Added tag jdk8u242-b00 for changeset 8a951fd037e2

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

mercurial