0

This is my repository in github: https://github.com/joedayz/lazybones-templates/

I used processTemplates according with the documentation

processTemplates 'build.gradle', props
processTemplates 'gradle.properties', props
processTemplates 'src/main/java/*.java', props
processTemplates 'settings.gradle', props

I request the user this information:

    props.project_megaproceso = ask("Define value for 'megaproceso'  [megaproceso]: ", "megaproceso", "megaproceso")
    props.project_macroproceso = ask("Define value for 'macroproceso' [macroproceso]: ", "macroproceso", "macroproceso")
    props.project_proceso = ask("Define value for 'proceso' [proceso]: ", "proceso", "proceso")

megaproceso2, macroproceso, proceso are directories or part of file names in my template.

How do I change the names of the unpacked directories and files? The code is in my github.

Peter Ledbrook
  • 4,302
  • 1
  • 21
  • 18

1 Answers1

0

The post-install scripts for Lazybones currently have full access to both the standard JDK classes and the Apache Commons IO library, specifically to aid with file manipulation.

In this specific case, you can either use File.renameTo() or FileUtils.moveFile/Directory(). For example:

def prevPath = new File(projectDir, "megaproceso2-macroproceso-proceso.ear")
prevPath.renameTo(new File(
    projectDir,
    "${props.megaproceso}-${props.macroproceso}-${props.processo}.ear"))

The projectDir variable is one of several properties injected into the post-install script. You can find a list of them in the Template Developers Guide.

I think the main advantage of FileUtils.moveFile() is that it works even if you're moving files across devices, but that's not necessary here. Also note that you have to explicitly import the classes from Commons IO if you want to use them.

Peter Ledbrook
  • 4,302
  • 1
  • 21
  • 18
  • 1
    Indeed. `FileUtils` is the way to go, however be careful with it as it's likely to fail on Windows. We had to use the following code in the Griffon templates to make sure intermediate directories were created https://github.com/griffon/griffon/blob/development/templates/griffon-javafx-java-templates/templates/griffon-javafx-java/lazybones.groovy#L49-L55 – Andres Almiray Mar 18 '16 at 10:00
  • Thanks a lot guys. I used FileUtils in my lazybones.groovy and I got it. – Jose Amadeo Diaz Diaz Mar 22 '16 at 19:16
  • @aalmiray, I use your rename function and in windows works perfectly – Jose Amadeo Diaz Diaz Mar 22 '16 at 19:21