Merge branch 'develop' into stable

This commit is contained in:
Brian Long 2025-04-25 00:04:21 -04:00
commit 1ef59056bf
12 changed files with 148 additions and 88 deletions

View File

@ -58,52 +58,59 @@ This is a maven plugin that provides various regular expression based goals to M
| `copy-file` | A convenience goal that copies all files/folders specified in a source path to a target path. | | `copy-file` | A convenience goal that copies all files/folders specified in a source path to a target path. |
| `move-file` | A convenience goal that moves all files/folders specified in a source path to a target path. | | `move-file` | A convenience goal that moves all files/folders specified in a source path to a target path. |
### Common Configuration Properties
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
| `verbose` | `boolean` | | `false` | |
### Goal: `replace-file` ### Goal: `replace-file`
Manipulates all the contents in the specified files based the specified regular expression replacements.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- | | ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `chunkSize` | `int` | | `1024` | The streaming buffer/chunk size in bytes, while evaluating the regular expressions. Adjust for classic speed/memory trade-off. Be aware that files are processed line-by-line, unless `allowMultiLineMatch` is set to `true`. | | `chunkSize` | `int` | | `1024` | The streaming buffer/chunk size in bytes, while evaluating the regular expressions. Adjust for classic speed/memory trade-off. Be aware that files are processed line-by-line, unless `allowMultiLineMatch` is set to `true`. |
| `filesets` | `FileSet[]` | Yes | | Executes against these files. | | `filesets` | `FileSet[]` | Yes | | Executes against these files. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. | | `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `replace-properties` ### Goal: `replace-properties`
Copies and replaces the values of the specified properties based on the specified regular expression replacements; storing the changed values in new properties.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| -------- | ----------- | | ---------------------- |:----------:|:--------:| -------- | ----------- |
| `properties` | `String[]` | Yes | | Executes against these properties. | | `properties` | `String[]` | Yes | | Executes against these properties. |
| `newPropertySuffix` | `String` | | `-regex` | All evaluated properties will be copied to new properties with the same property name plus this suffix. | | `newPropertySuffix` | `String` | | `-regex` | All evaluated properties will be copied to new properties with the same property name plus this suffix. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. | | `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `replace-property` ### Goal: `replace-property`
Copies and replaces the value of the specified property based on the specified regular expression replacements; storing the changed value in a new property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- | | ---------------------- |:----------:|:--------:| ------- | ----------- |
| `property` | `String` | Yes | | Executes against this property. | | `property` | `String` | Yes | | Executes against this property. |
| `newProperty` | `String` | | | The evaluated property will be copied to this property name. If not specified, it will be the same name as the `property` with a `-regex` suffix. | | `newProperty` | `String` | | | The evaluated property will be copied to this property name. If not specified, it will be the same name as the `property` with a `-regex` suffix. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. | | `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `replace-text` ### Goal: `replace-text`
Replaces the specified text based on the specified regular expression replacements; storing the result in a property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- | | ---------------------- |:----------:|:--------:| ------- | ----------- |
| `text` | `String` | Yes | | Execute against this text. | | `text` | `String` | Yes | | Execute against this text. |
| `newProperty` | `String` | Yes | | The evaluated text will be copied to this property name. | | `newProperty` | `String` | Yes | | The evaluated text will be copied to this property name. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. | | `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `match-file` ### Goal: `match-file`
Searches the contents of the specified files based using the specified regular expressions; storing the result of the search in a property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- | | ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `chunkSize` | `int` | | `1024` | The streaming buffer/chunk size in bytes, while evaluating the regular expressions. Adjust for classic speed/memory trade-off. Be aware that files are processed line-by-line, unless `allowMultiLineMatch` is set to `true`. | | `chunkSize` | `int` | | `1024` | The streaming buffer/chunk size in bytes, while evaluating the regular expressions. Adjust for classic speed/memory trade-off. Be aware that files are processed line-by-line, unless `allowMultiLineMatch` is set to `true`. |
@ -112,12 +119,11 @@ This is a maven plugin that provides various regular expression based goals to M
| `patterns` | `String[]` | Yes | | Evaluates these regular expressions against those files. | | `patterns` | `String[]` | Yes | | Evaluates these regular expressions against those files. |
| `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact line-by-line matching. | | `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact line-by-line matching. |
| `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. | | `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. This takes substantially more memory/time to process. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `match-filename` ### Goal: `match-filename`
Checks the filenames of the specified files based using the specified regular expressions; storing the result in a property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- | | ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `sourceDirectory` | `File` | Yes | | Executes against this file. | | `sourceDirectory` | `File` | Yes | | Executes against this file. |
@ -125,11 +131,11 @@ This is a maven plugin that provides various regular expression based goals to M
| `patterns` | `String[]` | Yes | | Evaluates these regular expressions the file. | | `patterns` | `String[]` | Yes | | Evaluates these regular expressions the file. |
| `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact filename matching. | | `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact filename matching. |
| `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. | | `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `match-properties` ### Goal: `match-properties`
Checks the values of the specified properties based on the specified regular expressions; storing the results in new properties.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| -------- | ----------- | | ---------------------- |:----------:|:--------:| -------- | ----------- |
| `properties` | `String[]` | Yes | | Executes against these properties. | | `properties` | `String[]` | Yes | | Executes against these properties. |
@ -137,12 +143,11 @@ This is a maven plugin that provides various regular expression based goals to M
| `patterns` | `String[]` | Yes | | Evaluates these regular expressions against those properties' values. | | `patterns` | `String[]` | Yes | | Evaluates these regular expressions against those properties' values. |
| `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. | | `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. |
| `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. | | `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. Very rare for property evaluation. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `match-property` ### Goal: `match-property`
Checks the value of the specified property based on the specified regular expressions; storing the result in a new property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- | | ---------------------- |:----------:|:--------:| ------- | ----------- |
| `property` | `String` | Yes | | Executes against this property. | | `property` | `String` | Yes | | Executes against this property. |
@ -150,12 +155,11 @@ This is a maven plugin that provides various regular expression based goals to M
| `patterns` | `String[]` | Yes | | Evaluates these regular expressions against the property value. | | `patterns` | `String[]` | Yes | | Evaluates these regular expressions against the property value. |
| `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. | | `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. |
| `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. | | `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. Very rare for property evaluation. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `match-text` ### Goal: `match-text`
Checks the specified text based on the specified regular expressions; storing the result in a property.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- | | ---------------------- |:----------:|:--------:| ------- | ----------- |
| `text` | `String` | Yes | | Execute against this text. | | `text` | `String` | Yes | | Execute against this text. |
@ -163,24 +167,27 @@ This is a maven plugin that provides various regular expression based goals to M
| `patterns` | `String[]` | Yes | | Evaluates these regular expressions against the property value. | | `patterns` | `String[]` | Yes | | Evaluates these regular expressions against the property value. |
| `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. | | `allowPartialMatch` | `boolean` | | `true` | A value of `true` allows for partial matching, rather than exact matching. |
| `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. | | `negate` | `boolean` | | `false` | A value of `true` will reverse the `true`/`false` on the resultant property value. |
| `allowMultiLineMatch` | `boolean` | | `false` | A value of `true` allows for multi-line matching. Very rare for property evaluation. |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
### Goal: `copy-file` ### Goal: `copy-file`
Copies all the files in the specified source directory while applying the specified regular expression replacements to their contents; storing the files in the specified target directory.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| --------- | ----------- | | ---------------------- |:---------:|:--------:| ---------- | ----------- |
| `sourceDirectory` | `File` | | ${basedir} | Copy all files from this directory. | | `sourceDirectory` | `File` | | ${basedir} | Copy all files from this directory. |
| `targetDirectory` | `File` | | ${basedir} | Copy all files to this directory. | | `targetDirectory` | `File` | | ${basedir} | Copy all files to this directory. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `overwrite` | `boolean` | | `true` | | | `overwrite` | `boolean` | | `true` | |
### Goal: `move-file` ### Goal: `move-file`
Moves all the files from the specified source directory while applying the specified regular expression replacements to their contents; storing the files in the specified target directory.
| Configuration Property | Data Type | Required | Default | Description | | Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| --------- | ----------- | | ---------------------- |:---------:|:--------:| ---------- | ----------- |
| `sourceDirectory` | `File` | | ${basedir} | Move all files from this directory. | | `sourceDirectory` | `File` | | ${basedir} | Move all files from this directory. |
| `targetDirectory` | `File` | | ${basedir} | Move all files to this directory. | | `targetDirectory` | `File` | | ${basedir} | Move all files to this directory. |
| `regexes` | `Regex[]` | Yes | | Applies these regular expressions and replacement text against those files. |
| `overwrite` | `boolean` | | `true` | | | `overwrite` | `boolean` | | `true` | |
## Model ## Model
@ -193,4 +200,4 @@ This is a maven plugin that provides various regular expression based goals to M
| `replacement` | `String` | | `` | A regular expression replacement string. | | `replacement` | `String` | | `` | A regular expression replacement string. |
| `previousPattern` | `String` | | | A regular expression pattern to look back against, removing everything down to and including the pattern. | | `previousPattern` | `String` | | | A regular expression pattern to look back against, removing everything down to and including the pattern. |
The `previousPattern` allows for you to match some text and remove everything before the match, up to the `prevoiusPattern. This is useful when matching a method and removing it and all its annotations. The `previousPattern` allows for you to match some text and remove everything before the match, up to the `prevoiusPattern`. This is useful when matching a method and removing it and all its annotations. If the `previousPattern` has no match, it will not remove any text before the primary match.

View File

@ -3,4 +3,6 @@ this is a multi line test file.
it is supposed to emulate larger files and multiline pattern matching. it is supposed to emulate larger files and multiline pattern matching.
sometimes this doesn՚t work with unicode characters.
good luck! good luck!

View File

@ -160,17 +160,17 @@
</requireFileChecksum> </requireFileChecksum>
<requireFileChecksum> <requireFileChecksum>
<file>${project.build.directory}/noreplace-one/folder1/file12.txt</file> <file>${project.build.directory}/noreplace-one/folder1/file12.txt</file>
<checksum>925a6e3bd25cdd61695aa55d008ab4d2</checksum> <checksum>725d3a15f631dda5b058357129fd17fd</checksum>
<type>md5</type> <type>md5</type>
</requireFileChecksum> </requireFileChecksum>
<requireFileChecksum> <requireFileChecksum>
<file>${project.build.directory}/replace-linestart/file12.txt</file> <file>${project.build.directory}/replace-linestart/file12.txt</file>
<checksum>fb1f2b040970526fc99b1339f22465f1</checksum> <checksum>791882a340c18da89b524d7735cc085c</checksum>
<type>md5</type> <type>md5</type>
</requireFileChecksum> </requireFileChecksum>
<requireFileChecksum> <requireFileChecksum>
<file>${basedir}/folder1/file12.txt</file> <file>${basedir}/folder1/file12.txt</file>
<checksum>a7f509275e16ff57cd7756cdca70822a</checksum> <checksum>6fb82d67ec64b04df220a11adfba81a3</checksum>
<type>md5</type> <type>md5</type>
</requireFileChecksum> </requireFileChecksum>
</rules> </rules>

View File

@ -21,9 +21,10 @@ import org.apache.maven.model.Profile;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@Component(role = ProjectPropertyResolver.class) @Component(role = ProjectPropertyResolver.class, instantiationStrategy = "per-lookup")
public class StandardProjectPropertyResolver implements ProjectPropertyResolver { public class StandardProjectPropertyResolver extends AbstractLogEnabled implements ProjectPropertyResolver {
@Requirement @Requirement
private MavenSession session; private MavenSession session;
@ -51,34 +52,38 @@ public class StandardProjectPropertyResolver implements ProjectPropertyResolver
private Properties findPropertiesObject(String key) { private Properties findPropertiesObject(String key) {
// search the user/cli properties first // search the user/cli properties first
Properties props = this.session.getUserProperties(); Properties props = this.session.getUserProperties();
if (props.containsKey(key)) if (props.containsKey(key)) {
this.getLogger().debug("Found in session user properties: " + key);
return props; return props;
// search the profiles next; in order (FIXME maybe we should go backwards?)
for (Profile profile : this.project.getActiveProfiles()) {
props = profile.getProperties();
if (props.containsKey(key))
return props;
} }
// now look at the project props MavenProject ancestor = this.project;
props = this.project.getProperties(); while (ancestor != null) {
if (props.containsKey(key)) // search the profiles next; in order (FIXME maybe we should go backwards?)
return props; for (Profile profile : ancestor.getActiveProfiles()) {
props = profile.getProperties();
// now recursively look up the parent project props if (props.containsKey(key)) {
MavenProject ancestor = this.project.getParent(); this.getLogger().debug("Found in project profile properties: " + ancestor.getArtifact() + ": " + profile.getId() + ": " + key);
while (ancestor != null) { return props;
props = ancestor.getProperties(); }
if (props.containsKey(key)) }
return props;
ancestor = ancestor.getParent(); // now look at the project props
} props = ancestor.getProperties();
if (props.containsKey(key)) {
this.getLogger().debug("Found in project properties: " + ancestor.getArtifact() + ": " + key);
return props;
}
ancestor = ancestor.getParent();
}
// search the system properties last (FIXME is this right?) // search the system properties last (FIXME is this right?)
props = this.session.getSystemProperties(); props = this.session.getSystemProperties();
if (props.containsKey(key)) if (props.containsKey(key)) {
this.getLogger().debug("Found in system properties: " + key);
return props; return props;
}
return null; return null;
} }

View File

@ -48,8 +48,10 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
@Override @Override
protected void executeOnText(Properties props, String text, String newPropertyName) { protected void executeOnText(Properties props, String text, String newPropertyName) {
boolean matches = this.matches(text); boolean matches = this.matches(text);
if (matches) if (this.verbose)
this.getLog().debug("Matches!"); this.getLog().info("Setting property: " + newPropertyName + ": " + matches);
else if (matches)
this.getLog().info("Matches!");
if (props == null) if (props == null)
props = this.project.getProperties(); props = this.project.getProperties();
props.setProperty(newPropertyName, String.valueOf(matches)); props.setProperty(newPropertyName, String.valueOf(matches));
@ -97,11 +99,17 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
Matcher matcher = pattern.matcher(text); Matcher matcher = pattern.matcher(text);
if (this.allowPartialMatch) { if (this.allowPartialMatch) {
if (matcher.find()) if (matcher.find()) {
if (this.verbose)
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
return !this.negate; return !this.negate;
}
} else { } else {
if (matcher.matches()) if (matcher.matches()) {
if (this.verbose)
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
return !this.negate; return !this.negate;
}
} }
} }

View File

@ -45,6 +45,9 @@ public abstract class AbstractRegexMojo extends AbstractMojo {
@Parameter( property = "skip", required = true, defaultValue = "false" ) @Parameter( property = "skip", required = true, defaultValue = "false" )
protected boolean skip = false; protected boolean skip = false;
@Parameter( property = "verbose", required = true, defaultValue = "false" )
protected boolean verbose = false;
public final void execute() throws MojoExecutionException, MojoFailureException { public final void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip) { if (this.skip) {

View File

@ -24,7 +24,6 @@ import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Properties; import java.util.Properties;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -42,7 +41,7 @@ import com.inteligr8.nio.DelimitedReadableByteChannel;
public abstract class AbstractReplaceMojo extends AbstractRegexMojo { public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
@Parameter( property = "regexes", required = true ) @Parameter( property = "regexes", required = true )
protected List<Regex> regexes; protected Regex[] regexes;
// Pattern does not implement hashCode, so not using a Map // Pattern does not implement hashCode, so not using a Map
private List<Triple<Pattern, String, Pattern>> compiledRegexes; private List<Triple<Pattern, String, Pattern>> compiledRegexes;
@ -53,9 +52,13 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
text = ""; text = "";
String originalText = text; String originalText = text;
text = this.replaceAll(text); text = this.replaceAll(text);
if (this.getLog().isDebugEnabled() && !text.equals(originalText)) if (!text.equals(originalText)) {
this.getLog().debug("Manipulated value: " + text); if (this.verbose)
this.getLog().info("Setting property: " + newPropertyName + ": " + text);
else if (this.getLog().isDebugEnabled())
this.getLog().debug("Manipulated value: " + text);
}
if (props == null) if (props == null)
props = this.project.getProperties(); props = this.project.getProperties();
props.setProperty(newPropertyName, text); props.setProperty(newPropertyName, text);
@ -205,8 +208,6 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
protected String replaceAll(String text) { protected String replaceAll(String text) {
if (text == null) if (text == null)
text = ""; text = "";
if (this.getLog().isDebugEnabled())
this.getLog().debug("replace all: " + text.length());
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) { for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
this.getLog().debug("Applying regex pattern: " + regex.getLeft()); this.getLog().debug("Applying regex pattern: " + regex.getLeft());
@ -214,13 +215,27 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
Matcher matcher = regex.getLeft().matcher(text); Matcher matcher = regex.getLeft().matcher(text);
if (regex.getRight() == null) { if (regex.getRight() == null) {
text = matcher.replaceAll(regex.getMiddle()); String newtext = matcher.replaceAll(regex.getMiddle());
if (this.verbose)
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
text = newtext;
} else while (matcher.find()) { } else while (matcher.find()) {
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start())); Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
text = text.substring(0, previousMatchStart) + text.substring(matcher.start()); if (previousMatchStart == null) {
// the previous pattern matches nothing; ignore
} else {
String newtext = text.substring(0, previousMatchStart) + text.substring(matcher.start());
if (this.verbose)
this.getLog().info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text);
text = newtext;
matcher = regex.getLeft().matcher(text);
}
matcher = regex.getLeft().matcher(text); String newtext = matcher.replaceFirst(regex.getMiddle());
text = matcher.replaceFirst(regex.getMiddle()); if (this.verbose)
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
text = newtext;
} }
} }
@ -240,7 +255,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
protected void validateParamsPreNormalization() throws MojoFailureException { protected void validateParamsPreNormalization() throws MojoFailureException {
super.validateParamsPreNormalization(); super.validateParamsPreNormalization();
if (this.regexes == null) if (this.regexes == null || this.regexes.length == 0)
throw new MojoFailureException("A 'regexes' element is required"); throw new MojoFailureException("A 'regexes' element is required");
} }
@ -248,22 +263,15 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
protected void normalizeParameters() throws MojoFailureException { protected void normalizeParameters() throws MojoFailureException {
super.normalizeParameters(); super.normalizeParameters();
ListIterator<Regex> r = this.regexes.listIterator(); for (Regex regex : this.regexes)
while (r.hasNext()) { regex.normalize();
Regex regex = r.next();
if (regex == null) {
r.remove();
} else {
regex.normalize();
}
}
} }
@Override @Override
protected void validateParamsPostNormalization() throws MojoFailureException { protected void validateParamsPostNormalization() throws MojoFailureException {
super.validateParamsPostNormalization(); super.validateParamsPostNormalization();
if (this.regexes.isEmpty()) if (this.regexes == null || this.regexes.length == 0)
throw new MojoFailureException("At least one 'regexes' element is required"); throw new MojoFailureException("At least one 'regexes' element is required");
this.compiledRegexes = new LinkedList<>(); this.compiledRegexes = new LinkedList<>();

View File

@ -33,6 +33,12 @@ public class CopyFileMojo extends AbstractFileMojo {
} else { } else {
Files.copy(sourcePath, targetPath); Files.copy(sourcePath, targetPath);
} }
if (this.verbose) {
this.getLog().info("Copied " + sourcePath + " to " + targetPath);
} else {
this.getLog().info("Copied " + sourcePath.getFileName() + " to " + targetPath);
}
} }
} }

View File

@ -47,7 +47,9 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
this.getLog().debug("Executing file regex match"); this.getLog().debug("Executing file regex match");
boolean matches = this.matchesContentInFileSet(); boolean matches = this.matchesContentInFileSet();
if (matches) if (this.verbose)
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
else if (matches)
this.getLog().info("Matches!"); this.getLog().info("Matches!");
this.project.getProperties().setProperty(this.newProperty, String.valueOf(matches)); this.project.getProperties().setProperty(this.newProperty, String.valueOf(matches));
} }
@ -64,8 +66,11 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
for (String filePathAndName : filePathsAndNames) { for (String filePathAndName : filePathsAndNames) {
Path file = baseInputPath.resolve(filePathAndName); Path file = baseInputPath.resolve(filePathAndName);
if (!Files.isDirectory(file)) if (!Files.isDirectory(file))
if (this.matches(file, this.chunkSize)) if (this.matches(file, this.chunkSize)) {
if (this.verbose)
this.getLog().info("A pattern matches file: " + file);
return true; return true;
}
} }
} }
} catch (IOException ie) { } catch (IOException ie) {

View File

@ -67,8 +67,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
if (!Files.isDirectory(file)) { if (!Files.isDirectory(file)) {
getLog().debug("Visiting file: " + file); getLog().debug("Visiting file: " + file);
if (matches(basepath.relativize(file).toString())) if (matches(basepath.relativize(file).toString())) {
if (MatchFilenameMojo.this.verbose)
MatchFilenameMojo.this.getLog().info("A pattern matches filename: " + file);
matches.setTrue(); matches.setTrue();
}
} }
return matches.isTrue() ? FileVisitResult.TERMINATE : FileVisitResult.CONTINUE; return matches.isTrue() ? FileVisitResult.TERMINATE : FileVisitResult.CONTINUE;
} }
@ -81,8 +84,10 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
} catch (IOException ie) { } catch (IOException ie) {
throw new MojoExecutionException(ie.getMessage(), ie); throw new MojoExecutionException(ie.getMessage(), ie);
} }
if (matches.booleanValue()) if (this.verbose)
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
else if (matches.booleanValue())
this.getLog().info("Matches!"); this.getLog().info("Matches!");
this.project.getProperties().setProperty(this.newProperty, matches.toString()); this.project.getProperties().setProperty(this.newProperty, matches.toString());
} }

View File

@ -33,6 +33,12 @@ public class MoveFileMojo extends AbstractFileMojo {
} else { } else {
Files.move(sourcePath, targetPath); Files.move(sourcePath, targetPath);
} }
if (this.verbose) {
this.getLog().info("Moved " + sourcePath + " to " + targetPath);
} else {
this.getLog().info("Moved " + sourcePath.getFileName() + " to " + targetPath);
}
} }
} }

View File

@ -62,8 +62,13 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
if (!Files.exists(tofile.getParent())) if (!Files.exists(tofile.getParent()))
Files.createDirectories(tofile.getParent()); Files.createDirectories(tofile.getParent());
if (!Files.isDirectory(file)) if (!Files.isDirectory(file)) {
didReplace = this.replaceAll(file, tofile, this.chunkSize) || didReplace; if (this.replaceAll(file, tofile, this.chunkSize)) {
if (this.verbose)
this.getLog().info("A pattern replaced in file: " + file + " => " + tofile);
didReplace = true;
}
}
} }
} }
} catch (IOException ie) { } catch (IOException ie) {