Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Oct 31, 2013
2 parents 500fe5a + 5c918ed commit 78fad94
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class GrailsSwingConsole extends ForkedGrailsProjectClassExecutor{
protected String getProjectClassType() { "org.codehaus.groovy.grails.project.ui.GrailsProjectConsole" }

@Override
void runInstance(instance) {
int runInstance(instance) {
((GroovyObject)instance).invokeMethod("run", null)
return 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,28 @@ abstract class ForkedGrailsProjectClassExecutor extends ForkedGrailsProcess {
}
}

protected final void run() {
protected final int run() {
ExpandoMetaClass.enableGlobally()

if (isDaemonProcess()) {
startDaemon { cmd ->
def projectClassInstance = initializeProjectInstance()
runInstance(projectClassInstance)
}
return 0
}
else if (isReserveProcess()) {
// don't wait if the resume directory already exists, another process exists
if (!resumeDir.exists()) {
executionContext = readExecutionContext()
Object projectClassInstance = initializeProjectInstance()
waitForResume()
runInstance(projectClassInstance)
return runInstance(projectClassInstance)
}
}
else {
Object projectClassInstance = initializeProjectInstance()
runInstance(projectClassInstance)
return runInstance(projectClassInstance)
}
}

Expand Down Expand Up @@ -126,7 +127,7 @@ abstract class ForkedGrailsProjectClassExecutor extends ForkedGrailsProcess {

protected abstract String getProjectClassType()

abstract void runInstance(instance)
abstract int runInstance(instance)
}

@CompileStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ class ForkedGrailsCompiler extends ForkedGrailsProjectClassExecutor {
}

@Override
void runInstance(instance) {
((GroovyObject)instance).invokeMethod("configureClasspath", null)
((GroovyObject)instance).invokeMethod("compileAll", null)
int runInstance(instance) {
try {
((GroovyObject)instance).invokeMethod("configureClasspath", null)
((GroovyObject)instance).invokeMethod("compileAll", null)
return 0
} catch (Throwable e) {
GrailsConsole.getInstance().error("Error running forked compiler: ${e.message}", e)
return 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class ForkedGrailsTestRunner extends ForkedGrailsProjectClassExecutor {

static void main(String[] args) {
try {
new ForkedGrailsTestRunner().run()
System.exit(0)
System.exit( new ForkedGrailsTestRunner().run() )
} catch (Throwable e) {
GrailsConsole.getInstance().error("Error running forked test-app: " + e.getMessage(), e)
System.exit(1)
Expand Down Expand Up @@ -122,11 +121,22 @@ class ForkedGrailsTestRunner extends ForkedGrailsProjectClassExecutor {

@Override
@CompileStatic(TypeCheckingMode.SKIP)
void runInstance(instance) {
int runInstance(instance) {

instance.projectPackager.projectCompiler.configureClasspath()
instance.projectPackager.packageApplication()
instance.runAllTests(executionContext.argsMap)
boolean testsPassed = instance.runAllTests(executionContext.argsMap)
if(!isDaemonProcess()) {
if (testsPassed) {
return 0
}
else {
return 1
}
}
else {
return 0
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ public static boolean isInnerClassNode(ClassNode classNode) {
* Marks a method to be staticly compiled
*
* @param annotatedNode
* @return
* @return The annotated method
*/
public static AnnotatedNode addCompileStaticAnnotation(AnnotatedNode annotatedNode) {
return addCompileStaticAnnotation(annotatedNode, false);
Expand All @@ -1002,7 +1002,7 @@ public static AnnotatedNode addCompileStaticAnnotation(AnnotatedNode annotatedNo
*
* @param annotatedNode
* @param skip
* @return
* @return The annotated method
*/
public static AnnotatedNode addCompileStaticAnnotation(AnnotatedNode annotatedNode, boolean skip) {
if(annotatedNode != null) {
Expand All @@ -1018,7 +1018,7 @@ public static AnnotatedNode addCompileStaticAnnotation(AnnotatedNode annotatedNo
return annotatedNode;
}

/*
/**
* Set the method target of a MethodCallExpression to the first matching method with same number of arguments.
* This doesn't check argument types.
*
Expand All @@ -1035,7 +1035,7 @@ public static MethodCallExpression applyDefaultMethodTarget(final MethodCallExpr
*
* @param methodCallExpression
* @param targetClass
* @return
* @return The method call expression
*/
public static MethodCallExpression applyDefaultMethodTarget(final MethodCallExpression methodCallExpression, final Class<?> targetClass) {
return applyDefaultMethodTarget(methodCallExpression, ClassHelper.make(targetClass).getPlainNodeReference());
Expand All @@ -1049,7 +1049,7 @@ public static MethodCallExpression applyDefaultMethodTarget(final MethodCallExpr
* @param methodCallExpression
* @param targetClassNode
* @param targetParameterTypes
* @return
* @return The method call expression
*/
public static MethodCallExpression applyMethodTarget(final MethodCallExpression methodCallExpression, final ClassNode targetClassNode, final ClassNode... targetParameterTypes) {
String methodName = methodCallExpression.getMethodAsString();
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public static MethodCallExpression applyMethodTarget(final MethodCallExpression
* @param methodCallExpression
* @param targetClass
* @param targetParameterClassTypes
* @return
* @return The method call expression
*/
public static MethodCallExpression applyMethodTarget(final MethodCallExpression methodCallExpression, final Class<?> targetClass, final Class<?>... targetParameterClassTypes) {
return applyMethodTarget(methodCallExpression, ClassHelper.make(targetClass).getPlainNodeReference(), convertTargetParameterTypes(targetParameterClassTypes));
Expand All @@ -1092,7 +1092,7 @@ public static MethodCallExpression applyMethodTarget(final MethodCallExpression
* @param methodCallExpression
* @param targetClassNode
* @param targetParameterClassTypes
* @return
* @return The method call expression
*/
public static MethodCallExpression applyMethodTarget(final MethodCallExpression methodCallExpression, final ClassNode targetClassNode, final Class<?>... targetParameterClassTypes) {
return applyMethodTarget(methodCallExpression, targetClassNode, convertTargetParameterTypes(targetParameterClassTypes));
Expand Down Expand Up @@ -1125,7 +1125,7 @@ private static boolean parameterTypesMatch(Parameter[] parameters, ClassNode[] t
* @param objectExpression
* @param propertyName
* @param targetClassNode
* @return
* @return The method call expression
*/
public static MethodCallExpression buildGetPropertyExpression(final Expression objectExpression, final String propertyName, final ClassNode targetClassNode) {
return buildGetPropertyExpression(objectExpression, propertyName, targetClassNode, false);
Expand All @@ -1138,7 +1138,7 @@ public static MethodCallExpression buildGetPropertyExpression(final Expression o
* @param propertyName
* @param targetClassNode
* @param useBooleanGetter
* @return
* @return The method call expression
*/
public static MethodCallExpression buildGetPropertyExpression(final Expression objectExpression, final String propertyName, final ClassNode targetClassNode, final boolean useBooleanGetter) {
String methodName = (useBooleanGetter ? "is" : "get") + MetaClassHelper.capitalize(propertyName);
Expand All @@ -1157,7 +1157,7 @@ public static MethodCallExpression buildGetPropertyExpression(final Expression o
* @param propertyName
* @param targetClassNode
* @param valueExpression
* @return
* @return The method call expression
*/
public static MethodCallExpression buildSetPropertyExpression(final Expression objectExpression, final String propertyName, final ClassNode targetClassNode, final Expression valueExpression) {
String methodName = "set" + MetaClassHelper.capitalize(propertyName);
Expand All @@ -1175,7 +1175,7 @@ public static MethodCallExpression buildSetPropertyExpression(final Expression o
* @param objectExpression
* @param keyName
* @param valueExpression
* @return
* @return The method call expression
*/
public static MethodCallExpression buildPutMapExpression(final Expression objectExpression, final String keyName, final Expression valueExpression) {
return applyDefaultMethodTarget(new MethodCallExpression(objectExpression, "put", new ArgumentListExpression(new ConstantExpression(keyName), valueExpression)), Map.class);
Expand All @@ -1186,7 +1186,7 @@ public static MethodCallExpression buildPutMapExpression(final Expression object
*
* @param objectExpression
* @param keyName
* @return
* @return The method call expression
*/
public static MethodCallExpression buildGetMapExpression(final Expression objectExpression, final String keyName) {
return applyDefaultMethodTarget(new MethodCallExpression(objectExpression, "get", new ArgumentListExpression(new ConstantExpression(keyName))), Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface DataBinder {
* will be ignored
* @param blackList A list of properties names to be excluded during
* this data binding.
* @param listener A listener which will be notifed of data binding events triggered
* @param listener A listener which will be notified of data binding events triggered
* by this binding
* @see DataBindingSource
* @see DataBindingListener
Expand Down Expand Up @@ -105,7 +105,7 @@ void bind(Object obj, DataBindingSource source, List<String> whiteList,
*
* @param obj The object being bound to
* @param source The data binding source
* @param listener A listener which will be notifed of data binding events triggered
* @param listener A listener which will be notified of data binding events triggered
* by this binding
* @see DataBindingSource
* @see DataBindingListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SimpleDataBinder implements DataBinder {
*
* @param obj The object being bound to
* @param source The data binding source
* @param listener A listener which will be notifed of data binding events triggered
* @param listener A listener which will be notified of data binding events triggered
* by this binding
* @see DataBindingSource
* @see DataBindingListener
Expand Down Expand Up @@ -199,7 +199,7 @@ class SimpleDataBinder implements DataBinder {
* will be ignored
* @param blackList A list of properties names to be excluded during
* this data binding.
* @param listener A listener which will be notifed of data binding events triggered
* @param listener A listener which will be notified of data binding events triggered
* by this binding
* @see DataBindingSource
* @see DataBindingListener
Expand All @@ -222,7 +222,16 @@ class SimpleDataBinder implements DataBinder {
if (metaProperty) { // normal property
if (isOkToBind(metaProperty.name, whiteList, blackList)) {
def val = source[key]
processProperty obj, metaProperty, val, source, listener, errors
try {
def converter = getValueConverterForField(obj, metaProperty.name)
if(converter) {
setPropertyValue(obj, source, metaProperty, converter.convert(source), listener, false)
} else {
processProperty obj, metaProperty, val, source, listener, errors
}
} catch (Exception e) {
addBindingError(obj, propName, val, e, listener, errors)
}
}
} else {
def descriptor = getIndexedPropertyReferenceDescriptor propName
Expand Down Expand Up @@ -488,7 +497,7 @@ class SimpleDataBinder implements DataBinder {
} catch (IllegalArgumentException iae) {}
}

protected setPropertyValue(obj, DataBindingSource source, MetaProperty metaProperty, propertyValue, DataBindingListener listener) {
protected setPropertyValue(obj, DataBindingSource source, MetaProperty metaProperty, propertyValue, DataBindingListener listener, boolean convertCollectionElements = true) {
def propName = metaProperty.name
def propertyType
def propertyGetter
Expand All @@ -501,7 +510,7 @@ class SimpleDataBinder implements DataBinder {
propertyType = metaProperty.type
}
if (propertyValue == null || propertyType == Object || propertyType.isAssignableFrom(propertyValue.getClass())) {
if (!(propertyValue instanceof Range) && propertyValue instanceof Collection && Collection.isAssignableFrom(propertyType) && propertyGetter) {
if (convertCollectionElements && ((!(propertyValue instanceof Range) && propertyValue instanceof Collection && Collection.isAssignableFrom(propertyType) && propertyGetter))) {
addElementsToCollection(obj, propName, propertyValue, true)
} else {
obj[propName] = propertyValue
Expand Down Expand Up @@ -604,7 +613,7 @@ class SimpleDataBinder implements DataBinder {
coll.clear()
}
for(element in collection) {
if (element == null || referencedType.isAssignableFrom(element.getClass())) {
if (element == null || referencedType == null || referencedType.isAssignableFrom(element.getClass())) {
coll << element
} else {
coll << convert(referencedType, element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ class SimpleDataBinderSpec extends Specification {
widget.names[1] == null
widget.names[2] == 'two'
}

void 'Test @BindUsing on a List<Integer>'() {
given:
def binder = new SimpleDataBinder()
def widget = new Widget()

when:
binder.bind widget, [listOfIntegers: '4'] as SimpleMapDataBindingSource

then:
widget.listOfIntegers == [0, 1, 2, 3]
}
}

class Factory {
Expand All @@ -499,6 +511,14 @@ class Widget {
byte[] byteArray
Integer[] integers
List<String> names
@BindUsing({ obj, source ->
def cnt = source['listOfIntegers'] as int
def result = []
cnt.times { result << it }
println "Result: $result"
result
})
List<Integer> listOfIntegers = []
}

class Gadget extends Widget {
Expand Down
Loading

0 comments on commit 78fad94

Please sign in to comment.