From 488dc2756bf3df572a478c99cd8b27946a245cf9 Mon Sep 17 00:00:00 2001 From: Mattias Reichel Date: Thu, 14 Mar 2024 13:04:18 +0100 Subject: [PATCH] fix: Remove dependency on grails-shell (#350) * fix: Remove dependency on grails-shell Grails-shell is deprecated for removal. * Delete unused files (#1) --------- Co-authored-by: Guillermo Calvo --- build.gradle | 3 - .../command/DbmChangelogToGroovy.groovy | 78 ------------------- .../command/DbmCreateChangelog.groovy | 55 ------------- .../ScriptDatabaseMigrationCommand.groovy | 66 ---------------- .../scripts/dbm-changelog-to-groovy.groovy | 17 ---- src/main/scripts/dbm-create-changelog.groovy | 16 ---- .../ScriptDatabaseMigrationCommandSpec.groovy | 56 ------------- 7 files changed, 291 deletions(-) delete mode 100644 src/main/groovy/org/grails/plugins/databasemigration/command/DbmChangelogToGroovy.groovy delete mode 100644 src/main/groovy/org/grails/plugins/databasemigration/command/DbmCreateChangelog.groovy delete mode 100644 src/main/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommand.groovy delete mode 100644 src/main/scripts/dbm-changelog-to-groovy.groovy delete mode 100644 src/main/scripts/dbm-create-changelog.groovy delete mode 100644 src/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy diff --git a/build.gradle b/build.gradle index 568d0343..ab0f5d0f 100644 --- a/build.gradle +++ b/build.gradle @@ -48,9 +48,6 @@ dependencies { exclude group: 'org.liquibase', module: 'liquibase-test-harness' exclude group: 'com.h2database', module: 'h2' } - api("org.grails:grails-shell") { - exclude group: 'org.slf4j', module: 'slf4j-simple' - } compileOnly "org.hibernate:hibernate-core:5.6.15.Final" compileOnly 'org.springframework.boot:spring-boot-starter-logging' diff --git a/src/main/groovy/org/grails/plugins/databasemigration/command/DbmChangelogToGroovy.groovy b/src/main/groovy/org/grails/plugins/databasemigration/command/DbmChangelogToGroovy.groovy deleted file mode 100644 index c313f2c8..00000000 --- a/src/main/groovy/org/grails/plugins/databasemigration/command/DbmChangelogToGroovy.groovy +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.grails.plugins.databasemigration.command - -import groovy.transform.CompileStatic -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType -import liquibase.parser.ChangeLogParserFactory -import liquibase.serializer.ChangeLogSerializerFactory -import org.grails.plugins.databasemigration.DatabaseMigrationException - -@CompileStatic -class DbmChangelogToGroovy implements ScriptDatabaseMigrationCommand { - - @Override - void handle() { - def srcFilename = args[0] - if (!srcFilename) { - throw new DatabaseMigrationException("The $name command requires a source filename") - } - - def resourceAccessor = createResourceAccessor() - - def parser = ChangeLogParserFactory.instance.getParser(srcFilename, resourceAccessor) - def databaseChangeLog = parser.parse(srcFilename, null, resourceAccessor) - - def destFilename = args[1] - def destChangeLogFile = resolveChangeLogFile(destFilename) - if (destChangeLogFile) { - if (!destChangeLogFile.path.endsWith('.groovy')) { - throw new DatabaseMigrationException("Destination ChangeLogFile ${destChangeLogFile} must be a Groovy file") - } - if (destChangeLogFile.exists()) { - if (hasOption('force')) { - destChangeLogFile.delete() - } else { - throw new DatabaseMigrationException("ChangeLogFile ${destChangeLogFile} already exists!") - } - } - } - - def serializer = ChangeLogSerializerFactory.instance.getSerializer('groovy') - withFileOrSystemOutputStream(destChangeLogFile) { OutputStream out -> - serializer.write(databaseChangeLog.changeSets, out) - } - - if (destChangeLogFile && hasOption('add')) { - appendToChangeLog(changeLogFile, destChangeLogFile) - } - } - - private static void withFileOrSystemOutputStream(File file, @ClosureParams(value = SimpleType, options = "java.io.OutputStream") Closure closure) { - if (!file) { - closure.call(System.out) - return - } - - if (!file.parentFile.exists()) { - file.parentFile.mkdirs() - } - file.withOutputStream { OutputStream out -> - closure.call(out) - } - } -} diff --git a/src/main/groovy/org/grails/plugins/databasemigration/command/DbmCreateChangelog.groovy b/src/main/groovy/org/grails/plugins/databasemigration/command/DbmCreateChangelog.groovy deleted file mode 100644 index 52167c92..00000000 --- a/src/main/groovy/org/grails/plugins/databasemigration/command/DbmCreateChangelog.groovy +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.grails.plugins.databasemigration.command - -import groovy.transform.CompileStatic -import liquibase.serializer.ChangeLogSerializer -import liquibase.serializer.ChangeLogSerializerFactory -import org.grails.plugins.databasemigration.DatabaseMigrationException - -@CompileStatic -class DbmCreateChangelog implements ScriptDatabaseMigrationCommand { - - @Override - void handle() { - def filename = args[0] - if (!filename) { - throw new DatabaseMigrationException("The $name command requires a filename") - } - - def outputChangeLogFile = resolveChangeLogFile(filename) - if (outputChangeLogFile.exists()) { - if (hasOption('force')) { - outputChangeLogFile.delete() - } else { - throw new DatabaseMigrationException("ChangeLogFile ${outputChangeLogFile} already exists!") - } - } - if (!outputChangeLogFile.parentFile.exists()) { - outputChangeLogFile.parentFile.mkdirs() - } - - ChangeLogSerializer serializer = ChangeLogSerializerFactory.instance.getSerializer(filename) - - outputChangeLogFile.withOutputStream { OutputStream out -> - serializer.write(new ArrayList(), out) - } - - if (hasOption('add')) { - appendToChangeLog(changeLogFile, outputChangeLogFile) - } - } -} diff --git a/src/main/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommand.groovy b/src/main/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommand.groovy deleted file mode 100644 index 61e90f90..00000000 --- a/src/main/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommand.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2015 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.grails.plugins.databasemigration.command - -import grails.config.ConfigMap -import grails.util.Environment -import grails.util.GrailsNameUtils -import groovy.transform.CompileStatic -import liquibase.parser.ChangeLogParser -import liquibase.parser.ChangeLogParserFactory -import org.grails.cli.profile.ExecutionContext -import org.grails.config.CodeGenConfig -import org.grails.plugins.databasemigration.EnvironmentAwareCodeGenConfig -import org.grails.plugins.databasemigration.liquibase.GroovyChangeLogParser - -import static org.grails.plugins.databasemigration.PluginConstants.DEFAULT_DATASOURCE_NAME - -@CompileStatic -trait ScriptDatabaseMigrationCommand implements DatabaseMigrationCommand { - - ConfigMap config - ConfigMap sourceConfig - ExecutionContext executionContext - - void handle(ExecutionContext executionContext) { - this.executionContext = executionContext - setConfig(executionContext.config) - - this.commandLine = executionContext.commandLine - this.contexts = optionValue('contexts') - this.defaultSchema = optionValue('defaultSchema') - this.dataSource = optionValue('dataSource') ?: DEFAULT_DATASOURCE_NAME - - configureLiquibase() - handle() - } - - void configureLiquibase() { - GroovyChangeLogParser groovyChangeLogParser = ChangeLogParserFactory.instance.parsers.find { ChangeLogParser changeLogParser -> changeLogParser instanceof GroovyChangeLogParser } as GroovyChangeLogParser - groovyChangeLogParser.config = config - } - - abstract void handle() - - String getName() { - return GrailsNameUtils.getScriptName(GrailsNameUtils.getLogicalName(getClass().getName(), "Command")) - } - - void setConfig(ConfigMap config) { - this.sourceConfig = config - this.config = new EnvironmentAwareCodeGenConfig(sourceConfig as CodeGenConfig, Environment.current.name) - } -} diff --git a/src/main/scripts/dbm-changelog-to-groovy.groovy b/src/main/scripts/dbm-changelog-to-groovy.groovy deleted file mode 100644 index 101c8e48..00000000 --- a/src/main/scripts/dbm-changelog-to-groovy.groovy +++ /dev/null @@ -1,17 +0,0 @@ -import org.grails.plugins.databasemigration.DatabaseMigrationException -import org.grails.plugins.databasemigration.command.DbmChangelogToGroovy - -description('Converts a changelog file to a Groovy DSL file') { - usage 'grails [environment] dbm-changelog-to-groovy [src_file_name] [dest_file_name]' - flag name: 'src_file_name', description: 'The name and path of the changelog file to convert' - flag name: 'dest_file_name', description: 'The name and path of the Groovy file' - flag name: 'dataSource', description: 'if provided will run the script for the specified dataSource creating a file named changelog-dataSource.groovy if a filename is not given. Not needed for the default dataSource' - flag name: 'force', description: 'Whether to overwrite existing files' - flag name: 'add', description: 'if provided will run the script for the specified dataSource. Not needed for the default dataSource.' -} - -try { - new DbmChangelogToGroovy().handle(executionContext) -} catch (DatabaseMigrationException e) { - error e.message, e -} diff --git a/src/main/scripts/dbm-create-changelog.groovy b/src/main/scripts/dbm-create-changelog.groovy deleted file mode 100644 index 252a5b7a..00000000 --- a/src/main/scripts/dbm-create-changelog.groovy +++ /dev/null @@ -1,16 +0,0 @@ -import org.grails.plugins.databasemigration.DatabaseMigrationException -import org.grails.plugins.databasemigration.command.DbmCreateChangelog - -description('Creates an empty changelog file') { - usage 'grails [environment] dbm-create-changelog [filename]' - flag name: 'filename', description: 'The path to the output file to write to' - flag name: 'dataSource', description: 'if provided will run the script for the specified dataSource creating a file named changelog-dataSource.groovy if a filename is not given. Not needed for the default dataSource' - flag name: 'force', description: 'Whether to overwrite existing files' - flag name: 'add', description: 'if provided will run the script for the specified dataSource. Not needed for the default dataSource.' -} - -try { - new DbmCreateChangelog().handle(executionContext) -} catch (DatabaseMigrationException e) { - error e.message, e -} diff --git a/src/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy b/src/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy deleted file mode 100644 index 398dc1af..00000000 --- a/src/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2015 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.grails.plugins.databasemigration.command - -import grails.util.GrailsNameUtils -import org.grails.build.parsing.CommandLineParser -import org.grails.cli.GrailsCli -import org.grails.cli.profile.ExecutionContext -import org.grails.config.CodeGenConfig -import org.h2.Driver - -abstract class ScriptDatabaseMigrationCommandSpec extends DatabaseMigrationCommandSpec { - - ScriptDatabaseMigrationCommand command - - CodeGenConfig config - - def setup() { - def configMap = [ - 'grails.plugin.databasemigration.changelogLocation': changeLogLocation.canonicalPath, - 'dataSource.url' : 'jdbc:h2:mem:testDb', - 'dataSource.username' : 'sa', - 'dataSource.password' : '', - 'dataSource.driverClassName' : Driver.name, - 'environments.other.dataSource.url' : 'jdbc:h2:mem:otherDb', - ] - config = new CodeGenConfig() - config.mergeMap(configMap) - config.mergeMap(configMap, true) - - command = commandClass.newInstance() - command.config = config - command.changeLogFile.parentFile.mkdirs() - } - - abstract protected Class getCommandClass() - - protected ExecutionContext getExecutionContext(String... args) { - def executionContext = new GrailsCli.ExecutionContextImpl(config) - executionContext.commandLine = new CommandLineParser().parse(([GrailsNameUtils.getScriptName(GrailsNameUtils.getLogicalName(commandClass.name, 'Command'))] + args.toList()) as String[]) - executionContext - } -}