test/script/trusted/JDK-8087292.js

changeset 1838
be4ef6af7d3d
parent 1525
e93960ae0b1e
equal deleted inserted replaced
1837:27842bf384fe 1838:be4ef6af7d3d
1 /* 1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
27 * @test 27 * @test
28 * @option -scripting 28 * @option -scripting
29 * @run 29 * @run
30 */ 30 */
31 31
32 load(__DIR__ + "JDK-util.js")
33
34 var jHomePath = System.getenv("JAVA_HOME")
35 var jLauncher = "${jHomePath}/bin/java"
36 var altjLauncher = which('java')
37
38 if (windows) {
39 if(winCyg) {
40 jLauncher = "${jHomePath}" + "/bin/java.exe"
41 jLauncher = cygpath(jLauncher,outPath.windows)
42 }
43 else {
44 jLauncher = "${jHomePath}" + "\\bin\\java.exe"
45 altjLauncher = which('java.exe')
46 altjLauncher = cygpath(altjLauncher,outPath.windows)
47 }
48 }
49
50 function exists(f) {
51 return Files.exists(Paths.get(f))
52 }
53
54 var javaLauncher = exists(jLauncher) ? jLauncher : altjLauncher
55
56
57 if (!exists(javaLauncher)) {
58 throw "no java launcher found; tried ${jLauncher} and ${altjLauncher}"
59 }
60
32 function tryExec() { 61 function tryExec() {
33 try { 62 try {
34 `java` 63 $EXEC("${javaLauncher}")
35 } catch (e) { 64 } catch (e) {
36 print(e); 65 print(e)
37 } 66 }
38 67
39 // make sure we got non-zero ("failure") exit code! 68 // make sure we got non-zero ("failure") exit code!
40 if ($EXIT == 0) { 69 if ($EXIT == 0) {
41 print("Error: expected $EXIT code to be non-zero"); 70 print("Error: expected $EXIT code to be non-zero")
42 } 71 }
43 } 72 }
73 //convert windows paths to cygwin
74 if (windows)
75 javaLauncher = (winCyg) ? cygpath(javaLauncher,outPath.mixed).trim() : cygpath(javaLauncher,outPath.windows).trim()
44 76
45 // no exception now! 77 // no exception now!
46 tryExec(); 78 tryExec()
47 79
48 // turn on error with non-zero exit code 80 // turn on error with non-zero exit code
49 $EXEC.throwOnError = true; 81 $EXEC.throwOnError = true
50 tryExec(); 82 tryExec()
51 83
52 // no exception after this 84 // no exception after this
53 $EXEC.throwOnError = false; 85 $EXEC.throwOnError = false
54 tryExec(); 86 tryExec()

mercurial