Class CreateMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
The build number is based on the revision number retrieved from SCM. It is known to work with Subversion, GIT, and Mercurial.
This mojo can also check to make sure that you have checked everything into SCM, before issuing the build number. That behaviour can be suppressed, and then the latest local build number is used.
Build numbers are not automatically reflected in your artifact's filename, but can be added to the metadata. You can access the build number in your pom with ${buildNumber}. You can also access ${timestamp} and the SCM branch of the build (if applicable) in ${scmBranch}
Note that there are several doFoo parameters. These parameters (doCheck, doUpdate, etc)
are the first thing evaluated. If there is no matching expression, we get the default-value. If there is (ie
-Dmaven.buildNumber.doUpdate=false), we get that value. So if the XML contains
<doCheck>true</doCheck>, then normally that's the final value of the param in question. However,
this mojo reverses that behaviour, such that the command line parameters get the last say.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileProperties file to be created when "format" is not null and item has "buildNumber".private StringYou can rename the buildNumber property name to another property name if desired.private StringIn cases where the doCheck shows that there are changes in the current working copy this property will be set with the valuetaintedotherwise it will beok.private static final Stringprivate booleanIf this is made true, we check for modified files but does not fail the build.private booleanIf this is made true, then the revision will be updated to the latest in the repo, otherwise it will remain what it is locally.private booleanThis will fail the build in cases where doCheck is set to true.private StringSpecify a message as specified by java.text.MessageFormat.private booleanIf set to true, will get the scm revision once for all modules of a multi-module project instead of fetching once for each module.private List<?> Specify the corresponding items for the format message, as specified by java.text.MessageFormat.private StringThe locale used for date and time formatting.Selects alternative SCM provider implementations.private List<org.apache.maven.project.MavenProject> Contains the full list of projects in the reactor.private Stringprivate StringYou can rename the buildScmBranch property name to another property name if desired.private org.apache.maven.execution.MavenSessionprivate StringApply thisSimpleDateFormatto the timestamp only (as opposed to theformatparameter).private StringYou can rename the timestamp property name to another property name if desired.private StringThe timezone of the generated timestamp.private booleanFields inherited from class AbstractScmMojo
password, project, revisionOnScmFailure, scmConnectionUrl, scmDeveloperConnectionUrl, scmDirectory, scmManager, scmTag, settings, shortRevisionLength, skip, usernameFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbuildNumberAndTimeStampForReactorProjects(Date now, String taintedValue) private voidprivate voidcreatePropertiesFileIfNotExists(File propertiesFile) private booleandoLocalModificationExist(StringBuilder message) voidexecute()protected StringfilterBranchFromScmUrl(String scmUrl) private StringFormats the given argument using the configured format template and locale.private booleangetBooleanProperty(String key, boolean defaultValue) Get the revision info from the repository.Get the branch info for this revision from the repository.private StringList<org.apache.maven.scm.ScmFile> private Object[]handleItems(Date now) voidsetBuildNumberPropertiesFileLocation(File buildNumberPropertiesFileLocation) voidsetDoCheck(boolean doCheck) voidsetDoUpdate(boolean doUpdate) (package private) void(package private) void(package private) voidvoidsetPassword(String password) voidsetRevisionOnScmFailure(String revisionOnScmFailure) voidsetScmDirectory(File scmDirectory) voidsetScmManager(org.apache.maven.scm.manager.ScmManager scmManager) voidsetShortRevisionLength(int shortRevision) voidvoidsetUsername(String username) List<org.apache.maven.scm.ScmFile> update()Methods inherited from class AbstractScmMojo
checkResult, getScmRepository, getScmRevision, infoMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
DEFAULT_BRANCH_NAME
- See Also:
-
buildNumberPropertyName
@Parameter(property="maven.buildNumber.buildNumberPropertyName", defaultValue="buildNumber") private String buildNumberPropertyNameYou can rename the buildNumber property name to another property name if desired.- Since:
- 1.0-beta-1
-
timestampPropertyName
@Parameter(property="maven.buildNumber.timestampPropertyName", defaultValue="timestamp") private String timestampPropertyNameYou can rename the timestamp property name to another property name if desired.- Since:
- 1.0-beta-1
-
doCheck
@Parameter(property="maven.buildNumber.doCheck", defaultValue="false") private boolean doCheckIf this is made true, we check for modified files but does not fail the build. If you like to fail the build such cases you have to set thefailTheBuildproperty as well. Settings doCheck to true a property is set to true if there are changes- Since:
- 1.0-beta-1
-
failTheBuild
@Parameter(property="maven.buildNumber.failTheBuild", defaultValue="true") private boolean failTheBuildThis will fail the build in cases where doCheck is set to true.- Since:
- 3.0.0
-
buildTaintedPropertyName
@Parameter(property="maven.buildNumber.buildTaintedPropertyName", defaultValue="buildIsTainted") private String buildTaintedPropertyNameIn cases where the doCheck shows that there are changes in the current working copy this property will be set with the valuetaintedotherwise it will beok. -
doUpdate
@Parameter(property="maven.buildNumber.doUpdate", defaultValue="false") private boolean doUpdateIf this is made true, then the revision will be updated to the latest in the repo, otherwise it will remain what it is locally. Note that this used to be inverted (skipUpdate), but needed to be changed to allow releases to work. This corresponds to 'svn update'.- Since:
- 1.0-beta-1
-
format
Specify a message as specified by java.text.MessageFormat. This triggers "items" configuration to be read- Since:
- 1.0-beta-1
-
buildNumberPropertiesFileLocation
@Parameter(defaultValue="${basedir}/buildNumber.properties") private File buildNumberPropertiesFileLocationProperties file to be created when "format" is not null and item has "buildNumber". See Usage for details- Since:
- 1.0-beta-2
-
items
Specify the corresponding items for the format message, as specified by java.text.MessageFormat. Special item values are "scmVersion", "timestamp" and "buildNumber[digits]", where [digits] are optional digits added to the end of the number to select a property.- Since:
- 1.0-beta-1
-
locale
The locale used for date and time formatting. The locale name should be in the format defined inLocale.toString(). The default locale is the platform default returned byLocale.getDefault().- Since:
- 1.0-beta-2
-
timestampFormat
Apply thisSimpleDateFormatto the timestamp only (as opposed to theformatparameter).- Since:
- 1.0-beta-2
-
timezone
The timezone of the generated timestamp. If blank will default toinvalid reference
TimeZone#getDefault()- Since:
- 3.0.0
-
providerImplementations
Selects alternative SCM provider implementations. Each map key denotes the original provider type as given in the SCM URL like "cvs" or "svn", the map value specifies the provider type of the desired implementation to use instead. In other words, this map configures a substitution mapping for SCM providers.- Since:
- 1.0-beta-3
-
getRevisionOnlyOnce
@Parameter(property="maven.buildNumber.getRevisionOnlyOnce", defaultValue="false") private boolean getRevisionOnlyOnceIf set to true, will get the scm revision once for all modules of a multi-module project instead of fetching once for each module.- Since:
- 1.0-beta-3
-
scmBranchPropertyName
@Parameter(property="maven.buildNumber.scmBranchPropertyName", defaultValue="scmBranch") private String scmBranchPropertyNameYou can rename the buildScmBranch property name to another property name if desired.- Since:
- 1.0-beta-4
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private List<org.apache.maven.project.MavenProject> reactorProjectsContains the full list of projects in the reactor.- Since:
- 1.0-beta-3
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session -
revision
-
useScm
private boolean useScm
-
-
Constructor Details
-
CreateMojo
public CreateMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
handleItems
-
createPropertiesFileIfNotExists
private void createPropertiesFileIfNotExists(File propertiesFile) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
buildNumberAndTimeStampForReactorProjects
-
changeProviderImplementation
private void changeProviderImplementation() -
format
-
doLocalModificationExist
private boolean doLocalModificationExist(StringBuilder message) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
update
public List<org.apache.maven.scm.ScmFile> update() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getStatus
- Throws:
org.apache.maven.scm.ScmException
-
getScmBranch
Get the branch info for this revision from the repository. For svn, it is in svn info.- Returns:
- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoExecutionException
-
getScmBranchFromUrl
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
filterBranchFromScmUrl
-
getRevision
Get the revision info from the repository. For svn, it is svn info- Returns:
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
setScmManager
public void setScmManager(org.apache.maven.scm.manager.ScmManager scmManager) -
setUrlScm
-
setUsername
-
setPassword
-
setDoCheck
public void setDoCheck(boolean doCheck) -
setDoUpdate
public void setDoUpdate(boolean doUpdate) -
getBooleanProperty
-
setFormat
-
setLocale
-
setItems
-
setBuildNumberPropertiesFileLocation
-
setScmDirectory
-
setRevisionOnScmFailure
-
setShortRevisionLength
public void setShortRevisionLength(int shortRevision)
-