8075550: Error "JavaFX runtime not found" in nashorn when load predefines scripts to import JavaFX packages

Reviewed-by: kcr, sundar
This commit is contained in:
Jim Laskey 2016-04-11 10:01:39 -03:00
parent 8cc178041e
commit 2e91e2e23c
9 changed files with 91 additions and 164 deletions
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/fx

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,135 +23,92 @@
* questions.
*/
var JFX_BASE_CLASSES = [];
var JFX_GRAPHICS_CLASSES = [];
var JFX_CONTROLS_CLASSES = [];
var JFX_FXML_CLASSES = [];
var JFX_WEB_CLASSES = [];
var JFX_MEDIA_CLASSES = [];
var JFX_SWING_CLASSES = [];
var JFX_SWT_CLASSES = [];
var JFX_CLASSES = {
"javafx.base": [],
"javafx.controls": [],
"javafx.deploy": [],
"javafx.fxml": [],
"javafx.graphics": [],
"javafx.media": [],
"javafx.swing": [],
"javafx.web": []
};
function LOAD_FX_CLASSES(clsList) {
for each (var cls in clsList) {
// Ex. Stage = Java.type("javafx.stage.Stage");
this[cls[cls.length - 1]] = Java.type(cls.join("."));
function LOAD_FX_CLASSES(global, module) {
if (JFX_CLASSES[module]) {
for each (var cls in JFX_CLASSES[module]) {
// Ex. Stage = Java.type("javafx.stage.Stage");
var name = cls.join(".");
var type = Java.type(name);
global[cls[cls.length - 1]] = type;
}
JFX_CLASSES[module] = undefined;
}
}
(function() {
var System = Java.type("java.lang.System");
var ZipFile = Java.type("java.util.zip.ZipFile");
var Files = Java.type("java.nio.file.Files");
var FileSystems = Java.type("java.nio.file.FileSystems");
var FileVisitor = Java.type("java.nio.file.FileVisitor");
var FileVisitResult = Java.type("java.nio.file.FileVisitResult");
var CONTINUE = FileVisitResult.CONTINUE;
var SKIP_SUBTREE = FileVisitResult.SKIP_SUBTREE;
var SUFFIX_LENGTH = ".class".length;
var URI = Java.type("java.net.URI");
var uri = new URI("jrt:/");
var jrtfs = FileSystems.getFileSystem(uri);
var rootDirectories = jrtfs.getRootDirectories();
// TODO - temporary patch until fx is moved to module system.
// <patch>
var jfxrtJar;
try {
jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/jfxrt.jar");
} catch (ex1) {
try {
jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar");
} catch (ex2) {
throw new Error("JavaFX runtime not found");
}
}
// </patch>
var JRTFSWalker = Java.extend(FileVisitor, {
preVisitDirectory: function(path, attrs) {
var name = path.toString();
var entries = jfxrtJar.entries();
while (entries.hasMoreElements()) {
var entry = entries.nextElement();
if (entry.isDirectory()) {
continue;
}
var name = entry.name;
if (!name.endsWith(".class")) {
continue;
}
name = name.substring(0, name.length - SUFFIX_LENGTH);
cls = name.split("/");
if (cls[0] != "javafx") {
continue;
}
var last = cls[cls.length - 1];
var nested = last.lastIndexOf("$");
// If class name ends with $nnn
if (nested != -1 && !(last.substring(nested) - 0)) {
continue;
}
switch (cls[1]) {
case "stage":
if (cls[2] == "Stage") {
JFX_BASE_CLASSES.push(cls);
} else {
JFX_GRAPHICS_CLASSES.push(cls);
if (name.startsWith("/packages")) {
return SKIP_SUBTREE;
}
break;
case "scene":
switch (cls[2]) {
case "Scene":
case "Group":
JFX_BASE_CLASSES.push(cls);
break;
case "chart":
case "control":
JFX_CONTROLS_CLASSES.push(cls);
break;
case "web":
JFX_WEB_CLASSES.push(cls);
break;
case "media":
JFX_MEDIA_CLASSES.push(cls);
break;
default:
JFX_GRAPHICS_CLASSES.push(cls);
break;
if (name.startsWith("/modules") && !name.equals("/modules") && !name.startsWith("/modules/javafx")) {
return SKIP_SUBTREE;
}
break;
case "beans":
case "collections":
case "events":
case "util":
JFX_BASE_CLASSES.push(cls);
break;
return CONTINUE;
},
case "animation":
case "application":
case "concurrent":
case "css":
case "geometry":
JFX_GRAPHICS_CLASSES.push(cls);
break;
postVisitDirectory: function(path, attrs) {
return CONTINUE;
},
case "fxml":
JFX_FXML_CLASSES.push(cls);
break;
visitFile: function(file, attrs) {
var name = file.toString();
case "embed":
if (cls[2] == "swing") {
JFX_SWING_CLASSES.push(cls);
} else {
JFX_SWT_CLASSES.push(cls);
if (!name.endsWith(".class") || name.endsWith("module-info.class")) {
return CONTINUE;
}
break;
var parts = name.split("/");
parts = parts.slice(2);
var module = parts.shift();
var path = parts;
var cls = path.pop();
cls = cls.substring(0, cls.length() - 6);
path.push(cls);
if (path[0] !== "javafx" || /\$\d+$/.test(cls)) {
return CONTINUE;
}
JFX_CLASSES[module].push(path);
return CONTINUE;
},
visitFileFailed: function(file, ex) {
return CONTINUE;
}
}
});
Files.walkFileTree(rootDirectories[0], new JRTFSWalker());
})();
LOAD_FX_CLASSES(JFX_BASE_CLASSES);
LOAD_FX_CLASSES(this, "javafx.base");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,7 @@ if (typeof javafx.application.Application != "function") {
}
// Extend the javafx.application.Application class overriding init, start and stop.
com.sun.javafx.application.LauncherImpl.launchApplication((Java.extend(javafx.application.Application, {
javafx.application.Application.launch((Java.extend(javafx.application.Application, {
// Overridden javafx.application.Application.init();
init: function() {
// Java FX packages and classes must be defined here because

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_CONTROLS_CLASSES);
LOAD_FX_CLASSES(this, "javafx.controls");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_FXML_CLASSES);
LOAD_FX_CLASSES(this, "javafx.fxml");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,10 +23,10 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_GRAPHICS_CLASSES);
LOAD_FX_CLASSES(this, "javafx.graphics");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_MEDIA_CLASSES);
LOAD_FX_CLASSES(this, "javafx.media");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_SWING_CLASSES);
LOAD_FX_CLASSES(this, "javafx.swing");

@ -1,30 +0,0 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_SWT_CLASSES);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,8 +23,8 @@
* questions.
*/
if (!this.JFX_BASE_CLASSES) {
if (!this.JFX_CLASSES) {
load("fx:base.js")
}
LOAD_FX_CLASSES(JFX_WEB_CLASSES);
LOAD_FX_CLASSES(this, "javafx.web");