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-10503 - Camel-Git: Add RemoteAdd command Finally add RemoteList command too as it goes together
Date Tue, 22 Nov 2016 09:22:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master 52459d26a -> 0be70c532


CAMEL-10503 - Camel-Git: Add RemoteAdd command
Finally add RemoteList command too as it goes together


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

Branch: refs/heads/master
Commit: 0be70c532e819bd6d8ab4b8cf24f83b86917214d
Parents: 52459d2
Author: Olivier Antibi <olivier.antibi@crossing-tech.com>
Authored: Mon Nov 21 19:36:40 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue Nov 22 10:21:58 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/component/git/GitEndpoint.java |  2 +-
 .../component/git/producer/GitOperation.java    |  2 +
 .../component/git/producer/GitProducer.java     | 43 ++++++++++++++++++++
 .../camel/component/git/GitTestSupport.java     | 12 ++++--
 .../component/git/producer/GitProducerTest.java | 43 ++++++++++++++++++++
 5 files changed, 97 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0be70c53/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 aec38d8..575784e 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
@@ -66,7 +66,7 @@ public class GitEndpoint extends DefaultEndpoint {
     @Metadata(label = "producer")
     private boolean allowEmpty = true;
 
-    @UriParam(enums = "clone,init,add,remove,commit,commitAll,createBranch,deleteBranch,createTag,deleteTag,status,log,push,pull,showBranches,cherryPick",
label = "producer")
+    @UriParam(enums = "clone,init,add,remove,commit,commitAll,createBranch,deleteBranch,createTag,deleteTag,status,log,push,pull,showBranches,cherryPick,remoteAdd,remoteList",
label = "producer")
     private String operation;
 
     public GitEndpoint(String uri, GitComponent component) {

http://git-wip-us.apache.org/repos/asf/camel/blob/0be70c53/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 ce6ae25..b74b48c 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
@@ -34,4 +34,6 @@ public interface GitOperation {
     String PULL_OPERATION = "pull";
     String SHOW_BRANCHES = "showBranches";
     String CHERRYPICK_OPERATION = "cherryPick";
+    String REMOTE_ADD_OPERATION = "remoteAdd";
+    String REMOTE_LIST_OPERATION = "remoteList";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0be70c53/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 b6bedd2..d45f309 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
@@ -19,6 +19,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;
 import org.apache.camel.component.git.GitEndpoint;
@@ -29,6 +30,7 @@ import org.eclipse.jgit.api.CherryPickResult;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.ListBranchCommand.ListMode;
 import org.eclipse.jgit.api.PullResult;
+import org.eclipse.jgit.api.RemoteAddCommand;
 import org.eclipse.jgit.api.Status;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
@@ -37,6 +39,8 @@ import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
 import org.eclipse.jgit.transport.PushResult;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.URIish;
 import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -148,6 +152,14 @@ public class GitProducer extends DefaultProducer {
             doShowBranches(exchange, operation);
             break;
 
+        case GitOperation.REMOTE_ADD_OPERATION:
+            doRemoteAdd(exchange, operation);
+            break;
+
+        case GitOperation.REMOTE_LIST_OPERATION:
+            doRemoteList(exchange, operation);
+            break;
+
         default:
             throw new IllegalArgumentException("Unsupported operation " + operation);
         }
@@ -456,6 +468,37 @@ public class GitProducer extends DefaultProducer {
         updateExchange(exchange, result);
     }
 
+    protected void doRemoteAdd(Exchange exchange, String operation) throws Exception {
+        if (ObjectHelper.isEmpty(endpoint.getRemoteName())) {
+            throw new IllegalArgumentException("Remote Name must be specified to execute
" + operation);
+        }
+        if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
+            throw new IllegalArgumentException("Remote Path must be specified to execute
" + operation);
+        }
+        RemoteConfig result = null;
+        try {
+            RemoteAddCommand remoteAddCommand = git.remoteAdd();
+            remoteAddCommand.setUri(new URIish(endpoint.getRemotePath()));
+            remoteAddCommand.setName(endpoint.getRemoteName());
+            result = remoteAddCommand.call();
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            throw e;
+        }
+        updateExchange(exchange, result);
+    }
+
+    protected void doRemoteList(Exchange exchange, String operation) throws Exception {
+        List<RemoteConfig> result = null;
+        try {
+            result = git.remoteList().call();
+        } catch (Exception e) {
+            LOG.error("There was an error in Git " + operation + " operation");
+            throw e;
+        }
+        updateExchange(exchange, result);
+    }
+
     private Repository getLocalRepository() throws IOException {
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
         Repository repo = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/0be70c53/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
index 5724736..ce0cc01 100644
--- a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
@@ -43,6 +43,8 @@ public class GitTestSupport extends CamelTestSupport {
 
     public final String tagTest = "testTag";
 
+    public final String remoteUriTest = "https://github.com/oscerd/json-webserver-example.git";
+
     @Override
     public void setUp() throws Exception {
         super.setUp();
@@ -64,10 +66,12 @@ public class GitTestSupport extends CamelTestSupport {
         Git.init().setDirectory(new File(gitLocalRepo, "")).setBare(false).call();
         // now open the resulting repository with a FileRepositoryBuilder
         FileRepositoryBuilder builder = new FileRepositoryBuilder();
-        Repository repo = builder.setGitDir(gitRepo)
-                .readEnvironment() // scan environment GIT_* variables
-                .findGitDir() // scan up the file system tree
-                .build();
+        Repository repo = builder.setGitDir(gitRepo).readEnvironment() // scan
+                                                                       // environment
+                                                                       // GIT_*
+                                                                       // variables
+            .findGitDir() // scan up the file system tree
+            .build();
         return repo;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0be70c53/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 35507b5..3d8674d 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
@@ -29,11 +29,14 @@ import org.apache.camel.component.git.GitTestSupport;
 import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.PullResult;
+import org.eclipse.jgit.api.RemoteAddCommand;
 import org.eclipse.jgit.api.Status;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.URIish;
 import org.junit.Test;
 
 public class GitProducerTest extends GitTestSupport {
@@ -1089,6 +1092,44 @@ public class GitProducerTest extends GitTestSupport {
         repository.close();
     }
 
+    @Test
+    public void remoteAddTest() throws Exception {
+        Repository repository = getTestRepository();
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        Git git = new Git(repository);
+        List<RemoteConfig> remoteConfigList = git.remoteList().call();
+        assertTrue(remoteConfigList.size() == 0);
+        Object result = template.requestBody("direct:remoteAdd", "");
+        assertTrue(result instanceof RemoteConfig);
+        RemoteConfig remoteConfig = (RemoteConfig)result;
+        remoteConfigList = git.remoteList().call();
+        assertTrue(remoteConfigList.size() == 1);
+        assertEquals(remoteConfigList.get(0).getName(), remoteConfig.getName());
+        assertEquals(remoteConfigList.get(0).getURIs(), remoteConfig.getURIs());
+        git.close();
+    }
+
+    @Test
+    public void remoteListTest() throws Exception {
+        Repository repository = getTestRepository();
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        Git git = new Git(repository);
+        RemoteAddCommand remoteAddCommand = git.remoteAdd();
+        remoteAddCommand.setName("origin");
+        remoteAddCommand.setUri(new URIish(remoteUriTest));
+        remoteAddCommand.call();
+        List<RemoteConfig> gitRemoteConfigs = git.remoteList().call();
+        Object result = template.requestBody("direct:remoteList", "");
+        assertTrue(result instanceof List);
+        List<RemoteConfig> remoteConfigs = (List<RemoteConfig>)result;
+        assertEquals(gitRemoteConfigs.size(), remoteConfigs.size());
+        assertEquals(gitRemoteConfigs.get(0).getName(), remoteConfigs.get(0).getName());
+        assertEquals(gitRemoteConfigs.get(0).getURIs(), remoteConfigs.get(0).getURIs());
+        git.close();
+    }
+
     private void validateGitLogs(Git git, String... messages) throws GitAPIException {
         Iterable<RevCommit> logs = git.log().call();
         int count = 0;
@@ -1130,6 +1171,8 @@ public class GitProducerTest extends GitTestSupport {
                 from("direct:cherrypick").to("git://" + gitLocalRepo + "?operation=cherryPick&branchName="
+ branchTest);
                 from("direct:cherrypick-master").to("git://" + gitLocalRepo + "?operation=cherryPick&branchName=refs/heads/master");
                 from("direct:pull").to("git://" + gitLocalRepo + "?remoteName=origin&operation=pull");
+                from("direct:remoteAdd").to("git://" + gitLocalRepo + "?operation=remoteAdd&remotePath=https://github.com/oscerd/json-webserver-example.git&remoteName=origin");
+                from("direct:remoteList").to("git://" + gitLocalRepo + "?operation=remoteList");
             }
         };
     }


Mime
View raw message