Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d18c6a136 | ||
|
|
1ef59056bf | ||
|
|
e42277aa14 | ||
|
|
d1dce94275 | ||
|
|
dafcc20e0f | ||
|
|
5ec4924743 | ||
|
|
a61e5bc538 | ||
|
|
e98241f06d | ||
|
|
e46dc26404 | ||
|
|
f8493c3983 | ||
|
|
1bb0190807 | ||
|
|
46b55e0ddc | ||
|
|
1adf5afc87 | ||
|
|
e8adafadfe |
@@ -1,18 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.1.0"
|
||||
<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.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
|
||||
<modelVersion>4.1.0</modelVersion>
|
||||
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>2.0-SNAPSHOT</version>
|
||||
<version>1.0.6</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>Regular Expression Maven Plugin</name>
|
||||
<description>A Maven plugin for regular expression operations</description>
|
||||
<url>https://git.inteligr8.com/inteligr8/regex-maven-plugin</url>
|
||||
<url>https://bitbucket.org/inteligr8/regex-maven-plugin</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
@@ -22,9 +22,9 @@
|
||||
</licenses>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://git.inteligr8.com/inteligr8/regex-maven-plugin.git</connection>
|
||||
<developerConnection>scm:git:git@git.inteligr8.com:inteligr8/regex-maven-plugin.git</developerConnection>
|
||||
<url>https://git.inteligr8.com/inteligr8/regex-maven-plugin</url>
|
||||
<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>
|
||||
<name>Inteligr8</name>
|
||||
@@ -35,110 +35,71 @@
|
||||
<id>brian.long</id>
|
||||
<name>Brian Long</name>
|
||||
<email>brian@inteligr8.com</email>
|
||||
<url>https://x.com/brianmlong</url>
|
||||
<url>https://twitter.com/brianmlong</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<maven.version>4.0.0-rc-5</maven.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.version>3.9.0</maven.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.20.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>file-management</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-core</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-annotations</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-testing</groupId>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-compat</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>6.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>file-management</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-core</artifactId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-annotations</artifactId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-testing</groupId>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-compat</artifactId>
|
||||
<version>${maven.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.15.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<goalPrefix>regex</goalPrefix>
|
||||
</configuration>
|
||||
@@ -157,10 +118,10 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-component-metadata</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -169,9 +130,9 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<configuration>
|
||||
<projectsDirectory>${basedir}/src/it</projectsDirectory>
|
||||
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
||||
@@ -207,6 +168,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-its</id>
|
||||
@@ -226,7 +188,7 @@
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>central-publish</id>
|
||||
<id>ossrh-release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -263,13 +225,14 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.13</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface ProjectPropertyResolver {
|
||||
|
||||
Properties resolveScope(String propertyName);
|
||||
|
||||
String resolve(String propertyName);
|
||||
|
||||
String resolve(String propertyName, String defaultValue);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
@Component(role = ProjectPropertyResolver.class, instantiationStrategy = "per-lookup")
|
||||
public class StandardProjectPropertyResolver extends AbstractLogEnabled implements ProjectPropertyResolver {
|
||||
|
||||
@Requirement
|
||||
private MavenSession session;
|
||||
|
||||
@Requirement
|
||||
private MavenProject project;
|
||||
|
||||
@Override
|
||||
public String resolve(String propertyName) {
|
||||
Properties props = this.findPropertiesObject(propertyName);
|
||||
return props == null ? null : props.getProperty(propertyName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(String propertyName, String defaultValue) {
|
||||
Properties props = this.findPropertiesObject(propertyName);
|
||||
return props == null ? null : props.getProperty(propertyName, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties resolveScope(String propertyName) {
|
||||
return this.findPropertiesObject(propertyName);
|
||||
}
|
||||
|
||||
private Properties findPropertiesObject(String key) {
|
||||
// search the user/cli properties first
|
||||
Properties props = this.session.getUserProperties();
|
||||
if (props.containsKey(key)) {
|
||||
this.getLogger().debug("Found in session user properties: " + key);
|
||||
return props;
|
||||
}
|
||||
|
||||
MavenProject ancestor = this.project;
|
||||
while (ancestor != null) {
|
||||
// search the profiles next; in order (FIXME maybe we should go backwards?)
|
||||
for (Profile profile : ancestor.getActiveProfiles()) {
|
||||
props = profile.getProperties();
|
||||
if (props.containsKey(key)) {
|
||||
this.getLogger().debug("Found in project profile properties: " + ancestor.getArtifact() + ": " + profile.getId() + ": " + key);
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
||||
// 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?)
|
||||
props = this.session.getSystemProperties();
|
||||
if (props.containsKey(key)) {
|
||||
this.getLogger().debug("Found in system properties: " + key);
|
||||
return props;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.regex.model;
|
||||
package com.inteligr8.maven.model;
|
||||
|
||||
public interface Normalizable {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.regex.model;
|
||||
package com.inteligr8.maven.model;
|
||||
|
||||
public class Regex implements Normalizable {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
@@ -21,31 +22,29 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "sourceDirectory", required = false )
|
||||
protected Path sourceDirectory;
|
||||
protected File sourceDirectory;
|
||||
|
||||
@Parameter( property = "targetDirectory", required = false )
|
||||
protected Path targetDirectory;
|
||||
protected File targetDirectory;
|
||||
|
||||
@Parameter( property = "overwrite", required = true, defaultValue = "true" )
|
||||
protected boolean overwrite = true;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing file regex");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing file regex");
|
||||
|
||||
final Path sourcePath = this.sourceDirectory.toPath();
|
||||
final Path targetPath = this.targetDirectory.toPath();
|
||||
try {
|
||||
Files.walkFileTree(this.sourceDirectory, new FileVisitor<Path>() {
|
||||
Files.walkFileTree(sourcePath, new FileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
@@ -62,12 +61,12 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (!Files.isDirectory(file)) {
|
||||
String relativePath = sourceDirectory.relativize(file).toString();
|
||||
String relativePath = sourcePath.relativize(file).toString();
|
||||
String replacedRelativePath = replaceFirst(relativePath);
|
||||
if (!relativePath.equals(replacedRelativePath)) {
|
||||
Path newFile = targetDirectory.resolve(replacedRelativePath);
|
||||
Path newFile = targetPath.resolve(replacedRelativePath);
|
||||
if (file.equals(newFile)) {
|
||||
AbstractFileMojo.this.logger.error("Relative paths are different, but the resultant paths are the same??");
|
||||
AbstractFileMojo.this.getLog().error("Relative paths are different, but the resultant paths are the same??");
|
||||
throw new RuntimeException("This should never happen");
|
||||
}
|
||||
|
||||
@@ -84,14 +83,14 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
||||
}
|
||||
});
|
||||
} catch (IOException ie) {
|
||||
throw new MojoException(ie.getMessage(), ie);
|
||||
throw new MojoExecutionException(ie.getMessage(), ie);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void executeOnFile(Path sourcePath, Path targetPath) throws IOException;
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
if (this.sourceDirectory == null)
|
||||
|
||||
@@ -22,21 +22,17 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel;
|
||||
import com.inteligr8.nio.DelimitedReadableByteChannel;
|
||||
|
||||
public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "allowPartialMatch", required = true, defaultValue = "true" )
|
||||
protected boolean allowPartialMatch = true;
|
||||
@@ -50,14 +46,15 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||
private List<Pattern> compiledPatterns;
|
||||
|
||||
@Override
|
||||
protected void executeOnText(String text, String newPropertyName) {
|
||||
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
||||
boolean matches = this.matches(text);
|
||||
if (this.verbose)
|
||||
this.logger.info("Setting property: " + newPropertyName + ": " + matches);
|
||||
this.getLog().info("Setting property: " + newPropertyName + ": " + matches);
|
||||
else if (matches)
|
||||
this.logger.info("Matches!");
|
||||
|
||||
this.manager.setProperty(this.project, newPropertyName, String.valueOf(matches));
|
||||
this.getLog().info("Matches!");
|
||||
if (props == null)
|
||||
props = this.project.getProperties();
|
||||
props.setProperty(newPropertyName, String.valueOf(matches));
|
||||
}
|
||||
|
||||
protected boolean matches(Path file, int chunkSize) throws IOException {
|
||||
@@ -97,20 +94,20 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||
text = "";
|
||||
|
||||
for (Pattern pattern : this.compiledPatterns) {
|
||||
this.logger.debug("Applying regex pattern: " + pattern);
|
||||
this.logger.debug("Operating on value: " + text);
|
||||
this.getLog().debug("Applying regex pattern: " + pattern);
|
||||
this.getLog().debug("Operating on value: " + text);
|
||||
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (this.allowPartialMatch) {
|
||||
if (matcher.find()) {
|
||||
if (this.verbose)
|
||||
this.logger.info("Pattern '" + pattern + "' matches text: " + text);
|
||||
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
|
||||
return !this.negate;
|
||||
}
|
||||
} else {
|
||||
if (matcher.matches()) {
|
||||
if (this.verbose)
|
||||
this.logger.info("Pattern '" + pattern + "' matches text: " + text);
|
||||
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
|
||||
return !this.negate;
|
||||
}
|
||||
}
|
||||
@@ -120,15 +117,15 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.patterns == null)
|
||||
throw new MojoException("A 'patterns' element is required");
|
||||
throw new MojoFailureException("A 'patterns' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
ListIterator<String> p = this.patterns.listIterator();
|
||||
@@ -141,19 +138,19 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.patterns.isEmpty())
|
||||
throw new MojoException("At least one 'patterns' element is required");
|
||||
throw new MojoFailureException("At least one 'patterns' element is required");
|
||||
|
||||
this.compiledPatterns = new LinkedList<>();
|
||||
for (String pattern : this.patterns) {
|
||||
this.logger.debug("Compiling regex pattern: " + pattern);
|
||||
this.getLog().debug("Compiling regex pattern: " + pattern);
|
||||
try {
|
||||
this.compiledPatterns.add(Pattern.compile(pattern));
|
||||
} catch (PatternSyntaxException pse) {
|
||||
throw new MojoException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage());
|
||||
throw new MojoFailureException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,30 +14,28 @@
|
||||
*/
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.api.Project;
|
||||
import org.apache.maven.api.Session;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.Mojo;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.api.services.ProjectManager;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
public abstract class AbstractRegexMojo implements Mojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
import com.inteligr8.maven.ProjectPropertyResolver;
|
||||
|
||||
public abstract class AbstractRegexMojo extends AbstractMojo {
|
||||
|
||||
@Inject
|
||||
protected Project project;
|
||||
@Parameter( defaultValue = "${project}", readonly = true )
|
||||
protected MavenProject project;
|
||||
|
||||
@Inject
|
||||
protected Session session;
|
||||
|
||||
@Inject
|
||||
protected ProjectManager manager;
|
||||
@Parameter( defaultValue = "${session}", readonly = true )
|
||||
protected MavenSession session;
|
||||
|
||||
@Requirement
|
||||
private ProjectPropertyResolver propResolver;
|
||||
|
||||
@Parameter( property = "allowMultiLineMatch", required = true, defaultValue = "false" )
|
||||
protected boolean allowMultiLineMatch = false;
|
||||
@@ -51,9 +49,9 @@ public abstract class AbstractRegexMojo implements Mojo {
|
||||
@Parameter( property = "verbose", required = true, defaultValue = "false" )
|
||||
protected boolean verbose = false;
|
||||
|
||||
public final void execute() throws MojoException {
|
||||
public final void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (this.skip) {
|
||||
this.logger.debug("Skipped execution");
|
||||
this.getLog().debug("Skipped execution");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,33 +62,31 @@ public abstract class AbstractRegexMojo implements Mojo {
|
||||
this.go();
|
||||
}
|
||||
|
||||
protected abstract void go() throws MojoException;
|
||||
protected abstract void go() throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
this.logger.debug("Validating parameters before their normalization");
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
this.getLog().debug("Validating parameters before their normalization");
|
||||
}
|
||||
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
this.logger.debug("Normalizing parameters");
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
this.getLog().debug("Normalizing parameters");
|
||||
}
|
||||
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
this.logger.debug("Validating parameters after their normalization");
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
this.getLog().debug("Validating parameters after their normalization");
|
||||
}
|
||||
|
||||
protected final void executeOnProperty(String propertyName, String newPropertyName) {
|
||||
this.logger.debug("Finding property: " + propertyName);
|
||||
this.getLog().debug("Finding property: " + propertyName);
|
||||
|
||||
// FIXME getEffectiveProperties() is not cached and could be expensive if called a lot
|
||||
// maybe create a session scoped service that handles that part
|
||||
Map<String, String> props = this.session.getEffectiveProperties(this.project);
|
||||
String existingPropertyValue = props.get(propertyName);
|
||||
if (existingPropertyValue == null)
|
||||
this.logger.debug("Property not found: " + propertyName);
|
||||
Properties props = this.propResolver.resolveScope(propertyName);
|
||||
if (props == null)
|
||||
this.getLog().debug("Property not found: " + propertyName);
|
||||
|
||||
this.executeOnText(existingPropertyValue, newPropertyName);
|
||||
String propertyValue = props == null ? null : props.getProperty(propertyName);
|
||||
this.executeOnText(props, propertyValue, newPropertyName);
|
||||
}
|
||||
|
||||
protected abstract void executeOnText(String text, String newPropertyName);
|
||||
protected abstract void executeOnText(Properties props, String text, String newPropertyName);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
@@ -31,18 +32,13 @@ import java.util.regex.PatternSyntaxException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import com.inteligr8.maven.regex.model.Regex;
|
||||
import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel;
|
||||
import com.inteligr8.maven.model.Regex;
|
||||
import com.inteligr8.nio.DelimitedReadableByteChannel;
|
||||
|
||||
public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "regexes", required = true )
|
||||
protected Regex[] regexes;
|
||||
@@ -51,7 +47,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
private List<Triple<Pattern, String, Pattern>> compiledRegexes;
|
||||
|
||||
@Override
|
||||
protected void executeOnText(String text, String newPropertyName) {
|
||||
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
||||
if (text == null)
|
||||
text = "";
|
||||
String originalText = text;
|
||||
@@ -59,17 +55,18 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
|
||||
if (!text.equals(originalText)) {
|
||||
if (this.verbose)
|
||||
this.logger.info("Setting property: " + newPropertyName + ": " + text);
|
||||
else if (this.logger.isDebugEnabled())
|
||||
this.logger.debug("Manipulated value: " + text);
|
||||
this.getLog().info("Setting property: " + newPropertyName + ": " + text);
|
||||
else if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("Manipulated value: " + text);
|
||||
}
|
||||
|
||||
this.manager.setProperty(this.project, newPropertyName, text);
|
||||
if (props == null)
|
||||
props = this.project.getProperties();
|
||||
props.setProperty(newPropertyName, text);
|
||||
}
|
||||
|
||||
protected boolean replaceFirst(Path file, Path tofile, int chunkSize) throws IOException {
|
||||
if (this.logger.isDebugEnabled())
|
||||
this.logger.debug("replace first: " + file + " => " + tofile);
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("replace first: " + file + " => " + tofile);
|
||||
|
||||
boolean didReplace = false;
|
||||
Charset charset = Charset.forName(this.charsetName);
|
||||
@@ -122,12 +119,12 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
protected String replaceFirst(String text) {
|
||||
if (text == null)
|
||||
text = "";
|
||||
if (this.logger.isDebugEnabled())
|
||||
this.logger.debug("replace first: " + text.length());
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("replace first: " + text.length());
|
||||
|
||||
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
||||
this.logger.debug("Applying regex pattern: " + regex.getLeft());
|
||||
this.logger.debug("Operating on value: " + text);
|
||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
||||
this.getLog().debug("Operating on value: " + text);
|
||||
|
||||
Matcher matcher = regex.getLeft().matcher(text);
|
||||
if (regex.getRight() == null) {
|
||||
@@ -145,8 +142,8 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
}
|
||||
|
||||
protected boolean replaceAll(Path file, Path tofile, int chunkSize) throws IOException {
|
||||
if (this.logger.isDebugEnabled())
|
||||
this.logger.debug("replace all: " + file + " => " + tofile);
|
||||
if (this.getLog().isDebugEnabled())
|
||||
this.getLog().debug("replace all: " + file + " => " + tofile);
|
||||
|
||||
boolean overwrite = file.equals(tofile);
|
||||
boolean didReplace = false;
|
||||
@@ -172,10 +169,10 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
strbuilder.append(rbchannel.getLastDelimiterRead());
|
||||
} else {
|
||||
String line = strbuilder.toString();
|
||||
this.logger.debug("line: " + line);
|
||||
this.getLog().debug("line: " + line);
|
||||
String processedLine = this.replaceAll(line);
|
||||
if (!didReplace || (this.logger.isDebugEnabled() && !line.equals(processedLine))) {
|
||||
this.logger.debug("replaced line: " + processedLine);
|
||||
if (!didReplace || (this.getLog().isDebugEnabled() && !line.equals(processedLine))) {
|
||||
this.getLog().debug("replaced line: " + processedLine);
|
||||
didReplace = true;
|
||||
}
|
||||
|
||||
@@ -213,14 +210,14 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
text = "";
|
||||
|
||||
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
||||
this.logger.debug("Applying regex pattern: " + regex.getLeft());
|
||||
this.logger.debug("Operating on value: " + text);
|
||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
||||
this.getLog().debug("Operating on value: " + text);
|
||||
|
||||
Matcher matcher = regex.getLeft().matcher(text);
|
||||
if (regex.getRight() == null) {
|
||||
String newtext = matcher.replaceAll(regex.getMiddle());
|
||||
if (this.verbose)
|
||||
this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||
text = newtext;
|
||||
} else while (matcher.find()) {
|
||||
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
|
||||
@@ -229,7 +226,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
} else {
|
||||
String newtext = text.substring(0, previousMatchStart) + text.substring(matcher.start());
|
||||
if (this.verbose)
|
||||
this.logger.info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text);
|
||||
this.getLog().info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text);
|
||||
text = newtext;
|
||||
|
||||
matcher = regex.getLeft().matcher(text);
|
||||
@@ -237,7 +234,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
|
||||
String newtext = matcher.replaceFirst(regex.getMiddle());
|
||||
if (this.verbose)
|
||||
this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||
text = newtext;
|
||||
}
|
||||
}
|
||||
@@ -255,15 +252,15 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.regexes == null || this.regexes.length == 0)
|
||||
throw new MojoException("A 'regexes' element is required");
|
||||
throw new MojoFailureException("A 'regexes' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
for (Regex regex : this.regexes)
|
||||
@@ -271,22 +268,22 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.regexes == null || this.regexes.length == 0)
|
||||
throw new MojoException("At least one 'regexes' element is required");
|
||||
throw new MojoFailureException("At least one 'regexes' element is required");
|
||||
|
||||
this.compiledRegexes = new LinkedList<>();
|
||||
for (Regex regex : this.regexes) {
|
||||
this.logger.debug("Compiling regex pattern: " + regex.getPattern());
|
||||
this.getLog().debug("Compiling regex pattern: " + regex.getPattern());
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(regex.getPattern());
|
||||
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 MojoException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage());
|
||||
throw new MojoFailureException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,12 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "copy-file")
|
||||
@Mojo( name = "copy-file", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class CopyFileMojo extends AbstractFileMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Override
|
||||
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
||||
@@ -38,9 +35,9 @@ public class CopyFileMojo extends AbstractFileMojo {
|
||||
}
|
||||
|
||||
if (this.verbose) {
|
||||
this.logger.info("Copied " + sourcePath + " to " + targetPath);
|
||||
this.getLog().info("Copied " + sourcePath + " to " + targetPath);
|
||||
} else {
|
||||
this.logger.info("Copied " + sourcePath.getFileName() + " to " + targetPath);
|
||||
this.getLog().info("Copied " + sourcePath.getFileName() + " to " + targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,19 +21,17 @@ import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.shared.model.fileset.FileSet;
|
||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "match-file")
|
||||
@Mojo( name = "match-file", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MatchFileContentMojo extends AbstractMatchMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
||||
protected int chunkSize = 1024;
|
||||
@@ -45,20 +43,20 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing file regex match");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing file regex match");
|
||||
|
||||
boolean matches = this.matchesContentInFileSet();
|
||||
if (this.verbose)
|
||||
this.logger.info("Setting property: " + this.newProperty + ": " + matches);
|
||||
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
|
||||
else if (matches)
|
||||
this.logger.info("Matches!");
|
||||
this.manager.setProperty(this.project, this.newProperty, String.valueOf(matches));
|
||||
this.getLog().info("Matches!");
|
||||
this.project.getProperties().setProperty(this.newProperty, String.valueOf(matches));
|
||||
}
|
||||
|
||||
private boolean matchesContentInFileSet() throws MojoException {
|
||||
private boolean matchesContentInFileSet() throws MojoExecutionException {
|
||||
FileSetManager fsman = new FileSetManager();
|
||||
Path basepath = this.project.getBasedir();
|
||||
Path basepath = this.project.getBasedir().toPath();
|
||||
|
||||
try {
|
||||
for (FileSet fileSet : this.filesets) {
|
||||
@@ -70,58 +68,58 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
||||
if (!Files.isDirectory(file))
|
||||
if (this.matches(file, this.chunkSize)) {
|
||||
if (this.verbose)
|
||||
this.logger.info("A pattern matches file: " + file);
|
||||
this.getLog().info("A pattern matches file: " + file);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ie) {
|
||||
throw new MojoException("Execution failed due to an I/O related issue", ie);
|
||||
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
||||
}
|
||||
|
||||
return this.negate;
|
||||
}
|
||||
|
||||
private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoException {
|
||||
private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoExecutionException {
|
||||
Path path = new File(directory).toPath();
|
||||
if (!path.isAbsolute())
|
||||
path = basepath.resolve(path);
|
||||
|
||||
if (!Files.exists(path))
|
||||
throw new MojoException("A " + errorName + " directory does not exist: " + directory);
|
||||
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
||||
|
||||
if (!Files.isDirectory(path))
|
||||
throw new MojoException("A " + errorName + " does reference a directory: " + directory);
|
||||
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.filesets == null || this.filesets.isEmpty())
|
||||
throw new MojoException("At least one 'fileset' is required");
|
||||
throw new MojoFailureException("At least one 'fileset' is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
for (FileSet fileset : this.filesets) {
|
||||
if (fileset.getDirectory() == null)
|
||||
fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString());
|
||||
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
|
||||
}
|
||||
|
||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.newProperty == null)
|
||||
throw new MojoException("The 'newProperty' element is required");
|
||||
throw new MojoFailureException("The 'newProperty' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
@@ -23,32 +24,31 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "match-filename")
|
||||
@Mojo( name = "match-filename", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MatchFilenameMojo extends AbstractMatchMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "sourceDirectory", required = false )
|
||||
protected Path sourceDirectory;
|
||||
protected File sourceDirectory;
|
||||
|
||||
@Parameter( property = "newProperty", required = true )
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing file regex match");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing file regex match");
|
||||
|
||||
final MutableBoolean matches = new MutableBoolean(false);
|
||||
final Path basepath = this.sourceDirectory.toPath();
|
||||
|
||||
try {
|
||||
Files.walkFileTree(this.sourceDirectory, new FileVisitor<Path>() {
|
||||
Files.walkFileTree(basepath, new FileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
@@ -65,11 +65,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (!Files.isDirectory(file)) {
|
||||
logger.debug("Visiting file: " + file);
|
||||
getLog().debug("Visiting file: " + file);
|
||||
|
||||
if (matches(sourceDirectory.relativize(file).toString())) {
|
||||
if (matches(basepath.relativize(file).toString())) {
|
||||
if (MatchFilenameMojo.this.verbose)
|
||||
MatchFilenameMojo.this.logger.info("A pattern matches filename: " + file);
|
||||
MatchFilenameMojo.this.getLog().info("A pattern matches filename: " + file);
|
||||
matches.setTrue();
|
||||
}
|
||||
}
|
||||
@@ -82,18 +82,18 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
||||
}
|
||||
});
|
||||
} catch (IOException ie) {
|
||||
throw new MojoException(ie.getMessage(), ie);
|
||||
throw new MojoExecutionException(ie.getMessage(), ie);
|
||||
}
|
||||
|
||||
if (this.verbose)
|
||||
this.logger.info("Setting property: " + this.newProperty + ": " + matches);
|
||||
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
|
||||
else if (matches.booleanValue())
|
||||
this.logger.info("Matches!");
|
||||
this.manager.setProperty(this.project, this.newProperty, matches.toString());
|
||||
this.getLog().info("Matches!");
|
||||
this.project.getProperties().setProperty(this.newProperty, matches.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
if (this.sourceDirectory == null)
|
||||
@@ -102,11 +102,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.newProperty == null)
|
||||
throw new MojoException("The 'newProperty' element is required");
|
||||
throw new MojoFailureException("The 'newProperty' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,17 +18,15 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "match-properties")
|
||||
@Mojo( name = "match-properties", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MatchPropertiesMojo extends AbstractMatchMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "properties", required = true )
|
||||
protected List<String> properties;
|
||||
@@ -37,8 +35,8 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
||||
protected String propertySuffix;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing properties regex match");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing properties regex match");
|
||||
|
||||
for (String propertyName : this.properties) {
|
||||
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
||||
@@ -46,15 +44,15 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.properties == null)
|
||||
throw new MojoException("A 'properties' element is required");
|
||||
throw new MojoFailureException("A 'properties' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
// make sure we have a list and it is nice and neat
|
||||
@@ -76,13 +74,13 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.propertySuffix == null)
|
||||
throw new MojoException("The 'propertySuffix' element is required");
|
||||
throw new MojoFailureException("The 'propertySuffix' element is required");
|
||||
if (this.properties.isEmpty())
|
||||
throw new MojoException("At least one 'property' element is required");
|
||||
throw new MojoFailureException("At least one 'property' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "match-property")
|
||||
@Mojo( name = "match-property", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MatchPropertyMojo extends AbstractMatchMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "property", required = true )
|
||||
protected String property;
|
||||
@@ -34,14 +32,14 @@ public class MatchPropertyMojo extends AbstractMatchMojo {
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing property regex match");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing property regex match");
|
||||
|
||||
this.executeOnProperty(this.property, this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
this.property = StringUtils.trimToNull(this.property);
|
||||
@@ -51,11 +49,11 @@ public class MatchPropertyMojo extends AbstractMatchMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.property == null)
|
||||
throw new MojoException("The 'property' element is required");
|
||||
throw new MojoFailureException("The 'property' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "match-text")
|
||||
@Mojo( name = "match-text", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MatchTextMojo extends AbstractMatchMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "text", required = true )
|
||||
protected String text;
|
||||
@@ -34,33 +32,33 @@ public class MatchTextMojo extends AbstractMatchMojo {
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing property regex match");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing property regex match");
|
||||
|
||||
this.executeOnText(this.text, this.newProperty);
|
||||
this.executeOnText(this.project.getProperties(), this.text, this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.text == null)
|
||||
throw new MojoException("The 'text' element is required");
|
||||
throw new MojoFailureException("The 'text' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.newProperty == null)
|
||||
throw new MojoException("The 'newProperty' element is required");
|
||||
throw new MojoFailureException("The 'newProperty' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,15 +19,12 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "move-file")
|
||||
@Mojo( name = "move-file", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class MoveFileMojo extends AbstractFileMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Override
|
||||
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
||||
@@ -38,9 +35,9 @@ public class MoveFileMojo extends AbstractFileMojo {
|
||||
}
|
||||
|
||||
if (this.verbose) {
|
||||
this.logger.info("Moved " + sourcePath + " to " + targetPath);
|
||||
this.getLog().info("Moved " + sourcePath + " to " + targetPath);
|
||||
} else {
|
||||
this.logger.info("Moved " + sourcePath.getFileName() + " to " + targetPath);
|
||||
this.getLog().info("Moved " + sourcePath.getFileName() + " to " + targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,17 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.shared.model.fileset.FileSet;
|
||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "replace-file")
|
||||
@Mojo( name = "replace-file", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
||||
protected int chunkSize = 1024;
|
||||
@@ -41,16 +39,16 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
||||
protected List<FileSet> filesets;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing file regex replace");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing file regex replace");
|
||||
|
||||
this.replaceContentInFileSet();
|
||||
}
|
||||
|
||||
private boolean replaceContentInFileSet() throws MojoException {
|
||||
private boolean replaceContentInFileSet() throws MojoExecutionException {
|
||||
boolean didReplace = false;
|
||||
FileSetManager fsman = new FileSetManager();
|
||||
Path basepath = this.project.getBasedir();
|
||||
Path basepath = this.project.getBasedir().toPath();
|
||||
|
||||
try {
|
||||
for (FileSet fileSet : this.filesets) {
|
||||
@@ -67,22 +65,22 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
||||
if (!Files.isDirectory(file)) {
|
||||
if (this.replaceAll(file, tofile, this.chunkSize)) {
|
||||
if (this.verbose)
|
||||
this.logger.info("A pattern replaced in file: " + file + " => " + tofile);
|
||||
this.getLog().info("A pattern replaced in file: " + file + " => " + tofile);
|
||||
didReplace = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ie) {
|
||||
throw new MojoException("Execution failed due to an I/O related issue", ie);
|
||||
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
||||
}
|
||||
|
||||
return didReplace;
|
||||
}
|
||||
|
||||
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoException {
|
||||
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoExecutionException {
|
||||
if (directory == null)
|
||||
return this.project.getBasedir();
|
||||
return this.project.getBasedir().toPath();
|
||||
|
||||
Path path = new File(directory).toPath();
|
||||
if (!path.isAbsolute())
|
||||
@@ -92,31 +90,31 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
||||
if (createIfMissing) {
|
||||
Files.createDirectories(path);
|
||||
} else {
|
||||
throw new MojoException("A " + errorName + " directory does not exist: " + directory);
|
||||
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Files.isDirectory(path))
|
||||
throw new MojoException("A " + errorName + " does reference a directory: " + directory);
|
||||
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.filesets == null || this.filesets.isEmpty())
|
||||
throw new MojoException("At least one 'fileset' is required");
|
||||
throw new MojoFailureException("At least one 'fileset' is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
for (FileSet fileset : this.filesets) {
|
||||
if (fileset.getDirectory() == null)
|
||||
fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString());
|
||||
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
|
||||
if (fileset.getOutputDirectory() == null)
|
||||
fileset.setOutputDirectory(fileset.getDirectory());
|
||||
}
|
||||
|
||||
@@ -18,18 +18,15 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.di.MojoExecutionScoped;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "replace-properties")
|
||||
@Mojo( name = "replace-properties", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "properties", required = true )
|
||||
protected List<String> properties;
|
||||
@@ -38,8 +35,8 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
||||
protected String propertySuffix;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing properties regex replacement");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing properties regex replacement");
|
||||
|
||||
for (String propertyName : this.properties) {
|
||||
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
||||
@@ -47,15 +44,15 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.properties == null)
|
||||
throw new MojoException("A 'properties' element is required");
|
||||
throw new MojoFailureException("A 'properties' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
// make sure we have a list and it is nice and neat
|
||||
@@ -77,13 +74,13 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.propertySuffix == null)
|
||||
throw new MojoException("The 'propertySuffix' element is required");
|
||||
throw new MojoFailureException("The 'propertySuffix' element is required");
|
||||
if (this.properties.isEmpty())
|
||||
throw new MojoException("At least one 'property' element is required");
|
||||
throw new MojoFailureException("At least one 'property' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "replace-property")
|
||||
@Mojo( name = "replace-property", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "property", required = true )
|
||||
protected String property;
|
||||
@@ -34,14 +32,14 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing property regex replacement");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing property regex replacement");
|
||||
|
||||
this.executeOnProperty(this.property, this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
this.property = StringUtils.trimToNull(this.property);
|
||||
@@ -51,11 +49,11 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.property == null)
|
||||
throw new MojoException("The 'property' element is required");
|
||||
throw new MojoFailureException("The 'property' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,15 @@
|
||||
package com.inteligr8.maven.regex;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.maven.api.di.Inject;
|
||||
import org.apache.maven.api.plugin.Log;
|
||||
import org.apache.maven.api.plugin.MojoException;
|
||||
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
@Mojo(name = "replace-text")
|
||||
@Mojo( name = "replace-text", threadSafe = true )
|
||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
||||
public class ReplaceTextMojo extends AbstractReplaceMojo {
|
||||
|
||||
@Inject
|
||||
private Log logger;
|
||||
|
||||
@Parameter( property = "text", required = true )
|
||||
protected String text;
|
||||
@@ -34,33 +32,33 @@ public class ReplaceTextMojo extends AbstractReplaceMojo {
|
||||
protected String newProperty;
|
||||
|
||||
@Override
|
||||
public void go() throws MojoException {
|
||||
this.logger.debug("Executing property regex replacement");
|
||||
public void go() throws MojoExecutionException {
|
||||
this.getLog().debug("Executing property regex replacement");
|
||||
|
||||
this.executeOnText(this.text, this.newProperty);
|
||||
this.executeOnText(this.project.getProperties(), this.text, this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPreNormalization() throws MojoException {
|
||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||
super.validateParamsPreNormalization();
|
||||
|
||||
if (this.text == null)
|
||||
throw new MojoException("The 'text' element is required");
|
||||
throw new MojoFailureException("The 'text' element is required");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void normalizeParameters() throws MojoException {
|
||||
protected void normalizeParameters() throws MojoFailureException {
|
||||
super.normalizeParameters();
|
||||
|
||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateParamsPostNormalization() throws MojoException {
|
||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||
super.validateParamsPostNormalization();
|
||||
|
||||
if (this.newProperty == null)
|
||||
throw new MojoException("The 'newProperty' element is required");
|
||||
throw new MojoFailureException("The 'newProperty' element is required");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.regex.nio;
|
||||
package com.inteligr8.nio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -7,8 +7,8 @@ import java.util.Set;
|
||||
|
||||
import org.apache.maven.shared.model.fileset.FileSet;
|
||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileSetUnitTest {
|
||||
|
||||
@@ -21,9 +21,9 @@ public class FileSetUnitTest {
|
||||
String fs = File.separator;
|
||||
FileSetManager fsman = new FileSetManager();
|
||||
Set<String> files = new HashSet<>(Arrays.asList(fsman.getIncludedFiles(fileset)));
|
||||
Assertions.assertTrue(files.size() > 15);
|
||||
Assert.assertTrue(files.size() > 15);
|
||||
System.err.println(files);
|
||||
Assertions.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java"));
|
||||
Assert.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+28
-28
@@ -1,4 +1,4 @@
|
||||
package com.inteligr8.maven.regex.nio;
|
||||
package com.inteligr8.nio;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -10,8 +10,8 @@ import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DelimitedReadableByteChannelUnitTest {
|
||||
|
||||
@@ -24,9 +24,9 @@ public class DelimitedReadableByteChannelUnitTest {
|
||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\n");
|
||||
try {
|
||||
StringBuilder strbuilder = new StringBuilder();
|
||||
Assertions.assertEquals(-1L, drbchannel.read(strbuilder));
|
||||
Assertions.assertEquals(0, strbuilder.length());
|
||||
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertEquals(-1L, drbchannel.read(strbuilder));
|
||||
Assert.assertEquals(0, strbuilder.length());
|
||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
||||
} finally {
|
||||
drbchannel.close();
|
||||
}
|
||||
@@ -44,18 +44,18 @@ public class DelimitedReadableByteChannelUnitTest {
|
||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
||||
try {
|
||||
StringWriter writer = new StringWriter(1024);
|
||||
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertEquals("", writer.toString());
|
||||
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertEquals("", writer.toString());
|
||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
|
||||
writer = new StringWriter(1024);
|
||||
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertEquals("here is a line", writer.toString());
|
||||
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertEquals("here is a line", writer.toString());
|
||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
|
||||
writer = new StringWriter(1024);
|
||||
Assertions.assertEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
||||
} finally {
|
||||
drbchannel.close();
|
||||
}
|
||||
@@ -73,18 +73,18 @@ public class DelimitedReadableByteChannelUnitTest {
|
||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
||||
try {
|
||||
StringWriter writer = new StringWriter(1024);
|
||||
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertEquals("the first line", writer.toString());
|
||||
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertEquals("the first line", writer.toString());
|
||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||
|
||||
writer = new StringWriter(1024);
|
||||
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertEquals("the last line", writer.toString());
|
||||
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertEquals("the last line", writer.toString());
|
||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
||||
|
||||
writer = new StringWriter(1024);
|
||||
Assertions.assertEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||
Assert.assertEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
||||
} finally {
|
||||
drbchannel.close();
|
||||
}
|
||||
@@ -111,14 +111,14 @@ public class DelimitedReadableByteChannelUnitTest {
|
||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(chunkSize, fchannel, Charset.defaultCharset(), "\n");
|
||||
try {
|
||||
StringWriter writer = new StringWriter(1024);
|
||||
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assertions.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", writer.toString());
|
||||
Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
||||
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", writer.toString());
|
||||
Assert.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||
|
||||
writer = new StringWriter(1024);
|
||||
Assertions.assertEquals(1, drbchannel.read(writer));
|
||||
Assertions.assertEquals("", writer.toString());
|
||||
Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||
Assert.assertEquals(1, drbchannel.read(writer));
|
||||
Assert.assertEquals("", writer.toString());
|
||||
Assert.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||
} finally {
|
||||
drbchannel.close();
|
||||
}
|
||||
Reference in New Issue
Block a user