Author: jmcconnell
Date: Wed Jun 20 10:09:55 2007
New Revision: 549155
URL: http://svn.apache.org/viewvc?view=rev&rev=549155
Log:
added naturalOrderProcessing option to the ApplyPatchDirectoryMojo and moved
the execute logic from the abstract mojo to enable this behavior. now you can
apply the directory mojo to a directory that follows a naming convention and
have it apply accordingly
Modified:
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/AbstractPatchMojo.java
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchesMojo.java
Modified:
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/AbstractPatchMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/AbstractPatchMojo.java?view=diff&rev=549155&r1=549154&r2=549155
==============================================================================
---
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/AbstractPatchMojo.java
(original)
+++
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/AbstractPatchMojo.java
Wed Jun 20 10:09:55 2007
@@ -41,12 +41,12 @@
/**
* The list of patch file names (without directory information), supplying
the order in which patches should be
- * applied.
+ * applied. (relative to 'patchSourceDir')
*
* @parameter
*/
- private List patches;
-
+ protected List patches;
+
protected List getPatches()
{
return patches;
@@ -59,12 +59,6 @@
public final void execute() throws MojoExecutionException,
MojoFailureException
{
- if ( ( patches == null ) || patches.isEmpty() )
- {
- getLog().info( "Patching is disabled for this project." );
- return;
- }
-
doExecute();
}
Modified:
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java?view=diff&rev=549155&r1=549154&r2=549155
==============================================================================
---
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java
(original)
+++
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java
Wed Jun 20 10:09:55 2007
@@ -21,6 +21,8 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -29,6 +31,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -97,6 +100,14 @@
private File targetDirectory;
/**
+ * setting natural order processing to true will all patches in a
directory to be processed in an natural order
+ * alleviating the need to declare patches directly in the project file.
+ *
+ * @parameter default-value="false"
+ */
+ private boolean naturalOrderProcessing;
+
+ /**
* When the strictPatching flag is set, this parameter is useful to mark
certain contents of the patch-source
* directory that should be ignored without causing the build to fail.
*
@@ -167,6 +178,13 @@
public void doExecute()
throws MojoExecutionException, MojoFailureException
{
+ // if patches is null or empty, and naturalOrderProcessing is not true
then disable patching
+ if ( ( patches == null || patches.isEmpty() ) &&
!naturalOrderProcessing )
+ {
+ getLog().info( "Patching is disabled for this project." );
+ return;
+ }
+
if ( skipApplication )
{
getLog().info( "Skipping patchfile application (per
configuration)." );
@@ -180,17 +198,24 @@
return;
}
- List foundPatchFiles = new ArrayList( Arrays.asList(
patchDirectory.list() ) );
-
- Map patchesApplied = findPatchesToApply( foundPatchFiles,
patchDirectory );
-
- checkStrictPatchCompliance( foundPatchFiles );
-
- String output = applyPatches( patchesApplied );
-
- checkForWatchPhrases( output );
-
- writeTrackingFile( patchesApplied );
+ try
+ {
+ List foundPatchFiles = FileUtils.getFileNames(
patchDirectory, "*", null, false );
+
+ Map patchesApplied =
findPatchesToApply(foundPatchFiles, patchDirectory);
+
+ checkStrictPatchCompliance(foundPatchFiles);
+
+ String output = applyPatches(patchesApplied);
+
+ checkForWatchPhrases(output);
+
+ writeTrackingFile(patchesApplied);
+ }
+ catch (IOException ioe)
+ {
+ throw new MojoExecutionException( "unable to obtain
list of patch files", ioe);
+ }
}
private Map findPatchesToApply( List foundPatchFiles, File patchSourceDir )
@@ -198,8 +223,14 @@
{
List patches = getPatches();
- Map patchesApplied = new LinkedHashMap( patches.size() );
+ Map patchesApplied = new LinkedHashMap( );
+ if ( naturalOrderProcessing )
+ {
+ patches = new ArrayList( foundPatchFiles ) ;
+ Collections.sort( patches );
+ }
+
for ( Iterator it = patches.iterator(); it.hasNext(); )
{
String patch = (String) it.next();
@@ -209,7 +240,7 @@
getLog().debug( "Looking for patch: " + patch + " in: " +
patchFile );
if ( !patchFile.exists() )
- {
+ {
if ( strictPatching )
{
throw new MojoFailureException(
@@ -233,6 +264,7 @@
patchesApplied.put( patch, createPatchCommand( patchFile ) );
}
}
+
return patchesApplied;
}
Modified:
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchesMojo.java
URL:
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchesMojo.java?view=diff&rev=549155&r1=549154&r2=549155
==============================================================================
---
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchesMojo.java
(original)
+++
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchesMojo.java
Wed Jun 20 10:09:55 2007
@@ -114,6 +114,13 @@
*/
public void doExecute() throws MojoExecutionException, MojoFailureException
{
+ // if the patches is not specified, and patchfile is not specified,
then disable execution
+ if ( ( patches == null || patches.isEmpty() ) && patchFile == null )
+ {
+ getLog().info( "Patching is disabled for this project." );
+ return;
+ }
+
if ( skipApplication )
{
getLog().info( "Skipping patchfile application (per
configuration)." );