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);
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class StandardPropertiesModuleFactory method newModule.
@Override
@SuppressWarnings("unchecked")
public ExtensionModule newModule(final Properties properties, final ClassLoader classLoader) {
String factoryName = properties.getProperty(MODULE_FACTORY_KEY);
if (factoryName != null) {
try {
Class<? extends PropertiesModuleFactory> factoryClass = (Class<? extends PropertiesModuleFactory>) classLoader.loadClass(factoryName);
PropertiesModuleFactory delegate = factoryClass.newInstance();
return delegate.newModule(properties, classLoader);
} catch (ClassNotFoundException e) {
throw new GroovyRuntimeException("Unable to load module factory [" + factoryName + "]", e);
} catch (InstantiationException e) {
throw new GroovyRuntimeException("Unable to instantiate module factory [" + factoryName + "]", e);
} catch (IllegalAccessException e) {
throw new GroovyRuntimeException("Unable to instantiate module factory [" + factoryName + "]", e);
}
}
return MetaInfExtensionModule.newModule(properties, classLoader);
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class DataSet method visit.
private void visit(Closure closure, CodeVisitorSupport visitor) {
if (closure != null) {
ClassNode classNode = closure.getMetaClass().getClassNode();
if (classNode == null) {
throw new GroovyRuntimeException("DataSet unable to evaluate expression. AST not available for closure: " + closure.getMetaClass().getTheClass().getName() + ". Is the source code on the classpath?");
}
List methods = classNode.getDeclaredMethods("doCall");
if (!methods.isEmpty()) {
MethodNode method = (MethodNode) methods.get(0);
if (method != null) {
Statement statement = method.getCode();
if (statement != null) {
statement.visit(visitor);
}
}
}
}
}
use of groovy.lang.GroovyRuntimeException in project groovy by apache.
the class GroovyAssert method shouldFail.
/**
* Asserts that the given script fails when it is evaluated
*
* @param script the script expected to fail
* @return the caught exception
*/
public static Throwable shouldFail(String script) {
boolean failed = false;
Throwable th = null;
try {
GroovyShell shell = new GroovyShell();
shell.evaluate(script, genericScriptName());
} catch (GroovyRuntimeException gre) {
failed = true;
th = ScriptBytecodeAdapter.unwrap(gre);
} catch (Throwable e) {
failed = true;
th = e;
}
assertTrue("Script should have failed", failed);
return th;
}
Aggregations