You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/01/08 08:07:10 UTC

[camel] branch master updated (0fa355c -> ba80781)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 0fa355c  Merge branch 'CAMEL-13033'
     new bc0a230  CAMEL-13034 - Implement 'checkout' operation for Git component
     new ba80781  CAMEL-13034 - Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/git/GitEndpoint.java    |  2 +-
 .../camel/component/git/producer/GitOperation.java |  1 +
 .../camel/component/git/producer/GitProducer.java  | 37 ++++++++---
 .../component/git/producer/GitProducerTest.java    | 72 ++++++++++++++++++++++
 4 files changed, 102 insertions(+), 10 deletions(-)


[camel] 01/02: CAMEL-13034 - Implement 'checkout' operation for Git component

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bc0a230ffc5c2031a3cb1d7a62855f29c6c884ba
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Jan 8 09:03:45 2019 +0100

    CAMEL-13034 - Implement 'checkout' operation for Git component
---
 .../camel/component/git/producer/GitOperation.java |  1 +
 .../camel/component/git/producer/GitProducer.java  | 20 ++++++
 .../component/git/producer/GitProducerTest.java    | 72 ++++++++++++++++++++++
 3 files changed, 93 insertions(+)

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 d5f63fa..fb03361 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
@@ -19,6 +19,7 @@ package org.apache.camel.component.git.producer;
 public interface GitOperation {
 
     String CLONE_OPERATION = "clone";
+    String CHECKOUT_OPERATION = "checkout";
     String INIT_OPERATION = "init";
     String ADD_OPERATION = "add";
     String REMOVE_OPERATION = "remove";
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 c73b7a7..6046296 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
@@ -93,6 +93,10 @@ public class GitProducer extends DefaultProducer {
         case GitOperation.CLONE_OPERATION:
             doClone(exchange, operation);
             break;
+            
+        case GitOperation.CHECKOUT_OPERATION:
+            doCheckout(exchange, operation);
+            break;
 
         case GitOperation.INIT_OPERATION:
             doInit(exchange, operation);
@@ -213,6 +217,22 @@ public class GitProducer extends DefaultProducer {
             }
         }
     }
+    
+    protected void doCheckout(Exchange exchange, String operation) throws Exception {
+        if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
+            throw new IllegalArgumentException("Branch Name must be specified to execute " + operation);
+        }
+        try {
+        	if (ObjectHelper.isEmpty(endpoint.getTagName())) {
+                git.checkout().setCreateBranch(true).setName(endpoint.getBranchName()).call();
+        	} else {
+        		git.checkout().setCreateBranch(true).setName(endpoint.getBranchName()).setStartPoint(endpoint.getTagName()).call();
+        	}
+        } catch (Exception e) {
+            log.error("There was an error in Git {} operation", operation);
+            throw e;
+        }
+    }
 
     protected void doInit(Exchange exchange, String operation) throws Exception {
         Git result = null;
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 3a09f42..a3303ac 100644
--- 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
@@ -58,6 +58,76 @@ public class GitProducerTest extends GitTestSupport {
         File gitDir = new File(gitLocalRepo, ".git");
         assertEquals(gitDir.exists(), true);
     }
+    
+    @Test
+    public void checkoutTest() throws Exception {
+        // Init
+        Git git = getGitTestRepository();
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        File fileToAdd = new File(gitLocalRepo, filenameToAdd);
+        fileToAdd.createNewFile();
+        git.add().addFilepattern(filenameToAdd).call();
+        Status status = git.status().call();
+        assertTrue(status.getAdded().contains(filenameToAdd));
+        git.commit().setMessage(commitMessage).call();
+
+        // Test camel-git checkout
+        template.sendBody("direct:checkout", "");
+
+        // Check
+        List<Ref> ref = git.branchList().call();
+        boolean branchCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/heads/" + branchTest)) {
+                branchCreated = true;
+            }
+        }
+        assertEquals(branchCreated, true);
+        git.close();
+    }
+    
+    
+    @Test
+    public void checkoutSpecificTagTest() throws Exception {
+        // Init
+        Git git = getGitTestRepository();
+        File fileToAdd = new File(gitLocalRepo, filenameToAdd);
+        fileToAdd.createNewFile();
+        git.add().addFilepattern(filenameToAdd).call();
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        Status status = git.status().call();
+        assertTrue(status.getAdded().contains(filenameToAdd));
+        git.commit().setMessage(commitMessage).call();
+        
+        // Test camel-git create tag
+        template.sendBody("direct:create-tag", "");
+
+        // Check
+        List<Ref> ref = git.tagList().call();
+        boolean tagCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/tags/" + tagTest)) {
+                tagCreated = true;
+            }
+        }
+        assertEquals(tagCreated, true);
+
+        // Test camel-git create-branch
+        template.sendBody("direct:checkout-specific-tag", "");
+
+        // Check
+        ref = git.branchList().call();
+        boolean branchCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/heads/" + branchTest)) {
+                branchCreated = true;
+            }
+        }
+        assertEquals(branchCreated, true);
+        git.close();
+    }
 
     @Test(expected = CamelExecutionException.class)
     public void doubleCloneOperationTest() throws Exception {
@@ -814,6 +884,8 @@ public class GitProducerTest extends GitTestSupport {
                 from("direct:clone").to("git://" + gitLocalRepo + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone");
                 from("direct:init").to("git://" + gitLocalRepo + "?operation=init");
                 from("direct:add").to("git://" + gitLocalRepo + "?operation=add");
+                from("direct:checkout").to("git://" + gitLocalRepo + "?operation=checkout&branchName=" + branchTest);
+                from("direct:checkout-specific-tag").to("git://" + gitLocalRepo + "?operation=checkout&branchName=" + branchTest + "&tagName=" + tagTest);
                 from("direct:remove").to("git://" + gitLocalRepo + "?operation=remove");
                 from("direct:add-on-branch").to("git://" + gitLocalRepo + "?operation=add&branchName=" + branchTest);
                 from("direct:remove-on-branch").to("git://" + gitLocalRepo + "?operation=add&branchName=" + branchTest);


[camel] 02/02: CAMEL-13034 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ba8078176dab0808008e5398d36ebaf0c0feaca1
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Jan 8 09:06:08 2019 +0100

    CAMEL-13034 - Fixed CS
---
 .../apache/camel/component/git/GitEndpoint.java    |  2 +-
 .../camel/component/git/producer/GitProducer.java  | 29 +++++++++++-----------
 2 files changed, 15 insertions(+), 16 deletions(-)

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 9c644ff..9841d08 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
@@ -24,11 +24,11 @@ import org.apache.camel.component.git.consumer.GitCommitConsumer;
 import org.apache.camel.component.git.consumer.GitTagConsumer;
 import org.apache.camel.component.git.consumer.GitType;
 import org.apache.camel.component.git.producer.GitProducer;
-import org.apache.camel.support.DefaultEndpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultEndpoint;
 
 /**
  * The git component is used for working with git repositories.
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 6046296..7517b9f 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
@@ -48,7 +48,6 @@ import org.eclipse.jgit.transport.RemoteConfig;
 import org.eclipse.jgit.transport.URIish;
 import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 
-
 public class GitProducer extends DefaultProducer {
 
     private final GitEndpoint endpoint;
@@ -93,7 +92,7 @@ public class GitProducer extends DefaultProducer {
         case GitOperation.CLONE_OPERATION:
             doClone(exchange, operation);
             break;
-            
+
         case GitOperation.CHECKOUT_OPERATION:
             doCheckout(exchange, operation);
             break;
@@ -149,7 +148,7 @@ public class GitProducer extends DefaultProducer {
         case GitOperation.PULL_OPERATION:
             doPull(exchange, operation);
             break;
-            
+
         case GitOperation.MERGE_OPERATION:
             doMerge(exchange, operation);
             break;
@@ -165,15 +164,15 @@ public class GitProducer extends DefaultProducer {
         case GitOperation.SHOW_BRANCHES_OPERATION:
             doShowBranches(exchange, operation);
             break;
-            
+
         case GitOperation.SHOW_TAGS_OPERATION:
             doShowTags(exchange, operation);
             break;
-           
+
         case GitOperation.CLEAN_OPERATION:
             doClean(exchange, operation);
             break;
-            
+
         case GitOperation.GC_OPERATION:
             doGc(exchange, operation);
             break;
@@ -217,17 +216,17 @@ public class GitProducer extends DefaultProducer {
             }
         }
     }
-    
+
     protected void doCheckout(Exchange exchange, String operation) throws Exception {
         if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
             throw new IllegalArgumentException("Branch Name must be specified to execute " + operation);
         }
         try {
-        	if (ObjectHelper.isEmpty(endpoint.getTagName())) {
+            if (ObjectHelper.isEmpty(endpoint.getTagName())) {
                 git.checkout().setCreateBranch(true).setName(endpoint.getBranchName()).call();
-        	} else {
-        		git.checkout().setCreateBranch(true).setName(endpoint.getBranchName()).setStartPoint(endpoint.getTagName()).call();
-        	}
+            } else {
+                git.checkout().setCreateBranch(true).setName(endpoint.getBranchName()).setStartPoint(endpoint.getTagName()).call();
+            }
         } catch (Exception e) {
             log.error("There was an error in Git {} operation", operation);
             throw e;
@@ -472,7 +471,7 @@ public class GitProducer extends DefaultProducer {
         }
         updateExchange(exchange, result);
     }
-    
+
     protected void doMerge(Exchange exchange, String operation) throws Exception {
         MergeResult result = null;
         ObjectId mergeBase;
@@ -524,7 +523,7 @@ public class GitProducer extends DefaultProducer {
         }
         updateExchange(exchange, result);
     }
-    
+
     protected void doShowTags(Exchange exchange, String operation) throws Exception {
         List<Ref> result = null;
         try {
@@ -559,7 +558,7 @@ public class GitProducer extends DefaultProducer {
         }
         updateExchange(exchange, result);
     }
-    
+
     protected void doClean(Exchange exchange, String operation) throws Exception {
         Set<String> result = null;
         try {
@@ -573,7 +572,7 @@ public class GitProducer extends DefaultProducer {
         }
         updateExchange(exchange, result);
     }
-    
+
     protected void doGc(Exchange exchange, String operation) throws Exception {
         Properties result = null;
         try {