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.
- Version:
- $Id: CreateMojo.java 19675 2014-04-26 21:50:31Z baptiste $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate File
Properties file to be created when "format" is not null and item has "buildNumber".private String
You can rename the buildNumber property name to another property name if desired.private static final String
private static final int
private boolean
If this is made true, we check for modified files, and if there are any, we fail the build.private boolean
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 String
Specify a message as specified by java.text.MessageFormat.private boolean
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 List
Specify the corresponding items for the format message, as specified by java.text.MessageFormat.private String
The locale used for date and time formatting.private org.apache.maven.scm.log.ScmLogDispatcher
private String
The password that is used when connecting to the SCM system.private org.apache.maven.project.MavenProject
Selects alternative SCM provider implementations.private List
Contains the full list of projects in the reactor.private String
private String
private String
Setting this value allows the build to continue even in the event of an SCM failure.private String
You can rename the buildScmBranch property name to another property name if desired.private File
Local directory to be used to issue SCM actionsprivate org.apache.maven.scm.manager.ScmManager
protected org.apache.maven.execution.MavenSession
private int
Max length of a revision id (used only for git)private boolean
Whether to skip this execution.private String
Apply this java.text.MessageFormat to the timestamp only (as opposed to theformat
parameter).private String
You can rename the timestamp property name to another property name if desired.private String
private boolean
whether to retrieve the revision for the last commit, or the last revision of the repository.private String
The username that is used when connecting to the SCM system.private boolean
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
checkResult
(org.apache.maven.scm.ScmResult result) private void
closeStream
(Closeable stream) void
execute()
protected String
filterBranchFromScmUrl
(String scmUrl) private String
Formats the given argument using the configured format template and locale.private org.apache.maven.scm.log.ScmLogger
Get the revision info from the repository.Get the branch info for this revision from the repository.protected String
private org.apache.maven.scm.repository.ScmRepository
List
<org.apache.maven.scm.ScmFile> 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
(File buildNumberPropertiesFileLocation) void
setDoCheck
(boolean doCheck) void
setDoUpdate
(boolean doUpdate) (package private) void
(package private) void
(package private) void
void
setPassword
(String password) void
setRevisionOnScmFailure
(String revisionOnScmFailure) void
setScmDirectory
(File scmDirectory) void
setScmManager
(org.apache.maven.scm.manager.ScmManager scmManager) void
setShortRevisionLength
(int shortRevision) void
void
setUsername
(String username) List
<org.apache.maven.scm.ScmFile> update()
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
DEFAULT_BRANCH_NAME
- See Also:
-
urlScm
-
readUrlScm
- Since:
- 1.0-beta-5
-
username
The username that is used when connecting to the SCM system.- Since:
- 1.0-beta-1
-
password
The password that is used when connecting to the SCM system.- Since:
- 1.0-beta-1
-
scmDirectory
@Parameter(property="maven.buildNumber.scmDirectory", defaultValue="${basedir}") private File scmDirectoryLocal directory to be used to issue SCM actions- Since:
- 1.0-beta-
-
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, and if there are any, we fail the build. Note that this used to be inverted (skipCheck), but needed to be changed to allow releases to work. This corresponds to 'svn status'.- Since:
- 1.0-beta-1
-
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
-
useLastCommittedRevision
@Parameter(property="maven.buildNumber.useLastCommittedRevision", defaultValue="false") private boolean useLastCommittedRevisionwhether to retrieve the revision for the last commit, or the last revision of the repository.- Since:
- 1.0-beta-2
-
timestampFormat
Apply this java.text.MessageFormat to the timestamp only (as opposed to theformat
parameter).- Since:
- 1.0-beta-2
-
revisionOnScmFailure
Setting this value allows the build to continue even in the event of an SCM failure. The value set will be used as the revision string in the event of a failure to retrieve the revision it from the SCM.- Since:
- 1.0-beta-2
-
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 substitition mapping for SCM providers.- Since:
- 1.0-beta-3
-
scmManager
@Component private org.apache.maven.scm.manager.ScmManager scmManager -
project
@Parameter(defaultValue="${project}", required=true, readonly=true) private org.apache.maven.project.MavenProject project -
reactorProjects
@Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) private List reactorProjectsContains the full list of projects in the reactor.- 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
-
skip
@Parameter(property="maven.buildNumber.skip", defaultValue="false") private boolean skipWhether to skip this execution.- Since:
- 1.3
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession session -
logger
private org.apache.maven.scm.log.ScmLogDispatcher logger -
revision
-
shortRevisionLength
@Parameter private int shortRevisionLengthMax length of a revision id (used only for git)- Since:
- 1.1
-
DEFAULT_SHORT_REVISION_DISABLED
private static final int DEFAULT_SHORT_REVISION_DISABLED- Since:
- 1.1
- See Also:
-
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.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
-
closeStream
-
format
Formats the given argument using the configured format template and locale.- Parameters:
arguments
- arguments to be formatted @ @return formatted result
-
checkForLocalModifications
private void checkForLocalModifications() 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.MojoExecutionException
org.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
-
info
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 Get info from scm.- Parameters:
repository
-fileSet
-- Returns:
- Throws:
org.apache.maven.scm.ScmException
-
getLogger
private org.apache.maven.scm.log.ScmLogger getLogger()- Returns:
-
getScmRepository
private org.apache.maven.scm.repository.ScmRepository getScmRepository() throws org.apache.maven.scm.ScmException- Throws:
org.apache.maven.scm.ScmException
-
checkResult
private void checkResult(org.apache.maven.scm.ScmResult result) throws org.apache.maven.scm.ScmException - Throws:
org.apache.maven.scm.ScmException
-
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) -
setFormat
-
setLocale
-
setItems
-
setBuildNumberPropertiesFileLocation
-
setScmDirectory
-
setRevisionOnScmFailure
-
setShortRevisionLength
public void setShortRevisionLength(int shortRevision)
-