Skip to content

Commit

Permalink
2.2.0: Grails 3.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrignon committed Nov 15, 2017
1 parent b81af2e commit 207d13a
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 72 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ It contains several branches for each version of this plugin

## Change log

### v2.2
* Grails 3.3.x
* GORM 6.1
* Hibernate 5.2.9
* Hibernate Search 5.7

### v2.1.2
* Supports hibernate.configClass if any
* Removed dependencies to info.app.grailsVersion, info.app.name
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ buildscript {
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.4"
}
}

version "2.1.2"
version "2.2.0"
group "org.grails.plugins"

apply plugin: 'java'
Expand Down Expand Up @@ -56,7 +56,6 @@ dependencies {
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"

// GORM 6
compile "org.grails.plugins:hibernate5:6.1.4"
compile 'org.grails.plugins:cache'

Expand All @@ -69,7 +68,7 @@ dependencies {
profile "org.grails.profiles:web-plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.4"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
Expand All @@ -83,7 +82,6 @@ dependencies {
grailsPublish {
// user/key: useless, see https://medium.com/@benorama/how-to-publish-your-grails-3-plugin-to-bintray-c341b24f567d#.elz43j5nq
user = 'lgrignon'
// key = '????'
githubSlug = 'mathpere/grails-hibernate-search-plugin'
license { name = 'Apache-2.0' }
title = "Grails Hibernate Search Plugin"
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
grailsVersion=3.2.10
gradleWrapperVersion=3.3
gormVersion=6.1.4.RELEASE
grailsVersion=3.3.1
gradleWrapperVersion=3.5
gormVersion=6.1.8.RELEASE
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Jul 19 05:54:46 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
72 changes: 42 additions & 30 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,26 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -85,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand Down Expand Up @@ -150,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
14 changes: 4 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public class HibernateSearchConfigurationInterceptor {

if (searchClosure != null) {
SearchMappingEntityConfig searchMappingEntityConfig = new SearchMappingEntityConfig(searchMapping,
domainClass);
domainClass.getClazz());

searchClosure.setDelegate(searchMappingEntityConfig);
searchClosure.setResolveStrategy(Closure.DELEGATE_FIRST);
searchClosure.call();

Map<String, PropertyDescriptor> indexedProperties = new HashMap<>();
for (GrailsDomainClassProperty property : domainClass.getPersistentProperties()) {
for (String indexedPropertyName : searchMappingEntityConfig.getIndexedPropertyNames()) {
PropertyDescriptor indexedPropertyDescriptor = searchMapping
.getEntityDescriptor(domainClass.getClazz())
.getPropertyDescriptor(property.getName(), ElementType.FIELD);
.getPropertyDescriptor(indexedPropertyName, ElementType.FIELD);
if (indexedPropertyDescriptor != null) {
indexedProperties.put(indexedPropertyDescriptor.getName(), indexedPropertyDescriptor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.hibernate.search.cfg.DocumentIdMapping;
import org.hibernate.search.cfg.EntityDescriptor
import org.hibernate.search.cfg.EntityMapping
import org.hibernate.search.cfg.FieldMapping;
import org.hibernate.search.cfg.IndexEmbeddedMapping
import org.hibernate.search.cfg.PropertyMapping;
import org.hibernate.search.cfg.SearchMapping
import org.slf4j.Logger
Expand All @@ -32,8 +33,6 @@ import org.slf4j.LoggerFactory;
import java.lang.annotation.ElementType
import java.lang.reflect.Field;

import grails.core.GrailsDomainClass
import grails.core.GrailsDomainClassProperty;
import grails.plugins.*;

class SearchMappingEntityConfig {
Expand All @@ -44,19 +43,22 @@ class SearchMappingEntityConfig {

def analyzer

def mapping
private final GrailsDomainClass domainClass
private final DocumentIdMapping mapping
private final Class<?> domainClass

private final EntityMapping entityMapping
private final SearchMapping searchMapping
private final List<String> indexedPropertyNames;

public SearchMappingEntityConfig( SearchMapping searchMapping, GrailsDomainClass domainClass ) {
public SearchMappingEntityConfig( SearchMapping searchMapping, Class<?> domainClass ) {
this.domainClass = domainClass

this.searchMapping = searchMapping;
this.entityMapping = searchMapping.entity( domainClass.getClazz() )
this.entityMapping = searchMapping.entity( domainClass )
this.mapping = entityMapping.indexed().property( IDENTITY, ElementType.FIELD ).documentId()

this.indexedPropertyNames = new LinkedList<>();

}

def setClassBridge( Map classBridge ) {
Expand All @@ -75,42 +77,45 @@ class SearchMappingEntityConfig {

log.debug "adding indexEmbedded property: " + name

mapping = mapping.property( name, ElementType.FIELD ).indexEmbedded()
IndexEmbeddedMapping propertyMapping = mapping.property( name, ElementType.FIELD ).indexEmbedded()

if ( args.indexEmbedded instanceof Map ) {
def depth = args.indexEmbedded["depth"]
if ( depth ) {
mapping = mapping.depth( depth )
propertyMapping.depth( depth )
}

def includeEmbeddedObjectId = args.indexEmbedded["includeEmbeddedObjectId"]
if ( includeEmbeddedObjectId ) {
mapping = mapping.includeEmbeddedObjectId(includeEmbeddedObjectId)
propertyMapping.includeEmbeddedObjectId(includeEmbeddedObjectId)
}
}

indexedPropertyNames.add(name);

} else if ( args.containedIn ) {

log.debug "adding containedIn property: " + name

mapping = mapping.property( name, ElementType.FIELD ).containedIn()

mapping.property( name, ElementType.FIELD ).containedIn()

indexedPropertyNames.add(name);

} else {

log.debug "adding indexed property: " + name

GrailsDomainClassProperty property = domainClass.getPersistentProperty(name);

Field backingField = null;

// try to find the field in the parent class hierarchy (starting from domain class itself)
Class currentDomainClass = domainClass.getClazz();
Class currentDomainClass = domainClass;
while (currentDomainClass != null) {
try {
backingField = currentDomainClass.getDeclaredField(property.getName());
backingField = currentDomainClass.getDeclaredField(name);
break;
} catch (NoSuchFieldException e) {
// and in groovy's traits
backingField = currentDomainClass.getDeclaredFields().find { field -> field.getName().endsWith('__' + property.getName()) };
backingField = currentDomainClass.getDeclaredFields().find { field -> field.getName().endsWith('__' + name) };
if (backingField != null) {
break;
}
Expand All @@ -128,8 +133,12 @@ class SearchMappingEntityConfig {

EntityMapping targetEntityMapping = mapping.entity( currentDomainClass );

FieldMapping fieldMapping = targetEntityMapping.property( backingField.getName(), ElementType.FIELD ).field().name( args.name ?: name )
String fieldName = backingField.getName();
FieldMapping fieldMapping = targetEntityMapping.property( fieldName, ElementType.FIELD ).field().name( args.name ?: name )
registerIndexedProperty(fieldMapping, args)

indexedPropertyNames.add(fieldName);

}
}

Expand Down Expand Up @@ -189,7 +198,11 @@ class SearchMappingEntityConfig {
}
}

public EntityDescriptor getEntityDescriptor() {
return searchMapping.getEntity( domainClass.getClazz() )
EntityDescriptor getEntityDescriptor() {
return searchMapping.getEntity( domainClass )
}

List<String> getIndexedPropertyNames() {
return indexedPropertyNames;
}
}

0 comments on commit 207d13a

Please sign in to comment.