@Mojo(name="create",
defaultPhase=INITIALIZE,
requiresProject=true,
threadSafe=true)
public class CreateMojo
extends org.apache.maven.plugin.AbstractMojo
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.
Modifier and Type | Field and Description |
---|---|
private java.io.File |
buildNumberPropertiesFileLocation
Properties file to be created when "format" is not null and item has "buildNumber".
|
private java.lang.String |
buildNumberPropertyName
You can rename the buildNumber property name to another property name if desired.
|
private static java.lang.String |
DEFAULT_BRANCH_NAME |
private static int |
DEFAULT_SHORT_REVISION_DISABLED |
private boolean |
doCheck
If this is made true, we check for modified files, and if there are any, we fail the build.
|
private boolean |
doUpdate
If 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 java.lang.String |
format
Specify a message as specified by java.text.MessageFormat.
|
private boolean |
getRevisionOnlyOnce
If 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 |
items
Specify the corresponding items for the format message, as specified by java.text.MessageFormat.
|
private java.lang.String |
locale
The locale used for date and time formatting.
|
private org.apache.maven.scm.log.ScmLogDispatcher |
logger |
private java.lang.String |
password
The password that is used when connecting to the SCM system.
|
private org.apache.maven.project.MavenProject |
project |
private java.util.Map<java.lang.String,java.lang.String> |
providerImplementations
Selects alternative SCM provider implementations.
|
private java.util.List |
reactorProjects
Contains the full list of projects in the reactor.
|
private java.lang.String |
readUrlScm |
private java.lang.String |
revision |
private java.lang.String |
revisionOnScmFailure
Setting this value allows the build to continue even in the event of an SCM failure.
|
private java.lang.String |
scmBranchPropertyName
You can rename the buildScmBranch property name to another property name if desired.
|
private java.io.File |
scmDirectory
Local directory to be used to issue SCM actions
|
private org.apache.maven.scm.manager.ScmManager |
scmManager |
protected org.apache.maven.execution.MavenSession |
session |
private int |
shortRevisionLength
Max length of a revision id (used only for git)
|
private boolean |
skip
Whether to skip this execution.
|
private java.lang.String |
timestampFormat
Apply this java.text.MessageFormat to the timestamp only (as opposed to the
format parameter). |
private java.lang.String |
timestampPropertyName
You can rename the timestamp property name to another property name if desired.
|
private java.lang.String |
urlScm |
private boolean |
useLastCommittedRevision
whether to retrieve the revision for the last commit, or the last revision of the repository.
|
private java.lang.String |
username
The username that is used when connecting to the SCM system.
|
private boolean |
useScm |
Constructor and Description |
---|
CreateMojo() |
Modifier and Type | Method and Description |
---|---|
private void |
checkForLocalModifications() |
private void |
checkResult(org.apache.maven.scm.ScmResult result) |
private void |
closeStream(java.io.Closeable stream) |
void |
execute() |
protected java.lang.String |
filterBranchFromScmUrl(java.lang.String scmUrl) |
private java.lang.String |
format(java.lang.Object[] arguments)
Formats the given argument using the configured format template and locale.
|
private org.apache.maven.scm.log.ScmLogger |
getLogger() |
java.lang.String |
getRevision()
Get the revision info from the repository.
|
java.lang.String |
getScmBranch()
Get the branch info for this revision from the repository.
|
protected java.lang.String |
getScmBranchFromUrl() |
private org.apache.maven.scm.repository.ScmRepository |
getScmRepository() |
java.util.List<org.apache.maven.scm.ScmFile> |
getStatus() |
org.apache.maven.scm.command.info.InfoScmResult |
info(org.apache.maven.scm.repository.ScmRepository repository,
org.apache.maven.scm.ScmFileSet fileSet)
Get info from scm.
|
void |
setBuildNumberPropertiesFileLocation(java.io.File buildNumberPropertiesFileLocation) |
void |
setDoCheck(boolean doCheck) |
void |
setDoUpdate(boolean doUpdate) |
(package private) void |
setFormat(java.lang.String format) |
(package private) void |
setItems(java.util.List items) |
(package private) void |
setLocale(java.lang.String locale) |
void |
setPassword(java.lang.String password) |
void |
setRevisionOnScmFailure(java.lang.String revisionOnScmFailure) |
void |
setScmDirectory(java.io.File scmDirectory) |
void |
setScmManager(org.apache.maven.scm.manager.ScmManager scmManager) |
void |
setShortRevisionLength(int shortRevision) |
void |
setUrlScm(java.lang.String urlScm) |
void |
setUsername(java.lang.String username) |
java.util.List<org.apache.maven.scm.ScmFile> |
update() |
private static final java.lang.String DEFAULT_BRANCH_NAME
@Parameter(defaultValue="${project.scm.developerConnection}", readonly=true) private java.lang.String urlScm
@Parameter(defaultValue="${project.scm.connection}", readonly=true) private java.lang.String readUrlScm
@Parameter(property="username") private java.lang.String username
@Parameter(property="password") private java.lang.String password
@Parameter(property="maven.buildNumber.scmDirectory", defaultValue="${basedir}") private java.io.File scmDirectory
@Parameter(property="maven.buildNumber.buildNumberPropertyName", defaultValue="buildNumber") private java.lang.String buildNumberPropertyName
@Parameter(property="maven.buildNumber.timestampPropertyName", defaultValue="timestamp") private java.lang.String timestampPropertyName
@Parameter(property="maven.buildNumber.doCheck", defaultValue="false") private boolean doCheck
@Parameter(property="maven.buildNumber.doUpdate", defaultValue="false") private boolean doUpdate
@Parameter(property="maven.buildNumber.format") private java.lang.String format
@Parameter(defaultValue="${basedir}/buildNumber.properties") private java.io.File buildNumberPropertiesFileLocation
@Parameter private java.util.List items
@Parameter(property="maven.buildNumber.locale") private java.lang.String locale
Locale.toString()
. The default locale is the platform default returned by Locale.getDefault()
.@Parameter(property="maven.buildNumber.useLastCommittedRevision", defaultValue="false") private boolean useLastCommittedRevision
@Parameter(property="maven.buildNumber.timestampFormat") private java.lang.String timestampFormat
format
parameter).@Parameter(property="maven.buildNumber.revisionOnScmFailure") private java.lang.String revisionOnScmFailure
@Parameter private java.util.Map<java.lang.String,java.lang.String> providerImplementations
@Component private org.apache.maven.scm.manager.ScmManager scmManager
@Parameter(defaultValue="${project}", required=true, readonly=true) private org.apache.maven.project.MavenProject project
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private java.util.List reactorProjects
@Parameter(property="maven.buildNumber.getRevisionOnlyOnce", defaultValue="false") private boolean getRevisionOnlyOnce
@Parameter(property="maven.buildNumber.scmBranchPropertyName", defaultValue="scmBranch") private java.lang.String scmBranchPropertyName
@Parameter(property="maven.buildNumber.skip", defaultValue="false") private boolean skip
@Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession session
private org.apache.maven.scm.log.ScmLogDispatcher logger
private java.lang.String revision
@Parameter private int shortRevisionLength
private static final int DEFAULT_SHORT_REVISION_DISABLED
private boolean useScm
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 void closeStream(java.io.Closeable stream)
private java.lang.String format(java.lang.Object[] arguments)
arguments
- arguments to be formatted @ @return formatted resultprivate void checkForLocalModifications() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
public java.util.List<org.apache.maven.scm.ScmFile> update() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
public java.util.List<org.apache.maven.scm.ScmFile> getStatus() throws org.apache.maven.scm.ScmException
org.apache.maven.scm.ScmException
public java.lang.String getScmBranch() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected java.lang.String getScmBranchFromUrl() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected java.lang.String filterBranchFromScmUrl(java.lang.String scmUrl)
public java.lang.String getRevision() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
public org.apache.maven.scm.command.info.InfoScmResult info(org.apache.maven.scm.repository.ScmRepository repository, org.apache.maven.scm.ScmFileSet fileSet) throws org.apache.maven.scm.ScmException
repository
- fileSet
- org.apache.maven.scm.ScmException
private org.apache.maven.scm.log.ScmLogger getLogger()
private org.apache.maven.scm.repository.ScmRepository getScmRepository() throws org.apache.maven.scm.ScmException
org.apache.maven.scm.ScmException
private void checkResult(org.apache.maven.scm.ScmResult result) throws org.apache.maven.scm.ScmException
org.apache.maven.scm.ScmException
public void setScmManager(org.apache.maven.scm.manager.ScmManager scmManager)
public void setUrlScm(java.lang.String urlScm)
public void setUsername(java.lang.String username)
public void setPassword(java.lang.String password)
public void setDoCheck(boolean doCheck)
public void setDoUpdate(boolean doUpdate)
void setFormat(java.lang.String format)
void setLocale(java.lang.String locale)
void setItems(java.util.List items)
public void setBuildNumberPropertiesFileLocation(java.io.File buildNumberPropertiesFileLocation)
public void setScmDirectory(java.io.File scmDirectory)
public void setRevisionOnScmFailure(java.lang.String revisionOnScmFailure)
public void setShortRevisionLength(int shortRevision)