Skip to content

Commit

Permalink
Added a configurable regex to filter out certain file generated by te…
Browse files Browse the repository at this point in the history
…xt editors
  • Loading branch information
jebeaudet committed May 2, 2017
1 parent 3810a8a commit c51b739
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ By using this plugin, the build will fail when problematic version numbers are f
I plan on publishing to maven central soon but in the meantime, clone this project and publish it to your local maven repo. Then, add this to your project/parent pom.xml :
```
<plugin>
<groupId>jebeaudet</groupId>
<groupId>io.github.jebeaudet</groupId>
<artifactId>flyway-validator-maven-plugin</artifactId>
<version>0.2</version>
<executions>
Expand All @@ -26,19 +26,21 @@ The following properties can be configured :
* Root path of source files;
* Path for SQL migrations;
* Base package for .java migrations;
* Flag to fail the build if invalid SQL filenames are found.
* Flag to fail the build if invalid SQL filenames are found;
* Regex to ignore when scanning for filenames, useful to filter out automatic save file generated by editors.

This is done in the plugin configuration (defaults value shown here) :
This is done in the plugin configuration (default values shown here) :
```
<plugin>
<groupId>com.coveo</groupId>
<groupId>io.github.jebeaudet</groupId>
<artifactId>flyway-validator-maven-plugin</artifactId>
<version>0.2</version>
<configuration>
<rootPath>/src/main/resources</rootPath>
<sqlRevisesRootPath>db/migration</sqlRevisesRootPath>
<javaRevisesPackage>db.migration</javaRevisesPackage>
<abortBuildOnInvalidFilenames>true</abortBuildOnInvalidFilenames>
<ignoredFileRegex>.*~$</ignoredFileRegex>
</configuration>
[...]
</plugin>
Expand All @@ -50,7 +52,7 @@ Here's an example of a failed build :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.coveo:flyway-validator-maven-plugin:0.2:validate-flyway-revises (default) on project test-project:
[ERROR] Failed to execute goal io.github.jebeaudet:flyway-validator-maven-plugin:0.2:validate-flyway-revises (default) on project test-project:
[ERROR] ------------------------------------------------------------------------
[ERROR] Duplicate migration version(s) found : [1.0, 1.0.1].
[ERROR] Details :
Expand All @@ -62,4 +64,4 @@ Here's an example of a failed build :
```

## Question or found a bug?
Open an issue! PR are also welcome.
Open an issue! PR are also welcome.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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>

<groupId>jebeaudet</groupId>
<groupId>io.github.jebeaudet</groupId>
<artifactId>flyway-validator-maven-plugin</artifactId>
<version>0.2</version>
<version>0.3-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>flyway-validator-maven-plugin</name>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/jebeaudet/flywayvalidator/FlywayValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FlywayValidator extends AbstractMojo
private static final String SLASH = "/";

@Parameter(defaultValue = "${session.currentProject}", required = true, readonly = true)
protected MavenProject mavenProject;
private MavenProject mavenProject;

/**
* Root path of source files. Defaults to <b>src/main/resources</b>.
Expand Down Expand Up @@ -60,6 +60,12 @@ public class FlywayValidator extends AbstractMojo
required = true)
private boolean abortBuildOnInvalidFilenames;

/**
* Filename regex to ignore in the validation of invalid filenames. Useful to filter out automatic save file generated by editors. Defaults to <b>.*~$</b>.
*/
@Parameter(property = "validate-flyway-revises.ignoredFileRegex", defaultValue = ".*~$", required = true)
private String ignoredFileRegex;

@Override
public void execute() throws MojoFailureException, MojoExecutionException
{
Expand Down Expand Up @@ -149,6 +155,7 @@ private List<FlywayMigration> getSqlFlywayMigrationFromPath(String path)
List<String> filenames = filesArray.map(fileArray -> Arrays.stream(fileArray)
.filter(file -> file.isFile())
.map(filename -> filename.getName())
.filter(filename -> !filename.matches(ignoredFileRegex))
.collect(Collectors.toList()))
.orElseGet(() -> new ArrayList<>());

Expand Down

0 comments on commit c51b739

Please sign in to comment.