Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP 8238080: FXMLLoader: if script engines implement javax.script.Compilable compile scripts #129

Closed
wants to merge 14 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3572,6 +3572,7 @@ project(":systemTests") {
testapp5
testapp6
testscriptapp1
testscriptapp2
}

def nonModSrcSets = [
@@ -3585,7 +3586,8 @@ project(":systemTests") {
sourceSets.testapp4,
sourceSets.testapp5,
sourceSets.testapp6,
sourceSets.testscriptapp1
sourceSets.testscriptapp1,
sourceSets.testscriptapp2
]

project.ext.buildModule = false
@@ -3685,7 +3687,7 @@ project(":systemTests") {
}
test.dependsOn(createTestApps);

def modtestapps = [ "testapp2", "testapp3", "testapp4", "testapp5", "testapp6", "testscriptapp1" ]
def modtestapps = [ "testapp2", "testapp3", "testapp4", "testapp5", "testapp6", "testscriptapp1", "testscriptapp2" ]
modtestapps.each { testapp ->
def testappCapital = testapp.capitalize()
def copyTestAppTask = task("copy${testappCapital}", type: Copy) {
@@ -63,6 +63,8 @@
import javafx.util.Callback;

import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
@@ -1563,7 +1565,12 @@ public void processStartElement() throws IOException {
InputStreamReader scriptReader = null;
try {
scriptReader = new InputStreamReader(location.openStream(), charset);
engine.eval(scriptReader);
if (engine instanceof Compilable) {
((Compilable) engine).compile(scriptReader).eval();
}
else {
engine.eval(scriptReader);
}
} catch(ScriptException exception) {
exception.printStackTrace();
} finally {
@@ -1587,7 +1594,13 @@ public void processEndElement() throws IOException {
Bindings engineBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
engineBindings.put(scriptEngine.FILENAME, location.getPath() + "-script_starting_at_line_"
+ (getLineNumber() - (int) ((String) value).codePoints().filter(c -> c == '\n').count()));
scriptEngine.eval((String)value);

if (scriptEngine instanceof Compilable) {
((Compilable) scriptEngine).compile((String)value).eval();
}
else {
scriptEngine.eval((String)value);
}
} catch (ScriptException exception) {
System.err.println(exception.getMessage());
}
@@ -1681,11 +1694,23 @@ public void handle(T event) {
public final String script;
public final ScriptEngine scriptEngine;
public final String filename;
public CompiledScript compiledScript;
public boolean isCompiled=false;

public ScriptEventHandler(String script, ScriptEngine scriptEngine, String filename) {
this.script = script;
this.scriptEngine = scriptEngine;
this.filename = filename;
if (scriptEngine instanceof Compilable) {
try {
// supply the filename to the scriptEngine engine scope Bindings in case it is needed for compilation
scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).put(scriptEngine.FILENAME, filename);
this.compiledScript = ((Compilable) scriptEngine).compile(script);
this.isCompiled = true;
} catch (ScriptException exception){
throw new RuntimeException(exception);
}
}
}

@Override
@@ -1699,7 +1724,12 @@ public void handle(Event event) {
localBindings.put(scriptEngine.FILENAME, filename);
// Execute the script
try {
scriptEngine.eval(script, localBindings);
if (isCompiled) {
compiledScript.eval(localBindings);
}
else {
scriptEngine.eval(script, localBindings);
}
} catch (ScriptException exception){
throw new RuntimeException(exception);
}
@@ -44,6 +44,7 @@
private static final String modulePath5 = System.getProperty("launchertest.testapp5.module.path");
private static final String modulePath6 = System.getProperty("launchertest.testapp6.module.path");
private static final String modulePathScript1 = System.getProperty("launchertest.testscriptapp1.module.path");
private static final String modulePathScript2 = System.getProperty("launchertest.testscriptapp2.module.path");

private static final String moduleName = "mymod";

@@ -277,8 +278,12 @@ public void testModuleFXMLQualOpened() throws Exception {
}

@Test (timeout = 15000)
public void testFXMLScriptDeployment() throws Exception {
public void testFXMLScriptDeployment1() throws Exception {
doTestLaunchModule(modulePathScript1, "myapp1.FXMLScriptDeployment");
}

@Test (timeout = 15000)
public void testFXMLScriptDeployment2() throws Exception {
doTestLaunchModule(modulePathScript2, "myapp2.FXMLScriptDeployment");
}
}
@@ -1,2 +1 @@
pseudoScriptEngine.RgfPseudoScriptEngineFactory

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, 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.
*/

module mymod {
requires javafx.controls;
requires javafx.fxml;

requires java.scripting;
provides javax.script.ScriptEngineFactory with pseudoScriptEngineCompilable.RgfPseudoScriptEngineCompilableFactory;
exports pseudoScriptEngineCompilable;
exports myapp2;
}
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 2020, 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.
*/

package myapp2; // verbatim from myapp6

public class Constants {

public static final int SHOWTIME = 2500;

// NOTE: these constants must match those in test.launchertest.Constants
public static final int ERROR_NONE = 2;
public static final int ERROR_UNEXPECTED_EXCEPTION = 4;

public static final int ERROR_ASSERTION_FAILURE = 28;
}
ProTip! Use n and p to navigate between commits in a pull request.