To elaborate, I have enhanced the functionality of the archetype implementation to better harness the versatility of the velocity templating engine. This enhancement could be used to address ARCHETYPE-23 and ARCHETYPE-26. This enhancement involved creating a new Archetype implementation and tweaking the existing ArchetypeMojo.
The ArchetypeMojo was only enhanced to take in a packageName value such as com.mypackage and compute a package value such as com/mypackage. This could probably be rolled into the new Archetype implementation.
The real meat of the modification takes place in the new archetype implementation BobberArchetype. It is slightly refactored and adds the following functionality:
1. Unzips the archetype as is to the destination directory
2. it reads in a archetype descriptor that contains variables and templates
3. For each variable, it reads in the default value and the value from the System properties
4. If maven is run in interactive mode, it prompts for each value
5. After all the values are determined, it process all the macros in the archetype descriptor
6. After it process the archetype, for each template in the descriptor that ends in .vm, it process the template using the variables specified earlier.
Here is an example archetype I have created:
<archetype>
<id>maven-archetype-jbi-component</id>
<variables>
<variable>
<name>ComponentName</name>
<description>JBI Component Name</description>
<defvalue>JBI</defvalue>
</variable>
<variable>
<name>ServiceName</name>
<description>service-name value used to read endpoint name from the SU deployment descriptor</description>
<defvalue>JBI</defvalue>
</variable>
<variable>
<name>ServiceEngine</name>
<description>Boolean flag if JBI Component is a service engine</description>
<defvalue>false</defvalue>
</variable>
</variables>
<templates>
<template>
<file>pom.vm</file>
<output>pom.xml</output>
</template>
<template>
<file>component/pom.vm</file>
<output>component/pom.xml</output>
</template>
<template>
<file>component/src/main/jbi/META-INF/jbi.vm</file>
<output>component/src/main/jbi/META-INF/jbi.xml</output>
</template>
<template>
<file>component/src/main/jbi/ping.vm</file>
<output>component/src/main/jbi/ping.wsdl</output>
</template>
<template>
<file>boot/pom.vm</file>
<output>boot/pom.xml</output>
</template>
<template>
<file>boot/src/main/java/Bootstrap.vm</file>
<output>boot/src/main/java/${packagePath}/${ComponentName}Bootstrap.java</output>
</template>
<template>
<file>runtime/pom.vm</file>
<output>runtime/pom.xml</output>
</template>
<template>
<file>runtime/src/main/java/SUManager.vm</file>
<output>runtime/src/main/java/${packagePath}/${ComponentName}SUManager.java</output>
</template>
<template>
<file>runtime/src/main/java/Component.vm</file>
<output>runtime/src/main/java/${packagePath}/${ComponentName}Component.java</output>
</template>
<template>
<file>runtime/src/main/java/Lifecycle.vm</file>
<output>runtime/src/main/java/${packagePath}/${ComponentName}LifeCycle.java</output>
</template>
</templates>
</archetype>
When the custom archetype plugin runs and calls the archetype implementation, It first extracts the archetype files as is from the zip. Next it iterates through the variables and sets their values to the default value and then sets them from the System properties in case they were set at the command line. In interactive mode, it iterates through the variables and displays the description and default value and prompts the user for new values if desired. After all the values are read in and their values set, the archetype implementation iterates through the templates and processes them, outputing the template output to the interpreted output path and then deletes the .vm template.
This implementation allows greater flexability by:
1. Unziping all files in the archetype to the destination directory. Typically one would not put files in the archetype unless they are expected to be used.
2. Introduces the concept of variables that may be used in templates, allowing archetype creators expanded capabilities when creating templates
3. Allows interactive prompts to confirm default values or override them
4. Customizable template output files so Java files can be generated to correct package paths.
Can you explain what it is exactly you changed. You either have to comment or provide a patch so I can see the differences.