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:18:25 UTC
[camel] branch master updated: CAMEL-12368 - Camel-Git: add clean
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 1a1c96f CAMEL-12368 - Camel-Git: add clean operation
1a1c96f is described below
commit 1a1c96f51923c741a67d0c54da5193a37a1c721e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Mar 19 14:15:37 2018 +0100
CAMEL-12368 - Camel-Git: add clean operation
---
.../camel/component/git/producer/GitOperation.java | 1 +
.../camel/component/git/producer/GitProducer.java | 19 +++++++++++++++++++
.../camel/component/git/producer/GitProducerTest.java | 17 +++++++++++++++++
3 files changed, 37 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 b74b48c..c8a1d50 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
@@ -36,4 +36,5 @@ public interface GitOperation {
String CHERRYPICK_OPERATION = "cherryPick";
String REMOTE_ADD_OPERATION = "remoteAdd";
String REMOTE_LIST_OPERATION = "remoteList";
+ String CLEAN_OPERATION = "clean";
}
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 d45f309..276f2e7 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.Set;
import org.apache.camel.Exchange;
import org.apache.camel.component.git.GitConstants;
@@ -151,6 +152,10 @@ public class GitProducer extends DefaultProducer {
case GitOperation.SHOW_BRANCHES:
doShowBranches(exchange, operation);
break;
+
+ case GitOperation.CLEAN_OPERATION:
+ doClean(exchange, operation);
+ break;
case GitOperation.REMOTE_ADD_OPERATION:
doRemoteAdd(exchange, operation);
@@ -467,6 +472,20 @@ public class GitProducer extends DefaultProducer {
}
updateExchange(exchange, result);
}
+
+ protected void doClean(Exchange exchange, String operation) throws Exception {
+ Set<String> result = null;
+ try {
+ if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
+ git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
+ }
+ result = git.clean().setCleanDirectories(true).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 6f73e21..4999a99 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.Set;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
@@ -703,6 +704,21 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(gitRemoteConfigs.get(0).getURIs(), remoteConfigs.get(0).getURIs());
git.close();
}
+
+ @Test
+ public void cleanTest() throws Exception {
+ Git git = getGitTestRepository();
+ File fileToAdd = new File(gitLocalRepo, filenameToAdd);
+ fileToAdd.createNewFile();
+
+ // Test camel-git add
+ Set<String> cleaned = template.requestBodyAndHeader("direct:clean", "", GitConstants.GIT_FILE_NAME, filenameToAdd, Set.class);
+
+ File gitDir = new File(gitLocalRepo, ".git");
+ assertEquals(gitDir.exists(), true);
+ assertTrue(cleaned.contains(filenameToAdd));
+ git.close();
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -735,6 +751,7 @@ 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:clean").to("git://" + gitLocalRepo + "?operation=clean");
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.