use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class Launcher method sortedInstruments.
static List<Instrument> sortedInstruments(Engine engine) {
List<Instrument> instruments = new ArrayList<>();
for (Instrument instrument : engine.getInstruments().values()) {
// no options not accessible to the user.
if (!instrument.getOptions().iterator().hasNext()) {
continue;
}
instruments.add(instrument);
}
instruments.sort(Comparator.comparing(Instrument::getId));
return instruments;
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class Launcher method collectAllArguments.
private Set<String> collectAllArguments() {
Engine engine = getTempEngine();
Set<String> options = new LinkedHashSet<>();
collectArguments(options);
options.add("--polylgot");
options.add("--native");
options.add("--jvm");
options.add("--help");
options.add("--help:languages");
options.add("--help:tools");
options.add("--help:expert");
options.add("--version:graalvm");
options.add("--show-version:graalvm");
if (helpExpert || helpDebug) {
options.add("--help:debug");
}
addOptions(engine.getOptions(), options);
for (Language language : engine.getLanguages().values()) {
addOptions(language.getOptions(), options);
}
for (Instrument instrument : engine.getInstruments().values()) {
addOptions(instrument.getOptions(), options);
}
return options;
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class Launcher method printInstrumentOptions.
private static void printInstrumentOptions(Engine engine, OptionCategory optionCategory) {
Map<Instrument, List<PrintableOption>> instrumentsOptions = new HashMap<>();
List<Instrument> instruments = sortedInstruments(engine);
for (Instrument instrument : instruments) {
List<PrintableOption> options = new ArrayList<>();
for (OptionDescriptor descriptor : instrument.getOptions()) {
if (descriptor.getCategory().ordinal() == optionCategory.ordinal()) {
options.add(asPrintableOption(descriptor));
}
}
if (!options.isEmpty()) {
instrumentsOptions.put(instrument, options);
}
}
if (!instrumentsOptions.isEmpty()) {
System.out.println();
System.out.println("Tool options:");
for (Instrument instrument : instruments) {
List<PrintableOption> options = instrumentsOptions.get(instrument);
if (options != null) {
printOptions(options, " " + instrument.getName() + ":", 4);
}
}
}
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class SLSharedCodeSeparatedEnvTest method instrumentsSeeOutputOfBoth.
@Test
public void instrumentsSeeOutputOfBoth() throws Exception {
Instrument outInstr = e2.getEngine().getInstruments().get("captureOutput");
ByteArrayOutputStream outConsumer = outInstr.lookup(ByteArrayOutputStream.class);
assertNotNull("Stream capturing is ready", outConsumer);
String sayHello = "function main() {\n" + " println(\"Ahoj\" + import(\"extra\"));" + "}";
// @formatter:on
e1.eval("sl", sayHello);
assertEquals("Ahoj1\n", os1.toString("UTF-8"));
assertEquals("", os2.toString("UTF-8"));
e2.eval("sl", sayHello);
assertEquals("Ahoj1\n", os1.toString("UTF-8"));
assertEquals("Ahoj2\n", os2.toString("UTF-8"));
engine.close();
assertEquals("Output of both contexts and instruments is capturable", "initializingOutputCapture\n" + "Ahoj1\n" + "Ahoj2\n" + "endOfOutputCapture\n", outConsumer.toString("UTF-8"));
assertEquals("Output of instrument goes not to os runtime if specified otherwise", "initializingOutputCapture\n" + "endOfOutputCapture\n", osRuntime.toString("UTF-8"));
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class PolyglotEngineImpl method initializeInstruments.
private Map<String, PolyglotInstrument> initializeInstruments(Map<String, InstrumentInfo> infos) {
Map<String, PolyglotInstrument> instruments = new LinkedHashMap<>();
List<InstrumentCache> cachedInstruments = InstrumentCache.load(SPI.allLoaders());
for (InstrumentCache instrumentCache : cachedInstruments) {
PolyglotInstrument instrumentImpl = new PolyglotInstrument(this, instrumentCache);
instrumentImpl.info = LANGUAGE.createInstrument(instrumentImpl, instrumentCache.getId(), instrumentCache.getName(), instrumentCache.getVersion());
Instrument instrument = impl.getAPIAccess().newInstrument(instrumentImpl);
instrumentImpl.api = instrument;
String id = instrumentImpl.cache.getId();
verifyId(id, instrumentCache.getClassName());
if (instruments.containsKey(id)) {
throw failDuplicateId(id, instrumentImpl.cache.getClassName(), instruments.get(id).cache.getClassName());
}
instruments.put(id, instrumentImpl);
infos.put(id, instrumentImpl.info);
}
return instruments;
}
Aggregations