
com.google.code.maven_replacer_plugin.Replacement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-replacer-plugin Show documentation
Show all versions of maven-replacer-plugin Show documentation
Maven plugin to replace tokens in a given file with a value
The newest version!
package com.google.code.maven_replacer_plugin;
import java.io.IOException;
import org.apache.commons.lang.StringEscapeUtils;
import com.google.code.maven_replacer_plugin.file.FileUtils;
public class Replacement {
private final FileUtils fileUtils;
private DelimiterBuilder delimiter;
private boolean unescape;
private String token;
private String value;
private String xpath;
public Replacement() {
this.fileUtils = new FileUtils();
this.unescape = false;
}
public Replacement(FileUtils fileUtils, String token, String value, boolean unescape, String xpath) {
this.fileUtils = fileUtils;
setUnescape(unescape);
setToken(token);
setValue(value);
setXpath(xpath);
}
public void setTokenFile(String tokenFile) throws IOException {
if (tokenFile != null) {
setToken(fileUtils.readFile(tokenFile));
}
}
public void setValueFile(String valueFile) throws IOException {
if (valueFile != null) {
setValue(fileUtils.readFile(valueFile));
}
}
public String getToken() {
String newToken = unescape ? unescape(token) : token;
if (delimiter != null) {
return delimiter.apply(newToken);
}
return newToken;
}
public String getValue() {
return unescape ? unescape(value) : value;
}
public void setToken(String token) {
this.token = token;
}
public void setValue(String value) {
this.value = value;
}
private String unescape(String text) {
return StringEscapeUtils.unescapeJava(text);
}
public void setUnescape(boolean unescape) {
this.unescape = unescape;
}
public boolean isUnescape() {
return unescape;
}
public static Replacement from(Replacement replacement) {
return new Replacement(replacement.fileUtils, replacement.token, replacement.value,
replacement.unescape, replacement.xpath);
}
public Replacement withDelimiter(DelimiterBuilder delimiter) {
this.delimiter = delimiter;
return this;
}
public void setXpath(String xpath) {
this.xpath = xpath;
}
public String getXpath() {
return xpath;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy