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 2018/03/19 13:29:40 UTC
[camel] branch master updated: CAMEL-12369 - Camel-Git: Add GC
operation
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
The following commit(s) were added to refs/heads/master by this push:
new 02c124d CAMEL-12369 - Camel-Git: Add GC operation
02c124d is described below
commit 02c124d19f6776eb537dc0622ffdcc2798f137fa
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Mar 19 14:29:06 2018 +0100
CAMEL-12369 - Camel-Git: Add GC operation
---
.../camel/component/git/producer/GitOperation.java | 1 +
.../camel/component/git/producer/GitProducer.java | 16 +++++++++++++
.../component/git/producer/GitProducerTest.java | 28 ++++++++++++++++++++++
3 files changed, 45 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 c8a1d50..55ae08b 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
@@ -37,4 +37,5 @@ public interface GitOperation {
String REMOTE_ADD_OPERATION = "remoteAdd";
String REMOTE_LIST_OPERATION = "remoteList";
String CLEAN_OPERATION = "clean";
+ String GC_OPERATION = "gc";
}
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 276f2e7..8d671ad 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 java.util.Properties;
import java.util.Set;
import org.apache.camel.Exchange;
@@ -156,6 +157,10 @@ public class GitProducer extends DefaultProducer {
case GitOperation.CLEAN_OPERATION:
doClean(exchange, operation);
break;
+
+ case GitOperation.GC_OPERATION:
+ doGc(exchange, operation);
+ break;
case GitOperation.REMOTE_ADD_OPERATION:
doRemoteAdd(exchange, operation);
@@ -486,6 +491,17 @@ public class GitProducer extends DefaultProducer {
}
updateExchange(exchange, result);
}
+
+ protected void doGc(Exchange exchange, String operation) throws Exception {
+ Properties result = null;
+ try {
+ result = git.gc().call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
+ updateExchange(exchange, result);
+ }
protected void doRemoteAdd(Exchange exchange, String operation) throws Exception {
if (ObjectHelper.isEmpty(endpoint.getRemoteName())) {
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 4999a99..8fc324a 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
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.apache.camel.CamelExecutionException;
@@ -719,6 +720,32 @@ public class GitProducerTest extends GitTestSupport {
assertTrue(cleaned.contains(filenameToAdd));
git.close();
}
+
+ @Test
+ public void gcTest() throws Exception {
+ 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 commit (with no changes)
+ template.requestBodyAndHeader("direct:commit", "", GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
+
+ // Check that it has been commited twice
+ validateGitLogs(git, commitMessage, commitMessage);
+
+ // Test camel-git add
+ Properties gcResult = template.requestBodyAndHeader("direct:gc", "", GitConstants.GIT_FILE_NAME, filenameToAdd, Properties.class);
+
+
+ assertNotNull(gcResult);
+ git.close();
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -752,6 +779,7 @@ public class GitProducerTest extends GitTestSupport {
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:clean").to("git://" + gitLocalRepo + "?operation=clean");
+ from("direct:gc").to("git://" + gitLocalRepo + "?operation=gc");
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");
}
--
To stop receiving notification emails like this one, please contact
acosentino@apache.org.