10 Commits
Author SHA1 Message Date
brian.long e42277aa14 v1.0.5 pom 2023-06-16 08:58:46 -04:00
brian.long d1dce94275 Merge branch 'develop' into stable 2023-06-16 08:58:30 -04:00
brian.long 036a672b65 added 'previousPattern' support 2023-06-16 08:58:18 -04:00
brian.long dafcc20e0f v1.0.4 pom 2023-03-04 16:04:02 -05:00
brian.long 5ec4924743 Merge branch 'develop' into stable 2023-03-04 16:03:16 -05:00
brian.long 434045f5d1 updated to Maven v3.9.0 2023-03-04 16:03:05 -05:00
brian.long 0af5425292 minor spacing fixes 2022-10-01 21:27:36 -04:00
brian.long 085f7231f7 http to https XSI 2022-09-30 22:40:48 -04:00
brian.long a61e5bc538 Merge branch 'develop' into stable 2022-07-18 11:35:18 -04:00
brian.long 903cdcee6b documentation update 2022-07-18 11:35:00 -04:00
20 changed files with 324 additions and 58 deletions
+196
View File
@@ -0,0 +1,196 @@
# Regular Expression Maven Plugin
This is a maven plugin that provides various regular expression based goals to Maven.
## Usage
```xml
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>com.inteligr8</groupId>
<artifactId>regex-maven-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<id>sample-regex-test</id>
<phase>validate</phase>
<goals><goal>replace-property</goal></goals>
<configuration>
<property>a.property.to.eval</property>
<regexes>
<regex>
<pattern>\.txt<pattern>
<replacement></replacement>
</regex>
</regexes>
<newProperty>a.new.property.to.set</newProperty>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
```
## Goals
| Goal | Description |
| -------------------- | ----------- |
| `replace-file` | Apply a regular expression pattern against the contents of a file, replacing matches with the regex-compliant replacement text. The existing file is changed. |
| `replace-properties` | Apply a regular expression pattern against a set of property values, replacing matches with the regex-compliant replacement text, and storing in new properties. |
| `replace-property` | Apply a regular expression pattern against a property value, replacing matches with the regex-compliant replacement text, and storing in a new property. |
| `replace-text` | Apply a regular expression pattern against text, replacing matches with the regex-compliant replacement text, and storing in a new property. |
| `match-file` | Evaluate a regular expression pattern against the contents of a file, storing the result in a boolean property. |
| `match-filename` | Evaluate a regular expression pattern against the name of a file, storing the result in a boolean property. |
| `match-properties` | Evaluate a regular expression pattern against a set of property values, storing the result in boolean properties. |
| `match-property` | Evaluate a regular expression pattern against a property value, storing the result in a boolean property. |
| `match-text` | Evaluate a regular expression pattern against text, storing the result in a boolean property. |
| `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. |
### Goal: `replace-file`
| 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`. |
| `filesets` | `FileSet[]` | Yes | | Executes against these 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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| -------- | ----------- |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- |
| `text` | `String` | Yes | | Execute against this text. |
| `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. |
| `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`
| 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`. |
| `filesets` | `FileSet[]` | Yes | | Executes against these files. |
| `newProperty` | `String` | Yes | | If a single regular expression matches the contents in a single file, then this property will be set to `true`; `false` otherwise. |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `sourceDirectory` | `File` | Yes | | Executes against this file. |
| `newProperty` | `String` | Yes | | If a single regular expression matches the name of the file, then this property will be set to `true`; `false` otherwise. |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| -------- | ----------- |
| `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. |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- |
| `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. |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- |
| `text` | `String` | Yes | | Execute against this text. |
| `newProperty` | `String` | Yes | | The evaluated text will be copied to this property name. |
| `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. |
| `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`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| --------- | ----------- |
| `sourceDirectory` | `File` | | ${basedir} | Copy all files from this directory. |
| `targetDirectory` | `File` | | ${basedir} | Copy all files to this directory. |
| `overwrite` | `boolean` | | `true` | |
### Goal: `move-file`
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| --------- | ----------- |
| `sourceDirectory` | `File` | | ${basedir} | Move all files from this directory. |
| `targetDirectory` | `File` | | ${basedir} | Move all files to this directory. |
| `overwrite` | `boolean` | | `true` | |
## Model
### Object Type: `Regex`
| Element | Data Type | Required | Default | Description |
| ----------------- |:---------:|:--------:| ------- | ----------- |
| `pattern` | `String` | Yes | | A regular expression pattern. |
| `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. |
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.
+68 -28
View File
@@ -2,17 +2,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
<artifactId>regex-maven-plugin</artifactId>
<version>1.0.3</version>
<version>1.0.5</version>
<packaging>maven-plugin</packaging>
<name>A Maven plugin for regex operations</name>
<name>Regular Expression Maven Plugin</name>
<description>A Maven plugin for regular expression operations</description>
<url>https://bitbucket.org/inteligr8/regex-maven-plugin</url>
<licenses>
<license>
<name>GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:https://bitbucket.org/inteligr8/regex-maven-plugin.git</connection>
<developerConnection>scm:git:git@bitbucket.org:inteligr8/regex-maven-plugin.git</developerConnection>
<url>https://bitbucket.org/inteligr8/regex-maven-plugin</url>
</scm>
<organization>
@@ -32,7 +43,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.version>3.6.3</maven.version>
<maven.version>3.9.0</maven.version>
</properties>
<dependencies>
@@ -44,7 +55,7 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>file-management</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
@@ -55,7 +66,7 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<version>3.7.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -142,19 +153,6 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>javadoc</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<show>public</show>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
@@ -189,14 +187,56 @@
</plugins>
</build>
</profile>
<profile>
<id>ossrh-release</id>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>source</id>
<phase>package</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>javadoc</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<show>public</show>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign</id>
<phase>verify</phase>
<goals><goal>sign</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<repository>
<id>inteligr8-releases</id>
<name>Inteligr8 Releases</name>
<url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
</repository>
</distributionManagement>
</project>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId>
@@ -18,6 +18,7 @@ public class Regex implements Normalizable {
private String pattern;
private String replacement;
private String previousPattern;
public String getPattern() {
return this.pattern;
@@ -27,6 +28,10 @@ public class Regex implements Normalizable {
return this.replacement;
}
public String getPreviousPattern() {
return previousPattern;
}
public Regex setPattern(String pattern) {
this.pattern = pattern;
return this;
@@ -37,6 +42,11 @@ public class Regex implements Normalizable {
return this;
}
public Regex setPreviousPattern(String previousPattern) {
this.previousPattern = previousPattern;
return this;
}
@Override
public void normalize() {
if (this.replacement == null)
@@ -16,8 +16,6 @@ package com.inteligr8.maven.regex;
import java.util.Properties;
import javax.annotation.OverridingMethodsMustInvokeSuper;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -63,17 +61,14 @@ public abstract class AbstractRegexMojo extends AbstractMojo {
protected abstract void go() throws MojoExecutionException, MojoFailureException;
@OverridingMethodsMustInvokeSuper
protected void validateParamsPreNormalization() throws MojoFailureException {
this.getLog().debug("Validating parameters before their normalization");
}
@OverridingMethodsMustInvokeSuper
protected void normalizeParameters() throws MojoFailureException {
this.getLog().debug("Normalizing parameters");
}
@OverridingMethodsMustInvokeSuper
protected void validateParamsPostNormalization() throws MojoFailureException {
this.getLog().debug("Validating parameters after their normalization");
}
@@ -30,8 +30,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
@@ -44,7 +45,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
protected List<Regex> regexes;
// Pattern does not implement hashCode, so not using a Map
private List<Pair<Pattern, String>> compiledRegexes;
private List<Triple<Pattern, String, Pattern>> compiledRegexes;
@Override
protected void executeOnText(Properties props, String text, String newPropertyName) {
@@ -118,12 +119,20 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
if (this.getLog().isDebugEnabled())
this.getLog().debug("replace first: " + text.length());
for (Pair<Pattern, String> regex : this.compiledRegexes) {
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
this.getLog().debug("Operating on value: " + text);
Matcher matcher = regex.getLeft().matcher(text);
text = matcher.replaceFirst(regex.getRight());
if (regex.getRight() == null) {
text = matcher.replaceFirst(regex.getMiddle());
} else if (matcher.find()) {
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
text = text.substring(0, previousMatchStart) + text.substring(matcher.start());
matcher = regex.getLeft().matcher(text);
text = matcher.replaceFirst(regex.getMiddle());
}
}
return text;
@@ -199,16 +208,33 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
if (this.getLog().isDebugEnabled())
this.getLog().debug("replace all: " + text.length());
for (Pair<Pattern, String> regex : this.compiledRegexes) {
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
this.getLog().debug("Operating on value: " + text);
Matcher matcher = regex.getLeft().matcher(text);
text = matcher.replaceAll(regex.getRight());
if (regex.getRight() == null) {
text = matcher.replaceAll(regex.getMiddle());
} else while (matcher.find()) {
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
text = text.substring(0, previousMatchStart) + text.substring(matcher.start());
matcher = regex.getLeft().matcher(text);
text = matcher.replaceFirst(regex.getMiddle());
}
}
return text;
}
private Integer findLastMatchIndex(Pattern pattern, String text) {
Matcher matcher = pattern.matcher(text);
Integer index = null;
while (matcher.find())
index = matcher.start();
return index;
}
@Override
protected void validateParamsPreNormalization() throws MojoFailureException {
@@ -245,7 +271,9 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
this.getLog().debug("Compiling regex pattern: " + regex.getPattern());
try {
Pattern pattern = Pattern.compile(regex.getPattern());
this.compiledRegexes.add(new ImmutablePair<Pattern, String>(pattern, regex.getReplacement()));
String previousPatternStr = StringUtils.trimToNull(regex.getPreviousPattern());
Pattern previousPattern = previousPatternStr == null ? null : Pattern.compile(previousPatternStr);
this.compiledRegexes.add(new ImmutableTriple<>(pattern, regex.getReplacement(), previousPattern));
} catch (PatternSyntaxException pse) {
throw new MojoFailureException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage());
}
@@ -53,7 +53,7 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
}
private boolean matchesContentInFileSet() throws MojoExecutionException {
FileSetManager fsman = new FileSetManager(this.getLog());
FileSetManager fsman = new FileSetManager();
Path basepath = this.project.getBasedir().toPath();
try {
@@ -47,7 +47,7 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
private boolean replaceContentInFileSet() throws MojoExecutionException {
boolean didReplace = false;
FileSetManager fsman = new FileSetManager(this.getLog());
FileSetManager fsman = new FileSetManager();
Path basepath = this.project.getBasedir().toPath();
try {
@@ -28,7 +28,7 @@ public class ReplaceTextMojo extends AbstractReplaceMojo {
@Parameter( property = "text", required = true )
protected String text;
@Parameter( property = "newProperty", required = false )
@Parameter( property = "newProperty", required = true )
protected String newProperty;
@Override
@@ -23,8 +23,6 @@ import java.nio.charset.CharsetDecoder;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.OverridingMethodsMustInvokeSuper;
public class DelimitedReadableByteChannel implements ReadableByteChannel {
private final CharBuffer buffer;
@@ -50,7 +48,6 @@ public class DelimitedReadableByteChannel implements ReadableByteChannel {
}
@Override
@OverridingMethodsMustInvokeSuper
public void close() throws IOException {
this.rbchannel.close();
}