Merge branch 'develop' into stable

This commit is contained in:
Brian Long 2021-06-03 20:08:09 -04:00
commit e46dc26404
5 changed files with 73 additions and 14 deletions

View File

@ -99,6 +99,31 @@
</regexes>
</configuration>
</execution>
<execution>
<id>inplace</id>
<phase>validate</phase>
<goals>
<goal>replace-file</goal>
</goals>
<configuration>
<filesets>
<fileset>
<includes>
<include>**/file12.txt</include>
</includes>
<excludes>
<exclude>target/**/*</exclude>
</excludes>
</fileset>
</filesets>
<regexes>
<regex>
<pattern>is supposed</pattern>
<replacement>is likely</replacement>
</regex>
</regexes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@ -143,6 +168,11 @@
<checksum>fb1f2b040970526fc99b1339f22465f1</checksum>
<type>md5</type>
</requireFileChecksum>
<requireFileChecksum>
<file>${basedir}/folder1/file12.txt</file>
<checksum>a7f509275e16ff57cd7756cdca70822a</checksum>
<type>md5</type>
</requireFileChecksum>
</rules>
</configuration>
</execution>

View File

@ -14,8 +14,6 @@
*/
package com.inteligr8.maven.model;
import org.apache.commons.lang3.StringUtils;
public class Regex implements Normalizable {
private String pattern;
@ -41,8 +39,8 @@ public class Regex implements Normalizable {
@Override
public void normalize() {
this.pattern = StringUtils.trimToNull(this.pattern);
this.replacement = StringUtils.trimToNull(this.replacement);
if (this.replacement == null)
this.replacement = "";
}
}

View File

@ -14,10 +14,13 @@
*/
package com.inteligr8.maven.regex;
import java.io.File;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.LinkedList;
import java.util.List;
@ -130,10 +133,16 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
if (this.getLog().isDebugEnabled())
this.getLog().debug("replace all: " + file + " => " + tofile);
boolean overwrite = file.equals(tofile);
boolean didReplace = false;
Charset charset = Charset.forName(this.charsetName);
StringBuilder strbuilder = new StringBuilder();
if (overwrite) {
// if overwriting the existing file, use a temporary file
tofile = File.createTempFile("regexed-", ".tmp").toPath();
}
FileChannel targetChannel = FileChannel.open(tofile, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
try {
FileChannel sourceChannel = FileChannel.open(file, StandardOpenOption.READ);
@ -177,6 +186,10 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
targetChannel.close();
}
if (overwrite) {
Files.move(tofile, file, StandardCopyOption.REPLACE_EXISTING);
}
return didReplace;
}

View File

@ -89,10 +89,23 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
return path;
}
@Override
protected void validateParamsPreNormalization() throws MojoFailureException {
super.validateParamsPreNormalization();
if (this.filesets == null || this.filesets.isEmpty())
throw new MojoFailureException("At least one 'fileset' is required");
}
@Override
protected void normalizeParameters() throws MojoFailureException {
super.normalizeParameters();
for (FileSet fileset : this.filesets) {
if (fileset.getDirectory() == null)
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
}
this.newProperty = StringUtils.trimToNull(this.newProperty);
}
@ -100,8 +113,6 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
protected void validateParamsPostNormalization() throws MojoFailureException {
super.validateParamsPostNormalization();
if (this.filesets == null || this.filesets.isEmpty())
throw new MojoFailureException("At least one 'fileset' is required");
if (this.newProperty == null)
throw new MojoFailureException("The 'newProperty' element is required");
}

View File

@ -74,6 +74,9 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
}
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoExecutionException {
if (directory == null)
return this.project.getBasedir().toPath();
Path path = new File(directory).toPath();
if (!path.isAbsolute())
path = basepath.resolve(path);
@ -93,19 +96,23 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
}
@Override
protected void normalizeParameters() throws MojoFailureException {
super.normalizeParameters();
}
@Override
protected void validateParamsPostNormalization() throws MojoFailureException {
super.validateParamsPostNormalization();
protected void validateParamsPreNormalization() throws MojoFailureException {
super.validateParamsPreNormalization();
if (this.filesets == null || this.filesets.isEmpty())
throw new MojoFailureException("At least one 'fileset' is required");
for (FileSet fileset : this.filesets)
}
@Override
protected void normalizeParameters() throws MojoFailureException {
super.normalizeParameters();
for (FileSet fileset : this.filesets) {
if (fileset.getDirectory() == null)
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
if (fileset.getOutputDirectory() == null)
throw new MojoFailureException("All 'fileset' must have an 'outputDirectory'");
fileset.setOutputDirectory(fileset.getDirectory());
}
}
}