Author: jmcconnell
Date: Wed Jun 20 13:50:47 2007
New Revision: 549227

URL: http://svn.apache.org/viewvc?view=rev&rev=549227
Log:
patch optimization on the directory mojo will now respond to new patches that 
appear in the patch directory and process accordingly

Modified:
    maven/sandbox/trunk/plugins/maven-patch-plugin/pom.xml
    
maven/sandbox/trunk/plugins/maven-patch-plugin/src/main/java/org/apache/maven/plugin/patch/ApplyPatchDirectoryMojo.java

Modified: maven/sandbox/trunk/plugins/maven-patch-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-plugin/pom.xml?view=diff&rev=549227&r1=549226&r2=549227
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-plugin/pom.xml Wed Jun 20 13:50:47 
2007
@@ -12,11 +12,16 @@
   <version>1.0-SNAPSHOT</version>
   <name>maven-patch-plugin Maven Mojo</name>
   <url>http://maven.apache.org</url>
-  <dependencies>
+  <dependencies> 
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.4.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-20</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>

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=549227&r1=549226&r2=549227
==============================================================================
--- 
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 13:50:47 2007
@@ -191,18 +191,13 @@
             return;
         }
 
-        patchTrackingFile.getParentFile().mkdirs();
-        if ( optimizations && patchTrackingFile.exists() )
-        {
-            getLog().info( "Skipping patchfile application (patches already 
applied in previous build)." );
-            return;
-        }
+        patchTrackingFile.getParentFile().mkdirs();             
 
         try 
         {
                        List foundPatchFiles = FileUtils.getFileNames( 
patchDirectory, "*", null, false );
                
-                       Map patchesApplied = 
findPatchesToApply(foundPatchFiles, patchDirectory);
+                       Map patchesApplied = 
findPatchesToApply(foundPatchFiles, patchDirectory );
 
                        checkStrictPatchCompliance(foundPatchFiles);
 
@@ -231,37 +226,54 @@
                Collections.sort( patches );
         }
         
+        String alreadyAppliedPatches = "";
+        
+        try
+        {
+            if ( optimizations && patchTrackingFile.exists() )
+            {
+                alreadyAppliedPatches = FileUtils.fileRead( patchTrackingFile 
);
+            }
+        }
+        catch (IOException ioe)
+        {
+            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 );
 
-            File patchFile = new File( patchSourceDir, patch );
-
-            getLog().debug( "Looking for patch: " + patch + " in: " + 
patchFile );
+                getLog().debug( "Looking for patch: " + patch + " in: " + 
patchFile );
 
-            if ( !patchFile.exists() )
-            {          
-                if ( strictPatching )
-                {
-                    throw new MojoFailureException(
-                                                    this,
-                                                    "Patch operation cannot 
proceed.",
-                                                    "Cannot find specified 
patch: \'"
-                                                                    + patch
-                                                                    + "\' in 
patch-source directory: \'"
-                                                                    + 
patchSourceDir
-                                                                    + 
"\'.\n\nEither fix this error, or relax strictPatching." );
+                if ( !patchFile.exists() )
+                {
+                    if ( strictPatching )
+                    {
+                        throw new MojoFailureException(
+                                                        this,
+                                                        "Patch operation 
cannot proceed.",
+                                                        "Cannot find specified 
patch: \'"
+                                                                        + patch
+                                                                        + "\' 
in patch-source directory: \'"
+                                                                        + 
patchSourceDir
+                                                                        + 
"\'.\n\nEither fix this error, or relax strictPatching." );
+                    }
+                    else
+                    {
+                        getLog().info( "Skipping patch: " + patch + " listed 
in the patches parameter; it is missing." );
+                    }
                 }
                 else
                 {
-                    getLog().info( "Skipping patch: " + patch + " listed in 
the patches parameter; it is missing." );
-                }
-            }
-            else
-            {
-                foundPatchFiles.remove( patch );
+                    foundPatchFiles.remove( patch );
 
-                patchesApplied.put( patch, createPatchCommand( patchFile ) );
+                    patchesApplied.put( patch, createPatchCommand( patchFile ) 
);
+                }
             }
         }
         
@@ -341,11 +353,12 @@
 
             try
             {
+                getLog().info( "Applying patch: " + patchName );
                 int result = CommandLineUtils.executeCommandLine( cli, 
consumer, consumer );
 
                 if ( result != 0 )
                 {
-                    throw new MojoExecutionException( "Patch command failed 
(exit value != 0). Please see debug output for more information." );
+                    throw new MojoExecutionException( "Patch command failed 
(exit value != 0) for " + patchName + ". Please see debug output for more 
information." );
                 }
             }
             catch ( CommandLineException e )
@@ -364,10 +377,17 @@
         FileWriter writer = null;
         try
         {
-            writer = new FileWriter( patchTrackingFile );
-
+            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" ) );  
+                }
+                
                 String patch = (String) it.next();
                 writer.write( patch );
 


Reply via email to