Merge branch 'develop' into stable
This commit is contained in:
commit
1adf5afc87
@ -39,6 +39,9 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
|
|
||||||
@Parameter( property = "patterns", required = true )
|
@Parameter( property = "patterns", required = true )
|
||||||
protected List<String> patterns;
|
protected List<String> patterns;
|
||||||
|
|
||||||
|
@Parameter( property = "negate", required = true, defaultValue = "false" )
|
||||||
|
protected boolean negate = false;
|
||||||
|
|
||||||
private List<Pattern> compiledPatterns;
|
private List<Pattern> compiledPatterns;
|
||||||
|
|
||||||
@ -47,6 +50,8 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
boolean matches = this.matches(text);
|
boolean matches = this.matches(text);
|
||||||
if (matches)
|
if (matches)
|
||||||
this.getLog().debug("Matches!");
|
this.getLog().debug("Matches!");
|
||||||
|
if (props == null)
|
||||||
|
props = this.project.getProperties();
|
||||||
props.setProperty(newPropertyName, String.valueOf(matches));
|
props.setProperty(newPropertyName, String.valueOf(matches));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,30 +84,28 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
|
|
||||||
if (this.allowMultiLineMatch)
|
if (this.allowMultiLineMatch)
|
||||||
return this.matches(strbuilder.toString());
|
return this.matches(strbuilder.toString());
|
||||||
return false;
|
return this.negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matches(String text) {
|
protected boolean matches(String text) {
|
||||||
|
if (text == null)
|
||||||
|
text = "";
|
||||||
|
|
||||||
for (Pattern pattern : this.compiledPatterns) {
|
for (Pattern pattern : this.compiledPatterns) {
|
||||||
this.getLog().debug("Applying regex pattern: " + pattern);
|
this.getLog().debug("Applying regex pattern: " + pattern);
|
||||||
|
this.getLog().debug("Operating on value: " + text);
|
||||||
if (text == null) {
|
|
||||||
// TODO we want to capture this somehow
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
if (this.allowPartialMatch) {
|
||||||
|
if (matcher.find())
|
||||||
|
return !this.negate;
|
||||||
} else {
|
} else {
|
||||||
this.getLog().debug("Operating on value: " + text);
|
if (matcher.matches())
|
||||||
|
return !this.negate;
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
if (this.allowPartialMatch) {
|
|
||||||
if (matcher.find())
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (matcher.matches())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return this.negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,12 +82,10 @@ public abstract class AbstractRegexMojo extends AbstractMojo {
|
|||||||
this.getLog().debug("Finding property: " + propertyName);
|
this.getLog().debug("Finding property: " + propertyName);
|
||||||
|
|
||||||
Properties props = this.propResolver.resolveScope(propertyName);
|
Properties props = this.propResolver.resolveScope(propertyName);
|
||||||
if (props == null) {
|
if (props == null)
|
||||||
this.getLog().info("Property not found: " + propertyName);
|
this.getLog().debug("Property not found: " + propertyName);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String propertyValue = props.getProperty(propertyName);
|
String propertyValue = props == null ? null : props.getProperty(propertyName);
|
||||||
this.executeOnText(props, propertyValue, newPropertyName);
|
this.executeOnText(props, propertyValue, newPropertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,15 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
||||||
|
if (text == null)
|
||||||
|
text = "";
|
||||||
String originalText = text;
|
String originalText = text;
|
||||||
text = this.replaceAll(text);
|
text = this.replaceAll(text);
|
||||||
|
|
||||||
if (this.getLog().isDebugEnabled() && !text.equals(originalText))
|
if (this.getLog().isDebugEnabled() && !text.equals(originalText))
|
||||||
this.getLog().debug("Manipulated value: " + text);
|
this.getLog().debug("Manipulated value: " + text);
|
||||||
|
if (props == null)
|
||||||
|
props = this.project.getProperties();
|
||||||
props.setProperty(newPropertyName, text);
|
props.setProperty(newPropertyName, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,20 +110,17 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String replaceFirst(String text) {
|
protected String replaceFirst(String text) {
|
||||||
|
if (text == null)
|
||||||
|
text = "";
|
||||||
if (this.getLog().isDebugEnabled())
|
if (this.getLog().isDebugEnabled())
|
||||||
this.getLog().debug("replace first: " + text.length());
|
this.getLog().debug("replace first: " + text.length());
|
||||||
|
|
||||||
for (Pair<Pattern, String> regex : this.compiledRegexes) {
|
for (Pair<Pattern, String> regex : this.compiledRegexes) {
|
||||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
||||||
|
this.getLog().debug("Operating on value: " + text);
|
||||||
if (text == null) {
|
|
||||||
// TODO we want to capture this somehow
|
Matcher matcher = regex.getLeft().matcher(text);
|
||||||
} else {
|
text = matcher.replaceFirst(regex.getRight());
|
||||||
this.getLog().debug("Operating on value: " + text);
|
|
||||||
|
|
||||||
Matcher matcher = regex.getLeft().matcher(text);
|
|
||||||
text = matcher.replaceFirst(regex.getRight());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
@ -180,20 +181,17 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String replaceAll(String text) {
|
protected String replaceAll(String text) {
|
||||||
|
if (text == null)
|
||||||
|
text = "";
|
||||||
if (this.getLog().isDebugEnabled())
|
if (this.getLog().isDebugEnabled())
|
||||||
this.getLog().debug("replace all: " + text.length());
|
this.getLog().debug("replace all: " + text.length());
|
||||||
|
|
||||||
for (Pair<Pattern, String> regex : this.compiledRegexes) {
|
for (Pair<Pattern, String> regex : this.compiledRegexes) {
|
||||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
||||||
|
this.getLog().debug("Operating on value: " + text);
|
||||||
if (text == null) {
|
|
||||||
// TODO we want to capture this somehow
|
Matcher matcher = regex.getLeft().matcher(text);
|
||||||
} else {
|
text = matcher.replaceAll(regex.getRight());
|
||||||
this.getLog().debug("Operating on value: " + text);
|
|
||||||
|
|
||||||
Matcher matcher = regex.getLeft().matcher(text);
|
|
||||||
text = matcher.replaceAll(regex.getRight());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
@ -69,7 +69,7 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return this.negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user