Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/trusted/JDK-util.js
32285 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* This file contains utility functions used by other tests.25* @subtest26*/2728var Files = Java.type('java.nio.file.Files'),29Paths = Java.type('java.nio.file.Paths'),30System = Java.type('java.lang.System')3132var File = java.io.File33var windows = System.getProperty("os.name").startsWith("Windows")34var winCyg = false3536var outPath = {37windows:0, //C:\dir38mixed:1 //C:/dir39}4041if (windows) {42//Is there any better way to diffrentiate between cygwin/command prompt on windows43var term = System.getenv("TERM")44winCyg = term ? true:false45}4647/**48* Returns which command is selected from PATH49* @param cmd name of the command searched from PATH50*/51function which(cmd) {52var path = System.getenv("PATH")53var st = new java.util.StringTokenizer(path, File.pathSeparator)54while (st.hasMoreTokens()) {55var file = new File(st.nextToken(), cmd)56if (file.exists()) {57return (file.getAbsolutePath())58}59}60}6162/**63* Unix cygpath implementation64* Supports only two outputs,windows(C:\dir\) and mixed(C:/dir/)65*/6667function cygpath(path,mode) {6869var newpath = path70if(path.startsWith("/cygdrive/")){71var str = path.substring(10)72var index = str.indexOf('/',0)73var drv = str.substring(0,index)74var rstr = drv.toUpperCase() + ":"75newpath = str.replaceFirst(drv,rstr)76}77if (mode == outPath.windows)78return Paths.get(newpath).toString()79else {80newpath = newpath.replaceAll('\\\\','/')81return newpath82}8384}8586878889