Skip to content

Commit ce32384

Browse files
committed
Support Groovy 5
Closes gh-4
1 parent 8558e6f commit ce32384

File tree

5 files changed

+127
-21
lines changed

5 files changed

+127
-21
lines changed

grace-datastore-core/src/main/groovy/org/grails/datastore/mapping/config/ConfigurationBuilder.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
/* Copyright 2016 the original author or authors.
1+
/*
2+
* Copyright 2016-2024 the original author or authors.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
56
* You may obtain a copy of the License at
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
89
*
910
* Unless required by applicable law or agreed to in writing, software
1011
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,8 +17,6 @@ package org.grails.datastore.mapping.config
1617

1718
import groovy.transform.CompileDynamic
1819
import groovy.transform.CompileStatic
19-
import groovy.transform.builder.Builder
20-
import groovy.transform.builder.SimpleStrategy
2120
import groovy.util.logging.Slf4j
2221
import org.springframework.core.convert.ConversionFailedException
2322
import org.springframework.core.env.PropertyResolver
@@ -36,6 +35,7 @@ import org.grails.datastore.mapping.reflect.NameUtils
3635
* @param <C> The finalized configuration constructions from the builder (examples are MongoClientSettings or Neo4j Bolt's Config)
3736
*
3837
* @author Graeme Rocher
38+
* @author Michael Yan
3939
*/
4040
@CompileStatic
4141
@Slf4j
@@ -163,7 +163,7 @@ abstract class ConfigurationBuilder<B, C> {
163163
}
164164
else if (!hasBuilderPrefix &&
165165
((org.grails.datastore.mapping.reflect.ReflectionUtils.isGetter(methodName, parameterTypes) &&
166-
method.returnType.getAnnotation(Builder) == null) ||
166+
method.returnType.getAnnotation(ConfigurationSettings) == null) ||
167167
org.grails.datastore.mapping.reflect.ReflectionUtils.isSetter(methodName, parameterTypes))) {
168168
// don't process getters or setters, unless the getter returns a builder
169169
continue
@@ -216,7 +216,7 @@ abstract class ConfigurationBuilder<B, C> {
216216
continue
217217
}
218218

219-
def buildMethod = ReflectionUtils.findMethod(argType, 'build')
219+
Method buildMethod = ReflectionUtils.findMethod(argType, 'build')
220220
if (buildMethod != null) {
221221
Method existingGetter = ReflectionUtils.findMethod(builderClass, NameUtils.getGetterName(methodName))
222222
def newBuilder
@@ -239,8 +239,8 @@ abstract class ConfigurationBuilder<B, C> {
239239
}
240240
}
241241

242-
Builder builderAnnotation = argType.getAnnotation(Builder)
243-
if (builderAnnotation != null && builderAnnotation.builderStrategy() == SimpleStrategy) {
242+
ConfigurationSettings builderAnnotation = argType.getAnnotation(ConfigurationSettings)
243+
if (builderAnnotation != null) {
244244
Method existingGetter = ReflectionUtils.findMethod(builderClass, NameUtils.getGetterName(methodName))
245245
def newBuilder
246246
if (existingGetter != null) {
@@ -300,7 +300,7 @@ abstract class ConfigurationBuilder<B, C> {
300300
}
301301
}
302302
else if (methodName.startsWith("get") && parameterTypes.length == 0) {
303-
if (method.returnType.getAnnotation(Builder)) {
303+
if (method.returnType.getAnnotation(ConfigurationSettings)) {
304304
def childBuilder = method.invoke(builder)
305305
if (childBuilder != null) {
306306
Object fallBackChildConfig = null
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.grails.datastore.mapping.config
17+
18+
import java.lang.annotation.Documented
19+
import java.lang.annotation.ElementType
20+
import java.lang.annotation.Retention
21+
import java.lang.annotation.RetentionPolicy
22+
import java.lang.annotation.Target
23+
24+
/**
25+
* ConfigurationSettings
26+
*
27+
* @author Michael Yan
28+
* @since 2023.1
29+
*/
30+
@Documented
31+
@Retention(RetentionPolicy.RUNTIME)
32+
@Target([ ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD ])
33+
@interface ConfigurationSettings {
34+
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.grails.datastore.mapping.config
17+
18+
import java.lang.annotation.Documented
19+
import java.lang.annotation.ElementType
20+
import java.lang.annotation.Retention
21+
import java.lang.annotation.RetentionPolicy
22+
import java.lang.annotation.Target
23+
24+
import groovy.transform.AnnotationCollector
25+
import groovy.transform.AutoClone
26+
import groovy.transform.builder.Builder
27+
import groovy.transform.builder.SimpleStrategy
28+
29+
/**
30+
* SettingsBuilder
31+
*
32+
* @author Michael Yan
33+
* @since 2023.1
34+
*/
35+
@AnnotationCollector
36+
@AutoClone
37+
@Builder(builderStrategy = SimpleStrategy, prefix = '')
38+
@ConfigurationSettings
39+
@Documented
40+
@Retention(RetentionPolicy.RUNTIME)
41+
@Target([ ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD ])
42+
@interface SettingsBuilder {
43+
44+
}

grace-datastore-core/src/main/groovy/org/grails/datastore/mapping/core/connections/ConnectionSourceSettings.groovy

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1+
/*
2+
* Copyright 2016-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.grails.datastore.mapping.core.connections
217

318
import jakarta.persistence.FlushModeType
419

5-
import groovy.transform.AutoClone
620
import groovy.transform.CompileStatic
7-
import groovy.transform.builder.Builder
8-
import groovy.transform.builder.SimpleStrategy
921

1022
import org.grails.datastore.mapping.config.Settings
23+
import org.grails.datastore.mapping.config.SettingsBuilder
1124
import org.grails.datastore.mapping.engine.types.CustomTypeMarshaller
1225
import org.grails.datastore.mapping.multitenancy.MultiTenancySettings
1326

1427
/**
1528
* Default settings shared across all implementations
1629
*
1730
* @author Graeme Rocher
31+
* @author Michael Yan
1832
* @since 6.0
1933
*/
20-
@Builder(builderStrategy = SimpleStrategy, prefix = '')
21-
@AutoClone
2234
@CompileStatic
35+
@SettingsBuilder
2336
class ConnectionSourceSettings implements Settings {
2437

2538
/**
@@ -89,7 +102,7 @@ class ConnectionSourceSettings implements Settings {
89102
/**
90103
* Represents the default settings
91104
*/
92-
@Builder(builderStrategy = SimpleStrategy, prefix = '')
105+
@SettingsBuilder
93106
static class DefaultSettings {
94107

95108
/**
@@ -107,7 +120,7 @@ class ConnectionSourceSettings implements Settings {
107120
/**
108121
* Any custom settings
109122
*/
110-
@Builder(builderStrategy = SimpleStrategy, prefix = '')
123+
@SettingsBuilder
111124
static class CustomSettings {
112125

113126
/**

grace-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/jdbc/connections/DataSourceSettings.groovy

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1+
/*
2+
* Copyright 2016-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.grails.datastore.gorm.jdbc.connections
217

318
import javax.sql.DataSource
419

5-
import groovy.transform.AutoClone
620
import groovy.transform.CompileStatic
7-
import groovy.transform.builder.Builder
8-
import groovy.transform.builder.SimpleStrategy
921

1022
import org.grails.datastore.gorm.jdbc.schema.DefaultSchemaHandler
1123
import org.grails.datastore.gorm.jdbc.schema.SchemaHandler
24+
import org.grails.datastore.mapping.config.SettingsBuilder
1225
import org.grails.datastore.mapping.core.connections.ConnectionSourceSettings
1326

1427
/**
1528
* DataSource settings
1629
*
1730
* @author Graeme Rocher
31+
* @author Michael Yan
1832
*/
19-
@Builder(builderStrategy = SimpleStrategy, prefix = '')
20-
@AutoClone
33+
@CompileStatic
34+
@SettingsBuilder
2135
class DataSourceSettings extends ConnectionSourceSettings {
2236

2337
/**

0 commit comments

Comments
 (0)