1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/trusted/JDK-util.js Tue Jun 07 11:58:05 2016 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +/* 1.5 + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * This file contains utility functions used by other tests. 1.29 + * @subtest 1.30 + */ 1.31 + 1.32 +var Files = Java.type('java.nio.file.Files'), 1.33 + Paths = Java.type('java.nio.file.Paths'), 1.34 + System = Java.type('java.lang.System') 1.35 + 1.36 +var File = java.io.File 1.37 +var windows = System.getProperty("os.name").startsWith("Windows") 1.38 +var winCyg = false 1.39 + 1.40 +var outPath = { 1.41 + windows:0, //C:\dir 1.42 + mixed:1 //C:/dir 1.43 +} 1.44 + 1.45 +if (windows) { 1.46 + //Is there any better way to diffrentiate between cygwin/command prompt on windows 1.47 + var term = System.getenv("TERM") 1.48 + winCyg = term ? true:false 1.49 +} 1.50 + 1.51 +/** 1.52 + * Returns which command is selected from PATH 1.53 + * @param cmd name of the command searched from PATH 1.54 + */ 1.55 +function which(cmd) { 1.56 + var path = System.getenv("PATH") 1.57 + var st = new java.util.StringTokenizer(path, File.pathSeparator) 1.58 + while (st.hasMoreTokens()) { 1.59 + var file = new File(st.nextToken(), cmd) 1.60 + if (file.exists()) { 1.61 + return (file.getAbsolutePath()) 1.62 + } 1.63 + } 1.64 +} 1.65 + 1.66 +/** 1.67 + * Unix cygpath implementation 1.68 + * Supports only two outputs,windows(C:\dir\) and mixed(C:/dir/) 1.69 + */ 1.70 + 1.71 +function cygpath(path,mode) { 1.72 + 1.73 + var newpath = path 1.74 + if(path.startsWith("/cygdrive/")){ 1.75 + var str = path.substring(10) 1.76 + var index = str.indexOf('/',0) 1.77 + var drv = str.substring(0,index) 1.78 + var rstr = drv.toUpperCase() + ":" 1.79 + newpath = str.replaceFirst(drv,rstr) 1.80 + } 1.81 + if (mode == outPath.windows) 1.82 + return Paths.get(newpath).toString() 1.83 + else { 1.84 + newpath = newpath.replaceAll('\\\\','/') 1.85 + return newpath 1.86 + } 1.87 + 1.88 +} 1.89 + 1.90 +