use of javax.script.ScriptException in project enumerable by hraberg.
the class JRubyTestBase method testUnit.
void testUnit(String file, String testClass) throws ScriptException {
StringWriter writer = new StringWriter();
Writer originalWriter = rb.getContext().getWriter();
rb.getContext().setWriter(writer);
try {
require(file);
require("test/unit/ui/console/testrunner");
beforeRunningTestUnit();
eval("r = Test::Unit::UI::Console::TestRunner.run(" + testClass + ")");
eval("raise r.to_s unless r.passed?");
if (debug)
out.println(writer);
} catch (ScriptException e) {
out.println(writer);
throw uncheck(e);
} finally {
rb.getContext().setWriter(originalWriter);
}
}
use of javax.script.ScriptException in project enumerable by hraberg.
the class RubySpecTestBase method mspec.
void mspec(List<String> files) throws Exception {
StringWriter stdout = new StringWriter();
StringWriter stderr = new StringWriter();
Writer originalOut = rb.getContext().getWriter();
Writer originalErr = rb.getContext().getErrorWriter();
if (!specdoc)
rb.getContext().setWriter(stdout);
if (!debug)
rb.getContext().setErrorWriter(stderr);
try {
// We need to trick MSpec into thinking we're running a real ruby
eval("RUBY_EXE = '/usr/bin/jruby'");
// While telling it we're not, to skip specs for our "platform"
eval("RUBY_PLATFORM = 'enumerable_java'");
// We support Enumerable from 1.8.8
eval("RUBY_VERSION = '1.8.8'");
require("mspec");
require("mspec/utils/script");
// Identity won't work as JRuby will turn Ruby objects into Java
// and then back again.
eval("class EqualMatcher; def matches?(actual); @actual = actual; @actual == @expected; end; end");
eval("formatter = SpecdocFormatter.new; formatter.register;");
eval("MSpec.store :formatter, formatter");
eval("MSpec.register_files " + files);
eval("MSpec.process");
try {
eval("raise formatter.exceptions[0] unless MSpec.exit_code == 0");
} catch (RaiseException e) {
try {
fail(e.getException().message.asJavaString());
} catch (AssertionError error) {
error.setStackTrace(e.getStackTrace());
throw error;
}
}
} catch (ScriptException e) {
out.println(stdout.toString());
err.println(stderr.toString());
throw uncheck(e);
} finally {
rb.getContext().setWriter(originalOut);
rb.getContext().setErrorWriter(originalErr);
eval("MSpec.unregister :exception, formatter; MSpec.unregister :before, formatter; " + "MSpec.unregister :after, formatter; MSpec.unregister :finish, formatter; " + "MSpec.unregister :enter, formatter; MSpec.register_exit(nil); " + "MSpec.clear_current; MSpec.clear_modes; MSpec.clear_expectations");
}
}
use of javax.script.ScriptException in project cryptomator by cryptomator.
the class ExitUtil method showTrayNotification.
private void showTrayNotification(TrayIcon trayIcon) {
int remainingTrayNotification = settings.numTrayNotifications().get();
if (remainingTrayNotification <= 0) {
return;
} else {
settings.numTrayNotifications().set(remainingTrayNotification - 1);
}
final Runnable notificationCmd;
if (SystemUtils.IS_OS_MAC_OSX) {
final String title = localization.getString("tray.infoMsg.title");
final String msg = localization.getString("tray.infoMsg.msg.osx");
final String notificationCenterAppleScript = String.format("display notification \"%s\" with title \"%s\"", msg, title);
notificationCmd = () -> {
try {
final ScriptEngineManager mgr = new ScriptEngineManager();
final ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine");
if (engine != null) {
engine.eval(notificationCenterAppleScript);
} else {
Runtime.getRuntime().exec(new String[] { "/usr/bin/osascript", "-e", notificationCenterAppleScript });
}
} catch (ScriptException | IOException e) {
// ignore, user will notice the tray icon anyway.
}
};
} else {
final String title = localization.getString("tray.infoMsg.title");
final String msg = localization.getString("tray.infoMsg.msg");
notificationCmd = () -> {
trayIcon.displayMessage(title, msg, MessageType.INFO);
};
}
SwingUtilities.invokeLater(() -> {
notificationCmd.run();
});
}
use of javax.script.ScriptException in project gradle by gradle.
the class AppleScriptBackedGrowlAnnouncer method send.
@Override
public void send(String title, String message) {
String isRunning = "\ntell application \"System Events\"\n" + "set isRunning to count of (every process whose bundle identifier is \"com.Growl.GrowlHelperApp\") > 0\n" + "end tell\n" + "return isRunning\n";
try {
Object value = engine.eval(isRunning);
if (value.equals(0)) {
throw new AnnouncerUnavailableException("Growl is not running.");
}
final File icon = iconProvider.getIcon(48, 48);
String iconDef = icon != null ? "image from location ((POSIX file \"" + icon.getAbsolutePath() + "\") as string) as alias" : "";
String script = "\ntell application id \"com.Growl.GrowlHelperApp\"\n" + "register as application \"Gradle\" all notifications {\"Build Notification\"} default notifications {\"Build Notification\"}\n" + "notify with name \"Build Notification\" title \"" + escape(title) + "\" description \"" + escape(message) + "\" application name \"Gradle\"" + iconDef + "\nend tell\n";
engine.eval(script);
} catch (ScriptException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of javax.script.ScriptException in project groovy-core by groovy.
the class GroovyScriptEngineImpl method readFully.
private String readFully(Reader reader) throws ScriptException {
// 8K at a time
char[] arr = new char[8 * 1024];
StringBuilder buf = new StringBuilder();
int numChars;
try {
while ((numChars = reader.read(arr, 0, arr.length)) > 0) {
buf.append(arr, 0, numChars);
}
} catch (IOException exp) {
throw new ScriptException(exp);
}
return buf.toString();
}
Aggregations