You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/03/16 13:42:06 UTC
[maven-patch-plugin] 01/08: MPATCH-20 added support for
excludePattern
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-patch-plugin.git
commit db58bb0932593f43e3e96a0496da5a4ceedd58a5
Author: Matthias Balke <ma...@googlemail.com>
AuthorDate: Mon Mar 5 16:33:29 2018 +0100
MPATCH-20 added support for excludePattern
---
src/it/cant-exclude-patches-from-patches/pom.xml | 67 ++++++++++++++++++++++
.../src/main/patches/first.patch | 26 +++++++++
.../src/main/patches/second.patch | 25 ++++++++
.../cant-exclude-patches-from-patches/verify.bsh | 45 +++++++++++++++
src/it/exclude-patches-from-patchDirectory/pom.xml | 63 ++++++++++++++++++++
.../src/main/patches/first.patch | 26 +++++++++
.../src/main/patches/second.patch | 25 ++++++++
.../exclude-patches-from-patchDirectory/verify.bsh | 45 +++++++++++++++
.../org/apache/maven/plugin/patch/ApplyMojo.java | 10 +++-
9 files changed, 331 insertions(+), 1 deletion(-)
diff --git a/src/it/cant-exclude-patches-from-patches/pom.xml b/src/it/cant-exclude-patches-from-patches/pom.xml
new file mode 100644
index 0000000..e13970e
--- /dev/null
+++ b/src/it/cant-exclude-patches-from-patches/pom.xml
@@ -0,0 +1,67 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>test</groupId>
+ <artifactId>cant-exclude-patches-from-patches</artifactId>
+ <name>cant-exclude-patches-from-patches</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-patch-plugin</artifactId>
+ <version>@pom.version@</version>
+
+ <configuration>
+ <targetDirectory>${basedir}</targetDirectory>
+ <!-- this exclude does not work, as it is only excluding files from patchDirectory -->
+ <excludePattern>se*.patch</excludePattern>
+ <!-- both patches should be executed -->
+ <patches>
+ <patch>first.patch</patch>
+ <patch>second.patch</patch>
+ </patches>
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>apply-patches</id>
+
+ <phase>initialize</phase>
+
+ <goals>
+ <goal>apply</goal>
+ </goals>
+
+ <configuration>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/cant-exclude-patches-from-patches/src/main/patches/first.patch b/src/it/cant-exclude-patches-from-patches/src/main/patches/first.patch
new file mode 100644
index 0000000..5c6f211
--- /dev/null
+++ b/src/it/cant-exclude-patches-from-patches/src/main/patches/first.patch
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+Index: target/test.txt
+===================================================================
+--- target/test.txt (revision 0)
++++ target/test.txt (revision 0)
+@@ -0,0 +1 @@
++This is a test.
+\ No newline at end of file
+
diff --git a/src/it/cant-exclude-patches-from-patches/src/main/patches/second.patch b/src/it/cant-exclude-patches-from-patches/src/main/patches/second.patch
new file mode 100644
index 0000000..0ae1671
--- /dev/null
+++ b/src/it/cant-exclude-patches-from-patches/src/main/patches/second.patch
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+Index: target/test2.txt
+===================================================================
+--- target/test2.txt (revision 0)
++++ target/test2.txt (revision 0)
+@@ -0,0 +1 @@
++This is a test.
+
diff --git a/src/it/cant-exclude-patches-from-patches/verify.bsh b/src/it/cant-exclude-patches-from-patches/verify.bsh
new file mode 100644
index 0000000..dd3f3b8
--- /dev/null
+++ b/src/it/cant-exclude-patches-from-patches/verify.bsh
@@ -0,0 +1,45 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+import java.io.*;
+import java.util.*;
+
+try
+{
+ File testFile = new File( basedir, "target/test.txt" );
+ if ( !testFile.isFile() )
+ {
+ System.err.println( "Missing test file: " + testFile );
+ return false;
+ }
+
+ testFile = new File( basedir, "target/test2.txt" );
+ if ( !testFile.isFile() )
+ {
+ System.err.println( "Missing test file: " + testFile );
+ return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
diff --git a/src/it/exclude-patches-from-patchDirectory/pom.xml b/src/it/exclude-patches-from-patchDirectory/pom.xml
new file mode 100644
index 0000000..6e5b626
--- /dev/null
+++ b/src/it/exclude-patches-from-patchDirectory/pom.xml
@@ -0,0 +1,63 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>test</groupId>
+ <artifactId>exclude-patches-from-patchDirectory</artifactId>
+ <name>exclude-patches-from-patchDirectory</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-patch-plugin</artifactId>
+ <version>@pom.version@</version>
+
+ <configuration>
+ <targetDirectory>${basedir}</targetDirectory>
+ <excludePattern>se*.patch</excludePattern>
+ <!-- enables reading of patches from src/main/patches -->
+ <naturalOrderProcessing>true</naturalOrderProcessing>
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>apply-patches</id>
+
+ <phase>initialize</phase>
+
+ <goals>
+ <goal>apply</goal>
+ </goals>
+
+ <configuration>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/exclude-patches-from-patchDirectory/src/main/patches/first.patch b/src/it/exclude-patches-from-patchDirectory/src/main/patches/first.patch
new file mode 100644
index 0000000..5c6f211
--- /dev/null
+++ b/src/it/exclude-patches-from-patchDirectory/src/main/patches/first.patch
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+Index: target/test.txt
+===================================================================
+--- target/test.txt (revision 0)
++++ target/test.txt (revision 0)
+@@ -0,0 +1 @@
++This is a test.
+\ No newline at end of file
+
diff --git a/src/it/exclude-patches-from-patchDirectory/src/main/patches/second.patch b/src/it/exclude-patches-from-patchDirectory/src/main/patches/second.patch
new file mode 100644
index 0000000..0ae1671
--- /dev/null
+++ b/src/it/exclude-patches-from-patchDirectory/src/main/patches/second.patch
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+Index: target/test2.txt
+===================================================================
+--- target/test2.txt (revision 0)
++++ target/test2.txt (revision 0)
+@@ -0,0 +1 @@
++This is a test.
+
diff --git a/src/it/exclude-patches-from-patchDirectory/verify.bsh b/src/it/exclude-patches-from-patchDirectory/verify.bsh
new file mode 100644
index 0000000..7be8344
--- /dev/null
+++ b/src/it/exclude-patches-from-patchDirectory/verify.bsh
@@ -0,0 +1,45 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+import java.io.*;
+import java.util.*;
+
+try
+{
+ File testFile = new File( basedir, "target/test.txt" );
+ if ( !testFile.isFile() )
+ {
+ System.err.println( "Missing test file: " + testFile );
+ return false;
+ }
+
+ testFile = new File( basedir, "target/test2.txt" );
+ if ( testFile.isFile() )
+ {
+ System.err.println( "File must not exist: " + testFile );
+ return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java b/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
index 2066b8a..83da555 100644
--- a/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
+++ b/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
@@ -237,6 +237,9 @@ public class ApplyMojo
@Parameter( defaultValue = "false" )
private boolean binary;
+ @Parameter
+ private String excludePattern;
+
/**
* Apply the patches. Give preference to patchFile over patchSourceDir/patches, and preference to originalFile over
* workDir.
@@ -278,7 +281,12 @@ public class ApplyMojo
+ patchDirectory );
}
- List foundPatchFiles = FileUtils.getFileNames( patchDirectory, "*", null, false );
+ if ( excludePattern != null )
+ {
+ getLog().info( "Exclude pattern: " + excludePattern );
+ }
+
+ List foundPatchFiles = FileUtils.getFileNames( patchDirectory, "*", excludePattern, false );
patchesToApply = findPatchesToApply( foundPatchFiles, patchDirectory );