You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2007/06/22 23:14:02 UTC
svn commit: r549959 - in /maven/sandbox/trunk/plugins/maven-patch-plugin/src:
it/projects/apply/apply-single-patch/
it/projects/apply/apply-two-patches-in-order/
it/projects/autoskip/skip-when-patch-enum-missing/
it/projects/autoskip/skip-when-patch-tr...
Author: jdcasey
Date: Fri Jun 22 14:14:01 2007
New Revision: 549959
URL: http://svn.apache.org/viewvc?view=rev&rev=549959
Log:
Consolidating down to one apply mojo, and adjusting documentation to match.
Added:
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java (contents, props changed)
- copied, changed from r549941, maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java
Removed:
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/it/projects/apply/apply-single-patch/pom.xml
maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-two-patches-in-order/pom.xml
maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-enum-missing/pom.xml
maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-tracking-file-present/pom.xml
maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/examples/multiple.apt
maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/index.apt
maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/usage.apt
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-single-patch/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-single-patch/pom.xml?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-single-patch/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-single-patch/pom.xml Fri Jun 22 14:14:01 2007
@@ -49,7 +49,7 @@
<phase>initialize</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
</execution>
</executions>
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-two-patches-in-order/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-two-patches-in-order/pom.xml?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-two-patches-in-order/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/apply/apply-two-patches-in-order/pom.xml Fri Jun 22 14:14:01 2007
@@ -50,7 +50,7 @@
<phase>initialize</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
<configuration>
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-enum-missing/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-enum-missing/pom.xml?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-enum-missing/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-enum-missing/pom.xml Fri Jun 22 14:14:01 2007
@@ -46,7 +46,7 @@
<phase>initialize</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
</execution>
</executions>
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-tracking-file-present/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-tracking-file-present/pom.xml?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-tracking-file-present/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/it/projects/autoskip/skip-when-patch-tracking-file-present/pom.xml Fri Jun 22 14:14:01 2007
@@ -42,7 +42,7 @@
<phase>initialize</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
</execution>
</executions>
Copied: maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java (from r549941, 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/ApplyMojo.java?view=diff&rev=549959&p1=maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java&r1=549941&p2=maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java&r2=549959
==============================================================================
--- 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/ApplyMojo.java Fri Jun 22 14:14:01 2007
@@ -15,13 +15,22 @@
*
*/
+import org.apache.maven.plugin.AbstractMojo;
+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;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+import org.codehaus.plexus.util.cli.shell.BourneShell;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
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;
@@ -29,28 +38,22 @@
import java.util.Map;
import java.util.Map.Entry;
-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;
-import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.StreamConsumer;
-import org.codehaus.plexus.util.cli.shell.BourneShell;
-
/**
- * Apply a set of patches to project sources.
+ * Apply one or more patches to project sources.
*
- * @goal apply-directory
- * @phase generate-sources
+ * @goal apply
+ * @phase process-sources
*/
-public class ApplyPatchDirectoryMojo
- extends AbstractPatchMojo
+public class ApplyMojo
+ extends AbstractMojo
{
public static final List PATCH_FAILURE_WATCH_PHRASES;
+ public static final List DEFAULT_IGNORED_PATCHES;
+
+ public static final List DEFAULT_IGNORED_PATCH_PATTERNS;
+
static
{
List watches = new ArrayList();
@@ -60,9 +63,38 @@
watches.add( "reject" );
PATCH_FAILURE_WATCH_PHRASES = watches;
+
+ List ignored = new ArrayList();
+
+ ignored.add( ".svn" );
+ ignored.add( "CVS" );
+
+ DEFAULT_IGNORED_PATCHES = ignored;
+
+ List ignoredPatterns = new ArrayList();
+
+ ignoredPatterns.add( ".svn/**" );
+ ignoredPatterns.add( "CVS/**" );
+
+ DEFAULT_IGNORED_PATCH_PATTERNS = ignoredPatterns;
}
/**
+ * Whether to exclude default ignored patch items, such as .svn or CVS directories.
+ *
+ * @parameter default-value="true"
+ */
+ private boolean useDefaultIgnores;
+
+ /**
+ * The list of patch file names (without directory information), supplying the order in which patches should be
+ * applied. (relative to 'patchSourceDir')
+ *
+ * @parameter
+ */
+ protected List patches;
+
+ /**
* Whether to skip this mojo's execution.
*
* @parameter default-value="false" alias="patch.apply.skip"
@@ -102,11 +134,11 @@
/**
* 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.
@@ -163,7 +195,28 @@
*
* @parameter
*/
- private List patchFailureWatchPhrases = PATCH_FAILURE_WATCH_PHRASES;
+ private List failurePhrases = PATCH_FAILURE_WATCH_PHRASES;
+
+ /**
+ * The original file which will be modified by the patch. Mutually exclusive with workDir.
+ *
+ * @parameter
+ */
+ private File originalFile;
+
+ /**
+ * The file which is the original file, plus modifications from the patch. Mutually exclusive with workDir.
+ *
+ * @parameter
+ */
+ private File destFile;
+
+ /**
+ * The single patch file to apply. Mutually exclusive with 'patches'.
+ *
+ * @parameter
+ */
+ private File patchFile;
/**
* @parameter default-value="src/main/patches"
@@ -175,39 +228,51 @@
* Apply the patches. Give preference to patchFile over patchSourceDir/patches, and preference to originalFile over
* workDir.
*/
- public void doExecute()
+ public void execute()
throws MojoExecutionException, MojoFailureException
{
+ boolean patchDirEnabled = ( ( patches != null ) && !patches.isEmpty() ) || naturalOrderProcessing;
+ boolean patchFileEnabled = patchFile != null;
+
// if patches is null or empty, and naturalOrderProcessing is not true then disable patching
- if ( ( patches == null || patches.isEmpty() ) && !naturalOrderProcessing )
+ if ( !patchFileEnabled && !patchDirEnabled )
{
getLog().info( "Patching is disabled for this project." );
return;
}
-
+
if ( skipApplication )
{
getLog().info( "Skipping patchfile application (per configuration)." );
return;
}
- patchTrackingFile.getParentFile().mkdirs();
+ patchTrackingFile.getParentFile().mkdirs();
+
+ Map patchesToApply = null;
- try
+ try
{
- List foundPatchFiles = FileUtils.getFileNames( patchDirectory, "*", null, false );
-
- Map patchesApplied = findPatchesToApply(foundPatchFiles, patchDirectory );
+ if ( patchFileEnabled )
+ {
+ patchesToApply = Collections.singletonMap( patchFile.getName(), createPatchCommand( patchFile ) );
+ }
+ else
+ {
+ List foundPatchFiles = FileUtils.getFileNames( patchDirectory, "*", null, false );
- checkStrictPatchCompliance(foundPatchFiles);
+ patchesToApply = findPatchesToApply(foundPatchFiles, patchDirectory );
- String output = applyPatches(patchesApplied);
+ checkStrictPatchCompliance(foundPatchFiles);
+ }
+
+ String output = applyPatches(patchesToApply);
checkForWatchPhrases(output);
- writeTrackingFile(patchesApplied);
- }
- catch (IOException ioe)
+ writeTrackingFile(patchesToApply);
+ }
+ catch (IOException ioe)
{
throw new MojoExecutionException( "unable to obtain list of patch files", ioe);
}
@@ -216,18 +281,16 @@
private Map findPatchesToApply( List foundPatchFiles, File patchSourceDir )
throws MojoFailureException
{
- List patches = getPatches();
-
- Map patchesApplied = new LinkedHashMap( );
+ Map patchesApplied = new LinkedHashMap();
if ( naturalOrderProcessing )
{
patches = new ArrayList( foundPatchFiles ) ;
Collections.sort( patches );
}
-
+
String alreadyAppliedPatches = "";
-
+
try
{
if ( optimizations && patchTrackingFile.exists() )
@@ -239,11 +302,11 @@
{
throw new MojoFailureException( "unable to read patch tracking file: " + ioe.getMessage() );
}
-
+
for ( Iterator it = patches.iterator(); it.hasNext(); )
{
String patch = (String) it.next();
-
+
if ( alreadyAppliedPatches.indexOf( patch ) == -1 )
{
File patchFile = new File( patchSourceDir, patch );
@@ -276,7 +339,7 @@
}
}
}
-
+
return patchesApplied;
}
@@ -293,7 +356,7 @@
ignored.addAll( ignoredPatches );
}
- if ( useDefaultIgnores() )
+ if ( useDefaultIgnores )
{
ignored.addAll( DEFAULT_IGNORED_PATCHES );
}
@@ -354,7 +417,7 @@
try
{
getLog().info( "Applying patch: " + patchName );
- int result = CommandLineUtils.executeCommandLine( cli, consumer, consumer );
+ int result = executeCommandLine( cli, consumer, consumer );
if ( result != 0 )
{
@@ -371,6 +434,17 @@
return outputWriter.toString();
}
+ private int executeCommandLine( Commandline cli, StreamConsumer out, StreamConsumer err )
+ throws CommandLineException
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Executing:\n" + cli + "\n" );
+ }
+
+ return CommandLineUtils.executeCommandLine( cli, out, err );
+ }
+
private void writeTrackingFile( Map patchesApplied )
throws MojoExecutionException
{
@@ -378,16 +452,16 @@
try
{
boolean appending = patchTrackingFile.exists();
-
+
writer = new FileWriter( patchTrackingFile, appending );
-
+
for ( Iterator it = patchesApplied.keySet().iterator(); it.hasNext(); )
{
if ( appending )
{
- writer.write( System.getProperty( "line.separator" ) );
+ writer.write( System.getProperty( "line.separator" ) );
}
-
+
String patch = (String) it.next();
writer.write( patch );
@@ -412,7 +486,7 @@
private void checkForWatchPhrases( String output )
throws MojoExecutionException
{
- for ( Iterator it = patchFailureWatchPhrases.iterator(); it.hasNext(); )
+ for ( Iterator it = failurePhrases.iterator(); it.hasNext(); )
{
String phrase = (String) it.next();
@@ -437,6 +511,18 @@
cli.setExecutable( "patch" );
cli.setWorkingDirectory( targetDirectory.getAbsolutePath() );
+
+ if ( originalFile != null )
+ {
+ cli.createArg().setLine( originalFile.getAbsolutePath() );
+
+ if ( destFile != null )
+ {
+ cli.createArg().setLine( "-o " + destFile.getAbsolutePath() );
+ }
+
+ cli.createArg().setLine( patchFile.getAbsolutePath() );
+ }
cli.createArg().setLine( "-p" + strip );
Propchange: maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/examples/multiple.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/examples/multiple.apt?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/examples/multiple.apt (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/examples/multiple.apt Fri Jun 22 14:14:01 2007
@@ -59,7 +59,7 @@
</configuration>
<phase>process-sources</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
</execution>
<execution>
@@ -73,7 +73,7 @@
</configuration>
<phase>process-sources</phase>
<goals>
- <goal>apply-directory</goal>
+ <goal>apply</goal>
</goals>
</execution>
</executions>
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/index.apt?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/index.apt (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/index.apt Fri Jun 22 14:14:01 2007
@@ -33,7 +33,7 @@
* Goals Overview
- The patch plugin has two goals, one for applying a single declared patch and another for applying a directory of patches.
+ The patch plugin has a single goal that can apply either a single declared patch or a directory of patches. Application of an entire patch directory can be configured with various patch-inclusion, -exclusion, and -ordering options.
* Usage
Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/usage.apt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/usage.apt?view=diff&rev=549959&r1=549958&r2=549959
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/usage.apt (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/src/site/apt/usage.apt Fri Jun 22 14:14:01 2007
@@ -56,7 +56,6 @@
<executions>
<execution>
<id>patch</id>
- <phase>process-sources</phase>
<goals>
<goal>apply</goal>
</goals>