Merge branch 'develop' into stable
This commit is contained in:
commit
e46dc26404
@ -99,6 +99,31 @@
|
|||||||
</regexes>
|
</regexes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</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>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -143,6 +168,11 @@
|
|||||||
<checksum>fb1f2b040970526fc99b1339f22465f1</checksum>
|
<checksum>fb1f2b040970526fc99b1339f22465f1</checksum>
|
||||||
<type>md5</type>
|
<type>md5</type>
|
||||||
</requireFileChecksum>
|
</requireFileChecksum>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${basedir}/folder1/file12.txt</file>
|
||||||
|
<checksum>a7f509275e16ff57cd7756cdca70822a</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
</rules>
|
</rules>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.maven.model;
|
package com.inteligr8.maven.model;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
public class Regex implements Normalizable {
|
public class Regex implements Normalizable {
|
||||||
|
|
||||||
private String pattern;
|
private String pattern;
|
||||||
@ -41,8 +39,8 @@ public class Regex implements Normalizable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void normalize() {
|
public void normalize() {
|
||||||
this.pattern = StringUtils.trimToNull(this.pattern);
|
if (this.replacement == null)
|
||||||
this.replacement = StringUtils.trimToNull(this.replacement);
|
this.replacement = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,13 @@
|
|||||||
*/
|
*/
|
||||||
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.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
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;
|
||||||
@ -130,10 +133,16 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
if (this.getLog().isDebugEnabled())
|
if (this.getLog().isDebugEnabled())
|
||||||
this.getLog().debug("replace all: " + file + " => " + tofile);
|
this.getLog().debug("replace all: " + file + " => " + tofile);
|
||||||
|
|
||||||
|
boolean overwrite = file.equals(tofile);
|
||||||
boolean didReplace = false;
|
boolean didReplace = false;
|
||||||
Charset charset = Charset.forName(this.charsetName);
|
Charset charset = Charset.forName(this.charsetName);
|
||||||
StringBuilder strbuilder = new StringBuilder();
|
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);
|
FileChannel targetChannel = FileChannel.open(tofile, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
try {
|
try {
|
||||||
FileChannel sourceChannel = FileChannel.open(file, StandardOpenOption.READ);
|
FileChannel sourceChannel = FileChannel.open(file, StandardOpenOption.READ);
|
||||||
@ -177,6 +186,10 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo {
|
|||||||
targetChannel.close();
|
targetChannel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (overwrite) {
|
||||||
|
Files.move(tofile, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
return didReplace;
|
return didReplace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,10 +89,23 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
return path;
|
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
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoFailureException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
|
||||||
|
for (FileSet fileset : this.filesets) {
|
||||||
|
if (fileset.getDirectory() == null)
|
||||||
|
fileset.setDirectory(this.project.getBasedir().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
this.newProperty = StringUtils.trimToNull(this.newProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,8 +113,6 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
protected void validateParamsPostNormalization() throws MojoFailureException {
|
||||||
super.validateParamsPostNormalization();
|
super.validateParamsPostNormalization();
|
||||||
|
|
||||||
if (this.filesets == null || this.filesets.isEmpty())
|
|
||||||
throw new MojoFailureException("At least one 'fileset' is required");
|
|
||||||
if (this.newProperty == null)
|
if (this.newProperty == null)
|
||||||
throw new MojoFailureException("The 'newProperty' element is required");
|
throw new MojoFailureException("The 'newProperty' element is required");
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,9 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, MojoExecutionException {
|
||||||
|
if (directory == null)
|
||||||
|
return this.project.getBasedir().toPath();
|
||||||
|
|
||||||
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);
|
||||||
@ -93,19 +96,23 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void validateParamsPreNormalization() throws MojoFailureException {
|
||||||
super.normalizeParameters();
|
super.validateParamsPreNormalization();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void validateParamsPostNormalization() throws MojoFailureException {
|
|
||||||
super.validateParamsPostNormalization();
|
|
||||||
|
|
||||||
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 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)
|
if (fileset.getOutputDirectory() == null)
|
||||||
throw new MojoFailureException("All 'fileset' must have an 'outputDirectory'");
|
fileset.setOutputDirectory(fileset.getDirectory());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user