camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-8997: Camel-Git: Add a show branches operation
Date Thu, 23 Jul 2015 15:52:09 GMT
Repository: camel
Updated Branches:
  refs/heads/master bff0d4fdf -> b390f91a9


CAMEL-8997: Camel-Git: Add a show branches operation


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

Branch: refs/heads/master
Commit: b390f91a99dbe47f1e1608e83e3d7875dc8105c7
Parents: bff0d4f
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Jul 23 17:51:22 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Jul 23 17:51:22 2015 +0200

----------------------------------------------------------------------
 .../component/git/producer/GitOperation.java    |  1 +
 .../component/git/producer/GitProducer.java     | 18 ++++++++
 .../component/git/producer/GitProducerTest.java | 47 ++++++++++++++++++++
 3 files changed, 66 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b390f91a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
index f5f07f2..884b154 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
@@ -32,4 +32,5 @@ public interface GitOperation {
     String LOG_OPERATION = "log";
     String PUSH_OPERATION = "push";
     String PULL_OPERATION = "pull";
+    String SHOW_BRANCHES = "showBranches";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b390f91a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
index 6e6a783..73affbf 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.git.producer;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.component.git.GitConstants;
@@ -25,8 +26,10 @@ import org.apache.camel.component.git.GitEndpoint;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.ListBranchCommand.ListMode;
 import org.eclipse.jgit.api.PullResult;
 import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
@@ -133,6 +136,10 @@ public class GitProducer extends DefaultProducer {
         case GitOperation.DELETE_TAG_OPERATION:
             doDeleteTag(exchange, operation);
             break;
+            
+        case GitOperation.SHOW_BRANCHES:
+            doShowBranches(exchange, operation);
+            break;
                 
         default:
             throw new IllegalArgumentException("Local path must specified to execute " +
operation);
@@ -365,6 +372,17 @@ public class GitProducer extends DefaultProducer {
             throw e;
         }
     }
+    
+    protected void doShowBranches(Exchange exchange, String operation) throws Exception {
+        List<Ref> result = null;
+        try {
+            result = git.branchList().setListMode(ListMode.ALL).call();
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            throw e;
+        }
+        exchange.getOut().setBody(result);
+    }
 
     private Repository getLocalRepository() throws IOException {
         FileRepositoryBuilder builder = new FileRepositoryBuilder();

http://git-wip-us.apache.org/repos/asf/camel/blob/b390f91a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
index f45d503..1a4fc2d 100755
--- a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
@@ -786,6 +786,51 @@ public class GitProducerTest extends GitTestSupport {
         repository.close();
     }
     
+    @Test
+    public void showBranchesTest() throws Exception {
+
+        Repository repository = getTestRepository();
+        
+        File fileToAdd = new File(gitLocalRepo, filenameToAdd);
+        fileToAdd.createNewFile();
+        
+        template.send("direct:add", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameToAdd);
+            }
+        });
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        
+        Status status = new Git(repository).status().call();
+        assertTrue(status.getAdded().contains(filenameToAdd));
+        
+        template.send("direct:commit", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
+            }
+        });
+        
+        Git git = new Git(repository);
+        
+        template.sendBody("direct:create-branch", "");
+        
+        List<Ref> branches = template.requestBody("direct:show-branches", "", List.class);
+        
+        Boolean branchExists = false;
+        
+        for (Ref reference : branches) {
+            if (("refs/heads/" + branchTest).equals(reference.getName())) {
+                branchExists = true;
+            }
+        }
+        assertTrue(branchExists);
+        
+        repository.close();
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {            
@@ -827,6 +872,8 @@ public class GitProducerTest extends GitTestSupport {
                         .to("git://" + gitLocalRepo + "?operation=createTag&tagName="
+ tagTest);
                 from("direct:delete-tag")
                         .to("git://" + gitLocalRepo + "?operation=deleteTag&tagName="
+ tagTest);
+                from("direct:show-branches")
+                        .to("git://" + gitLocalRepo + "?operation=showBranches");
             } 
         };
     }


Mime
View raw message