use of groovy.lang.GroovyRuntimeException in project gradle by gradle.
the class AbstractDynamicObject method getWriteOnlyProperty.
protected GroovyRuntimeException getWriteOnlyProperty(String name) {
Class<?> publicType = getPublicType();
boolean includeDisplayName = hasUsefulDisplayName();
if (publicType != null && includeDisplayName) {
return new GroovyRuntimeException(String.format("Cannot get the value of write-only property '%s' for %s of type %s.", name, getDisplayName(), publicType.getName()));
} else if (publicType != null) {
return new GroovyRuntimeException(String.format("Cannot get the value of write-only property '%s' for object of type %s.", name, publicType.getName()));
} else {
// Use the display name anyway
return new GroovyRuntimeException(String.format("Cannot get the value of write-only property '%s' for %s.", name, getDisplayName()));
}
}
use of groovy.lang.GroovyRuntimeException in project gradle by gradle.
the class AbstractDynamicObject method setReadOnlyProperty.
protected GroovyRuntimeException setReadOnlyProperty(String name) {
Class<?> publicType = getPublicType();
boolean includeDisplayName = hasUsefulDisplayName();
if (publicType != null && includeDisplayName) {
return new GroovyRuntimeException(String.format("Cannot set the value of read-only property '%s' for %s of type %s.", name, getDisplayName(), publicType.getName()));
} else if (publicType != null) {
return new GroovyRuntimeException(String.format("Cannot set the value of read-only property '%s' for object of type %s.", name, publicType.getName()));
} else {
// Use the display name anyway
return new GroovyRuntimeException(String.format("Cannot set the value of read-only property '%s' for %s.", name, getDisplayName()));
}
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class MixinInMetaClass method mixinClassesToMetaClass.
public static void mixinClassesToMetaClass(MetaClass self, List<Class> categoryClasses) {
final Class selfClass = self.getTheClass();
if (self instanceof HandleMetaClass) {
self = (MetaClass) ((HandleMetaClass) self).replaceDelegate();
}
if (!(self instanceof ExpandoMetaClass)) {
if (self instanceof DelegatingMetaClass && ((DelegatingMetaClass) self).getAdaptee() instanceof ExpandoMetaClass) {
self = ((DelegatingMetaClass) self).getAdaptee();
} else {
throw new GroovyRuntimeException("Can't mixin methods to meta class: " + self);
}
}
ExpandoMetaClass mc = (ExpandoMetaClass) self;
List<MetaMethod> arr = new ArrayList<MetaMethod>();
for (Class categoryClass : categoryClasses) {
final CachedClass cachedCategoryClass = ReflectionCache.getCachedClass(categoryClass);
final MixinInMetaClass mixin = new MixinInMetaClass(mc, cachedCategoryClass);
final MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(categoryClass);
final List<MetaProperty> propList = metaClass.getProperties();
for (MetaProperty prop : propList) if (self.getMetaProperty(prop.getName()) == null) {
mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin));
}
for (MetaProperty prop : cachedCategoryClass.getFields()) if (self.getMetaProperty(prop.getName()) == null) {
mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin));
}
for (MetaMethod method : metaClass.getMethods()) {
final int mod = method.getModifiers();
if (!Modifier.isPublic(mod))
continue;
if (method instanceof CachedMethod && ((CachedMethod) method).getCachedMethod().isSynthetic())
continue;
if (Modifier.isStatic(mod)) {
if (method instanceof CachedMethod)
staticMethod(self, arr, (CachedMethod) method);
} else if (method.getDeclaringClass().getTheClass() != Object.class || method.getName().equals("toString")) {
// if (self.pickMethod(method.getName(), method.getNativeParameterTypes()) == null) {
final MixinInstanceMetaMethod metaMethod = new MixinInstanceMetaMethod(method, mixin);
arr.add(metaMethod);
// }
}
}
}
for (Object res : arr) {
final MetaMethod metaMethod = (MetaMethod) res;
if (metaMethod.getDeclaringClass().isAssignableFrom(selfClass))
mc.registerInstanceMethod(metaMethod);
else {
mc.registerSubclassInstanceMethod(metaMethod);
}
}
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class ProcessGroovyMethods method pipeTo.
/**
* Allows one Process to asynchronously pipe data to another Process.
*
* @param left a Process instance
* @param right a Process to pipe output to
* @return the second Process to allow chaining
* @throws java.io.IOException if an IOException occurs.
* @since 1.5.2
*/
public static Process pipeTo(final Process left, final Process right) throws IOException {
new Thread(new Runnable() {
public void run() {
InputStream in = new BufferedInputStream(getIn(left));
OutputStream out = new BufferedOutputStream(getOut(right));
byte[] buf = new byte[8192];
int next;
try {
while ((next = in.read(buf)) != -1) {
out.write(buf, 0, next);
}
} catch (IOException e) {
throw new GroovyRuntimeException("exception while reading process stream", e);
} finally {
closeWithWarning(out);
}
}
}).start();
return right;
}
use of groovy.lang.GroovyRuntimeException in project groovy-core by groovy.
the class ProxyGeneratorAdapter method proxy.
@SuppressWarnings("unchecked")
public GroovyObject proxy(Map<Object, Object> map, Object... constructorArgs) {
if (constructorArgs == null && cachedNoArgConstructor != null) {
// if there isn't any argument, we can make invocation faster using the cached constructor
try {
return (GroovyObject) cachedNoArgConstructor.newInstance(map);
} catch (InstantiationException e) {
throw new GroovyRuntimeException(e);
} catch (IllegalAccessException e) {
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
throw new GroovyRuntimeException(e);
}
}
if (constructorArgs == null)
constructorArgs = EMPTY_ARGS;
Object[] values = new Object[constructorArgs.length + 1];
System.arraycopy(constructorArgs, 0, values, 0, constructorArgs.length);
values[values.length - 1] = map;
return DefaultGroovyMethods.<GroovyObject>newInstance(cachedClass, values);
}
Aggregations