camel-commits mailing list archives

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


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

Branch: refs/heads/master
Commit: 903e88f8e86d95ea99a7ebc3b9fd36e1d4d8bba4
Parents: db6f6e1
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Sat Jul 18 11:06:26 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Sat Jul 18 11:08:15 2015 +0200

----------------------------------------------------------------------
 .../camel/component/git/GitOperation.java       |  1 +
 .../apache/camel/component/git/GitProducer.java | 21 +++++
 .../github/producer/GitProducerTest.java        | 83 ++++++++++++++++++++
 3 files changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/903e88f8/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 431540a..88e03de 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
@@ -26,4 +26,5 @@ public interface GitOperation {
     public final static String COMMIT_ALL_OPERATION = "commitAll";
     public final static String CREATE_BRANCH_OPERATION = "createBranch";
     public final static String DELETE_BRANCH_OPERATION = "deleteBranch";
+    public final static String STATUS_OPERATION = "status";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/903e88f8/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 c134475..e7c2fbe 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
@@ -7,6 +7,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.Status;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
 import org.slf4j.Logger;
@@ -68,6 +69,10 @@ public class GitProducer extends DefaultProducer{
             case GitOperation.DELETE_BRANCH_OPERATION:
                 doDeleteBranch(exchange, operation, repo);
                 break;
+                
+            case GitOperation.STATUS_OPERATION:
+                doStatus(exchange, operation, repo);
+                break;
 	    }
 	    repo.close();
 	}
@@ -215,6 +220,22 @@ public class GitProducer extends DefaultProducer{
         }
     }
     
+    protected void doStatus(Exchange exchange, String operation, Repository repo) {
+        Git git = null;
+        Status status = null;
+        try {
+            git = new Git(repo);
+            if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
+                git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
+            }
+                status = git.status().call();
+                } catch (Exception e) {
+                        LOG.error("There was an error in Git " + operation + " operation");
+                        e.printStackTrace();
+                }
+        exchange.getOut().setBody(status);
+    }
+    
     private Repository getLocalRepository(){
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
         Repository repo = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/903e88f8/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 791e2aa..73693cc 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
@@ -516,6 +516,85 @@ public class GitProducerTest extends CamelTestSupport {
         repository.close();
     }
     
+    @Test
+    public void statusTest() 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 = template.requestBody("direct:status", "", Status.class);
+        assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+        
+        repository.close();
+    }
+    
+    @Test
+    public void statusBranchTest() 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 = template.requestBody("direct:status", "", Status.class);
+        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);
+            }
+        });
+        
+        template.sendBody("direct:create-branch", "");
+        
+        Git git = new Git(repository);
+        
+        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);
+        
+        File fileToAddDifferent = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+        fileToAddDifferent.createNewFile();
+        
+        template.send("direct:add-on-branch", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+            }
+        });
+        
+        status = template.requestBody("direct:status-branch", "", Status.class);
+        assertTrue(status.getAdded().contains(FILENAME_BRANCH_TO_ADD));
+        
+        repository.close();
+    }
+    
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {            
@@ -545,6 +624,10 @@ public class GitProducerTest extends CamelTestSupport {
                         .to("git://" + GIT_LOCAL_REPO + "?operation=createBranch&branchName="
+ BRANCH_TEST);
                 from("direct:delete-branch")
                         .to("git://" + GIT_LOCAL_REPO + "?operation=deleteBranch&branchName="
+ BRANCH_TEST);
+                from("direct:status")
+                        .to("git://" + GIT_LOCAL_REPO + "?operation=status");
+                from("direct:status-branch")
+                        .to("git://" + GIT_LOCAL_REPO + "?operation=status&branchName="
+ BRANCH_TEST);
             } 
         };
     }


Mime
View raw message