use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class PropertyBinding method updateTargetValue.
public void updateTargetValue(final Object newValue) {
Runnable runnable = new Runnable() {
public void run() {
Object sourceValue = getSourceValue();
// if (isNonChangeCheck()) {
if ((sourceValue == null && newValue == null) || DefaultTypeTransformation.compareEqual(sourceValue, newValue)) {
// not a change, don't fire it
return;
}
// }
setBeanProperty(newValue);
}
};
switch(updateStrategy) {
case MIXED:
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
SwingUtilities.invokeLater(runnable);
}
break;
case ASYNC:
SwingUtilities.invokeLater(runnable);
break;
case SYNC:
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e);
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e.getTargetException());
throw new GroovyRuntimeException(e.getTargetException());
}
}
break;
case SAME:
runnable.run();
break;
case OUTSIDE:
if (SwingUtilities.isEventDispatchThread()) {
DEFAULT_EXECUTOR_SERVICE.submit(runnable);
} else {
runnable.run();
}
break;
case DEFER:
DEFAULT_EXECUTOR_SERVICE.submit(runnable);
}
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class XmlTemplateEngine method createTemplate.
public Template createTemplate(Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException {
Node root;
try {
root = xmlParser.parse(reader);
} catch (SAXException e) {
throw new RuntimeException("Parsing XML source failed.", e);
}
if (root == null) {
throw new IOException("Parsing XML source failed: root node is null.");
}
StringWriter writer = new StringWriter(1024);
writer.write("/* Generated by XmlTemplateEngine */\n");
new GspPrinter(new PrintWriter(writer), indentation).print(root);
Script script;
try {
script = groovyShell.parse(writer.toString(), "XmlTemplateScript" + counter++ + ".groovy");
} catch (Exception e) {
throw new GroovyRuntimeException("Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): " + e.getMessage());
}
return new XmlTemplate(script);
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class TestNgRunner method run.
/**
* Utility method to run a TestNG test.
*
* @param scriptClass the class we want to run as a test
* @param loader the class loader to use
* @return the result of running the test
*/
public Object run(Class scriptClass, GroovyClassLoader loader) {
// invoke through reflection to eliminate mandatory TestNG jar dependency
try {
Class testNGClass = loader.loadClass("org.testng.TestNG");
Object testng = InvokerHelper.invokeConstructorOf(testNGClass, new Object[] {});
InvokerHelper.invokeMethod(testng, "setTestClasses", new Object[] { scriptClass });
Class listenerClass = loader.loadClass("org.testng.TestListenerAdapter");
Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[] {});
InvokerHelper.invokeMethod(testng, "addListener", new Object[] { listener });
return InvokerHelper.invokeMethod(testng, "run", new Object[] {});
} catch (ClassNotFoundException e) {
throw new GroovyRuntimeException("Error running TestNG test.", e);
}
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class ExtensionModuleScanner method scanExtensionModuleFromMetaInf.
private void scanExtensionModuleFromMetaInf(final URL metadata) {
Properties properties = new Properties();
InputStream inStream = null;
try {
inStream = metadata.openStream();
properties.load(inStream);
} catch (IOException e) {
throw new GroovyRuntimeException("Unable to load module META-INF descriptor", e);
} finally {
closeQuietly(inStream);
}
scanExtensionModuleFromProperties(properties);
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class MetaInfExtensionModule method newModule.
public static MetaInfExtensionModule newModule(final Properties properties, final ClassLoader loader) {
String name = properties.getProperty(PropertiesModuleFactory.MODULE_NAME_KEY);
if (name == null)
throw new GroovyRuntimeException("Module file hasn't set the module name using key [" + PropertiesModuleFactory.MODULE_NAME_KEY + "]");
String version = properties.getProperty(PropertiesModuleFactory.MODULE_VERSION_KEY);
if (version == null)
throw new GroovyRuntimeException("Module file hasn't set the module version using key [" + PropertiesModuleFactory.MODULE_VERSION_KEY + "]");
String[] extensionClasses = properties.getProperty(MODULE_INSTANCE_CLASSES_KEY, "").trim().split("[,; ]");
String[] staticExtensionClasses = properties.getProperty(MODULE_STATIC_CLASSES_KEY, "").trim().split("[,; ]");
List<Class> instanceClasses = new ArrayList<Class>(extensionClasses.length);
List<Class> staticClasses = new ArrayList<Class>(staticExtensionClasses.length);
List<String> errors = new LinkedList<String>();
for (String extensionClass : extensionClasses) {
try {
extensionClass = extensionClass.trim();
if (extensionClass.length() > 0) {
instanceClasses.add(loader.loadClass(extensionClass));
}
} catch (ClassNotFoundException e) {
errors.add(extensionClass);
} catch (NoClassDefFoundError e) {
errors.add(extensionClass);
} catch (UnsupportedClassVersionError e) {
errors.add(extensionClass);
}
}
for (String extensionClass : staticExtensionClasses) {
try {
extensionClass = extensionClass.trim();
if (extensionClass.length() > 0) {
staticClasses.add(loader.loadClass(extensionClass));
}
} catch (ClassNotFoundException e) {
errors.add(extensionClass);
} catch (NoClassDefFoundError e) {
errors.add(extensionClass);
} catch (UnsupportedClassVersionError e) {
errors.add(extensionClass);
}
}
if (!errors.isEmpty()) {
for (String error : errors) {
LOG.warning("Module [" + name + "] - Unable to load extension class [" + error + "]");
}
}
return new MetaInfExtensionModule(name, version, instanceClasses, staticClasses);
}
Aggregations