Search in sources :

Example 1 with OptionValues

use of org.graalvm.options.OptionValues in project graal by oracle.

the class InspectorInstrument method onCreate.

@Override
protected void onCreate(Env env) {
    OptionValues options = env.getOptions();
    if (options.hasSetOptions()) {
        Server server = new Server(env);
        try {
            InetSocketAddress socketAddress = options.get(Inspect).createSocket(options.get(Remote));
            server.start("Main Context", socketAddress, options.get(Suspend), options.get(WaitAttached), options.get(HideErrors), options.get(Path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : OptionValues(org.graalvm.options.OptionValues) WebSocketServer(com.oracle.truffle.tools.chromeinspector.server.WebSocketServer) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException)

Example 2 with OptionValues

use of org.graalvm.options.OptionValues in project graal by oracle.

the class OptionProcessorTest method testOptionValues.

@Test
public void testOptionValues() {
    Engine engine = Engine.create();
    OptionDescriptors descriptors = engine.getInstruments().get("optiontestinstr1").getOptions();
    OptionValues optionValues = engine.getInstruments().get("optiontestinstr1").lookup(OptionValues.class);
    assertSame(descriptors, optionValues.getDescriptors());
    assertFalse(optionValues.hasSetOptions());
    OptionKey<?> optionKey1 = descriptors.get("optiontestinstr1.StringOption1").getKey();
    OptionKey<?> optionKey2 = descriptors.get("optiontestinstr1.StringOption2").getKey();
    assertFalse(optionValues.hasBeenSet(optionKey1));
    assertEquals("defaultValue", optionValues.get(optionKey1));
    assertEquals("defaultValue", optionValues.get(optionKey2));
    engine = Engine.newBuilder().option("optiontestinstr1.StringOption1", "test").build();
    optionValues = engine.getInstruments().get("optiontestinstr1").lookup(OptionValues.class);
    assertTrue(optionValues.hasSetOptions());
    optionKey1 = descriptors.get("optiontestinstr1.StringOption1").getKey();
    optionKey2 = descriptors.get("optiontestinstr1.StringOption2").getKey();
    assertTrue(optionValues.hasBeenSet(optionKey1));
    assertFalse(optionValues.hasBeenSet(optionKey2));
    assertEquals("test", optionValues.get(optionKey1));
    assertEquals("defaultValue", optionValues.get(optionKey2));
    engine = Engine.newBuilder().option("optiontestlang1.StringOption1", "testLang").build();
    optionValues = engine.getInstruments().get("optiontestinstr1").lookup(OptionValues.class);
    // A language option was set, not the instrument one. Instrument sees no option set:
    assertFalse(optionValues.hasSetOptions());
}
Also used : OptionValues(org.graalvm.options.OptionValues) OptionDescriptors(org.graalvm.options.OptionDescriptors) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

Aggregations

OptionValues (org.graalvm.options.OptionValues)2 WebSocketServer (com.oracle.truffle.tools.chromeinspector.server.WebSocketServer)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 OptionDescriptors (org.graalvm.options.OptionDescriptors)1 Engine (org.graalvm.polyglot.Engine)1 Test (org.junit.Test)1