sdama@1838: /* sdama@1838: * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. sdama@1838: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sdama@1838: * sdama@1838: * This code is free software; you can redistribute it and/or modify it sdama@1838: * under the terms of the GNU General Public License version 2 only, as sdama@1838: * published by the Free Software Foundation. sdama@1838: * sdama@1838: * This code is distributed in the hope that it will be useful, but WITHOUT sdama@1838: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sdama@1838: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sdama@1838: * version 2 for more details (a copy is included in the LICENSE file that sdama@1838: * accompanied this code). sdama@1838: * sdama@1838: * You should have received a copy of the GNU General Public License version sdama@1838: * 2 along with this work; if not, write to the Free Software Foundation, sdama@1838: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sdama@1838: * sdama@1838: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sdama@1838: * or visit www.oracle.com if you need additional information or have any sdama@1838: * questions. sdama@1838: */ sdama@1838: sdama@1838: /** sdama@1838: * This file contains utility functions used by other tests. sdama@1838: * @subtest sdama@1838: */ sdama@1838: sdama@1838: var Files = Java.type('java.nio.file.Files'), sdama@1838: Paths = Java.type('java.nio.file.Paths'), sdama@1838: System = Java.type('java.lang.System') sdama@1838: sdama@1838: var File = java.io.File sdama@1838: var windows = System.getProperty("os.name").startsWith("Windows") sdama@1838: var winCyg = false sdama@1838: sdama@1838: var outPath = { sdama@1838: windows:0, //C:\dir sdama@1838: mixed:1 //C:/dir sdama@1838: } sdama@1838: sdama@1838: if (windows) { sdama@1838: //Is there any better way to diffrentiate between cygwin/command prompt on windows sdama@1838: var term = System.getenv("TERM") sdama@1838: winCyg = term ? true:false sdama@1838: } sdama@1838: sdama@1838: /** sdama@1838: * Returns which command is selected from PATH sdama@1838: * @param cmd name of the command searched from PATH sdama@1838: */ sdama@1838: function which(cmd) { sdama@1838: var path = System.getenv("PATH") sdama@1838: var st = new java.util.StringTokenizer(path, File.pathSeparator) sdama@1838: while (st.hasMoreTokens()) { sdama@1838: var file = new File(st.nextToken(), cmd) sdama@1838: if (file.exists()) { sdama@1838: return (file.getAbsolutePath()) sdama@1838: } sdama@1838: } sdama@1838: } sdama@1838: sdama@1838: /** sdama@1838: * Unix cygpath implementation sdama@1838: * Supports only two outputs,windows(C:\dir\) and mixed(C:/dir/) sdama@1838: */ sdama@1838: sdama@1838: function cygpath(path,mode) { sdama@1838: sdama@1838: var newpath = path sdama@1838: if(path.startsWith("/cygdrive/")){ sdama@1838: var str = path.substring(10) sdama@1838: var index = str.indexOf('/',0) sdama@1838: var drv = str.substring(0,index) sdama@1838: var rstr = drv.toUpperCase() + ":" sdama@1838: newpath = str.replaceFirst(drv,rstr) sdama@1838: } sdama@1838: if (mode == outPath.windows) sdama@1838: return Paths.get(newpath).toString() sdama@1838: else { sdama@1838: newpath = newpath.replaceAll('\\\\','/') sdama@1838: return newpath sdama@1838: } sdama@1838: sdama@1838: } sdama@1838: sdama@1838: