Merge branch 'develop' into stable
This commit is contained in:
commit
1bb0190807
@ -1,8 +1,8 @@
|
|||||||
<?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.0.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Replace File Plugin Tests</name>
|
<name>Replace File Plugin Tests</name>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -62,7 +62,7 @@
|
|||||||
<excludes>
|
<excludes>
|
||||||
<exclude>pom.xml</exclude>
|
<exclude>pom.xml</exclude>
|
||||||
<exclude>*.log</exclude>
|
<exclude>*.log</exclude>
|
||||||
<exclude>target</exclude>
|
<exclude>target/**/*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
<outputDirectory>${project.build.directory}/noreplace-one</outputDirectory>
|
<outputDirectory>${project.build.directory}/noreplace-one</outputDirectory>
|
||||||
</fileset>
|
</fileset>
|
||||||
@ -75,31 +75,74 @@
|
|||||||
</regexes>
|
</regexes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>replace-linestart</id>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>replace-file</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<filesets>
|
||||||
|
<fileset>
|
||||||
|
<directory>${basedir}/folder1</directory>
|
||||||
|
<includes>
|
||||||
|
<include>file12.txt</include>
|
||||||
|
</includes>
|
||||||
|
<outputDirectory>${project.build.directory}/replace-linestart</outputDirectory>
|
||||||
|
</fileset>
|
||||||
|
</filesets>
|
||||||
|
<regexes>
|
||||||
|
<regex>
|
||||||
|
<pattern>^it is</pattern>
|
||||||
|
<replacement># it is</replacement>
|
||||||
|
</regex>
|
||||||
|
</regexes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-enforcer-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>3.0.0-M3</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>assert</id>
|
<id>assert</id>
|
||||||
<goals><goal>enforce</goal></goals>
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<rules>
|
<rules>
|
||||||
<requireFilesExist>
|
|
||||||
<files>
|
|
||||||
<file>${project.build.directory}/replace-one/file1.txt</file>
|
|
||||||
<file>${project.build.directory}/noreplace-one/file1.txt</file>
|
|
||||||
<file>${project.build.directory}/noreplace-one/folder1/file11.txt</file>
|
|
||||||
<file>${project.build.directory}/noreplace-one/folder1/file12.txt</file>
|
|
||||||
</files>
|
|
||||||
</requireFilesExist>
|
|
||||||
<requireFilesDontExist>
|
<requireFilesDontExist>
|
||||||
<files>
|
<files>
|
||||||
<file>${project.build.directory}/replace-one/folder1/file11.txt</file>
|
<file>${project.build.directory}/replace-one/folder1/file11.txt</file>
|
||||||
<file>${project.build.directory}/replace-one/folder1/file12.txt</file>
|
<file>${project.build.directory}/replace-one/folder1/file12.txt</file>
|
||||||
</files>
|
</files>
|
||||||
</requireFilesDontExist>
|
</requireFilesDontExist>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${project.build.directory}/replace-one/file1.txt</file>
|
||||||
|
<checksum>6f1ed002ab5595859014ebf0951522d9</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${project.build.directory}/noreplace-one/file1.txt</file>
|
||||||
|
<checksum>6f1ed002ab5595859014ebf0951522d9</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${project.build.directory}/noreplace-one/folder1/file11.txt</file>
|
||||||
|
<checksum>72cd622783716925706f49d392089b48</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${project.build.directory}/noreplace-one/folder1/file12.txt</file>
|
||||||
|
<checksum>925a6e3bd25cdd61695aa55d008ab4d2</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
|
<requireFileChecksum>
|
||||||
|
<file>${project.build.directory}/replace-linestart/file12.txt</file>
|
||||||
|
<checksum>fb1f2b040970526fc99b1339f22465f1</checksum>
|
||||||
|
<type>md5</type>
|
||||||
|
</requireFileChecksum>
|
||||||
</rules>
|
</rules>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
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.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -57,9 +58,11 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (FileSet fileSet : this.filesets) {
|
for (FileSet fileSet : this.filesets) {
|
||||||
|
Path baseInputPath = this.resolveDirectory(basepath, fileSet.getDirectory(), "fileset input");
|
||||||
|
|
||||||
String[] filePathsAndNames = fsman.getIncludedFiles(fileSet);
|
String[] filePathsAndNames = fsman.getIncludedFiles(fileSet);
|
||||||
for (String filePathAndName : filePathsAndNames) {
|
for (String filePathAndName : filePathsAndNames) {
|
||||||
Path file = basepath.resolve(filePathAndName);
|
Path file = baseInputPath.resolve(filePathAndName);
|
||||||
if (!Files.isDirectory(file))
|
if (!Files.isDirectory(file))
|
||||||
if (this.matches(file, this.chunkSize))
|
if (this.matches(file, this.chunkSize))
|
||||||
return true;
|
return true;
|
||||||
@ -72,6 +75,20 @@ public class MatchFileContentMojo extends AbstractMatchMojo {
|
|||||||
return this.negate;
|
return this.negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoExecutionException {
|
||||||
|
Path path = new File(directory).toPath();
|
||||||
|
if (!path.isAbsolute())
|
||||||
|
path = basepath.resolve(path);
|
||||||
|
|
||||||
|
if (!Files.exists(path))
|
||||||
|
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
||||||
|
|
||||||
|
if (!Files.isDirectory(path))
|
||||||
|
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoFailureException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
@ -52,16 +52,12 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (FileSet fileSet : this.filesets) {
|
for (FileSet fileSet : this.filesets) {
|
||||||
String outputDir = fileSet.getOutputDirectory();
|
Path baseInputPath = this.resolveDirectory(basepath, fileSet.getDirectory(), false, "fileset input");
|
||||||
Path baseOutputPath = new File(outputDir).toPath();
|
Path baseOutputPath = this.resolveDirectory(basepath, fileSet.getOutputDirectory(), true, "fileset output");
|
||||||
if (!Files.exists(baseOutputPath))
|
|
||||||
Files.createDirectories(baseOutputPath);
|
|
||||||
if (!Files.isDirectory(baseOutputPath))
|
|
||||||
throw new MojoExecutionException("A fileset output directory does not reference a directory: " + outputDir);
|
|
||||||
|
|
||||||
String[] filePathsAndNames = fsman.getIncludedFiles(fileSet);
|
String[] filePathsAndNames = fsman.getIncludedFiles(fileSet);
|
||||||
for (String filePathAndName : filePathsAndNames) {
|
for (String filePathAndName : filePathsAndNames) {
|
||||||
Path file = basepath.resolve(filePathAndName);
|
Path file = baseInputPath.resolve(filePathAndName);
|
||||||
Path tofile = baseOutputPath.resolve(filePathAndName);
|
Path tofile = baseOutputPath.resolve(filePathAndName);
|
||||||
if (!Files.exists(tofile.getParent()))
|
if (!Files.exists(tofile.getParent()))
|
||||||
Files.createDirectories(tofile.getParent());
|
Files.createDirectories(tofile.getParent());
|
||||||
@ -77,6 +73,25 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo {
|
|||||||
return didReplace;
|
return didReplace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoExecutionException {
|
||||||
|
Path path = new File(directory).toPath();
|
||||||
|
if (!path.isAbsolute())
|
||||||
|
path = basepath.resolve(path);
|
||||||
|
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
if (createIfMissing) {
|
||||||
|
Files.createDirectories(path);
|
||||||
|
} else {
|
||||||
|
throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isDirectory(path))
|
||||||
|
throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void normalizeParameters() throws MojoFailureException {
|
protected void normalizeParameters() throws MojoFailureException {
|
||||||
super.normalizeParameters();
|
super.normalizeParameters();
|
||||||
|
29
src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java
Normal file
29
src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.inteligr8.maven.regex;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.maven.shared.model.fileset.FileSet;
|
||||||
|
import org.apache.maven.shared.model.fileset.util.FileSetManager;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FileSetUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void srcMainJava() {
|
||||||
|
FileSet fileset = new FileSet();
|
||||||
|
fileset.setDirectory("src/main/java");
|
||||||
|
fileset.setIncludes(Arrays.asList("**/*.java"));
|
||||||
|
|
||||||
|
String fs = File.separator;
|
||||||
|
FileSetManager fsman = new FileSetManager();
|
||||||
|
Set<String> files = new HashSet<>(Arrays.asList(fsman.getIncludedFiles(fileset)));
|
||||||
|
Assert.assertTrue(files.size() > 15);
|
||||||
|
System.err.println(files);
|
||||||
|
Assert.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user