@Mojo(name="create-from-project",
requiresProject=true,
aggregator=true)
@Execute(phase=GENERATE_SOURCES)
public class CreateArchetypeFromProjectMojo
extends org.apache.maven.plugin.AbstractMojo
Creates an archetype project from the current project.
This goal reads your source and resource files, the values of its parameters,
and properties you specify in a .property
file, and uses them to
create a Maven archetype project using the maven-archetype packaging.
If you build the resulting project, it will create the archetype. You can then
use this archetype to create new projects that resemble the original.
The maven-archetype-plugin uses Velocity to expand template files, and this documentation talks about 'Velocity Properties', which are values substituted into Velocity templates. See The Velocity User's Guide for more information.
This goal modifies the text of the files of the current project to form the Velocity template files that make up the archetype.
org.apache.saltedpeanuts
, then
any example of the string org.apache.saltedpeanuts
is replaced with the Velocity property
reference ${packageName}
. When the user generates a project, this is in turn replaced by
his or her choice of a package.
propertyFile
parameter to specify a property file.
See the documentation for propertyFile
for the details.
Note that you may need to edit the results of this goal. This goal has no way to exclude unwanted files, or add copyright notices to the Velocity templates, or add more complex elements to the archetype metadata file.
This goal also generates a simple integration-test that exercises the generated archetype.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
archetypeFilteredExtentions
File extensions which are checked for project's text files (vs binary files).
|
private java.lang.String |
archetypeLanguages
Directory names which are checked for project's sources main package.
|
private java.lang.String |
archetypePostPhase
The property telling which phase to call on the generated archetype.
|
private java.io.File |
archetypeRegistryFile
The location of the registry file.
|
private ArchetypeCreationConfigurator |
configurator |
private java.lang.String |
defaultEncoding
Velocity templates encoding.
|
private boolean |
interactive
Enable the interactive mode to define the archetype from the project.
|
private boolean |
keepParent
POMs in archetype are created with their initial parent.
|
private org.apache.maven.artifact.repository.ArtifactRepository |
localRepository |
private ArchetypeManager |
manager |
private java.io.File |
outputDirectory
The directory where the archetype should be created.
|
private java.lang.String |
packageName
The package name for Java source files to be incorporated in the archetype and
and relocated to the package that the user selects.
|
private boolean |
partialArchetype
Create a partial archetype.
|
private boolean |
preserveCData
Create pom's velocity templates with CDATA preservation.
|
private org.apache.maven.project.MavenProject |
project
The Maven project to create an archetype from.
|
private java.io.File |
propertyFile
The property file that holds the plugin configuration.
|
private org.apache.maven.execution.MavenSession |
session |
private boolean |
testMode |
Constructor and Description |
---|
CreateArchetypeFromProjectMojo() |
Modifier and Type | Method and Description |
---|---|
void |
execute() |
private java.util.List<java.lang.String> |
getFilteredExtensions(java.lang.String archetypeFilteredExtentions,
java.io.File propertyFile) |
private java.util.List<java.lang.String> |
getLanguages(java.lang.String archetypeLanguages,
java.io.File propertyFile) |
@Component private ArchetypeCreationConfigurator configurator
@Parameter(property="interactive", defaultValue="false") private boolean interactive
@Component private ArchetypeManager manager
@Parameter(property="archetype.filteredExtentions") private java.lang.String archetypeFilteredExtentions
@Parameter(property="archetype.languages") private java.lang.String archetypeLanguages
@Parameter(defaultValue="${user.home}/.m2/archetype.xml") private java.io.File archetypeRegistryFile
@Parameter(property="archetype.encoding", defaultValue="UTF-8") private java.lang.String defaultEncoding
@Parameter(property="archetype.partialArchetype") private boolean partialArchetype
@Parameter(property="archetype.preserveCData") private boolean preserveCData
String.replaceAll()
method and risks to have some overly replacement capabilities (beware of '1.0' value).@Parameter(defaultValue="${localRepository}", readonly=true) private org.apache.maven.artifact.repository.ArtifactRepository localRepository
@Parameter(property="archetype.keepParent") private boolean keepParent
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
@Parameter(property="archetype.properties") private java.io.File propertyFile
Custom properties allow you to replace some constant values in the project's files with Velocity macro references. When a user generates a project from your archetype he or she gets the opportunity to replace the value from the source project.
Custom property names may not contain the '.' character.
For example, if you include a line like the following in your property file:
cxf-version=2.5.1-SNAPSHOTthe plugin will search your files for the
2.5.1-SNAPSHOT
string and
replace them with references to a velocity macro cxf-version. It will
then list cxf-version
as a requiredProperty
in the
archetype-metadata.xml
, with 2.5.1-SNAPSHOT
as the default value.
@Parameter(property="archetype.postPhase", defaultValue="package") private java.lang.String archetypePostPhase
package
, integration-test
, install
and deploy
.@Parameter(defaultValue="${project.build.directory}/generated-sources/archetype") private java.io.File outputDirectory
@Parameter(property="testMode") private boolean testMode
@Parameter(property="packageName") private java.lang.String packageName
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
private java.util.List<java.lang.String> getFilteredExtensions(java.lang.String archetypeFilteredExtentions, java.io.File propertyFile) throws java.io.IOException
java.io.IOException
private java.util.List<java.lang.String> getLanguages(java.lang.String archetypeLanguages, java.io.File propertyFile) throws java.io.IOException
java.io.IOException