diff --git a/grace-cli/src/main/groovy/grails/cli/generator/AbstractGenerator.groovy b/grace-cli/src/main/groovy/grails/cli/generator/AbstractGenerator.groovy index 9dc62b96ca..39b154cb8f 100644 --- a/grace-cli/src/main/groovy/grails/cli/generator/AbstractGenerator.groovy +++ b/grace-cli/src/main/groovy/grails/cli/generator/AbstractGenerator.groovy @@ -96,6 +96,14 @@ class AbstractGenerator implements Generator { SpringIOUtils.copy(templateRenderer.template(getTemplateRoot(), source), file(destination)) } + void removeFile(String destination) { + this.console.addStatus('remove '.padLeft(13), destination, 'YELLOW') + File file = new File(getBaseDir(), destination) + if (file.exists()) { + file.delete() + } + } + File file(Object path) { if (path instanceof File) { return (File) path diff --git a/grace-cli/src/main/groovy/grails/cli/generator/Generator.java b/grace-cli/src/main/groovy/grails/cli/generator/Generator.java index 5e1ddb7489..5e6bbafd51 100644 --- a/grace-cli/src/main/groovy/grails/cli/generator/Generator.java +++ b/grace-cli/src/main/groovy/grails/cli/generator/Generator.java @@ -39,4 +39,8 @@ default boolean help(GenerationContext generationContext) { return true; } + default boolean revoke(GenerationContext generationContext) { + return true; + } + } diff --git a/grace-shell/src/main/groovy/org/grails/cli/generator/ControllerGenerator.groovy b/grace-shell/src/main/groovy/org/grails/cli/generator/ControllerGenerator.groovy index b485423fbd..14f7e20178 100644 --- a/grace-shell/src/main/groovy/org/grails/cli/generator/ControllerGenerator.groovy +++ b/grace-shell/src/main/groovy/org/grails/cli/generator/ControllerGenerator.groovy @@ -66,4 +66,31 @@ class ControllerGenerator extends AbstractGenerator { true } + @Override + boolean revoke(GenerationContext generationContext) { + CommandLine commandLine = generationContext.commandLine + String[] args = commandLine.remainingArgs.toArray(new String[0]) + if (args.size() < 2) { + return + } + + CodeGenConfig config = loadApplicationConfig() + String className = args[1].capitalize() + String propertyName = className.uncapitalize() + String defaultPackage = config.getProperty('grails.codegen.defaultPackage') + String packagePath = defaultPackage.replace('.', '/') + + String controllerFile = 'app/controllers/' + packagePath + '/' + className + 'Controller.groovy' + String controllerSpecFile = 'src/test/groovy/' + packagePath + '/' + className + 'ControllerSpec.groovy' + removeFile(controllerFile) + removeFile(controllerSpecFile) + + String gspViewDir = 'app/views/' + propertyName + new File(gspViewDir).list().each { + removeFile(gspViewDir + '/' + it) + } + + true + } + } diff --git a/grace-shell/src/main/groovy/org/grails/cli/generator/DomainGenerator.groovy b/grace-shell/src/main/groovy/org/grails/cli/generator/DomainGenerator.groovy index 72fc9e26b8..23f9e655d6 100644 --- a/grace-shell/src/main/groovy/org/grails/cli/generator/DomainGenerator.groovy +++ b/grace-shell/src/main/groovy/org/grails/cli/generator/DomainGenerator.groovy @@ -82,4 +82,25 @@ class DomainGenerator extends AbstractGenerator { true } + @Override + boolean revoke(GenerationContext generationContext) { + CommandLine commandLine = generationContext.commandLine + String[] args = commandLine.remainingArgs.toArray(new String[0]) + if (args.size() < 2) { + return + } + + CodeGenConfig config = loadApplicationConfig() + String className = args[1].capitalize() + String defaultPackage = config.getProperty('grails.codegen.defaultPackage') + String packagePath = defaultPackage.replace('.', '/') + + String domainClassFile = 'app/domain/' + packagePath + '/' + className + '.groovy' + String domainClassSpecFile = 'src/test/groovy/' + packagePath + '/' + className + 'Spec.groovy' + removeFile(domainClassFile) + removeFile(domainClassSpecFile) + + true + } + } diff --git a/grace-shell/src/main/groovy/org/grails/cli/generator/InterceptorGenerator.groovy b/grace-shell/src/main/groovy/org/grails/cli/generator/InterceptorGenerator.groovy index 068c3dd58c..42e5aad689 100644 --- a/grace-shell/src/main/groovy/org/grails/cli/generator/InterceptorGenerator.groovy +++ b/grace-shell/src/main/groovy/org/grails/cli/generator/InterceptorGenerator.groovy @@ -57,4 +57,26 @@ class InterceptorGenerator extends AbstractGenerator { true } + @Override + boolean revoke(GenerationContext generationContext) { + CommandLine commandLine = generationContext.commandLine + String[] args = commandLine.remainingArgs.toArray(new String[0]) + if (args.size() < 2) { + return + } + + CodeGenConfig config = loadApplicationConfig() + String className = args[1].capitalize() + String defaultPackage = config.getProperty('grails.codegen.defaultPackage') + String packagePath = defaultPackage.replace('.', '/') + + String interceptorClassFile = 'app/controllers/' + packagePath + '/' + className + 'Interceptor.groovy' + String interceptorClassSpecFile = 'src/test/groovy/' + packagePath + '/' + className + 'InterceptorSpec.groovy' + + removeFile(interceptorClassFile) + removeFile(interceptorClassSpecFile) + + true + } + } diff --git a/grace-shell/src/main/groovy/org/grails/cli/generator/ServiceGenerator.groovy b/grace-shell/src/main/groovy/org/grails/cli/generator/ServiceGenerator.groovy index b3dcdc4d52..278d350aec 100644 --- a/grace-shell/src/main/groovy/org/grails/cli/generator/ServiceGenerator.groovy +++ b/grace-shell/src/main/groovy/org/grails/cli/generator/ServiceGenerator.groovy @@ -59,4 +59,25 @@ class ServiceGenerator extends AbstractGenerator { true } + @Override + boolean revoke(GenerationContext generationContext) { + CommandLine commandLine = generationContext.commandLine + String[] args = commandLine.remainingArgs.toArray(new String[0]) + if (args.size() < 2) { + return + } + + CodeGenConfig config = loadApplicationConfig() + String className = args[1].capitalize() + String defaultPackage = config.getProperty('grails.codegen.defaultPackage') + String packagePath = defaultPackage.replace('.', '/') + + String serviceClassFile = 'app/services/' + packagePath + '/' + className + 'Service.groovy' + String serviceClassSpecFile = 'src/test/groovy/' + packagePath + '/' + className + 'ServiceSpec.groovy' + removeFile(serviceClassFile) + removeFile(serviceClassSpecFile) + + true + } + } diff --git a/grace-shell/src/main/groovy/org/grails/cli/generator/TaglibGenerator.groovy b/grace-shell/src/main/groovy/org/grails/cli/generator/TaglibGenerator.groovy index adfd9325e8..74164d0181 100644 --- a/grace-shell/src/main/groovy/org/grails/cli/generator/TaglibGenerator.groovy +++ b/grace-shell/src/main/groovy/org/grails/cli/generator/TaglibGenerator.groovy @@ -58,4 +58,25 @@ class TaglibGenerator extends AbstractGenerator { true } + @Override + boolean revoke(GenerationContext generationContext) { + CommandLine commandLine = generationContext.commandLine + String[] args = commandLine.remainingArgs.toArray(new String[0]) + if (args.size() < 2) { + return + } + + CodeGenConfig config = loadApplicationConfig() + String className = args[1].capitalize() + String defaultPackage = config.getProperty('grails.codegen.defaultPackage') + String packagePath = defaultPackage.replace('.', '/') + + String taglibClassFile = 'app/taglib/' + packagePath + '/' + className + 'TagLib.groovy' + String taglibClassSpecFile = 'src/test/groovy/' + packagePath + '/' + className + 'TagLibSpec.groovy' + removeFile(taglibClassFile) + removeFile(taglibClassSpecFile) + + true + } + }