Skip to content

Commit aa44851

Browse files
committed
Code formatting with Checkstyle and Codenarc
1 parent 2aaa2e7 commit aa44851

File tree

52 files changed

+546
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+546
-343
lines changed

grace-plugin-database-migration/src/main/groovy/org/grails/plugins/databasemigration/DatabaseMigrationException.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2015 original authors
2+
* Copyright 2015-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,4 +19,5 @@ import groovy.transform.InheritConstructors
1919

2020
@InheritConstructors
2121
class DatabaseMigrationException extends RuntimeException {
22+
2223
}
Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2015 original authors
2+
* Copyright 2015-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,34 +15,25 @@
1515
*/
1616
package org.grails.plugins.databasemigration
1717

18-
import grails.plugins.Plugin
18+
import javax.sql.DataSource
19+
1920
import liquibase.parser.ChangeLogParser
2021
import liquibase.parser.ChangeLogParserFactory
21-
import org.grails.plugins.databasemigration.liquibase.GormDatabase
22-
import org.grails.plugins.databasemigration.liquibase.GrailsLiquibase
23-
import org.grails.plugins.databasemigration.liquibase.GroovyChangeLogParser
2422
import org.springframework.context.ApplicationContext
2523

26-
import javax.sql.DataSource
24+
import grails.plugins.Plugin
25+
import grails.util.GrailsUtil
26+
27+
import org.grails.plugins.databasemigration.liquibase.GrailsLiquibase
28+
import org.grails.plugins.databasemigration.liquibase.GroovyChangeLogParser
2729

2830
class DatabaseMigrationGrailsPlugin extends Plugin {
2931

3032
static final String CONFIG_MAIN_PREFIX = 'grails.plugin.databasemigration'
3133

32-
def grailsVersion = "2023.0.0 > *"
33-
def pluginExcludes = [
34-
'testapp/**',
35-
'databasemigration/**',
36-
"grails-app/views/error.gsp"
37-
]
38-
39-
def title = "Grace Database Migration Plugin" // Headline display name of the plugin
40-
def author = "Michael Yan"
41-
def authorEmail = "rain@rainboyan.com"
42-
def description = 'Grace Database Migration Plugin'
43-
def documentation = "http://graceframework.org/plugin/database-migration"
44-
def license = "APACHE"
45-
def scm = [url: "https://github.com/graceframework/grace-database-migration"]
34+
def version = GrailsUtil.getGrailsVersion()
35+
def grailsVersion = '2023.0.0 > *'
36+
def title = 'Grace Database Migration Plugin'
4637

4738
@Override
4839
Closure doWithSpring() {
@@ -58,25 +49,28 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
5849

5950
dataSourceNames.each { String dataSourceName ->
6051
String configPrefix = isDefaultDataSource(dataSourceName) ? CONFIG_MAIN_PREFIX : "${CONFIG_MAIN_PREFIX}.${dataSourceName}"
61-
def skipMainClasses = config.getProperty("${configPrefix}.skipUpdateOnStartMainClasses", List, ['grails.ui.command.GrailsApplicationContextCommandRunner'])
52+
def skipMainClasses = config.getProperty("${configPrefix}.skipUpdateOnStartMainClasses", List,
53+
['grails.ui.command.GrailsApplicationContextCommandRunner'])
6254
if (skipMainClasses.contains(mainClassName)) {
6355
return
6456
}
6557

66-
if(!updateAllOnStart) {
58+
if (!updateAllOnStart) {
6759
def updateOnStart = config.getProperty("${configPrefix}.updateOnStart", Boolean, false)
6860
if (!updateOnStart) {
6961
return
7062
}
71-
} else {
63+
}
64+
else {
7265
configPrefix = CONFIG_MAIN_PREFIX
7366
}
7467

7568
new DatabaseMigrationTransactionManager(applicationContext, dataSourceName).withTransaction {
7669
GrailsLiquibase gl = new GrailsLiquibase(applicationContext)
7770
gl.dataSource = getDataSourceBean(applicationContext, dataSourceName)
7871
gl.dropFirst = config.getProperty("${configPrefix}.dropOnStart", Boolean, false)
79-
gl.changeLog = config.getProperty("${configPrefix}.updateOnStartFileName", String, isDefaultDataSource(dataSourceName) ? 'changelog.groovy' : "changelog-${dataSourceName}.groovy")
72+
gl.changeLog = config.getProperty("${configPrefix}.updateOnStartFileName", String,
73+
isDefaultDataSource(dataSourceName) ? 'changelog.groovy' : "changelog-${dataSourceName}.groovy")
8074
gl.contexts = config.getProperty("${configPrefix}.updateOnStartContexts", List, []).join(',')
8175
gl.labels = config.getProperty("${configPrefix}.updateOnStartLabels", List, []).join(',')
8276
gl.defaultSchema = config.getProperty("${configPrefix}.updateOnStartDefaultSchema", String)
@@ -88,12 +82,13 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
8882
}
8983
}
9084

91-
private def getDataSourceBean(ApplicationContext applicationContext, String dataSourceName) {
85+
private DataSource getDataSourceBean(ApplicationContext applicationContext, String dataSourceName) {
9286
applicationContext.getBean(getDataSourceName(dataSourceName), DataSource)
9387
}
9488

9589
private void configureLiquibase() {
96-
def groovyChangeLogParser = ChangeLogParserFactory.instance.parsers.find { ChangeLogParser changeLogParser -> changeLogParser instanceof GroovyChangeLogParser } as GroovyChangeLogParser
90+
def groovyChangeLogParser = ChangeLogParserFactory.instance.parsers.find { ChangeLogParser changeLogParser ->
91+
changeLogParser instanceof GroovyChangeLogParser } as GroovyChangeLogParser
9792
groovyChangeLogParser.applicationContext = applicationContext
9893
groovyChangeLogParser.config = config
9994
}
@@ -111,7 +106,9 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
111106
}
112107

113108
private String deduceApplicationMainClassName() {
114-
new RuntimeException().stackTrace.find { StackTraceElement stackTraceElement -> 'main' == stackTraceElement.methodName }?.className
109+
new RuntimeException().stackTrace.find { StackTraceElement stackTraceElement ->
110+
'main' == stackTraceElement.methodName
111+
}?.className
115112
}
116113

117114
static String getDataSourceName(String dataSourceName) {
@@ -121,4 +118,5 @@ class DatabaseMigrationGrailsPlugin extends Plugin {
121118
static Boolean isDefaultDataSource(String dataSourceName) {
122119
!dataSourceName || 'dataSource' == dataSourceName
123120
}
121+
124122
}

grace-plugin-database-migration/src/main/groovy/org/grails/plugins/databasemigration/DatabaseMigrationTransactionManager.groovy

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
/*
2+
* Copyright 2015-2025 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.plugins.databasemigration
217

3-
import grails.gorm.transactions.GrailsTransactionTemplate
418
import org.springframework.context.ApplicationContext
519
import org.springframework.transaction.PlatformTransactionManager
620
import org.springframework.transaction.TransactionDefinition
721
import org.springframework.transaction.support.DefaultTransactionDefinition
822
import org.springframework.util.Assert
923

24+
import grails.gorm.transactions.GrailsTransactionTemplate
25+
1026
/**
1127
* Created by Jim on 7/15/2016.
1228
*/
@@ -25,12 +41,12 @@ class DatabaseMigrationTransactionManager {
2541
* @return The transactionManager bean for the current dataSource
2642
*/
2743
PlatformTransactionManager getTransactionManager() {
28-
String dataSource = this.dataSource ?: "dataSource"
29-
String beanName = "transactionManager"
30-
if (dataSource != "dataSource") {
44+
String dataSource = this.dataSource ?: 'dataSource'
45+
String beanName = 'transactionManager'
46+
if (dataSource != 'dataSource') {
3147
beanName += "_${dataSource}"
3248
}
33-
applicationContext.getBean(beanName, PlatformTransactionManager)
49+
this.applicationContext.getBean(beanName, PlatformTransactionManager)
3450
}
3551

3652
/**
@@ -92,15 +108,16 @@ class DatabaseMigrationTransactionManager {
92108
withTransaction(props, callable)
93109
}
94110

95-
void withTransaction(Map transactionProperties, Closure callable) {
111+
void withTransaction(Map transactionProperties, Closure callable) {
96112
def transactionDefinition = new DefaultTransactionDefinition()
97113
transactionProperties.each { k, v ->
98-
if(v instanceof CharSequence && !(v instanceof String)) {
114+
if (v instanceof CharSequence && !(v instanceof String)) {
99115
v = v.toString()
100116
}
101117
try {
102118
transactionDefinition[k as String] = v
103-
} catch (MissingPropertyException mpe) {
119+
}
120+
catch (MissingPropertyException mpe) {
104121
throw new IllegalArgumentException("[${k}] is not a valid transaction property.", mpe)
105122
}
106123
}
@@ -114,12 +131,13 @@ class DatabaseMigrationTransactionManager {
114131
* @return The result of the closure execution
115132
*/
116133
void withTransaction(TransactionDefinition definition, Closure callable) {
117-
Assert.notNull transactionManager, "No transactionManager bean configured"
134+
Assert.notNull transactionManager, 'No transactionManager bean configured'
118135

119136
if (!callable) {
120137
return
121138
}
122139

123140
new GrailsTransactionTemplate(transactionManager, definition).execute(callable)
124141
}
142+
125143
}

grace-plugin-database-migration/src/main/groovy/org/grails/plugins/databasemigration/EnvironmentAwareCodeGenConfig.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2015 original authors
2+
* Copyright 2015-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,6 +17,7 @@ package org.grails.plugins.databasemigration
1717

1818
import groovy.transform.CompileDynamic
1919
import groovy.transform.CompileStatic
20+
2021
import org.grails.config.CodeGenConfig
2122

2223
@CompileStatic
@@ -31,4 +32,5 @@ class EnvironmentAwareCodeGenConfig extends CodeGenConfig {
3132
private void mergeEnvironmentConfig(CodeGenConfig copyOf, String environment) {
3233
mergeMap(copyOf.environments?."$environment" ?: [:])
3334
}
35+
3436
}

grace-plugin-database-migration/src/main/groovy/org/grails/plugins/databasemigration/NoopVisitor.groovy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2015-2025 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.plugins.databasemigration
217

318
import liquibase.changelog.ChangeSet
@@ -18,7 +33,9 @@ class NoopVisitor implements ChangeSetVisitor {
1833
Direction getDirection() { Direction.FORWARD }
1934

2035
@Override
21-
void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
36+
void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database,
37+
Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
2238
changeSet.execute(databaseChangeLog, database)
2339
}
40+
2441
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/*
2+
* Copyright 2015-2025 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.plugins.databasemigration
217

318
class PluginConstants {
4-
static final String DATA_SOURCE_NAME_KEY = "dataSourceName"
19+
20+
static final String DATA_SOURCE_NAME_KEY = 'dataSourceName'
521
static final String DEFAULT_DATASOURCE_NAME = 'dataSource'
622
static final String DEFAULT_CHANGE_LOG_LOCATION = 'db/migrations'
23+
724
}

0 commit comments

Comments
 (0)