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 Details

    • INVALID_IGNORE_MISSING_FILE_MESSAGE

      private static final String INVALID_IGNORE_MISSING_FILE_MESSAGE
      See Also:
    • REGEX_PATTERN_WITH_DELIMITERS_MESSAGE

      private static final String REGEX_PATTERN_WITH_DELIMITERS_MESSAGE
      See Also:
    • fileUtils

      private final FileUtils fileUtils
    • replacerFactory

      private final ReplacerFactory replacerFactory
    • tokenValueMapFactory

      private final TokenValueMapFactory tokenValueMapFactory
    • fileSelector

      private final FileSelector fileSelector
    • patternFlagsFactory

      private final PatternFlagsFactory patternFlagsFactory
    • outputFilenameBuilder

      private final OutputFilenameBuilder outputFilenameBuilder
    • summaryBuilder

      private final SummaryBuilder summaryBuilder
    • processor

      private final ReplacementProcessor processor
    • file

      private String 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

      private List<String> includes
      List of files to include for multiple (or single) replacement. In Ant format (*\/directory/**.properties) Cannot use with outputFile.
    • excludes

      private List<String> excludes
      List of files to exclude for multiple (or single) replacement. In Ant format (*\/directory/**.properties) Cannot use with outputFile.
    • filesToInclude

      private String 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

      private String 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

      private String 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

      private String 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 ignoreMissingFile
      Ignore 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

      private String 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

      private String 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 regex
      Indicates 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

      private String 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

      private String 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

      private String 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

      private String 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

      private List<String> 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

      private List<Replacement> 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 commentsEnabled
      Comments 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 skip
      Skip running this plugin. Default is false.
    • outputBasedir

      private String 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 preserveDir
      Parent directory is preserved when replacing files found from includes and being written to an outputDir. Default is true.
    • quiet

      private boolean quiet
      Stops printing a summary of files that have had replacements performed upon them when true. Default is false.
    • unescape

      private boolean unescape
      Unescape tokens and values to Java format. e.g. token\n is unescaped to token(carriage return). Default is false.
    • delimiters

      private List<String> 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

      private String 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 ignoreErrors
      Ignore 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

      private String 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

      private String encoding
      File encoding used when reading and writing files. Default system encoding used when not specified.
    • inputFilePattern

      private String 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

      private String 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

      private Integer maxReplacements
      Set a maximum number of files which can be replaced per execution.
    • files

      private List<String> files
      list files
    • outputFiles

      private List<String> outputFiles
      list out put file
  • Constructor Details

  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • limit

      private <T> List<T> limit(List<T> all)
    • checkFileExists

      private boolean checkFileExists() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getBaseDirPrefixedFilename

      private String getBaseDirPrefixedFilename(String file)
    • addIncludesFilesAndExcludedFiles

      private void addIncludesFilesAndExcludedFiles()
    • addToList

      private void addToList(List<String> toAdds, List<String> destination)
    • 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

      private List<Replacement> buildReplacements() throws IOException
      Throws:
      IOException
    • getDelimiterReplacements

      private List<Replacement> getDelimiterReplacements(List<Replacement> replacements)
    • buildDelimiters

      private List<DelimiterBuilder> buildDelimiters()
    • setRegex

      public void setRegex(boolean regex)
    • setFile

      public void setFile(String file)
    • getFile

      public String getFile()
    • setToken

      public void setToken(String token)
    • setValue

      public void setValue(String value)
    • setTokenFile

      public void setTokenFile(String tokenFile)
    • setValueFile

      public void setValueFile(String valueFile)
    • setIgnoreMissingFile

      public void setIgnoreMissingFile(boolean ignoreMissingFile)
    • setOutputFile

      public void setOutputFile(String outputFile)
    • setTokenValueMap

      public void setTokenValueMap(String tokenValueMap)
    • setFilesToInclude

      public void setFilesToInclude(String filesToInclude)
    • setFilesToExclude

      public void setFilesToExclude(String filesToExclude)
    • setBasedir

      public void setBasedir(String baseDir)
    • setReplacements

      public void setReplacements(List<Replacement> replacements)
    • setRegexFlags

      public void setRegexFlags(List<String> regexFlags)
    • setIncludes

      public void setIncludes(List<String> includes)
    • getIncludes

      public List<String> getIncludes()
    • setExcludes

      public void setExcludes(List<String> excludes)
    • getExcludes

      public List<String> getExcludes()
    • getFilesToInclude

      public String getFilesToInclude()
    • getFilesToExclude

      public String getFilesToExclude()
    • setOutputDir

      public void setOutputDir(String outputDir)
    • isCommentsEnabled

      public boolean isCommentsEnabled()
    • setCommentsEnabled

      public void setCommentsEnabled(boolean commentsEnabled)
    • setOutputBasedir

      public void setOutputBasedir(String outputBasedir)
    • isPreserveDir

      public boolean isPreserveDir()
    • setPreserveDir

      public void setPreserveDir(boolean preserveDir)
    • getBasedir

      public String getBasedir()
    • getOutputDir

      public String getOutputDir()
    • getOutputBasedir

      public String getOutputBasedir()
    • getOutputFile

      public String getOutputFile()
    • setQuiet

      public void setQuiet(boolean quiet)
    • setDelimiters

      public void setDelimiters(List<String> delimiters)
    • getDelimiters

      public List<String> getDelimiters()
    • setUnescape

      public void setUnescape(boolean unescape)
    • isUnescape

      public boolean isUnescape()
    • setVariableTokenValueMap

      public void setVariableTokenValueMap(String variableTokenValueMap)
    • getVariableTokenValueMap

      public String getVariableTokenValueMap()
    • setIgnoreErrors

      public void setIgnoreErrors(boolean ignoreErrors)
    • isIgnoreErrors

      public boolean isIgnoreErrors()
    • setXpath

      public void setXpath(String xpath)
    • setEncoding

      public void setEncoding(String encoding)
    • setInputFilePattern

      public void setInputFilePattern(String inputFilePattern)
    • setOutputFilePattern

      public void setOutputFilePattern(String outputFilePattern)
    • getInputFilePattern

      public String getInputFilePattern()
    • getOutputFilePattern

      public String getOutputFilePattern()
    • setSkip

      public void setSkip(boolean skip)
    • isSkip

      public boolean isSkip()
    • setMaxReplacements

      public void setMaxReplacements(Integer maxReplacements)
    • getFiles

      public List<String> getFiles()
    • setFiles

      public void setFiles(List<String> files)
    • getOutputFiles

      public List<String> getOutputFiles()
    • setOutputFiles

      public void setOutputFiles(List<String> outputFiles)