Class ReplacerMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
com.google.code.maven_replacer_plugin.ReplacerMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
public class ReplacerMojo
extends org.apache.maven.plugin.AbstractMojo
Goal replaces token with value inside file
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
Optional base directory for each file to replace.private boolean
Comments enabled in the tokenValueMapFile.Add a list of delimiters which are added on either side of tokens to match against.private String
File encoding used when reading and writing files.List of files to exclude for multiple (or single) replacement.private String
File to check and replace tokens.list filesprivate final FileSelector
private String
List of comma separated files to exclude (must have some includes) for multiple (or single) replacement.private String
Comma separated list of includes.private final FileUtils
private boolean
Ignore any errors produced by this plugin such as files not being found and continue with the build.private boolean
Ignore missing target file.List of files to include for multiple (or single) replacement.private String
Regular expression is run on an input file's name to create the output file with.private static final String
private Integer
Set a maximum number of files which can be replaced per execution.private String
Base directory (appended) to use for outputDir.private String
Output to another dir.private String
Output to another file.private final OutputFilenameBuilder
private String
Regular expression groups from inputFilePattern are used in this pattern to create an output file per input file.list out put fileprivate final PatternFlagsFactory
private boolean
Parent directory is preserved when replacing files found from includes and being written to an outputDir.private final ReplacementProcessor
private boolean
Stops printing a summary of files that have had replacements performed upon them when true.private boolean
Indicates if the token should be located with regular expressions.private static final String
List of standard Java regular expression Pattern flags (see Java Doc).private List<Replacement>
List of replacements with token/value pairs.private final ReplacerFactory
private boolean
Skip running this plugin.private final SummaryBuilder
private String
Token to replace.private String
Token file containing a token to be replaced in the target file/s.private String
Map of tokens and respective values to replace with.private final TokenValueMapFactory
private boolean
Unescape tokens and values to Java format.private String
Value to replace token with.private String
A file containing a value to replace the given token with.private String
Variable tokenValueMap.private String
X-Path expression for locating node's whose content you wish to replace.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
ConstructorsConstructorDescriptionReplacerMojo
(FileUtils fileUtils, ReplacementProcessor processor, ReplacerFactory replacerFactory, TokenValueMapFactory tokenValueMapFactory, FileSelector fileSelector, PatternFlagsFactory patternFlagsFactory, OutputFilenameBuilder outputFilenameBuilder, SummaryBuilder summaryBuilder) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private List<DelimiterBuilder>
private List<Replacement>
private boolean
void
execute()
private String
private List<Replacement>
getDelimiterReplacements
(List<Replacement> replacements) getFile()
getFiles()
boolean
boolean
boolean
boolean
isSkip()
boolean
private <T> List<T>
private void
replaceContents
(ReplacementProcessor processor, List<Replacement> replacements, String inputFile) private void
replaceContents
(ReplacementProcessor processor, List<Replacement> replacements, List<String> inputFiles) void
setBasedir
(String baseDir) void
setCommentsEnabled
(boolean commentsEnabled) void
setDelimiters
(List<String> delimiters) void
setEncoding
(String encoding) void
setExcludes
(List<String> excludes) void
void
void
setFilesToExclude
(String filesToExclude) void
setFilesToInclude
(String filesToInclude) void
setIgnoreErrors
(boolean ignoreErrors) void
setIgnoreMissingFile
(boolean ignoreMissingFile) void
setIncludes
(List<String> includes) void
setInputFilePattern
(String inputFilePattern) void
setMaxReplacements
(Integer maxReplacements) void
setOutputBasedir
(String outputBasedir) void
setOutputDir
(String outputDir) void
setOutputFile
(String outputFile) void
setOutputFilePattern
(String outputFilePattern) void
setOutputFiles
(List<String> outputFiles) void
setPreserveDir
(boolean preserveDir) void
setQuiet
(boolean quiet) void
setRegex
(boolean regex) void
setRegexFlags
(List<String> regexFlags) void
setReplacements
(List<Replacement> replacements) void
setSkip
(boolean skip) void
void
setTokenFile
(String tokenFile) void
setTokenValueMap
(String tokenValueMap) void
setUnescape
(boolean unescape) void
void
setValueFile
(String valueFile) void
setVariableTokenValueMap
(String variableTokenValueMap) void
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
INVALID_IGNORE_MISSING_FILE_MESSAGE
- See Also:
-
REGEX_PATTERN_WITH_DELIMITERS_MESSAGE
- See Also:
-
fileUtils
-
replacerFactory
-
tokenValueMapFactory
-
fileSelector
-
patternFlagsFactory
-
outputFilenameBuilder
-
summaryBuilder
-
processor
-
file
File to check and replace tokens. Path to single file to replace tokens in. The file must be text (ascii). Based on current execution path. -
includes
List of files to include for multiple (or single) replacement. In Ant format (*\/directory/**.properties) Cannot use with outputFile. -
excludes
List of files to exclude for multiple (or single) replacement. In Ant format (*\/directory/**.properties) Cannot use with outputFile. -
filesToInclude
Comma separated list of includes. This is split up and used the same way a array of includes would be. In Ant format (*\/directory/**.properties). Files not found are ignored by default. -
filesToExclude
List of comma separated files to exclude (must have some includes) for multiple (or single) replacement. This is split up and used the same way a array of excludes would be. In Ant format (**\/directory/do-not-replace.properties). The files replaced will be derived from the list of includes and excludes. -
token
Token to replace. The text to replace within the given file. This may or may not be a regular expression (see regex notes above). -
tokenFile
Token file containing a token to be replaced in the target file/s. May be multiple words or lines. This is useful if you do not wish to expose the token within your pom or the token is long. -
ignoreMissingFile
private boolean ignoreMissingFileIgnore missing target file. Use only with file configuration (not includes etc). Set to true to not fail build if the file is not found. First checks if file exists and exits without attempting to replace anything. -
value
Value to replace token with. The text to be written over any found tokens. If no value is given, the tokens found are replaced with an empty string (effectively removing any tokens found). You can also reference grouped regex matches made in the token here by $1, $2, etc. -
valueFile
A file containing a value to replace the given token with. May be multiple words or lines. This is useful if you do not wish to expose the value within your pom or the value is long. -
regex
private boolean regexIndicates if the token should be located with regular expressions. This should be set to false if the token contains regex characters which may miss the desired tokens or even replace the wrong tokens. -
outputFile
Output to another file. The input file is read and the final output (after replacing tokens) is written to this file. The path and file are created if it does not exist. If it does exist, the contents are overwritten. You should not use outputFile when using a list of includes. -
outputDir
Output to another dir. Destination directory relative to the execution directory for all replaced files to be written to. Use with outputDir to have files written to a specific base location. -
tokenValueMap
Map of tokens and respective values to replace with. A file containing tokens and respective values to replace with. This file may contain multiple entries to support a single file containing different tokens to have replaced. Each token/value pair should be in the format: "token=value" (without quotations). If your token contains ='s you must escape the = character to \=. e.g. tok\=en=value -
basedir
Optional base directory for each file to replace. Path to base relative files for replacements from. This feature is useful for multi-module projects. Default "." which is the default Maven basedir. -
regexFlags
List of standard Java regular expression Pattern flags (see Java Doc). Must contain one or more of: * CANON_EQ * CASE_INSENSITIVE * COMMENTS * DOTALL * LITERAL * MULTILINE * UNICODE_CASE * UNIX_LINES -
replacements
List of replacements with token/value pairs. Each replacement element to contain sub-elements as token/value pairs. Each token within the given file will be replaced by it's respective value. -
commentsEnabled
private boolean commentsEnabledComments enabled in the tokenValueMapFile. Comment lines start with '#'. If your token starts with an '#' then you must supply the commentsEnabled parameter and with a value of false. Default is true. -
skip
private boolean skipSkip running this plugin. Default is false. -
outputBasedir
Base directory (appended) to use for outputDir. Having this existing but blank will cause the outputDir to be based on the execution directory. -
preserveDir
private boolean preserveDirParent directory is preserved when replacing files found from includes and being written to an outputDir. Default is true. -
quiet
private boolean quietStops printing a summary of files that have had replacements performed upon them when true. Default is false. -
unescape
private boolean unescapeUnescape tokens and values to Java format. e.g. token\n is unescaped to token(carriage return). Default is false. -
delimiters
Add a list of delimiters which are added on either side of tokens to match against. You may also use the '' character to place the token in the desired location for matching. e.g. @ would match @token@. e.g. ${} would match ${token}. -
variableTokenValueMap
Variable tokenValueMap. Same as the tokenValueMap but can be an include configuration rather than an outside property file. Similar to tokenValueMap but incline configuration inside the pom. This parameter may contain multiple entries to support a single file containing different tokens to have replaced. Format is comma separated. e.g. token=value,token2=value2 Comments are not supported. -
ignoreErrors
private boolean ignoreErrorsIgnore any errors produced by this plugin such as files not being found and continue with the build. First checks if file exists and exits without attempting to replace anything. Only usable with file parameter. Default is false. -
xpath
X-Path expression for locating node's whose content you wish to replace. This is useful if you have the same token appearing in many nodes but wish to only replace the contents of one or more of them. -
encoding
File encoding used when reading and writing files. Default system encoding used when not specified. -
inputFilePattern
Regular expression is run on an input file's name to create the output file with. Must be used in conjunction with outputFilePattern. -
outputFilePattern
Regular expression groups from inputFilePattern are used in this pattern to create an output file per input file. Must be used in conjunction with inputFilePattern. The parameter outputFile is ignored when outputFilePattern is used. -
maxReplacements
Set a maximum number of files which can be replaced per execution. -
files
list files -
outputFiles
list out put file
-
-
Constructor Details
-
ReplacerMojo
public ReplacerMojo() -
ReplacerMojo
public ReplacerMojo(FileUtils fileUtils, ReplacementProcessor processor, ReplacerFactory replacerFactory, TokenValueMapFactory tokenValueMapFactory, FileSelector fileSelector, PatternFlagsFactory patternFlagsFactory, OutputFilenameBuilder outputFilenameBuilder, SummaryBuilder summaryBuilder)
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
limit
-
checkFileExists
private boolean checkFileExists() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getBaseDirPrefixedFilename
-
addIncludesFilesAndExcludedFiles
private void addIncludesFilesAndExcludedFiles() -
addToList
-
replaceContents
private void replaceContents(ReplacementProcessor processor, List<Replacement> replacements, String inputFile) throws IOException - Throws:
IOException
-
replaceContents
private void replaceContents(ReplacementProcessor processor, List<Replacement> replacements, List<String> inputFiles) throws IOException - Throws:
IOException
-
buildReplacements
- Throws:
IOException
-
getDelimiterReplacements
-
buildDelimiters
-
setRegex
public void setRegex(boolean regex) -
setFile
-
getFile
-
setToken
-
setValue
-
setTokenFile
-
setValueFile
-
setIgnoreMissingFile
public void setIgnoreMissingFile(boolean ignoreMissingFile) -
setOutputFile
-
setTokenValueMap
-
setFilesToInclude
-
setFilesToExclude
-
setBasedir
-
setReplacements
-
setRegexFlags
-
setIncludes
-
getIncludes
-
setExcludes
-
getExcludes
-
getFilesToInclude
-
getFilesToExclude
-
setOutputDir
-
isCommentsEnabled
public boolean isCommentsEnabled() -
setCommentsEnabled
public void setCommentsEnabled(boolean commentsEnabled) -
setOutputBasedir
-
isPreserveDir
public boolean isPreserveDir() -
setPreserveDir
public void setPreserveDir(boolean preserveDir) -
getBasedir
-
getOutputDir
-
getOutputBasedir
-
getOutputFile
-
setQuiet
public void setQuiet(boolean quiet) -
setDelimiters
-
getDelimiters
-
setUnescape
public void setUnescape(boolean unescape) -
isUnescape
public boolean isUnescape() -
setVariableTokenValueMap
-
getVariableTokenValueMap
-
setIgnoreErrors
public void setIgnoreErrors(boolean ignoreErrors) -
isIgnoreErrors
public boolean isIgnoreErrors() -
setXpath
-
setEncoding
-
setInputFilePattern
-
setOutputFilePattern
-
getInputFilePattern
-
getOutputFilePattern
-
setSkip
public void setSkip(boolean skip) -
isSkip
public boolean isSkip() -
setMaxReplacements
-
getFiles
-
setFiles
-
getOutputFiles
-
setOutputFiles
-