camel-commits mailing list archives

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


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

Branch: refs/heads/master
Commit: d38b525a31120965b127ce55c63fe6dd558da997
Parents: bc95806
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Sat Jul 18 11:07:09 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Sat Jul 18 11:08:16 2015 +0200

----------------------------------------------------------------------
 .../git/consumer/AbstractGitConsumer.java       | 13 +++--
 .../component/git/producer/GitOperation.java    |  1 +
 .../component/git/producer/GitProducer.java     | 20 ++++++-
 .../component/git/producer/GitProducerTest.java | 61 +++++++++++++++++++-
 4 files changed, 85 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d38b525a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
index 6e93849..ca58dcf 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
@@ -21,10 +21,13 @@ import java.io.IOException;
 
 import org.apache.camel.Processor;
 import org.apache.camel.component.git.GitEndpoint;
+import org.apache.camel.component.git.producer.GitProducer;
 import org.apache.camel.impl.ScheduledPollConsumer;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class AbstractGitConsumer extends ScheduledPollConsumer {
     
@@ -33,12 +36,12 @@ public abstract class AbstractGitConsumer extends ScheduledPollConsumer
{
     private Repository repo;
     
     private Git git;
+    
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractGitConsumer.class);
 
     public AbstractGitConsumer(GitEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
         this.endpoint = endpoint;
-        this.repo = getLocalRepository();
-        this.git = new Git(repo);
     }
     
     @Override
@@ -55,7 +58,7 @@ public abstract class AbstractGitConsumer extends ScheduledPollConsumer
{
         git.close();
     }
 
-    private Repository getLocalRepository(){
+    private Repository getLocalRepository() throws IOException{
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
         Repository repo = null;
                 try {
@@ -64,8 +67,8 @@ public abstract class AbstractGitConsumer extends ScheduledPollConsumer
{
                                 .findGitDir() // scan up the file system tree
                                 .build();
                 } catch (IOException e) {
-                        //LOG.error("There was an error, cannot open " + endpoint.getLocalPath()
+ " repository");
-                        e.printStackTrace();
+                        LOG.error("There was an error, cannot open " + endpoint.getLocalPath()
+ " repository");
+                        throw e;
                 }
                 return repo;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d38b525a/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 d45c743..dbd9813 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
@@ -27,6 +27,7 @@ public interface GitOperation {
     public final static String CREATE_BRANCH_OPERATION = "createBranch";
     public final static String DELETE_BRANCH_OPERATION = "deleteBranch";
     public final static String CREATE_TAG_OPERATION = "createTag";
+    public final static String DELETE_TAG_OPERATION = "deleteTag";
     public final static String STATUS_OPERATION = "status";
     public final static String LOG_OPERATION = "log";
     public final static String PUSH_OPERATION = "push";

http://git-wip-us.apache.org/repos/asf/camel/blob/d38b525a/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 f6eccf4..a397801 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
@@ -112,6 +112,10 @@ public class GitProducer extends DefaultProducer{
             case GitOperation.CREATE_TAG_OPERATION:
                 doCreateTag(exchange, operation);
                 break;
+                
+            case GitOperation.DELETE_TAG_OPERATION:
+                doDeleteTag(exchange, operation);
+                break;
 	    }
 	}
 	
@@ -330,7 +334,19 @@ public class GitProducer extends DefaultProducer{
         }
     }
     
-    private Repository getLocalRepository(){
+    protected void doDeleteTag(Exchange exchange, String operation) throws Exception {
+        if (ObjectHelper.isEmpty(endpoint.getTagName())) {
+            throw new IllegalArgumentException("Tag Name must be specified to execute " +
operation);
+        } 
+        try {
+            git.tagDelete().setTags(endpoint.getTagName()).call();
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            throw e;
+        }
+    }
+    
+    private Repository getLocalRepository() throws IOException{
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
         Repository repo = null;
 		try {
@@ -340,7 +356,7 @@ public class GitProducer extends DefaultProducer{
 			        .build();
 		} catch (IOException e) {
 			LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
-			e.printStackTrace();
+			throw e;
 		}
 		return repo;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d38b525a/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 910d942..cb6bee8 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
@@ -707,13 +707,66 @@ public class GitProducerTest extends GitTestSupport {
         template.sendBody("direct:create-tag", "");
         
         List<Ref> ref = git.tagList().call();
-        boolean branchCreated = false;
+        boolean tagCreated = false;
         for (Ref refInternal : ref) {
             if (refInternal.getName().equals("refs/tags/" + TAG_TEST)) {
-                branchCreated = true;
+                tagCreated = true;
             }
         }
-        assertEquals(branchCreated, true);
+        assertEquals(tagCreated, true);
+        repository.close();
+    }
+    
+    @Test
+    public void deleteTagTest() 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-tag", "");
+        
+        List<Ref> ref = git.tagList().call();
+        boolean tagCreated = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/tags/" + TAG_TEST)) {
+                tagCreated = true;
+            }
+        }
+        assertEquals(tagCreated, true);
+        
+        template.sendBody("direct:delete-tag", "");
+        
+        ref = git.tagList().call();
+        boolean tagExists = false;
+        for (Ref refInternal : ref) {
+            if (refInternal.getName().equals("refs/tags/" + TAG_TEST)) {
+                tagExists = true;
+            }
+        }
+        assertEquals(tagExists, false);
         repository.close();
     }
     
@@ -756,6 +809,8 @@ public class GitProducerTest extends GitTestSupport {
                         .to("git://" + GIT_LOCAL_REPO + "?operation=log&branchName="
+ BRANCH_TEST);
                 from("direct:create-tag")
                         .to("git://" + GIT_LOCAL_REPO + "?operation=createTag&tagName="
+ TAG_TEST);
+                from("direct:delete-tag")
+                        .to("git://" + GIT_LOCAL_REPO + "?operation=deleteTag&tagName="
+ TAG_TEST);
             } 
         };
     }


Mime
View raw message