From d64a3b125d39d9953a9719b9af40e81618924ea2 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Thu, 7 Mar 2024 21:07:47 +0100 Subject: [PATCH] Delete unused files (#1) --- .../command/DbmChangelogToGroovy.groovy | 78 ------------------- .../command/DbmCreateChangelog.groovy | 55 ------------- .../ScriptDatabaseMigrationCommand.groovy | 41 ---------- .../ScriptDatabaseMigrationCommandSpec.groovy | 47 ----------- 4 files changed, 221 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/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy 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 54d9c83d..00000000 --- a/src/main/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommand.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015-2024 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 org.grails.config.CodeGenConfig -import org.grails.plugins.databasemigration.EnvironmentAwareCodeGenConfig - -@CompileStatic -trait ScriptDatabaseMigrationCommand implements DatabaseMigrationCommand { - - ConfigMap config - ConfigMap sourceConfig - - 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/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 0874fb94..00000000 --- a/src/test/groovy/org/grails/plugins/databasemigration/command/ScriptDatabaseMigrationCommandSpec.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015-2024 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 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() - -}