1

I have been trying out fmpp for code generation. But I haven't been able to achieve one of the function that I want at this moment, which is dynamically replace the folder name and file name.

For example, if I have a folder with file as follows:

/template/src/main/java/com/${project_name}/${project_name}Test.java

it does not replace the ${project_name} value of file and folder when it execute and copy it over to the output generated directory.

Just wonder if anyone has an insight to this problem, or suggest any better tools that can do this.

5gon12eder
  • 24,280
  • 5
  • 45
  • 92
Hong Wei Wang
  • 1,388
  • 3
  • 19
  • 29

1 Answers1

0

While FMPP has no such feature built in (good idea BTW), you can achieve that if you add this to the FMPP configuration:

borders: [
  header("\
    <#if pp.outputFile?contains(r'${')>\
      <#assign finalOutputFile>/<@pp.outputFile?interpret /></#assign>\
      <@pp.renameOutputFile name=finalOutputFile />\
    </#if>\
    ", **/*)
]
ddekany
  • 29,656
  • 4
  • 57
  • 64
  • Another question - is there a way to pass in the values as java parameters for example -Dproject.name=someProject instead of having the values in the config file? – Hong Wei Wang Dec 07 '15 at 15:04
  • You could use `projectName: eval("System.getProperty('project.name')")` inside `data`. – ddekany Dec 07 '15 at 19:18
  • I have this code data: {tdd(data/data.tdd) plugin_info: eval('System.getProperty('project.name')')} but it is not working. – Hong Wei Wang Dec 07 '15 at 20:43
  • Do I have to escape the characters? – Hong Wei Wang Dec 07 '15 at 20:53
  • As you have a string literals inside another string literal, one should use `"` and the other `'`, just like in my comment. (Or you can escape the inner `'` too, but that's less nice.) – ddekany Dec 07 '15 at 22:56