Class CreateMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.codehaus.mojo.build.AbstractScmMojo
-
- org.codehaus.mojo.build.CreateMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="create", defaultPhase=INITIALIZE, requiresProject=true, threadSafe=true) public class CreateMojo extends AbstractScmMojoThis mojo is designed to give you a build number. So when you might make 100 builds of version 1.0-SNAPSHOT, you can differentiate between them all.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
doFooparameters. 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
Fields Modifier and Type Field Description private java.io.FilebuildNumberPropertiesFileLocationProperties file to be created when "format" is not null and item has "buildNumber".private java.lang.StringbuildNumberPropertyNameYou can rename the buildNumber property name to another property name if desired.private java.lang.StringbuildTaintedPropertyNameIn 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 java.lang.StringDEFAULT_BRANCH_NAMEprivate booleandoCheckIf this is made true, we check for modified files but does not fail the build.private booleandoUpdateIf 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 booleanfailTheBuildThis will fail the build in cases where doCheck is set to true.private java.lang.StringformatSpecify a message as specified by java.text.MessageFormat.private booleangetRevisionOnlyOnceIf 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 java.util.List<?>itemsSpecify the corresponding items for the format message, as specified by java.text.MessageFormat.private java.lang.StringlocaleThe locale used for date and time formatting.private java.util.Map<java.lang.String,java.lang.String>providerImplementationsSelects alternative SCM provider implementations.private java.util.List<org.apache.maven.project.MavenProject>reactorProjectsContains the full list of projects in the reactor.private java.lang.Stringrevisionprivate java.lang.StringscmBranchPropertyNameYou can rename the buildScmBranch property name to another property name if desired.private org.apache.maven.execution.MavenSessionsessionprivate java.lang.StringtimestampFormatApply thisSimpleDateFormatto the timestamp only (as opposed to theformatparameter).private java.lang.StringtimestampPropertyNameYou can rename the timestamp property name to another property name if desired.private java.lang.StringtimezoneThe timezone of the generated timestamp.private booleanuseScm-
Fields inherited from class org.codehaus.mojo.build.AbstractScmMojo
password, project, revisionOnScmFailure, scmConnectionUrl, scmDeveloperConnectionUrl, scmDirectory, scmManager, scmTag, settings, shortRevisionLength, skip, username
-
-
Constructor Summary
Constructors Constructor Description CreateMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildNumberAndTimeStampForReactorProjects(java.util.Date now, java.lang.String taintedValue)private voidchangeProviderImplementation()private voidcreatePropertiesFileIfNotExists(java.io.File propertiesFile)private booleandoLocalModificationExist(java.lang.StringBuilder message)voidexecute()protected java.lang.StringfilterBranchFromScmUrl(java.lang.String scmUrl)private java.lang.Stringformat(java.lang.Object[] arguments)Formats the given argument using the configured format template and locale.private booleangetBooleanProperty(java.lang.String key, boolean defaultValue)java.lang.StringgetRevision()Get the revision info from the repository.java.lang.StringgetScmBranch()Get the branch info for this revision from the repository.private java.lang.StringgetScmBranchFromUrl()java.util.List<org.apache.maven.scm.ScmFile>getStatus()private java.lang.Object[]handleItems(java.util.Date now)voidsetBuildNumberPropertiesFileLocation(java.io.File buildNumberPropertiesFileLocation)voidsetDoCheck(boolean doCheck)voidsetDoUpdate(boolean doUpdate)(package private) voidsetFormat(java.lang.String format)(package private) voidsetItems(java.util.List<?> items)(package private) voidsetLocale(java.lang.String locale)voidsetPassword(java.lang.String password)voidsetRevisionOnScmFailure(java.lang.String revisionOnScmFailure)voidsetScmDirectory(java.io.File scmDirectory)voidsetScmManager(org.apache.maven.scm.manager.ScmManager scmManager)voidsetShortRevisionLength(int shortRevision)voidsetUrlScm(java.lang.String urlScm)voidsetUsername(java.lang.String username)java.util.List<org.apache.maven.scm.ScmFile>update()-
Methods inherited from class org.codehaus.mojo.build.AbstractScmMojo
checkResult, getScmRepository, getScmRevision, info
-
-
-
-
Field Detail
-
DEFAULT_BRANCH_NAME
private static final java.lang.String DEFAULT_BRANCH_NAME
- See Also:
- Constant Field Values
-
buildNumberPropertyName
@Parameter(property="maven.buildNumber.buildNumberPropertyName", defaultValue="buildNumber") private java.lang.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 java.lang.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 java.lang.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
@Parameter(property="maven.buildNumber.format") private java.lang.String 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 java.io.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
@Parameter private java.util.List<?> 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
@Parameter(property="maven.buildNumber.locale") private java.lang.String 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
@Parameter(property="maven.buildNumber.timestampFormat") private java.lang.String timestampFormat
Apply thisSimpleDateFormatto the timestamp only (as opposed to theformatparameter).- Since:
- 1.0-beta-2
-
timezone
@Parameter(property="maven.buildNumber.timestampTimeZone", defaultValue="") private java.lang.String timezoneThe timezone of the generated timestamp. If blank will default toTimeZone#getDefault()- Since:
- 3.0.0
-
providerImplementations
@Parameter private java.util.Map<java.lang.String,java.lang.String> 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 java.lang.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 java.util.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
private java.lang.String revision
-
useScm
private boolean useScm
-
-
Method Detail
-
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
private java.lang.Object[] handleItems(java.util.Date now) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
createPropertiesFileIfNotExists
private void createPropertiesFileIfNotExists(java.io.File propertiesFile) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
buildNumberAndTimeStampForReactorProjects
private void buildNumberAndTimeStampForReactorProjects(java.util.Date now, java.lang.String taintedValue) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
changeProviderImplementation
private void changeProviderImplementation()
-
format
private java.lang.String format(java.lang.Object[] arguments)
Formats the given argument using the configured format template and locale.- Parameters:
arguments- arguments to be formatted @ @return formatted result
-
doLocalModificationExist
private boolean doLocalModificationExist(java.lang.StringBuilder message) throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
update
public java.util.List<org.apache.maven.scm.ScmFile> update() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getStatus
public java.util.List<org.apache.maven.scm.ScmFile> getStatus() throws org.apache.maven.scm.ScmException- Throws:
org.apache.maven.scm.ScmException
-
getScmBranch
public java.lang.String getScmBranch() throws org.apache.maven.plugin.MojoExecutionExceptionGet 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
private java.lang.String getScmBranchFromUrl() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
filterBranchFromScmUrl
protected java.lang.String filterBranchFromScmUrl(java.lang.String scmUrl)
-
getRevision
public java.lang.String getRevision() throws org.apache.maven.plugin.MojoExecutionExceptionGet 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
public void setUrlScm(java.lang.String urlScm)
-
setUsername
public void setUsername(java.lang.String username)
-
setPassword
public void setPassword(java.lang.String password)
-
setDoCheck
public void setDoCheck(boolean doCheck)
-
setDoUpdate
public void setDoUpdate(boolean doUpdate)
-
getBooleanProperty
private boolean getBooleanProperty(java.lang.String key, boolean defaultValue)
-
setFormat
void setFormat(java.lang.String format)
-
setLocale
void setLocale(java.lang.String locale)
-
setItems
void setItems(java.util.List<?> items)
-
setBuildNumberPropertiesFileLocation
public void setBuildNumberPropertiesFileLocation(java.io.File buildNumberPropertiesFileLocation)
-
setScmDirectory
public void setScmDirectory(java.io.File scmDirectory)
-
setRevisionOnScmFailure
public void setRevisionOnScmFailure(java.lang.String revisionOnScmFailure)
-
setShortRevisionLength
public void setShortRevisionLength(int shortRevision)
-
-