Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement developed for diffSummarized nested element [Tigris #1365] #8

Open
markphip opened this issue Sep 15, 2016 · 0 comments
Open

Comments

@markphip
Copy link
Contributor

Description

I've extended the DiffSummarized class with DiffSummarizedSelective to allow an
end user to selectively extract A/M/D paths between revisions.

Motivation: Allow subsequent treatment of change paths to differ.
Use Case: Synchronising changes on target that does not allow direct SVN access:
upload latest A and M paths; delete D paths

I chose to override the DiffSummarized class rather than extend with new
parameters since I have also changed the output format.

I have not attempted to store this back into the SVN repo since I could not
(quickly) work out how to add relevant test cases, but I have 1) re-run the
built-in tests (all passed) 2) tested my new jar locally against my ant script
(passed).

Implementation (patch based off revision 5289):

### Eclipse Workspace Patch 1.0
#P svnant
Index: src/main/org/tigris/subversion/svnant/SvnTask.java
===================================================================
--- src/main/org/tigris/subversion/svnant/SvnTask.java  (revision 5291)
+++ src/main/org/tigris/subversion/svnant/SvnTask.java  (working copy)
@@ -64,6 +64,7 @@
 import org.tigris.subversion.svnant.commands.Delete;
 import org.tigris.subversion.svnant.commands.Diff;
 import org.tigris.subversion.svnant.commands.DiffSummarize;
+import org.tigris.subversion.svnant.commands.DiffSummarizeSelective;
 import org.tigris.subversion.svnant.commands.Export;
 import org.tigris.subversion.svnant.commands.Feedback;
 import org.tigris.subversion.svnant.commands.Ignore;
@@ -308,6 +309,15 @@
     }

     /**
+     * Adds the <code>diffSummarizeSelective</code> command to this task.
+     * 
+     * @param a   The <code>diffSummarizeSelective</code> command. Not
<code>null</code>.
+     */
+    public void addDiffSummarizeSelective( DiffSummarizeSelective a ) {
+        addCommand( a );
+    }
+
+    /**
      * Adds the <code>keywordsSet</code> command to this task.
      * 
      * @param a   The <code>keywordsSet</code> command. Not <code>null</code>.
Index: src/main/org/tigris/subversion/svnant/commands/DiffSummarize.java
===================================================================
--- src/main/org/tigris/subversion/svnant/commands/DiffSummarize.java   (revision
5291)
+++ src/main/org/tigris/subversion/svnant/commands/DiffSummarize.java   (working copy)
@@ -76,10 +76,10 @@
  */
 public class DiffSummarize extends Diff {

-    private int     depth          = 1000;   // default depth of directory tree
descent
-    private boolean ignoreAncestry = true;
-    private boolean logToFile      = false;
-    private String  encoding       = "UTF-8";
+    protected int     depth          = 1000;   // default depth of directory
tree descent
+    protected boolean ignoreAncestry = true;
+    protected boolean logToFile      = false;
+    protected String  encoding       = "UTF-8";

     public void setEncoding( String e ) {
         encoding = e;
Index: src/main/org/tigris/subversion/svnant/commands/DiffSummarizeSelective.java
===================================================================
--- src/main/org/tigris/subversion/svnant/commands/DiffSummarizeSelective.java
(revision 0)
+++ src/main/org/tigris/subversion/svnant/commands/DiffSummarizeSelective.java
(revision 0)
@@ -0,0 +1,152 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.tigris.subversion.svnant.commands;
+
+import org.tigris.subversion.svnclientadapter.SVNClientException;
+import org.tigris.subversion.svnclientadapter.SVNDiffSummary;
+import org.tigris.subversion.svnant.SvnAntUtilities;
+
+import org.apache.tools.ant.BuildException;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+/**
+ * Diff summary (as in "svn diff --summarize") allowing the selective display
of A/M/D paths.
+ * 
+ * @author Gordon Stephens (gordon@komodo-solutions.co.uk)
+ */
+public class DiffSummarizeSelective extends DiffSummarize {
+
+    private boolean showAdditions     = false;
+    private boolean showModifications = false;
+    private boolean showDeletions     = false;
+
+    public void setShowAdditions( boolean show ) {
+        this.showAdditions = show;
+    }
+
+    protected boolean getShowAdditions() {
+        return this.showAdditions;
+    }
+
+    public void setShowModifications( boolean show ) {
+        this.showModifications = show;
+    }
+
+    protected boolean getShowModifications() {
+        return this.showModifications;
+    }
+
+    public void setShowDeletions( boolean show ) {
+        this.showDeletions = show;
+    }
+
+    protected boolean getShowDeletions() {
+        return this.showDeletions;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void execute() {
+        BufferedWriter out = null;
+        if( logToFile ) {
+            File f = getOutFile();
+            try {
+                log( "output to file: " + f );
+                out = new BufferedWriter( new OutputStreamWriter( (new
FileOutputStream( f )), encoding ) );
+            } catch( IOException ex ) {
+                throw ex( ex, ex.getMessage() );
+            }
+        }
+        try {
+
+            // summarize only supported on repo, so on URLs
+            logAction( true );
+
+            SVNDiffSummary[] summary = getClient().diffSummarize( getOldUrl(),
getOldTargetRevision(), getNewUrl(),
+                            getNewTargetRevision(), depth, ignoreAncestry );
+
+            StringBuilder sb = new StringBuilder();
+            for( SVNDiffSummary s : summary ) {
+                sb.setLength( 0 );
+                char first = Character.toUpperCase(
s.getDiffKind().toString().charAt( 0 ) );
+
+                if (   ((first == 'A') && showAdditions)
+                    || ((first == 'M') && showModifications)
+                    || ((first == 'D') && showDeletions))
+                {
+                    sb.append( s.getPath() );
+                    if( logToFile ) {
+                        sb.append( "\n" );
+                        out.write( sb.toString() );
+                    } else {
+                        log( sb.toString() );
+                    }
+                }
+            }
+        } catch( SVNClientException ex ) {
+            throw new BuildException( ex );
+        } catch( IOException ex ) {
+            throw new BuildException( ex );
+        } finally {
+            SvnAntUtilities.close( out );
+        }
+    }
+}

Metadata Imported from Tigris (Issue 1365)

  • Creation Date: 2012-01-20 05:38:26
  • Reporter: gordon_stephens
  • Subcomponent: svnant
  • Version: 1.8.x
  • Milestone: not determined
  • Keywords:
  • Cc:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant