camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [04/23] camel git commit: CAMEL-7982: camel-git - A generic git component, add deleteBranch operation
Date Sat, 18 Jul 2015 09:09:21 GMT
CAMEL-7982: camel-git - A generic git component, add deleteBranch operation


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9df0710d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9df0710d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9df0710d

Branch: refs/heads/master
Commit: 9df0710dff3e4a928bd42a23ee54ea05beb17625
Parents: a6057b5
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Sat Jul 18 11:06:15 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Sat Jul 18 11:08:14 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/component/git/GitEndpoint.java |  4 +-
 .../camel/component/git/GitOperation.java       |  1 +
 .../apache/camel/component/git/GitProducer.java | 18 ++++++
 .../github/producer/GitProducerTest.java        | 59 +++++++++++++++++++-
 4 files changed, 78 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9df0710d/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
index 612ee00..cbaed51 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
@@ -29,7 +29,7 @@ import org.apache.camel.spi.UriPath;
 public class GitEndpoint extends DefaultEndpoint {
 
     @UriPath @Metadata(required = "true")
-    private String remotePath;
+    private String localPath;
     @UriPath(label = "consumer")
     private String branchName;
     @UriParam
@@ -37,7 +37,7 @@ public class GitEndpoint extends DefaultEndpoint {
     @UriParam
     private String password;
     @UriParam
-    private String localPath;
+    private String remotePath;
     @UriParam
     private String operation;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/9df0710d/components/camel-git/src/main/java/org/apache/camel/component/git/GitOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitOperation.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/GitOperation.java
index c12c33d..f70728b 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitOperation.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitOperation.java
@@ -24,4 +24,5 @@ public interface GitOperation {
     public final static String COMMIT_OPERATION = "commit";
     public final static String COMMIT_ALL_OPERATION = "commitAll";
     public final static String CREATE_BRANCH_OPERATION = "createBranch";
+    public final static String DELETE_BRANCH_OPERATION = "deleteBranch";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9df0710d/components/camel-git/src/main/java/org/apache/camel/component/git/GitProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitProducer.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/GitProducer.java
index 1bd407a..1e0d3f5 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitProducer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitProducer.java
@@ -60,6 +60,10 @@ public class GitProducer extends DefaultProducer{
             case GitOperation.CREATE_BRANCH_OPERATION:
                 doCreateBranch(exchange, operation, repo);
                 break;
+                
+            case GitOperation.DELETE_BRANCH_OPERATION:
+                doDeleteBranch(exchange, operation, repo);
+                break;
 	    }
 	    repo.close();
 	}
@@ -173,6 +177,20 @@ public class GitProducer extends DefaultProducer{
         }
     }
     
+    protected void doDeleteBranch(Exchange exchange, String operation, Repository repo) {
+        Git git = null;
+        if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
+            throw new IllegalArgumentException("Branch Name must be specified to execute
" + operation);
+        } 
+        try {
+            git = new Git(repo);
+            git.branchDelete().setBranchNames(endpoint.getBranchName()).call();
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            e.printStackTrace();
+        }
+    }
+    
     private Repository getLocalRepository(){
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
         Repository repo = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/9df0710d/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
b/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
index c27139c..7122846 100755
--- a/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
@@ -57,8 +57,8 @@ public class GitProducerTest extends CamelTestSupport {
     @Override
     public void tearDown() throws Exception {
     	super.tearDown();
-//        File path = new File(GIT_LOCAL_REPO);
-//        deleteDirectory(path);
+        File path = new File(GIT_LOCAL_REPO);
+        deleteDirectory(path);
     }
     
     @Test
@@ -330,6 +330,59 @@ public class GitProducerTest extends CamelTestSupport {
         repository.close();
     }
     
+    @Test
+    public void deleteBranchTest() throws Exception {
+
+        Repository repository = getTestRepository();
+        
+        File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+        fileToAdd.createNewFile();
+        
+        template.send("direct:add", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+            }
+        });
+        File gitDir = new File(GIT_LOCAL_REPO, ".git");
+        assertEquals(gitDir.exists(), true);
+        
+        Status status = new Git(repository).status().call();
+        assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+        
+        template.send("direct:commit", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+            }
+        });
+        
+        Git git = new Git(repository);
+        
+        template.sendBody("direct:create-branch", "");
+        
+        List<Ref> ref = git.branchList().call();
+        boolean branchCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+                branchCreated = true;
+            }
+        }
+        assertEquals(branchCreated, true);
+        
+        template.sendBody("direct:delete-branch", "");
+        
+        ref = git.branchList().call();
+        branchCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+                branchCreated = true;
+            }
+        }
+        assertEquals(branchCreated, false);
+        repository.close();
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {            
@@ -353,6 +406,8 @@ public class GitProducerTest extends CamelTestSupport {
                         .to("git://" + GIT_LOCAL_REPO + "?operation=commit&branchName="
+ BRANCH_TEST);
                 from("direct:create-branch")
                         .to("git://" + GIT_LOCAL_REPO + "?operation=createBranch&branchName="
+ BRANCH_TEST);
+                from("direct:delete-branch")
+                        .to("git://" + GIT_LOCAL_REPO + "?operation=deleteBranch&branchName="
+ BRANCH_TEST);
             } 
         };
     }


Mime
View raw message