Path: blob/master/test/langtools/jdk/jshell/ExecutionControlSpecTest.java
40931 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 816861526* @summary Test ExecutionControlProvider specs can load user ExecutionControlProviders27* with direct maps.28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.jdeps/com.sun.tools.javap31* jdk.jshell/jdk.jshell.execution32* jdk.jshell/jdk.jshell.spi33* @library /tools/lib34* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask35* @build KullaTesting Compiler36* @run testng ExecutionControlSpecTest37*/3839import java.nio.file.Path;40import java.nio.file.Paths;41import org.testng.annotations.AfterMethod;42import org.testng.annotations.Test;43import org.testng.annotations.BeforeMethod;4445public class ExecutionControlSpecTest extends KullaTesting {4647ClassLoader ccl;4849@BeforeMethod50@Override51public void setUp() {52String mod = "my.ec";53String pkg = "package my.ec;\n";54Compiler compiler = new Compiler();55Path modDir = Paths.get("mod");56compiler.compile(modDir,57pkg +58"public class PrefixingExecutionControl extends jdk.jshell.execution.LocalExecutionControl {\n" +59" @Override\n" +60" public String invoke(String className, String methodName)\n" +61" throws RunException, InternalException, EngineTerminationException {\n" +62" return \"Blah:\" + super.invoke(className, methodName);\n" +63" }\n" +64"}\n",65pkg +66"public class PrefixingExecutionControlProvider implements jdk.jshell.spi.ExecutionControlProvider {\n" +67" @Override\n" +68" public String name() {\n" +69" return \"prefixing\";\n" +70" }\n" +71" @Override\n" +72" public jdk.jshell.spi.ExecutionControl generate(jdk.jshell.spi.ExecutionEnv env,\n" +73" java.util.Map<String, String> parameters) {\n" +74" return new PrefixingExecutionControl();\n" +75" }\n" +76"}\n",77"module my.ec {\n" +78" requires transitive jdk.jshell;\n" +79" provides jdk.jshell.spi.ExecutionControlProvider\n" +80" with my.ec.PrefixingExecutionControlProvider;\n" +81" }");82Path modPath = compiler.getPath(modDir);83ccl = createAndRunFromModule(mod, modPath);8485setUp(builder -> builder.executionEngine("prefixing"));86}8788@AfterMethod89@Override90public void tearDown() {91super.tearDown();92Thread.currentThread().setContextClassLoader(ccl);93}9495@Test96public void testPrefix() {97assertEval("43;", "Blah:43");98}99100}101102103