Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
478447b96d |
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.1.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.1.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>regex-maven-plugin</artifactId>
|
<artifactId>regex-maven-plugin</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
<name>Regular Expression Maven Plugin</name>
|
<name>Regular Expression Maven Plugin</name>
|
||||||
@@ -35,62 +35,90 @@
|
|||||||
<id>brian.long</id>
|
<id>brian.long</id>
|
||||||
<name>Brian Long</name>
|
<name>Brian Long</name>
|
||||||
<email>brian@inteligr8.com</email>
|
<email>brian@inteligr8.com</email>
|
||||||
<url>https://twitter.com/brianmlong</url>
|
<url>https://x.com/brianmlong</url>
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<maven.version>3.9.11</maven.version>
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<maven.version>4.0.0-rc-5</maven.version>
|
||||||
</properties>
|
</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>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.20.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.shared</groupId>
|
<groupId>org.apache.maven.shared</groupId>
|
||||||
<artifactId>file-management</artifactId>
|
<artifactId>file-management</artifactId>
|
||||||
<version>3.2.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-plugin-api</artifactId>
|
<artifactId>maven-api-core</artifactId>
|
||||||
<version>${maven.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
|
||||||
<artifactId>maven-plugin-annotations</artifactId>
|
|
||||||
<version>3.15.1</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-core</artifactId>
|
<artifactId>maven-api-annotations</artifactId>
|
||||||
<version>${maven.version}</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.plugin-testing</groupId>
|
<groupId>org.apache.maven.plugin-testing</groupId>
|
||||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||||
<version>3.3.0</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-compat</artifactId>
|
<artifactId>maven-compat</artifactId>
|
||||||
<version>${maven.version}</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.13.2</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -104,12 +132,7 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-invoker-plugin</artifactId>
|
<artifactId>maven-invoker-plugin</artifactId>
|
||||||
<version>3.9.1</version>
|
<version>3.10.1</version>
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
|
||||||
<artifactId>plexus-component-metadata</artifactId>
|
|
||||||
<version>2.2.0</version>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
@@ -134,6 +157,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!--
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
<artifactId>plexus-component-metadata</artifactId>
|
<artifactId>plexus-component-metadata</artifactId>
|
||||||
@@ -145,6 +169,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-invoker-plugin</artifactId>
|
<artifactId>maven-invoker-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.FileVisitor;
|
import java.nio.file.FileVisitor;
|
||||||
@@ -22,29 +21,31 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "sourceDirectory", required = false )
|
@Parameter( property = "sourceDirectory", required = false )
|
||||||
protected File sourceDirectory;
|
protected Path sourceDirectory;
|
||||||
|
|
||||||
@Parameter( property = "targetDirectory", required = false )
|
@Parameter( property = "targetDirectory", required = false )
|
||||||
protected File targetDirectory;
|
protected Path targetDirectory;
|
||||||
|
|
||||||
@Parameter( property = "overwrite", required = true, defaultValue = "true" )
|
@Parameter( property = "overwrite", required = true, defaultValue = "true" )
|
||||||
protected boolean overwrite = true;
|
protected boolean overwrite = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing file regex");
|
this.logger.debug("Executing file regex");
|
||||||
|
|
||||||
final Path sourcePath = this.sourceDirectory.toPath();
|
|
||||||
final Path targetPath = this.targetDirectory.toPath();
|
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(sourcePath, new FileVisitor<Path>() {
|
Files.walkFileTree(this.sourceDirectory, new FileVisitor<Path>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||||
@@ -61,12 +62,12 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
|||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
if (!Files.isDirectory(file)) {
|
if (!Files.isDirectory(file)) {
|
||||||
String relativePath = sourcePath.relativize(file).toString();
|
String relativePath = sourceDirectory.relativize(file).toString();
|
||||||
String replacedRelativePath = replaceFirst(relativePath);
|
String replacedRelativePath = replaceFirst(relativePath);
|
||||||
if (!relativePath.equals(replacedRelativePath)) {
|
if (!relativePath.equals(replacedRelativePath)) {
|
||||||
Path newFile = targetPath.resolve(replacedRelativePath);
|
Path newFile = targetDirectory.resolve(replacedRelativePath);
|
||||||
if (file.equals(newFile)) {
|
if (file.equals(newFile)) {
|
||||||
AbstractFileMojo.this.getLog().error("Relative paths are different, but the resultant paths are the same??");
|
AbstractFileMojo.this.logger.error("Relative paths are different, but the resultant paths are the same??");
|
||||||
throw new RuntimeException("This should never happen");
|
throw new RuntimeException("This should never happen");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,14 +84,14 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException(ie.getMessage(), ie);
|
throw new MojoException(ie.getMessage(), ie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void executeOnFile(Path sourcePath, Path targetPath) throws IOException;
|
protected abstract void executeOnFile(Path sourcePath, Path targetPath) throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
if (this.sourceDirectory == null)
|
if (this.sourceDirectory == null)
|
||||||
|
|||||||
@@ -22,18 +22,22 @@ import java.nio.file.StandardOpenOption;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.Log;
|
||||||
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
import com.inteligr8.nio.DelimitedReadableByteChannel;
|
import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel;
|
||||||
|
|
||||||
public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "allowPartialMatch", required = true, defaultValue = "true" )
|
@Parameter( property = "allowPartialMatch", required = true, defaultValue = "true" )
|
||||||
protected boolean allowPartialMatch = true;
|
protected boolean allowPartialMatch = true;
|
||||||
|
|
||||||
@@ -46,15 +50,14 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
private List<Pattern> compiledPatterns;
|
private List<Pattern> compiledPatterns;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
protected void executeOnText(String text, String newPropertyName) {
|
||||||
boolean matches = this.matches(text);
|
boolean matches = this.matches(text);
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Setting property: " + newPropertyName + ": " + matches);
|
this.logger.info("Setting property: " + newPropertyName + ": " + matches);
|
||||||
else if (matches)
|
else if (matches)
|
||||||
this.getLog().info("Matches!");
|
this.logger.info("Matches!");
|
||||||
if (props == null)
|
|
||||||
props = this.project.getProperties();
|
this.manager.setProperty(this.project, newPropertyName, String.valueOf(matches));
|
||||||
props.setProperty(newPropertyName, String.valueOf(matches));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matches(Path file, int chunkSize) throws IOException {
|
protected boolean matches(Path file, int chunkSize) throws IOException {
|
||||||
@@ -94,20 +97,20 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
text = "";
|
text = "";
|
||||||
|
|
||||||
for (Pattern pattern : this.compiledPatterns) {
|
for (Pattern pattern : this.compiledPatterns) {
|
||||||
this.getLog().debug("Applying regex pattern: " + pattern);
|
this.logger.debug("Applying regex pattern: " + pattern);
|
||||||
this.getLog().debug("Operating on value: " + text);
|
this.logger.debug("Operating on value: " + text);
|
||||||
|
|
||||||
Matcher matcher = pattern.matcher(text);
|
Matcher matcher = pattern.matcher(text);
|
||||||
if (this.allowPartialMatch) {
|
if (this.allowPartialMatch) {
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
|
this.logger.info("Pattern '" + pattern + "' matches text: " + text);
|
||||||
return !this.negate;
|
return !this.negate;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Pattern '" + pattern + "' matches text: " + text);
|
this.logger.info("Pattern '" + pattern + "' matches text: " + text);
|
||||||
return !this.negate;
|
return !this.negate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,15 +120,15 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.patterns == null)
|
if (this.patterns == null)
|
||||||
throw new MojoFailureException("A 'patterns' element is required");
|
throw new MojoException("A 'patterns' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
ListIterator<String> p = this.patterns.listIterator();
|
ListIterator<String> p = this.patterns.listIterator();
|
||||||
@@ -138,19 +141,19 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.patterns.isEmpty())
|
if (this.patterns.isEmpty())
|
||||||
throw new MojoFailureException("At least one 'patterns' element is required");
|
throw new MojoException("At least one 'patterns' element is required");
|
||||||
|
|
||||||
this.compiledPatterns = new LinkedList<>();
|
this.compiledPatterns = new LinkedList<>();
|
||||||
for (String pattern : this.patterns) {
|
for (String pattern : this.patterns) {
|
||||||
this.getLog().debug("Compiling regex pattern: " + pattern);
|
this.logger.debug("Compiling regex pattern: " + pattern);
|
||||||
try {
|
try {
|
||||||
this.compiledPatterns.add(Pattern.compile(pattern));
|
this.compiledPatterns.add(Pattern.compile(pattern));
|
||||||
} catch (PatternSyntaxException pse) {
|
} catch (PatternSyntaxException pse) {
|
||||||
throw new MojoFailureException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage());
|
throw new MojoException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,28 +14,30 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.api.Project;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.api.Session;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.Mojo;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
import org.apache.maven.api.services.ProjectManager;
|
||||||
|
|
||||||
import com.inteligr8.maven.ProjectPropertyResolver;
|
public abstract class AbstractRegexMojo implements Mojo {
|
||||||
|
|
||||||
public abstract class AbstractRegexMojo extends AbstractMojo {
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( defaultValue = "${project}", readonly = true )
|
@Inject
|
||||||
protected MavenProject project;
|
protected Project project;
|
||||||
|
|
||||||
@Parameter( defaultValue = "${session}", readonly = true )
|
@Inject
|
||||||
protected MavenSession session;
|
protected Session session;
|
||||||
|
|
||||||
@Requirement
|
@Inject
|
||||||
private ProjectPropertyResolver propResolver;
|
protected ProjectManager manager;
|
||||||
|
|
||||||
@Parameter( property = "allowMultiLineMatch", required = true, defaultValue = "false" )
|
@Parameter( property = "allowMultiLineMatch", required = true, defaultValue = "false" )
|
||||||
protected boolean allowMultiLineMatch = false;
|
protected boolean allowMultiLineMatch = false;
|
||||||
@@ -49,9 +51,9 @@ public abstract class AbstractRegexMojo extends AbstractMojo {
|
|||||||
@Parameter( property = "verbose", required = true, defaultValue = "false" )
|
@Parameter( property = "verbose", required = true, defaultValue = "false" )
|
||||||
protected boolean verbose = false;
|
protected boolean verbose = false;
|
||||||
|
|
||||||
public final void execute() throws MojoExecutionException, MojoFailureException {
|
public final void execute() throws MojoException {
|
||||||
if (this.skip) {
|
if (this.skip) {
|
||||||
this.getLog().debug("Skipped execution");
|
this.logger.debug("Skipped execution");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,31 +64,33 @@ public abstract class AbstractRegexMojo extends AbstractMojo {
|
|||||||
this.go();
|
this.go();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void go() throws MojoExecutionException, MojoFailureException;
|
protected abstract void go() throws MojoException;
|
||||||
|
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
this.getLog().debug("Validating parameters before their normalization");
|
this.logger.debug("Validating parameters before their normalization");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
this.getLog().debug("Normalizing parameters");
|
this.logger.debug("Normalizing parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
this.getLog().debug("Validating parameters after their normalization");
|
this.logger.debug("Validating parameters after their normalization");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void executeOnProperty(String propertyName, String newPropertyName) {
|
protected final void executeOnProperty(String propertyName, String newPropertyName) {
|
||||||
this.getLog().debug("Finding property: " + propertyName);
|
this.logger.debug("Finding property: " + propertyName);
|
||||||
|
|
||||||
Properties props = this.propResolver.resolveScope(propertyName);
|
// FIXME getEffectiveProperties() is not cached and could be expensive if called a lot
|
||||||
if (props == null)
|
// maybe create a session scoped service that handles that part
|
||||||
this.getLog().debug("Property not found: " + propertyName);
|
Map<String, String> props = this.session.getEffectiveProperties(this.project);
|
||||||
|
String existingPropertyValue = props.get(propertyName);
|
||||||
|
if (existingPropertyValue == null)
|
||||||
|
this.logger.debug("Property not found: " + propertyName);
|
||||||
|
|
||||||
String propertyValue = props == null ? null : props.getProperty(propertyName);
|
this.executeOnText(existingPropertyValue, newPropertyName);
|
||||||
this.executeOnText(props, propertyValue, newPropertyName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void executeOnText(Properties props, String text, String newPropertyName);
|
protected abstract void executeOnText(String text, String newPropertyName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
@@ -32,14 +31,19 @@ import java.util.regex.PatternSyntaxException;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.Log;
|
||||||
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
import com.inteligr8.maven.model.Regex;
|
import com.inteligr8.maven.regex.model.Regex;
|
||||||
import com.inteligr8.nio.DelimitedReadableByteChannel;
|
import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel;
|
||||||
|
|
||||||
public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "regexes", required = true )
|
@Parameter( property = "regexes", required = true )
|
||||||
protected Regex[] regexes;
|
protected Regex[] regexes;
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
private List<Triple<Pattern, String, Pattern>> compiledRegexes;
|
private List<Triple<Pattern, String, Pattern>> compiledRegexes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeOnText(Properties props, String text, String newPropertyName) {
|
protected void executeOnText(String text, String newPropertyName) {
|
||||||
if (text == null)
|
if (text == null)
|
||||||
text = "";
|
text = "";
|
||||||
String originalText = text;
|
String originalText = text;
|
||||||
@@ -55,18 +59,17 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
|
|
||||||
if (!text.equals(originalText)) {
|
if (!text.equals(originalText)) {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Setting property: " + newPropertyName + ": " + text);
|
this.logger.info("Setting property: " + newPropertyName + ": " + text);
|
||||||
else if (this.getLog().isDebugEnabled())
|
else if (this.logger.isDebugEnabled())
|
||||||
this.getLog().debug("Manipulated value: " + text);
|
this.logger.debug("Manipulated value: " + text);
|
||||||
}
|
}
|
||||||
if (props == null)
|
|
||||||
props = this.project.getProperties();
|
this.manager.setProperty(this.project, newPropertyName, text);
|
||||||
props.setProperty(newPropertyName, text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean replaceFirst(Path file, Path tofile, int chunkSize) throws IOException {
|
protected boolean replaceFirst(Path file, Path tofile, int chunkSize) throws IOException {
|
||||||
if (this.getLog().isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.getLog().debug("replace first: " + file + " => " + tofile);
|
this.logger.debug("replace first: " + file + " => " + tofile);
|
||||||
|
|
||||||
boolean didReplace = false;
|
boolean didReplace = false;
|
||||||
Charset charset = Charset.forName(this.charsetName);
|
Charset charset = Charset.forName(this.charsetName);
|
||||||
@@ -119,12 +122,12 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
protected String replaceFirst(String text) {
|
protected String replaceFirst(String text) {
|
||||||
if (text == null)
|
if (text == null)
|
||||||
text = "";
|
text = "";
|
||||||
if (this.getLog().isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.getLog().debug("replace first: " + text.length());
|
this.logger.debug("replace first: " + text.length());
|
||||||
|
|
||||||
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
||||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
this.logger.debug("Applying regex pattern: " + regex.getLeft());
|
||||||
this.getLog().debug("Operating on value: " + text);
|
this.logger.debug("Operating on value: " + text);
|
||||||
|
|
||||||
Matcher matcher = regex.getLeft().matcher(text);
|
Matcher matcher = regex.getLeft().matcher(text);
|
||||||
if (regex.getRight() == null) {
|
if (regex.getRight() == null) {
|
||||||
@@ -142,8 +145,8 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean replaceAll(Path file, Path tofile, int chunkSize) throws IOException {
|
protected boolean replaceAll(Path file, Path tofile, int chunkSize) throws IOException {
|
||||||
if (this.getLog().isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.getLog().debug("replace all: " + file + " => " + tofile);
|
this.logger.debug("replace all: " + file + " => " + tofile);
|
||||||
|
|
||||||
boolean overwrite = file.equals(tofile);
|
boolean overwrite = file.equals(tofile);
|
||||||
boolean didReplace = false;
|
boolean didReplace = false;
|
||||||
@@ -169,10 +172,10 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
strbuilder.append(rbchannel.getLastDelimiterRead());
|
strbuilder.append(rbchannel.getLastDelimiterRead());
|
||||||
} else {
|
} else {
|
||||||
String line = strbuilder.toString();
|
String line = strbuilder.toString();
|
||||||
this.getLog().debug("line: " + line);
|
this.logger.debug("line: " + line);
|
||||||
String processedLine = this.replaceAll(line);
|
String processedLine = this.replaceAll(line);
|
||||||
if (!didReplace || (this.getLog().isDebugEnabled() && !line.equals(processedLine))) {
|
if (!didReplace || (this.logger.isDebugEnabled() && !line.equals(processedLine))) {
|
||||||
this.getLog().debug("replaced line: " + processedLine);
|
this.logger.debug("replaced line: " + processedLine);
|
||||||
didReplace = true;
|
didReplace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,14 +213,14 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
text = "";
|
text = "";
|
||||||
|
|
||||||
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
for (Triple<Pattern, String, Pattern> regex : this.compiledRegexes) {
|
||||||
this.getLog().debug("Applying regex pattern: " + regex.getLeft());
|
this.logger.debug("Applying regex pattern: " + regex.getLeft());
|
||||||
this.getLog().debug("Operating on value: " + text);
|
this.logger.debug("Operating on value: " + text);
|
||||||
|
|
||||||
Matcher matcher = regex.getLeft().matcher(text);
|
Matcher matcher = regex.getLeft().matcher(text);
|
||||||
if (regex.getRight() == null) {
|
if (regex.getRight() == null) {
|
||||||
String newtext = matcher.replaceAll(regex.getMiddle());
|
String newtext = matcher.replaceAll(regex.getMiddle());
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||||
text = newtext;
|
text = newtext;
|
||||||
} else while (matcher.find()) {
|
} else while (matcher.find()) {
|
||||||
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
|
Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start()));
|
||||||
@@ -226,7 +229,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
} else {
|
} else {
|
||||||
String newtext = text.substring(0, previousMatchStart) + text.substring(matcher.start());
|
String newtext = text.substring(0, previousMatchStart) + text.substring(matcher.start());
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text);
|
this.logger.info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text);
|
||||||
text = newtext;
|
text = newtext;
|
||||||
|
|
||||||
matcher = regex.getLeft().matcher(text);
|
matcher = regex.getLeft().matcher(text);
|
||||||
@@ -234,7 +237,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
|
|
||||||
String newtext = matcher.replaceFirst(regex.getMiddle());
|
String newtext = matcher.replaceFirst(regex.getMiddle());
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext);
|
||||||
text = newtext;
|
text = newtext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,15 +255,15 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.regexes == null || this.regexes.length == 0)
|
if (this.regexes == null || this.regexes.length == 0)
|
||||||
throw new MojoFailureException("A 'regexes' element is required");
|
throw new MojoException("A 'regexes' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
for (Regex regex : this.regexes)
|
for (Regex regex : this.regexes)
|
||||||
@@ -268,22 +271,22 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.regexes == null || this.regexes.length == 0)
|
if (this.regexes == null || this.regexes.length == 0)
|
||||||
throw new MojoFailureException("At least one 'regexes' element is required");
|
throw new MojoException("At least one 'regexes' element is required");
|
||||||
|
|
||||||
this.compiledRegexes = new LinkedList<>();
|
this.compiledRegexes = new LinkedList<>();
|
||||||
for (Regex regex : this.regexes) {
|
for (Regex regex : this.regexes) {
|
||||||
this.getLog().debug("Compiling regex pattern: " + regex.getPattern());
|
this.logger.debug("Compiling regex pattern: " + regex.getPattern());
|
||||||
try {
|
try {
|
||||||
Pattern pattern = Pattern.compile(regex.getPattern());
|
Pattern pattern = Pattern.compile(regex.getPattern());
|
||||||
String previousPatternStr = StringUtils.trimToNull(regex.getPreviousPattern());
|
String previousPatternStr = StringUtils.trimToNull(regex.getPreviousPattern());
|
||||||
Pattern previousPattern = previousPatternStr == null ? null : Pattern.compile(previousPatternStr);
|
Pattern previousPattern = previousPatternStr == null ? null : Pattern.compile(previousPatternStr);
|
||||||
this.compiledRegexes.add(new ImmutableTriple<>(pattern, regex.getReplacement(), previousPattern));
|
this.compiledRegexes.add(new ImmutableTriple<>(pattern, regex.getReplacement(), previousPattern));
|
||||||
} catch (PatternSyntaxException pse) {
|
} catch (PatternSyntaxException pse) {
|
||||||
throw new MojoFailureException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage());
|
throw new MojoException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,16 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.Log;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
|
|
||||||
@Mojo( name = "copy-file", threadSafe = true )
|
@Mojo(name = "copy-file")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class CopyFileMojo extends AbstractFileMojo {
|
public class CopyFileMojo extends AbstractFileMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
||||||
if (CopyFileMojo.this.overwrite) {
|
if (CopyFileMojo.this.overwrite) {
|
||||||
@@ -35,9 +38,9 @@ public class CopyFileMojo extends AbstractFileMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
this.getLog().info("Copied " + sourcePath + " to " + targetPath);
|
this.logger.info("Copied " + sourcePath + " to " + targetPath);
|
||||||
} else {
|
} else {
|
||||||
this.getLog().info("Copied " + sourcePath.getFileName() + " to " + targetPath);
|
this.logger.info("Copied " + sourcePath.getFileName() + " to " + targetPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,18 +21,20 @@ import java.nio.file.Path;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
import org.apache.maven.shared.model.fileset.FileSet;
|
import org.apache.maven.shared.model.fileset.FileSet;
|
||||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
|
||||||
|
|
||||||
@Mojo( name = "match-file", threadSafe = true )
|
@Mojo(name = "match-file")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MatchFileContentMojo extends AbstractMatchMojo {
|
public class MatchFileContentMojo extends AbstractMatchMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
||||||
protected int chunkSize = 1024;
|
protected int chunkSize = 1024;
|
||||||
|
|
||||||
@@ -43,20 +45,20 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing file regex match");
|
this.logger.debug("Executing file regex match");
|
||||||
|
|
||||||
boolean matches = this.matchesContentInFileSet();
|
boolean matches = this.matchesContentInFileSet();
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
|
this.logger.info("Setting property: " + this.newProperty + ": " + matches);
|
||||||
else if (matches)
|
else if (matches)
|
||||||
this.getLog().info("Matches!");
|
this.logger.info("Matches!");
|
||||||
this.project.getProperties().setProperty(this.newProperty, String.valueOf(matches));
|
this.manager.setProperty(this.project, this.newProperty, String.valueOf(matches));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchesContentInFileSet() throws MojoExecutionException {
|
private boolean matchesContentInFileSet() throws MojoException {
|
||||||
FileSetManager fsman = new FileSetManager();
|
FileSetManager fsman = new FileSetManager();
|
||||||
Path basepath = this.project.getBasedir().toPath();
|
Path basepath = this.project.getBasedir();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (FileSet fileSet : this.filesets) {
|
for (FileSet fileSet : this.filesets) {
|
||||||
@@ -68,58 +70,58 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
if (!Files.isDirectory(file))
|
if (!Files.isDirectory(file))
|
||||||
if (this.matches(file, this.chunkSize)) {
|
if (this.matches(file, this.chunkSize)) {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("A pattern matches file: " + file);
|
this.logger.info("A pattern matches file: " + file);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
throw new MojoException("Execution failed due to an I/O related issue", ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.negate;
|
return this.negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoExecutionException {
|
private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoException {
|
||||||
Path path = new File(directory).toPath();
|
Path path = new File(directory).toPath();
|
||||||
if (!path.isAbsolute())
|
if (!path.isAbsolute())
|
||||||
path = basepath.resolve(path);
|
path = basepath.resolve(path);
|
||||||
|
|
||||||
if (!Files.exists(path))
|
if (!Files.exists(path))
|
||||||
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
throw new MojoException("A " + errorName + " directory does not exist: " + directory);
|
||||||
|
|
||||||
if (!Files.isDirectory(path))
|
if (!Files.isDirectory(path))
|
||||||
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
throw new MojoException("A " + errorName + " does reference a directory: " + directory);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.filesets == null || this.filesets.isEmpty())
|
if (this.filesets == null || this.filesets.isEmpty())
|
||||||
throw new MojoFailureException("At least one 'fileset' is required");
|
throw new MojoException("At least one 'fileset' is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
for (FileSet fileset : this.filesets) {
|
for (FileSet fileset : this.filesets) {
|
||||||
if (fileset.getDirectory() == null)
|
if (fileset.getDirectory() == null)
|
||||||
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
|
fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.newProperty == null)
|
if (this.newProperty == null)
|
||||||
throw new MojoFailureException("The 'newProperty' element is required");
|
throw new MojoException("The 'newProperty' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.FileVisitor;
|
import java.nio.file.FileVisitor;
|
||||||
@@ -24,31 +23,32 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "match-filename", threadSafe = true )
|
@Mojo(name = "match-filename")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MatchFilenameMojo extends AbstractMatchMojo {
|
public class MatchFilenameMojo extends AbstractMatchMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "sourceDirectory", required = false )
|
@Parameter( property = "sourceDirectory", required = false )
|
||||||
protected File sourceDirectory;
|
protected Path sourceDirectory;
|
||||||
|
|
||||||
@Parameter( property = "newProperty", required = true )
|
@Parameter( property = "newProperty", required = true )
|
||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing file regex match");
|
this.logger.debug("Executing file regex match");
|
||||||
|
|
||||||
final MutableBoolean matches = new MutableBoolean(false);
|
final MutableBoolean matches = new MutableBoolean(false);
|
||||||
final Path basepath = this.sourceDirectory.toPath();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(basepath, new FileVisitor<Path>() {
|
Files.walkFileTree(this.sourceDirectory, new FileVisitor<Path>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||||
@@ -65,11 +65,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
|||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
if (!Files.isDirectory(file)) {
|
if (!Files.isDirectory(file)) {
|
||||||
getLog().debug("Visiting file: " + file);
|
logger.debug("Visiting file: " + file);
|
||||||
|
|
||||||
if (matches(basepath.relativize(file).toString())) {
|
if (matches(sourceDirectory.relativize(file).toString())) {
|
||||||
if (MatchFilenameMojo.this.verbose)
|
if (MatchFilenameMojo.this.verbose)
|
||||||
MatchFilenameMojo.this.getLog().info("A pattern matches filename: " + file);
|
MatchFilenameMojo.this.logger.info("A pattern matches filename: " + file);
|
||||||
matches.setTrue();
|
matches.setTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,18 +82,18 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException(ie.getMessage(), ie);
|
throw new MojoException(ie.getMessage(), ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("Setting property: " + this.newProperty + ": " + matches);
|
this.logger.info("Setting property: " + this.newProperty + ": " + matches);
|
||||||
else if (matches.booleanValue())
|
else if (matches.booleanValue())
|
||||||
this.getLog().info("Matches!");
|
this.logger.info("Matches!");
|
||||||
this.project.getProperties().setProperty(this.newProperty, matches.toString());
|
this.manager.setProperty(this.project, this.newProperty, matches.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
if (this.sourceDirectory == null)
|
if (this.sourceDirectory == null)
|
||||||
@@ -102,11 +102,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.newProperty == null)
|
if (this.newProperty == null)
|
||||||
throw new MojoFailureException("The 'newProperty' element is required");
|
throw new MojoException("The 'newProperty' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,18 @@ import java.util.List;
|
|||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "match-properties", threadSafe = true )
|
@Mojo(name = "match-properties")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MatchPropertiesMojo extends AbstractMatchMojo {
|
public class MatchPropertiesMojo extends AbstractMatchMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "properties", required = true )
|
@Parameter( property = "properties", required = true )
|
||||||
protected List<String> properties;
|
protected List<String> properties;
|
||||||
|
|
||||||
@@ -35,8 +37,8 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
|||||||
protected String propertySuffix;
|
protected String propertySuffix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing properties regex match");
|
this.logger.debug("Executing properties regex match");
|
||||||
|
|
||||||
for (String propertyName : this.properties) {
|
for (String propertyName : this.properties) {
|
||||||
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
||||||
@@ -44,15 +46,15 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.properties == null)
|
if (this.properties == null)
|
||||||
throw new MojoFailureException("A 'properties' element is required");
|
throw new MojoException("A 'properties' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
// make sure we have a list and it is nice and neat
|
// make sure we have a list and it is nice and neat
|
||||||
@@ -74,13 +76,13 @@ public class MatchPropertiesMojo extends AbstractMatchMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.propertySuffix == null)
|
if (this.propertySuffix == null)
|
||||||
throw new MojoFailureException("The 'propertySuffix' element is required");
|
throw new MojoException("The 'propertySuffix' element is required");
|
||||||
if (this.properties.isEmpty())
|
if (this.properties.isEmpty())
|
||||||
throw new MojoFailureException("At least one 'property' element is required");
|
throw new MojoException("At least one 'property' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,18 @@
|
|||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "match-property", threadSafe = true )
|
@Mojo(name = "match-property")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MatchPropertyMojo extends AbstractMatchMojo {
|
public class MatchPropertyMojo extends AbstractMatchMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "property", required = true )
|
@Parameter( property = "property", required = true )
|
||||||
protected String property;
|
protected String property;
|
||||||
|
|
||||||
@@ -32,14 +34,14 @@ public class MatchPropertyMojo extends AbstractMatchMojo {
|
|||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing property regex match");
|
this.logger.debug("Executing property regex match");
|
||||||
|
|
||||||
this.executeOnProperty(this.property, this.newProperty);
|
this.executeOnProperty(this.property, this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
this.property = StringUtils.trimToNull(this.property);
|
this.property = StringUtils.trimToNull(this.property);
|
||||||
@@ -49,11 +51,11 @@ public class MatchPropertyMojo extends AbstractMatchMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.property == null)
|
if (this.property == null)
|
||||||
throw new MojoFailureException("The 'property' element is required");
|
throw new MojoException("The 'property' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,18 @@
|
|||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "match-text", threadSafe = true )
|
@Mojo(name = "match-text")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MatchTextMojo extends AbstractMatchMojo {
|
public class MatchTextMojo extends AbstractMatchMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "text", required = true )
|
@Parameter( property = "text", required = true )
|
||||||
protected String text;
|
protected String text;
|
||||||
|
|
||||||
@@ -32,33 +34,33 @@ public class MatchTextMojo extends AbstractMatchMojo {
|
|||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing property regex match");
|
this.logger.debug("Executing property regex match");
|
||||||
|
|
||||||
this.executeOnText(this.project.getProperties(), this.text, this.newProperty);
|
this.executeOnText(this.text, this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.text == null)
|
if (this.text == null)
|
||||||
throw new MojoFailureException("The 'text' element is required");
|
throw new MojoException("The 'text' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.newProperty == null)
|
if (this.newProperty == null)
|
||||||
throw new MojoFailureException("The 'newProperty' element is required");
|
throw new MojoException("The 'newProperty' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,16 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.Log;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
|
|
||||||
@Mojo( name = "move-file", threadSafe = true )
|
@Mojo(name = "move-file")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class MoveFileMojo extends AbstractFileMojo {
|
public class MoveFileMojo extends AbstractFileMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException {
|
||||||
if (MoveFileMojo.this.overwrite) {
|
if (MoveFileMojo.this.overwrite) {
|
||||||
@@ -35,9 +38,9 @@ public class MoveFileMojo extends AbstractFileMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.verbose) {
|
if (this.verbose) {
|
||||||
this.getLog().info("Moved " + sourcePath + " to " + targetPath);
|
this.logger.info("Moved " + sourcePath + " to " + targetPath);
|
||||||
} else {
|
} else {
|
||||||
this.getLog().info("Moved " + sourcePath.getFileName() + " to " + targetPath);
|
this.logger.info("Moved " + sourcePath.getFileName() + " to " + targetPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,18 +20,20 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
import org.apache.maven.shared.model.fileset.FileSet;
|
import org.apache.maven.shared.model.fileset.FileSet;
|
||||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
|
||||||
|
|
||||||
@Mojo( name = "replace-file", threadSafe = true )
|
@Mojo(name = "replace-file")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
@Parameter( property = "chunkSize", required = true, defaultValue = "1024" )
|
||||||
protected int chunkSize = 1024;
|
protected int chunkSize = 1024;
|
||||||
|
|
||||||
@@ -39,16 +41,16 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
protected List<FileSet> filesets;
|
protected List<FileSet> filesets;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing file regex replace");
|
this.logger.debug("Executing file regex replace");
|
||||||
|
|
||||||
this.replaceContentInFileSet();
|
this.replaceContentInFileSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean replaceContentInFileSet() throws MojoExecutionException {
|
private boolean replaceContentInFileSet() throws MojoException {
|
||||||
boolean didReplace = false;
|
boolean didReplace = false;
|
||||||
FileSetManager fsman = new FileSetManager();
|
FileSetManager fsman = new FileSetManager();
|
||||||
Path basepath = this.project.getBasedir().toPath();
|
Path basepath = this.project.getBasedir();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (FileSet fileSet : this.filesets) {
|
for (FileSet fileSet : this.filesets) {
|
||||||
@@ -65,22 +67,22 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
if (!Files.isDirectory(file)) {
|
if (!Files.isDirectory(file)) {
|
||||||
if (this.replaceAll(file, tofile, this.chunkSize)) {
|
if (this.replaceAll(file, tofile, this.chunkSize)) {
|
||||||
if (this.verbose)
|
if (this.verbose)
|
||||||
this.getLog().info("A pattern replaced in file: " + file + " => " + tofile);
|
this.logger.info("A pattern replaced in file: " + file + " => " + tofile);
|
||||||
didReplace = true;
|
didReplace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException("Execution failed due to an I/O related issue", ie);
|
throw new MojoException("Execution failed due to an I/O related issue", ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return didReplace;
|
return didReplace;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoExecutionException {
|
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoException {
|
||||||
if (directory == null)
|
if (directory == null)
|
||||||
return this.project.getBasedir().toPath();
|
return this.project.getBasedir();
|
||||||
|
|
||||||
Path path = new File(directory).toPath();
|
Path path = new File(directory).toPath();
|
||||||
if (!path.isAbsolute())
|
if (!path.isAbsolute())
|
||||||
@@ -90,31 +92,31 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
if (createIfMissing) {
|
if (createIfMissing) {
|
||||||
Files.createDirectories(path);
|
Files.createDirectories(path);
|
||||||
} else {
|
} else {
|
||||||
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
throw new MojoException("A " + errorName + " directory does not exist: " + directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Files.isDirectory(path))
|
if (!Files.isDirectory(path))
|
||||||
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
throw new MojoException("A " + errorName + " does reference a directory: " + directory);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.filesets == null || this.filesets.isEmpty())
|
if (this.filesets == null || this.filesets.isEmpty())
|
||||||
throw new MojoFailureException("At least one 'fileset' is required");
|
throw new MojoException("At least one 'fileset' is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
for (FileSet fileset : this.filesets) {
|
for (FileSet fileset : this.filesets) {
|
||||||
if (fileset.getDirectory() == null)
|
if (fileset.getDirectory() == null)
|
||||||
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
|
fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString());
|
||||||
if (fileset.getOutputDirectory() == null)
|
if (fileset.getOutputDirectory() == null)
|
||||||
fileset.setOutputDirectory(fileset.getDirectory());
|
fileset.setOutputDirectory(fileset.getDirectory());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,19 @@ import java.util.List;
|
|||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.di.MojoExecutionScoped;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "replace-properties", threadSafe = true )
|
@Mojo(name = "replace-properties")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "properties", required = true )
|
@Parameter( property = "properties", required = true )
|
||||||
protected List<String> properties;
|
protected List<String> properties;
|
||||||
|
|
||||||
@@ -35,8 +38,8 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
|||||||
protected String propertySuffix;
|
protected String propertySuffix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing properties regex replacement");
|
this.logger.debug("Executing properties regex replacement");
|
||||||
|
|
||||||
for (String propertyName : this.properties) {
|
for (String propertyName : this.properties) {
|
||||||
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
this.executeOnProperty(propertyName, propertyName + this.propertySuffix);
|
||||||
@@ -44,15 +47,15 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.properties == null)
|
if (this.properties == null)
|
||||||
throw new MojoFailureException("A 'properties' element is required");
|
throw new MojoException("A 'properties' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
// make sure we have a list and it is nice and neat
|
// make sure we have a list and it is nice and neat
|
||||||
@@ -74,13 +77,13 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.propertySuffix == null)
|
if (this.propertySuffix == null)
|
||||||
throw new MojoFailureException("The 'propertySuffix' element is required");
|
throw new MojoException("The 'propertySuffix' element is required");
|
||||||
if (this.properties.isEmpty())
|
if (this.properties.isEmpty())
|
||||||
throw new MojoFailureException("At least one 'property' element is required");
|
throw new MojoException("At least one 'property' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,18 @@
|
|||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "replace-property", threadSafe = true )
|
@Mojo(name = "replace-property")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "property", required = true )
|
@Parameter( property = "property", required = true )
|
||||||
protected String property;
|
protected String property;
|
||||||
|
|
||||||
@@ -32,14 +34,14 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
|||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing property regex replacement");
|
this.logger.debug("Executing property regex replacement");
|
||||||
|
|
||||||
this.executeOnProperty(this.property, this.newProperty);
|
this.executeOnProperty(this.property, this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
this.property = StringUtils.trimToNull(this.property);
|
this.property = StringUtils.trimToNull(this.property);
|
||||||
@@ -49,11 +51,11 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.property == null)
|
if (this.property == null)
|
||||||
throw new MojoFailureException("The 'property' element is required");
|
throw new MojoException("The 'property' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,18 @@
|
|||||||
package com.inteligr8.maven.regex;
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.api.di.Inject;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.api.plugin.Log;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.api.plugin.MojoException;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.api.plugin.annotations.Mojo;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.apache.maven.api.plugin.annotations.Parameter;
|
||||||
|
|
||||||
@Mojo( name = "replace-text", threadSafe = true )
|
@Mojo(name = "replace-text")
|
||||||
@Component( role = org.apache.maven.plugin.Mojo.class )
|
|
||||||
public class ReplaceTextMojo extends AbstractReplaceMojo {
|
public class ReplaceTextMojo extends AbstractReplaceMojo {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Log logger;
|
||||||
|
|
||||||
@Parameter( property = "text", required = true )
|
@Parameter( property = "text", required = true )
|
||||||
protected String text;
|
protected String text;
|
||||||
|
|
||||||
@@ -32,33 +34,33 @@ public class ReplaceTextMojo extends AbstractReplaceMojo {
|
|||||||
protected String newProperty;
|
protected String newProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void go() throws MojoExecutionException {
|
public void go() throws MojoException {
|
||||||
this.getLog().debug("Executing property regex replacement");
|
this.logger.debug("Executing property regex replacement");
|
||||||
|
|
||||||
this.executeOnText(this.project.getProperties(), this.text, this.newProperty);
|
this.executeOnText(this.text, this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPreNormalization() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoException {
|
||||||
super.validateParamsPreNormalization();
|
super.validateParamsPreNormalization();
|
||||||
|
|
||||||
if (this.text == null)
|
if (this.text == null)
|
||||||
throw new MojoFailureException("The 'text' element is required");
|
throw new MojoException("The 'text' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.newProperty == null)
|
if (this.newProperty == null)
|
||||||
throw new MojoFailureException("The 'newProperty' element is required");
|
throw new MojoException("The 'newProperty' element is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.model;
|
package com.inteligr8.maven.regex.model;
|
||||||
|
|
||||||
public interface Normalizable {
|
public interface Normalizable {
|
||||||
|
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.model;
|
package com.inteligr8.maven.regex.model;
|
||||||
|
|
||||||
public class Regex implements Normalizable {
|
public class Regex implements Normalizable {
|
||||||
|
|
||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.inteligr8.nio;
|
package com.inteligr8.maven.regex.nio;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
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.FileSet;
|
||||||
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class FileSetUnitTest {
|
public class FileSetUnitTest {
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ public class FileSetUnitTest {
|
|||||||
String fs = File.separator;
|
String fs = File.separator;
|
||||||
FileSetManager fsman = new FileSetManager();
|
FileSetManager fsman = new FileSetManager();
|
||||||
Set<String> files = new HashSet<>(Arrays.asList(fsman.getIncludedFiles(fileset)));
|
Set<String> files = new HashSet<>(Arrays.asList(fsman.getIncludedFiles(fileset)));
|
||||||
Assert.assertTrue(files.size() > 15);
|
Assertions.assertTrue(files.size() > 15);
|
||||||
System.err.println(files);
|
System.err.println(files);
|
||||||
Assert.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java"));
|
Assertions.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-28
@@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.nio;
|
package com.inteligr8.maven.regex.nio;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -10,8 +10,8 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class DelimitedReadableByteChannelUnitTest {
|
public class DelimitedReadableByteChannelUnitTest {
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ public class DelimitedReadableByteChannelUnitTest {
|
|||||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\n");
|
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\n");
|
||||||
try {
|
try {
|
||||||
StringBuilder strbuilder = new StringBuilder();
|
StringBuilder strbuilder = new StringBuilder();
|
||||||
Assert.assertEquals(-1L, drbchannel.read(strbuilder));
|
Assertions.assertEquals(-1L, drbchannel.read(strbuilder));
|
||||||
Assert.assertEquals(0, strbuilder.length());
|
Assertions.assertEquals(0, strbuilder.length());
|
||||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||||
} finally {
|
} finally {
|
||||||
drbchannel.close();
|
drbchannel.close();
|
||||||
}
|
}
|
||||||
@@ -44,18 +44,18 @@ public class DelimitedReadableByteChannelUnitTest {
|
|||||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
||||||
try {
|
try {
|
||||||
StringWriter writer = new StringWriter(1024);
|
StringWriter writer = new StringWriter(1024);
|
||||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertEquals("", writer.toString());
|
Assertions.assertEquals("", writer.toString());
|
||||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertEquals("here is a line", writer.toString());
|
Assertions.assertEquals("here is a line", writer.toString());
|
||||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
Assert.assertEquals(-1L, drbchannel.read(writer));
|
Assertions.assertEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||||
} finally {
|
} finally {
|
||||||
drbchannel.close();
|
drbchannel.close();
|
||||||
}
|
}
|
||||||
@@ -73,18 +73,18 @@ public class DelimitedReadableByteChannelUnitTest {
|
|||||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n");
|
||||||
try {
|
try {
|
||||||
StringWriter writer = new StringWriter(1024);
|
StringWriter writer = new StringWriter(1024);
|
||||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertEquals("the first line", writer.toString());
|
Assertions.assertEquals("the first line", writer.toString());
|
||||||
Assert.assertNotNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNotNull(drbchannel.getLastDelimiterRead());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertEquals("the last line", writer.toString());
|
Assertions.assertEquals("the last line", writer.toString());
|
||||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
Assert.assertEquals(-1L, drbchannel.read(writer));
|
Assertions.assertEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertNull(drbchannel.getLastDelimiterRead());
|
Assertions.assertNull(drbchannel.getLastDelimiterRead());
|
||||||
} finally {
|
} finally {
|
||||||
drbchannel.close();
|
drbchannel.close();
|
||||||
}
|
}
|
||||||
@@ -111,14 +111,14 @@ public class DelimitedReadableByteChannelUnitTest {
|
|||||||
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(chunkSize, fchannel, Charset.defaultCharset(), "\n");
|
DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(chunkSize, fchannel, Charset.defaultCharset(), "\n");
|
||||||
try {
|
try {
|
||||||
StringWriter writer = new StringWriter(1024);
|
StringWriter writer = new StringWriter(1024);
|
||||||
Assert.assertNotEquals(-1L, drbchannel.read(writer));
|
Assertions.assertNotEquals(-1L, drbchannel.read(writer));
|
||||||
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", writer.toString());
|
Assertions.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", writer.toString());
|
||||||
Assert.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||||
|
|
||||||
writer = new StringWriter(1024);
|
writer = new StringWriter(1024);
|
||||||
Assert.assertEquals(1, drbchannel.read(writer));
|
Assertions.assertEquals(1, drbchannel.read(writer));
|
||||||
Assert.assertEquals("", writer.toString());
|
Assertions.assertEquals("", writer.toString());
|
||||||
Assert.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead());
|
||||||
} finally {
|
} finally {
|
||||||
drbchannel.close();
|
drbchannel.close();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user