Skip to content

Commit 0ede341

Browse files
committed
Update build scripts
1 parent 0cf1d1a commit 0ede341

File tree

8 files changed

+529
-73
lines changed

8 files changed

+529
-73
lines changed

build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ subprojects { Project subproject ->
142142

143143
apply plugin: 'java-library'
144144
apply plugin: 'maven-publish'
145-
apply plugin: 'checkstyle'
146-
apply plugin: 'codenarc'
145+
// apply plugin: 'checkstyle'
146+
// apply plugin: 'codenarc'
147147
apply plugin: 'signing'
148148
apply plugin: "org.gradle.test-retry"
149149

@@ -270,15 +270,15 @@ subprojects { Project subproject ->
270270
inputs.files(tasks.named('processResources'))
271271
}
272272

273-
checkstyle {
274-
toolVersion = "10.26.1"
275-
configDirectory.set(rootProject.file("$rootDir/gradle/checkstyle"))
276-
}
273+
// checkstyle {
274+
// toolVersion = "10.26.1"
275+
// configDirectory.set(rootProject.file("$rootDir/gradle/checkstyle"))
276+
// }
277277

278-
codenarc {
279-
toolVersion = '3.6.0'
280-
setConfigFile(new File("$rootDir/gradle/codenarc/codenarc.groovy"))
281-
}
278+
// codenarc {
279+
// toolVersion = '3.6.0'
280+
// setConfigFile(new File("$rootDir/gradle/codenarc/codenarc.groovy"))
281+
// }
282282

283283
}
284284

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
gradlePluginPortal()
5+
maven {
6+
name = 'Maven Central Portal Snapshots'
7+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
8+
9+
content {
10+
includeGroupAndSubgroups 'org.graceframework'
11+
}
12+
mavenContent {
13+
snapshotsOnly()
14+
}
15+
}
16+
}
17+
dependencies {
18+
classpath "org.graceframework:grace-gradle-plugin:$graceVersion"
19+
classpath "org.graceframework.plugins:asset-pipeline-gradle:$assetPipelineVersion"
20+
// classpath "com.github.erdi:webdriver-binaries-gradle-plugin:3.2"
21+
}
22+
}
23+
24+
apply plugin: "org.graceframework.grace-web"
25+
apply plugin: "org.graceframework.grace-gsp"
26+
apply plugin: "org.graceframework.asset-pipeline"
27+
// apply plugin: "com.github.erdi.webdriver-binaries"
28+
29+
group = "examples"
30+
31+
configurations {
32+
developmentOnly
33+
}
34+
135
dependencies {
236
implementation "org.springframework.boot:spring-boot-starter-logging"
337
implementation "org.springframework.boot:spring-boot-autoconfigure"
@@ -6,8 +40,8 @@ dependencies {
640
implementation "org.graceframework:grace-core"
741
implementation "org.graceframework:grace-boot"
842
implementation "org.graceframework:grace-plugin-gsp"
9-
implementation project(":grace-plugin")
1043
implementation "org.graceframework:grace-boot-hibernate"
44+
implementation "org.graceframework:grace-boot-mongodb"
1145

1246
runtimeOnly "org.graceframework.plugins:asset-pipeline-plugin:$assetPipelineVersion"
1347
runtimeOnly "com.h2database:h2"
@@ -27,26 +61,22 @@ dependencies {
2761
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
2862
}
2963

30-
tasks.withType(Test) {
31-
systemProperty "geb.env", System.getProperty('geb.env')
32-
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
33-
if (!System.getenv().containsKey('CI')) {
34-
systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver')
35-
systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver')
36-
} else {
37-
systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
38-
systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
39-
}
40-
}
41-
42-
webdriverBinaries {
43-
chromedriver {
44-
version = '126.0.6478.126'
45-
fallbackTo32Bit = true
46-
}
47-
geckodriver '0.33.0'
48-
}
49-
//compileGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug','-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005']
50-
51-
64+
// tasks.withType(Test) {
65+
// systemProperty "geb.env", System.getProperty('geb.env')
66+
// systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
67+
// if (!System.getenv().containsKey('CI')) {
68+
// systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver')
69+
// systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver')
70+
// } else {
71+
// systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
72+
// systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
73+
// }
74+
// }
5275

76+
// webdriverBinaries {
77+
// chromedriver {
78+
// version = '126.0.6478.126'
79+
// fallbackTo32Bit = true
80+
// }
81+
// geckodriver '0.33.0'
82+
// }
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package grails.test.mongodb
2+
3+
import com.mongodb.client.MongoClient
4+
import grails.config.Config
5+
import groovy.transform.CompileStatic
6+
import org.grails.config.PropertySourcesConfig
7+
import org.grails.datastore.mapping.core.DatastoreUtils
8+
import org.grails.datastore.mapping.core.Session
9+
import org.grails.datastore.mapping.core.exceptions.ConfigurationException
10+
import org.grails.datastore.mapping.model.MappingContext
11+
import org.grails.datastore.mapping.mongo.MongoDatastore
12+
import org.springframework.boot.env.PropertySourceLoader
13+
import org.springframework.core.env.PropertyResolver
14+
import org.springframework.core.env.PropertySource
15+
import org.springframework.core.io.DefaultResourceLoader
16+
import org.springframework.core.io.Resource
17+
import org.springframework.core.io.ResourceLoader
18+
import org.springframework.core.io.support.SpringFactoriesLoader
19+
import org.springframework.transaction.support.TransactionSynchronizationManager
20+
import spock.lang.AutoCleanup
21+
import spock.lang.Shared
22+
import spock.lang.Specification
23+
24+
/**
25+
* Base class for MongoDB tests
26+
*
27+
* @author Álvaro Sánchez-Mariscal
28+
* @since 6.0.1
29+
*/
30+
@CompileStatic
31+
abstract class MongoSpec extends Specification {
32+
33+
@Shared
34+
@AutoCleanup
35+
MongoDatastore mongoDatastore
36+
37+
@Shared
38+
Session mongoSession
39+
40+
/**
41+
* @return Obtains the mapping context
42+
*/
43+
MappingContext getMappingContext() {
44+
mongoDatastore.getMappingContext()
45+
}
46+
47+
/**
48+
* @return The default mongo client
49+
*/
50+
MongoClient createMongoClient() {
51+
return null
52+
}
53+
54+
/**
55+
* @return The domain classes
56+
*/
57+
protected List<Class> getDomainClasses() { [] }
58+
59+
void setupSpec() {
60+
List<PropertySourceLoader> propertySourceLoaders = SpringFactoriesLoader.loadFactories(PropertySourceLoader.class, getClass().getClassLoader());
61+
ResourceLoader resourceLoader = new DefaultResourceLoader()
62+
63+
List<PropertySource> propertySources = []
64+
65+
PropertySourceLoader ymlLoader = propertySourceLoaders.find { it.getFileExtensions().toList().contains("yml") }
66+
if (ymlLoader) {
67+
propertySources.addAll(load(resourceLoader, ymlLoader, "application.yml"))
68+
}
69+
PropertySourceLoader groovyLoader = propertySourceLoaders.find { it.getFileExtensions().toList().contains("groovy") }
70+
if (groovyLoader) {
71+
propertySources.addAll(load(resourceLoader, groovyLoader, "application.groovy"))
72+
}
73+
74+
Map<String, Object> mapPropertySource = propertySources
75+
.findAll { it.getSource() }
76+
.collectEntries { it.getSource() as Map }
77+
78+
Config config = new PropertySourcesConfig(mapPropertySource)
79+
80+
List<Class> domainClasses = getDomainClasses()
81+
if (!domainClasses) {
82+
def packageToScan = getPackageToScan(config)
83+
MongoClient mongoClient = createMongoClient()
84+
def pkg = Package.getPackage(packageToScan)
85+
if(pkg == null) {
86+
throw new ConfigurationException("Package to scan [$packageToScan] cannot be found on the classpath")
87+
}
88+
89+
if (mongoClient) {
90+
mongoDatastore = new MongoDatastore(mongoClient, config, pkg)
91+
} else {
92+
mongoDatastore = new MongoDatastore((PropertyResolver) config, pkg)
93+
}
94+
}
95+
else {
96+
MongoClient mongoClient = createMongoClient()
97+
if (mongoClient) {
98+
mongoDatastore = new MongoDatastore(mongoClient, config, domainClasses as Class[])
99+
} else {
100+
mongoDatastore = new MongoDatastore((PropertyResolver) config, domainClasses as Class[])
101+
}
102+
}
103+
}
104+
105+
void setup() {
106+
boolean existing = mongoDatastore.hasCurrentSession()
107+
mongoSession = existing ? mongoDatastore.currentSession : DatastoreUtils.bindSession(mongoDatastore.connect())
108+
}
109+
110+
void cleanup() {
111+
if (!mongoDatastore.hasCurrentSession()) {
112+
TransactionSynchronizationManager.unbindResource(mongoDatastore)
113+
DatastoreUtils.closeSessionOrRegisterDeferredClose(mongoSession, mongoDatastore)
114+
}
115+
}
116+
117+
/**
118+
* @return Obtain the mongo client
119+
*/
120+
MongoClient getMongoClient() {
121+
mongoDatastore.getConnectionSources().defaultConnectionSource.source
122+
}
123+
124+
/**
125+
* Obtains the default package to scan
126+
*
127+
* @param config The configuration
128+
* @return The package to scan
129+
*/
130+
protected String getPackageToScan(Config config) {
131+
config.getProperty('grails.codegen.defaultPackage', getClass().package.name)
132+
}
133+
134+
private List<PropertySource> load(ResourceLoader resourceLoader, PropertySourceLoader loader, String filename) {
135+
if (canLoadFileExtension(loader, filename)) {
136+
Resource appYml = resourceLoader.getResource(filename)
137+
return loader.load(appYml.getDescription(), appYml) as List<PropertySource>
138+
} else {
139+
return Collections.emptyList()
140+
}
141+
}
142+
143+
private boolean canLoadFileExtension(PropertySourceLoader loader, String name) {
144+
return Arrays
145+
.stream(loader.fileExtensions)
146+
.map { String extension -> extension.toLowerCase() }
147+
.anyMatch { String extension -> name.toLowerCase().endsWith(extension) }
148+
}
149+
}
Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
gradlePluginPortal()
5+
maven {
6+
name = 'Maven Central Portal Snapshots'
7+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
8+
9+
content {
10+
includeGroupAndSubgroups 'org.graceframework'
11+
}
12+
mavenContent {
13+
snapshotsOnly()
14+
}
15+
}
16+
}
17+
dependencies {
18+
classpath "org.graceframework:grace-gradle-plugin:$graceVersion"
19+
classpath "org.graceframework.plugins:asset-pipeline-gradle:$assetPipelineVersion"
20+
// classpath "com.github.erdi:webdriver-binaries-gradle-plugin:3.2"
21+
}
22+
}
23+
24+
apply plugin: "org.graceframework.grace-web"
25+
apply plugin: "org.graceframework.grace-gsp"
26+
apply plugin: "org.graceframework.asset-pipeline"
27+
// apply plugin: "com.github.erdi.webdriver-binaries"
28+
29+
group = "examples"
30+
31+
configurations {
32+
developmentOnly
33+
}
34+
135
dependencies {
236
implementation "org.springframework.boot:spring-boot-starter-logging"
337
implementation "org.springframework.boot:spring-boot-autoconfigure"
438
implementation "org.springframework.boot:spring-boot-starter-actuator"
539
implementation "org.springframework.boot:spring-boot-starter-web"
640
implementation "org.graceframework:grace-core"
741
implementation "org.graceframework:grace-boot"
42+
implementation "org.graceframework:grace-boot-mongodb"
843
implementation "org.graceframework:grace-plugin-gsp"
9-
implementation project(":grace-plugin")
1044

1145
runtimeOnly "org.graceframework.plugins:asset-pipeline-plugin:$assetPipelineVersion"
1246
runtimeOnly "com.h2database:h2"
@@ -23,22 +57,22 @@ dependencies {
2357
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
2458
}
2559

26-
tasks.withType(Test) {
27-
systemProperty "geb.env", System.getProperty('geb.env')
28-
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
29-
if (!System.getenv().containsKey('CI')) {
30-
systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver')
31-
systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver')
32-
} else {
33-
systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
34-
systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
35-
}
36-
}
60+
// tasks.withType(Test) {
61+
// systemProperty "geb.env", System.getProperty('geb.env')
62+
// systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
63+
// if (!System.getenv().containsKey('CI')) {
64+
// systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver')
65+
// systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver')
66+
// } else {
67+
// systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
68+
// systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
69+
// }
70+
// }
3771

38-
webdriverBinaries {
39-
chromedriver {
40-
version = '126.0.6478.126'
41-
fallbackTo32Bit = true
42-
}
43-
geckodriver '0.33.0'
44-
}
72+
// webdriverBinaries {
73+
// chromedriver {
74+
// version = '126.0.6478.126'
75+
// fallbackTo32Bit = true
76+
// }
77+
// geckodriver '0.33.0'
78+
// }

0 commit comments

Comments
 (0)