Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grails/grails-core
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed May 8, 2012
2 parents 61b042a + b4dae55 commit a0d4f55
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 18 deletions.
2 changes: 1 addition & 1 deletion grails-resources/src/grails/home/bash/grails.bat
Expand Up @@ -12,4 +12,4 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.\

CALL "%DIRNAME%\startGrails.bat" "%DIRNAME%" %*
CALL "%DIRNAME%\startGrails.bat" %*
3 changes: 0 additions & 3 deletions grails-resources/src/grails/home/bash/startGrails.bat
Expand Up @@ -8,9 +8,6 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~1
shift

set CLASS=@starter.main.class@

if exist "%USERPROFILE%/.groovy/preinit.bat" call "%USERPROFILE%/.groovy/preinit.bat"
Expand Down
Expand Up @@ -28,7 +28,7 @@ grails.project.dependency.resolution = {

plugins {
build(":tomcat:$grailsVersion",
":release:1.0.1") {
":release:2.0.0") {
export = false
}
}
Expand Down
Expand Up @@ -66,9 +66,26 @@ class Person {
static constraints = {
birthDate nullable: true
}
}
@Entity
class Pet {
String name
Map detailMap
Person owner
}
''')
}

void testBindingMapValue() {
def petClass = ga.getDomainClass('databindingtests.Pet')
def pet = petClass.newInstance()
pet.properties = [name: 'lemur', detailMap: [first: 'one', second: 'two'], owner: [name: 'Jeff'], foo: 'bar', bar: [a: 'a', b: 'b']]

assert pet.name == 'lemur'
assert pet.detailMap.first == 'one'
assert pet.detailMap.second == 'two'
assert !pet.hasErrors()
}

void testBindingNullToANullableDateThatAlreadyHasAValue() {
def c = ga.getControllerClass('databindingtests.TestController').newInstance()
Expand Down
@@ -0,0 +1,36 @@
package org.codehaus.groovy.grails.web.pages

import grails.test.AbstractGrailsEnvChangingSpec

import spock.lang.Specification
import grails.test.mixin.TestFor
import grails.util.Environment;
import grails.artefact.Artefact


@TestFor(CustomTagLib)
class OptionalTagBodySpec extends AbstractGrailsEnvChangingSpec {
def "Test that the existence of a body can be tested with groovy truth"(grailsEnv) {
when:
changeGrailsEnv(grailsEnv)
def content = applyTemplate("<a:myBody />")
def content2 = applyTemplate("<a:myBody>Hello</a:myBody>")
then:
content == 'nobody'
content2 == 'Hello'
where:
grailsEnv << grailsEnvs
}
}
@Artefact("TagLibrary")
class CustomTagLib {
static namespace = "a"

def myBody = { attrs, body ->
if(body) {
out << body()
} else {
out << 'nobody'
}
}
}
Expand Up @@ -26,6 +26,7 @@
import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;

import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down Expand Up @@ -71,6 +72,7 @@
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.MetaClassHelper;
import org.codehaus.groovy.runtime.metaclass.ThreadManagedMetaBeanProperty;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.ConfigurablePropertyAccessor;
Expand Down Expand Up @@ -512,14 +514,29 @@ private void filterNestedParameterMaps(MutablePropertyValues mpvs) {
if (JSONObject.NULL.getClass().isInstance(value)) {
mpvs.removePropertyValue(pv);
}
if (isNotCandidateForBinding(value)) {
if (!isCandidateForBinding(pv)) {
mpvs.removePropertyValue(pv);
}
}
}

private boolean isNotCandidateForBinding(Object value) {
return value instanceof Map;
private boolean isCandidateForBinding(PropertyValue pv) {
boolean isCandidate = true;
final Object value = pv.getValue();
if(value instanceof GrailsParameterMap || value instanceof JSONObject) {
isCandidate = false;
} else if(value instanceof Map) {
isCandidate = false;
final String propertyName = pv.getName();
final PropertyDescriptor property = BeanUtils.getPropertyDescriptor(getTarget().getClass(), propertyName);
if(property != null) {
final Class<?> propertyType = property.getPropertyType();
if(propertyType.isAssignableFrom(value.getClass())) {
isCandidate = true;
}
}
}
return isCandidate;
}

private PropertyValues filterPropertyValues(PropertyValues propertyValues, String prefix) {
Expand Down
Expand Up @@ -47,6 +47,7 @@
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException;
import org.codehaus.groovy.grails.web.util.CodecPrintWriter;
import org.codehaus.groovy.grails.web.util.GrailsPrintWriter;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

/**
* NOTE: Based on work done by on the GSP standalone project (https://gsp.dev.java.net/)
Expand Down Expand Up @@ -154,6 +155,10 @@ public Object doCall(@SuppressWarnings("unused") Object[] args) {
public Object call(Object... args) {
return retval;
}

public boolean asBoolean() {
return DefaultTypeTransformation.castToBoolean(retval);
}
}

protected static final Closure<?> EMPTY_BODY_CLOSURE = new ConstantClosure(BLANK_STRING);
Expand Down
31 changes: 21 additions & 10 deletions grails-wrapper/src/main/java/org/grails/wrapper/GrailsWrapper.java
Expand Up @@ -11,7 +11,9 @@
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.ResourceBundle;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -44,6 +46,23 @@ public static void main(final String[] args) throws Exception{
final File grailsHome = new File(installDir, "grails-" + grailsVersion);

System.setProperty("grails.home", grailsHome.getAbsolutePath());

final List<String> newArgsList = new ArrayList<String>();
for(int i = 0; i < args.length; i++) {
final String arg = args[0];
if("--main".equals(arg) && i < args.length - 1) {
// skip --main and the following argument
i++;
} else if("--conf".equals(arg) && i < args.length - 1) {
newArgsList.add(arg);
final File groovyStarterConf = new File(grailsHome, "conf/groovy-starter.conf");
newArgsList.add(groovyStarterConf.getAbsolutePath());
} else {
newArgsList.add(arg);
}
}

final Object[] newArgsArray = newArgsList.toArray();
final URL[] urls = new URL[2];
urls[0] = new File(grailsHome, "dist/grails-bootstrap-" + grailsVersion + ".jar").toURI().toURL();
File[] groovyJarCandidates = new File(grailsHome, "lib/org.codehaus.groovy/groovy-all/jars/").listFiles(new FilenameFilter() {
Expand All @@ -55,16 +74,8 @@ public boolean accept(final File dir, final String name) {
final URLClassLoader urlClassLoader = new URLClassLoader(urls);
final Class<?> loadClass = urlClassLoader.loadClass("org.codehaus.groovy.grails.cli.support.GrailsStarter");
final Method mainMethod = loadClass.getMethod("main", String[].class);
final String[] args2 = new String[args.length];
System.arraycopy(args, 0, args2, 0, args.length);
for(int i = 0; i < args2.length; i++) {
if("--conf".equals(args2[i]) && (i < (args2.length - 1))) {
final File groovyStarterConf = new File(grailsHome, "conf/groovy-starter.conf");
args2[i + 1] = groovyStarterConf.getAbsolutePath();
break;
}
}
mainMethod.invoke(null, new Object[]{args2});

mainMethod.invoke(null, new Object[]{newArgsArray});
}

public static void extract(final File zip, final File dest) throws IOException {
Expand Down

0 comments on commit a0d4f55

Please sign in to comment.