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 2016/11/21 11:57:14 UTC
[1/3] camel git commit: CAMEL-10500 : Camel-Git: Add allowEmpty
commits option Formatting and check style
Repository: camel
Updated Branches:
refs/heads/master cdd35f0f5 -> 0ee24c1a9
CAMEL-10500 : Camel-Git: Add allowEmpty commits option
Formatting and check style
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c5c5aa3b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c5c5aa3b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c5c5aa3b
Branch: refs/heads/master
Commit: c5c5aa3b8f555b2945971bb08e9e23817e9367a5
Parents: 4034e2a
Author: Olivier Antibi <ol...@crossing-tech.com>
Authored: Mon Nov 21 11:31:28 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Mon Nov 21 12:54:10 2016 +0100
----------------------------------------------------------------------
.../camel/component/git/GitConstants.java | 6 +-
.../apache/camel/component/git/GitEndpoint.java | 10 +-
.../component/git/producer/GitProducer.java | 14 ++-
.../camel/component/git/GitTestSupport.java | 4 +-
.../component/git/producer/GitProducerTest.java | 117 ++++++-------------
.../git/producer/GitRemoteProducerTest.java | 27 ++---
6 files changed, 68 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java b/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
index 03f54ee..95ad94d 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
@@ -22,11 +22,11 @@ public interface GitConstants {
String GIT_FILE_NAME = "CamelGitFilename";
String GIT_COMMIT_MESSAGE = "CamelGitCommitMessage";
-
+
String GIT_COMMIT_USERNAME = "CamelGitCommitUsername";
-
+
String GIT_COMMIT_EMAIL = "CamelGitCommitEmail";
-
+
String GIT_COMMIT_ID = "CamelGitCommitId";
String GIT_ALLOW_EMPTY = "CamelGitAllowEmpty";
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/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 44aeb26..aec38d8 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
@@ -57,13 +57,13 @@ public class GitEndpoint extends DefaultEndpoint {
@UriParam
private String remotePath;
-
+
@UriParam
private String remoteName;
- @UriParam
- // Set to true For backward compatibility , better to set to false (native git behavior)
- @Metadata(defaultValue = "true", label = "producer")
+ // Set to true for backward compatibility , better to set to false (native git behavior)
+ @UriParam(defaultValue = "true")
+ @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")
@@ -183,7 +183,7 @@ public class GitEndpoint extends DefaultEndpoint {
public void setTagName(String tagName) {
this.tagName = tagName;
}
-
+
/**
* The remote repository name to use in particular operation like pull
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/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 2047aeb..f6eae4f 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,7 +19,6 @@ 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;
@@ -243,7 +242,7 @@ public class GitProducer extends DefaultProducer {
throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
}
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
- && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
+ && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
username = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME, String.class);
email = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL, String.class);
}
@@ -277,7 +276,7 @@ public class GitProducer extends DefaultProducer {
throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
}
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
- && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
+ && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
username = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME, String.class);
email = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL, String.class);
}
@@ -460,9 +459,12 @@ public class GitProducer extends DefaultProducer {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
- repo = builder.setGitDir(new File(endpoint.getLocalPath(), ".git")).readEnvironment() // scan environment GIT_* variables
- .findGitDir() // scan up the file system tree
- .build();
+ repo = builder.setGitDir(new File(endpoint.getLocalPath(), ".git")).readEnvironment() // scan
+ // environment
+ // GIT_*
+ // variables
+ .findGitDir() // scan up the file system tree
+ .build();
} catch (IOException e) {
LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
throw e;
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/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 10dd399..5724736 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
@@ -40,7 +40,7 @@ public class GitTestSupport extends CamelTestSupport {
public final String commitMessageBranch = "Test commit on a branch";
public final String branchTest = "testBranch";
-
+
public final String tagTest = "testTag";
@Override
@@ -58,7 +58,7 @@ public class GitTestSupport extends CamelTestSupport {
File path = new File(gitLocalRepo);
deleteDirectory(path);
}
-
+
protected Repository getTestRepository() throws IOException, IllegalStateException, GitAPIException {
File gitRepo = new File(gitLocalRepo, ".git");
Git.init().setDirectory(new File(gitLocalRepo, "")).setBare(false).call();
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/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 5491770..920e2ec 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
@@ -35,7 +35,6 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
-
public class GitProducerTest extends GitTestSupport {
@Test
@@ -126,8 +125,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
@@ -168,8 +166,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
@@ -214,7 +211,6 @@ public class GitProducerTest extends GitTestSupport {
template.requestBodyAndHeaders("direct:commit-not-allow-empty", "", headers);
}
-
@Test
public void commitBranchTest() throws Exception {
@@ -241,8 +237,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
@@ -250,8 +245,7 @@ public class GitProducerTest extends GitTestSupport {
}
assertEquals(count, 1);
Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+ git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
template.send("direct:commit-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -273,7 +267,6 @@ public class GitProducerTest extends GitTestSupport {
repository.close();
}
-
@Test
public void commitAllTest() throws Exception {
@@ -295,8 +288,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageAll);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessageAll);
@@ -332,8 +324,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
@@ -342,8 +333,7 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 1);
Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+ git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
@@ -402,8 +392,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
@@ -412,8 +401,7 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 1);
Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+ git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
@@ -911,8 +899,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
@@ -953,8 +940,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, "Test second commit");
}
});
- logs = new Git(repository).log()
- .call();
+ logs = new Git(repository).log().call();
count = 0;
String id = "";
for (RevCommit rev : logs) {
@@ -976,8 +962,7 @@ public class GitProducerTest extends GitTestSupport {
Git git = new Git(repository);
git.checkout().setCreateBranch(false).setName(branchTest).call();
- logs = git.log()
- .call();
+ logs = git.log().call();
count = 0;
for (RevCommit rev : logs) {
if (count == 0) {
@@ -1015,8 +1000,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
+ Iterable<RevCommit> logs = new Git(repository).log().call();
int count = 0;
for (RevCommit rev : logs) {
@@ -1058,8 +1042,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, "Test second commit");
}
});
- logs = git.log()
- .call();
+ logs = git.log().call();
count = 0;
String id = "";
for (RevCommit rev : logs) {
@@ -1081,8 +1064,7 @@ public class GitProducerTest extends GitTestSupport {
git = new Git(repository);
git.checkout().setCreateBranch(false).setName("refs/heads/master").call();
- logs = git.log()
- .call();
+ logs = git.log().call();
count = 0;
for (RevCommit rev : logs) {
if (count == 0) {
@@ -1099,52 +1081,29 @@ public class GitProducerTest extends GitTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- 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: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);
- from("direct:commit")
- .to("git://" + gitLocalRepo + "?operation=commit");
- from("direct:commit-not-allow-empty")
- .to("git://" + gitLocalRepo + "?operation=commit&allowEmpty=false");
- from("direct:commit-branch")
- .to("git://" + gitLocalRepo + "?operation=commit&branchName=" + branchTest);
- from("direct:commit-all")
- .to("git://" + gitLocalRepo + "?operation=commit");
- from("direct:commit-all-branch")
- .to("git://" + gitLocalRepo + "?operation=commit&branchName=" + branchTest);
- from("direct:create-branch")
- .to("git://" + gitLocalRepo + "?operation=createBranch&branchName=" + branchTest);
- from("direct:delete-branch")
- .to("git://" + gitLocalRepo + "?operation=deleteBranch&branchName=" + branchTest);
- from("direct:status")
- .to("git://" + gitLocalRepo + "?operation=status");
- from("direct:status-branch")
- .to("git://" + gitLocalRepo + "?operation=status&branchName=" + branchTest);
- from("direct:log")
- .to("git://" + gitLocalRepo + "?operation=log");
- from("direct:log-branch")
- .to("git://" + gitLocalRepo + "?operation=log&branchName=" + branchTest);
- from("direct:create-tag")
- .to("git://" + gitLocalRepo + "?operation=createTag&tagName=" + tagTest);
- from("direct:delete-tag")
- .to("git://" + gitLocalRepo + "?operation=deleteTag&tagName=" + tagTest);
- from("direct:show-branches")
- .to("git://" + gitLocalRepo + "?operation=showBranches");
- 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: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: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);
+ from("direct:commit").to("git://" + gitLocalRepo + "?operation=commit");
+ from("direct:commit-not-allow-empty").to("git://" + gitLocalRepo + "?operation=commit&allowEmpty=false");
+ from("direct:commit-branch").to("git://" + gitLocalRepo + "?operation=commit&branchName=" + branchTest);
+ from("direct:commit-all").to("git://" + gitLocalRepo + "?operation=commit");
+ from("direct:commit-all-branch").to("git://" + gitLocalRepo + "?operation=commit&branchName=" + branchTest);
+ from("direct:create-branch").to("git://" + gitLocalRepo + "?operation=createBranch&branchName=" + branchTest);
+ from("direct:delete-branch").to("git://" + gitLocalRepo + "?operation=deleteBranch&branchName=" + branchTest);
+ from("direct:status").to("git://" + gitLocalRepo + "?operation=status");
+ from("direct:status-branch").to("git://" + gitLocalRepo + "?operation=status&branchName=" + branchTest);
+ from("direct:log").to("git://" + gitLocalRepo + "?operation=log");
+ from("direct:log-branch").to("git://" + gitLocalRepo + "?operation=log&branchName=" + branchTest);
+ from("direct:create-tag").to("git://" + gitLocalRepo + "?operation=createTag&tagName=" + tagTest);
+ from("direct:delete-tag").to("git://" + gitLocalRepo + "?operation=deleteTag&tagName=" + tagTest);
+ from("direct:show-branches").to("git://" + gitLocalRepo + "?operation=showBranches");
+ 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");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c5c5aa3b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
index abdd7c9..571dcb1 100644
--- a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
@@ -31,16 +31,16 @@ import org.junit.Ignore;
import org.junit.Test;
public class GitRemoteProducerTest extends GitTestSupport {
-
+
@Ignore("Require a remote git repository")
@Test
public void pushTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -49,10 +49,10 @@ public class GitRemoteProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -61,22 +61,19 @@ public class GitRemoteProducerTest extends GitTestSupport {
});
Iterable<PushResult> result = template.requestBody("direct:push", "", Iterable.class);
-
+
repository.close();
}
-
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
+ return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:add")
- .to("git://" + gitLocalRepo + "?operation=add");
- from("direct:commit")
- .to("git://" + gitLocalRepo + "?operation=commit");
- from("direct:push")
- .to("git://" + gitLocalRepo + "?operation=push&remotePath=remoteURL&username=xxx&password=xxx");
- }
+ from("direct:add").to("git://" + gitLocalRepo + "?operation=add");
+ from("direct:commit").to("git://" + gitLocalRepo + "?operation=commit");
+ from("direct:push").to("git://" + gitLocalRepo + "?operation=push&remotePath=remoteURL&username=xxx&password=xxx");
+ }
};
}
[3/3] camel git commit: CAMEL-10500: Docs
Posted by ac...@apache.org.
CAMEL-10500: Docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0ee24c1a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0ee24c1a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0ee24c1a
Branch: refs/heads/master
Commit: 0ee24c1a9001bf7ef184940f441a39531119f53d
Parents: c5c5aa3
Author: Andrea Cosentino <an...@gmail.com>
Authored: Mon Nov 21 12:56:27 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Mon Nov 21 12:56:27 2016 +0100
----------------------------------------------------------------------
components/camel-git/src/main/docs/git-component.adoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0ee24c1a/components/camel-git/src/main/docs/git-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/docs/git-component.adoc b/components/camel-git/src/main/docs/git-component.adoc
index e7c26cb..f06ba76 100644
--- a/components/camel-git/src/main/docs/git-component.adoc
+++ b/components/camel-git/src/main/docs/git-component.adoc
@@ -87,7 +87,7 @@ Message Headers
|CamelGitCommitId |`null` |String |Producer |The commit id
-|CamelGitAlowEmpty |`null` |Boolean |Producer |The flag to manage empty git commits
+|CamelGitAllowEmpty |`null` |Boolean |Producer |The flag to manage empty git commits
|=======================================================================
[2/3] camel git commit: Add allowEmpty endpoint option
Posted by ac...@apache.org.
Add allowEmpty endpoint option
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4034e2a7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4034e2a7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4034e2a7
Branch: refs/heads/master
Commit: 4034e2a7854a0dc768c8786bf527e7d4474c38f1
Parents: cdd35f0
Author: Olivier Antibi <ol...@crossing-tech.com>
Authored: Sun Nov 20 22:43:15 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Mon Nov 21 12:54:10 2016 +0100
----------------------------------------------------------------------
.../camel-git/src/main/docs/git-component.adoc | 6 +-
.../camel/component/git/GitConstants.java | 2 +
.../apache/camel/component/git/GitEndpoint.java | 15 +
.../component/git/producer/GitProducer.java | 34 +-
.../component/git/producer/GitProducerTest.java | 397 ++++++++++---------
5 files changed, 261 insertions(+), 193 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4034e2a7/components/camel-git/src/main/docs/git-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/docs/git-component.adoc b/components/camel-git/src/main/docs/git-component.adoc
index 3ebe2ad..e7c26cb 100644
--- a/components/camel-git/src/main/docs/git-component.adoc
+++ b/components/camel-git/src/main/docs/git-component.adoc
@@ -40,7 +40,7 @@ The Git component has no options.
// endpoint options: START
-The Git component supports 13 endpoint options which are listed below:
+The Git component supports 14 endpoint options which are listed below:
{% raw %}
[width="100%",cols="2,1,1m,1m,5",options="header"]
@@ -57,6 +57,7 @@ The Git component supports 13 endpoint options which are listed below:
| type | consumer | | GitType | The consumer type
| exceptionHandler | consumer (advanced) | | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
| exchangePattern | consumer (advanced) | | ExchangePattern | Sets the exchange pattern when the consumer creates an exchange.
+| allowEmpty | producer | true | boolean | The flag to manage empty git commits
| operation | producer | | String | The operation to do on the repository
| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
|=======================================================================
@@ -85,6 +86,9 @@ Message Headers
|CamelGitCommitEmail |`null` |String |Producer |The commit email in a commit operation
|CamelGitCommitId |`null` |String |Producer |The commit id
+
+|CamelGitAlowEmpty |`null` |Boolean |Producer |The flag to manage empty git commits
+
|=======================================================================
[[Git-ProducerExample]]
http://git-wip-us.apache.org/repos/asf/camel/blob/4034e2a7/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java b/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
index 5e575ce..03f54ee 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitConstants.java
@@ -28,4 +28,6 @@ public interface GitConstants {
String GIT_COMMIT_EMAIL = "CamelGitCommitEmail";
String GIT_COMMIT_ID = "CamelGitCommitId";
+
+ String GIT_ALLOW_EMPTY = "CamelGitAllowEmpty";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4034e2a7/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 d25dbb2..44aeb26 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
@@ -61,6 +61,11 @@ public class GitEndpoint extends DefaultEndpoint {
@UriParam
private String remoteName;
+ @UriParam
+ // Set to true For backward compatibility , better to set to false (native git behavior)
+ @Metadata(defaultValue = "true", 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")
private String operation;
@@ -190,4 +195,14 @@ public class GitEndpoint extends DefaultEndpoint {
this.remoteName = remoteName;
}
+ /**
+ * The flag to manage empty git commits
+ */
+ public boolean isAllowEmpty() {
+ return allowEmpty;
+ }
+
+ public void setAllowEmpty(boolean allowEmpty) {
+ this.allowEmpty = allowEmpty;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4034e2a7/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 be7ef1d..2047aeb 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
@@ -83,7 +83,7 @@ public class GitProducer extends DefaultProducer {
}
switch (operation) {
-
+
case GitOperation.CLONE_OPERATION:
doClone(exchange, operation);
break;
@@ -99,7 +99,7 @@ public class GitProducer extends DefaultProducer {
case GitOperation.CHERRYPICK_OPERATION:
doCherryPick(exchange, operation);
break;
-
+
case GitOperation.REMOVE_OPERATION:
doRemove(exchange, operation);
break;
@@ -143,11 +143,11 @@ public class GitProducer extends DefaultProducer {
case GitOperation.DELETE_TAG_OPERATION:
doDeleteTag(exchange, operation);
break;
-
+
case GitOperation.SHOW_BRANCHES:
doShowBranches(exchange, operation);
break;
-
+
default:
throw new IllegalArgumentException("Unsupported operation " + operation);
}
@@ -242,19 +242,24 @@ public class GitProducer extends DefaultProducer {
} else {
throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
}
- if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
&& ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
username = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME, String.class);
email = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL, String.class);
}
+ boolean allowEmpty = endpoint.isAllowEmpty();
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_ALLOW_EMPTY))) {
+ allowEmpty = exchange.getIn().getHeader(GitConstants.GIT_ALLOW_EMPTY, Boolean.class);
+ }
+
try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
if (ObjectHelper.isNotEmpty(username) && ObjectHelper.isNotEmpty(email)) {
- git.commit().setCommitter(username, email).setMessage(commitMessage).call();
+ git.commit().setAllowEmpty(allowEmpty).setCommitter(username, email).setMessage(commitMessage).call();
} else {
- git.commit().setMessage(commitMessage).call();
+ git.commit().setAllowEmpty(allowEmpty).setMessage(commitMessage).call();
}
} catch (Exception e) {
LOG.error("There was an error in Git " + operation + " operation");
@@ -271,19 +276,24 @@ public class GitProducer extends DefaultProducer {
} else {
throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
}
- if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME))
&& ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL))) {
username = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_USERNAME, String.class);
email = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_EMAIL, String.class);
}
+ boolean allowEmpty = endpoint.isAllowEmpty();
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_ALLOW_EMPTY))) {
+ allowEmpty = exchange.getIn().getHeader(GitConstants.GIT_ALLOW_EMPTY, Boolean.class);
+ }
+
try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
if (ObjectHelper.isNotEmpty(username) && ObjectHelper.isNotEmpty(email)) {
- git.commit().setAll(true).setCommitter(username, email).setMessage(commitMessage).call();
+ git.commit().setAllowEmpty(allowEmpty).setAll(true).setCommitter(username, email).setMessage(commitMessage).call();
} else {
- git.commit().setAll(true).setMessage(commitMessage).call();
+ git.commit().setAllowEmpty(allowEmpty).setAll(true).setMessage(commitMessage).call();
}
} catch (Exception e) {
LOG.error("There was an error in Git " + operation + " operation");
@@ -410,7 +420,7 @@ public class GitProducer extends DefaultProducer {
throw e;
}
}
-
+
protected void doShowBranches(Exchange exchange, String operation) throws Exception {
List<Ref> result = null;
try {
@@ -421,7 +431,7 @@ public class GitProducer extends DefaultProducer {
}
exchange.getOut().setBody(result);
}
-
+
protected void doCherryPick(Exchange exchange, String operation) throws Exception {
CherryPickResult result = null;
String commitId = null;
http://git-wip-us.apache.org/repos/asf/camel/blob/4034e2a7/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 6dc66ed..5491770 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
@@ -17,8 +17,9 @@
package org.apache.camel.component.git.producer;
import java.io.File;
+import java.util.HashMap;
import java.util.List;
-
+import java.util.Map;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -34,22 +35,23 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
+
public class GitProducerTest extends GitTestSupport {
-
+
@Test
public void cloneTest() throws Exception {
template.sendBody("direct:clone", "");
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
}
-
+
@Test
public void initTest() throws Exception {
template.sendBody("direct:init", "");
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
}
-
+
@Test(expected = CamelExecutionException.class)
public void doubleCloneOperationTest() throws Exception {
template.sendBody("direct:clone", "");
@@ -57,7 +59,7 @@ public class GitProducerTest extends GitTestSupport {
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
}
-
+
@Test
public void pullTest() throws Exception {
template.sendBody("direct:clone", "");
@@ -66,15 +68,15 @@ public class GitProducerTest extends GitTestSupport {
PullResult pr = template.requestBody("direct:pull", "", PullResult.class);
assertTrue(pr.isSuccessful());
}
-
+
@Test
public void addTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -83,20 +85,20 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
repository.close();
}
-
+
@Test
public void removeTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -105,10 +107,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:remove", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -117,7 +119,7 @@ public class GitProducerTest extends GitTestSupport {
});
gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -132,22 +134,22 @@ public class GitProducerTest extends GitTestSupport {
count++;
}
assertEquals(count, 1);
-
+
status = new Git(repository).status().call();
assertFalse(status.getAdded().contains(filenameToAdd));
-
+
repository.close();
}
-
+
@Test
public void commitTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -156,10 +158,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -176,15 +178,51 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 1);
repository.close();
}
-
+
+ @Test
+ public void commitTestEmpty() throws Exception {
+ Repository repository = getTestRepository();
+ File gitDir = new File(gitLocalRepo, ".git");
+ assertEquals(gitDir.exists(), true);
+ Git git = new Git(repository);
+ 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();
+ template.requestBodyAndHeader("direct:commit", "", GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
+ }
+
+ @Test(expected = CamelExecutionException.class)
+ public void commitTestAllowEmptyFalse() throws Exception {
+ Repository repository = getTestRepository();
+ File gitDir = new File(gitLocalRepo, ".git");
+ assertEquals(gitDir.exists(), true);
+ Git git = new Git(repository);
+ 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();
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
+ headers.put(GitConstants.GIT_ALLOW_EMPTY, true);
+ template.requestBodyAndHeaders("direct:commit", "", headers);
+ headers.remove(GitConstants.GIT_ALLOW_EMPTY);
+ template.requestBodyAndHeaders("direct:commit-not-allow-empty", "", headers);
+ }
+
+
@Test
public void commitBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -193,10 +231,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -211,11 +249,9 @@ public class GitProducerTest extends GitTestSupport {
count++;
}
assertEquals(count, 1);
-
Git git = new Git(repository);
git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
template.send("direct:commit-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -236,24 +272,23 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 2);
repository.close();
}
-
-
+
@Test
public void commitAllTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameToAdd);
}
});
-
+
template.send("direct:commit-all", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -270,15 +305,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 1);
repository.close();
}
-
+
@Test
public void commitAllDifferentBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -287,10 +322,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -305,21 +340,21 @@ public class GitProducerTest extends GitTestSupport {
count++;
}
assertEquals(count, 1);
-
+
Git git = new Git(repository);
git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
-
+
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
-
+
template.send("direct:commit-all-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -340,15 +375,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 2);
repository.close();
}
-
+
@Test
public void removeFileBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -357,10 +392,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -375,21 +410,21 @@ public class GitProducerTest extends GitTestSupport {
count++;
}
assertEquals(count, 1);
-
+
Git git = new Git(repository);
git.checkout().setCreateBranch(true).setName(branchTest).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
-
+
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
-
+
template.send("direct:commit-all-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -408,31 +443,31 @@ public class GitProducerTest extends GitTestSupport {
count++;
}
assertEquals(count, 2);
-
+
template.send("direct:remove-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameToAdd);
}
});
-
+
git = new Git(repository);
git.checkout().setCreateBranch(false).setName(branchTest).call();
-
+
status = git.status().call();
assertFalse(status.getAdded().contains(filenameToAdd));
-
+
repository.close();
}
-
+
@Test
public void createBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -441,21 +476,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Git git = new Git(repository);
-
+
template.sendBody("direct:create-branch", "");
-
+
List<Ref> ref = git.branchList().call();
boolean branchCreated = false;
for (Ref refInternal : ref) {
@@ -466,15 +501,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(branchCreated, true);
repository.close();
}
-
+
@Test
public void deleteBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -483,21 +518,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Git git = new Git(repository);
-
+
template.sendBody("direct:create-branch", "");
-
+
List<Ref> ref = git.branchList().call();
boolean branchCreated = false;
for (Ref refInternal : ref) {
@@ -506,9 +541,9 @@ public class GitProducerTest extends GitTestSupport {
}
}
assertEquals(branchCreated, true);
-
+
template.sendBody("direct:delete-branch", "");
-
+
ref = git.branchList().call();
branchCreated = false;
for (Ref refInternal : ref) {
@@ -519,15 +554,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(branchCreated, false);
repository.close();
}
-
+
@Test
public void statusTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -536,21 +571,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = template.requestBody("direct:status", "", Status.class);
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
repository.close();
}
-
+
@Test
public void statusBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -559,21 +594,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = template.requestBody("direct:status", "", Status.class);
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
template.sendBody("direct:create-branch", "");
-
+
Git git = new Git(repository);
-
+
List<Ref> ref = git.branchList().call();
boolean branchCreated = false;
for (Ref refInternal : ref) {
@@ -582,31 +617,31 @@ public class GitProducerTest extends GitTestSupport {
}
}
assertEquals(branchCreated, true);
-
+
File fileToAddDifferent = new File(gitLocalRepo, filenameBranchToAdd);
fileToAddDifferent.createNewFile();
-
+
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
-
+
status = template.requestBody("direct:status-branch", "", Status.class);
assertTrue(status.getAdded().contains(filenameBranchToAdd));
-
+
repository.close();
}
-
+
@Test
public void logTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -615,32 +650,32 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = template.requestBody("direct:status", "", Status.class);
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
for (RevCommit rev : revCommits) {
assertEquals(rev.getShortMessage(), commitMessage);
- }
+ }
repository.close();
}
-
+
@Test
public void logBranchTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -649,26 +684,26 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = template.requestBody("direct:status", "", Status.class);
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
for (RevCommit rev : revCommits) {
assertEquals(rev.getShortMessage(), commitMessage);
}
-
+
template.sendBody("direct:create-branch", "");
-
+
Git git = new Git(repository);
-
+
List<Ref> ref = git.branchList().call();
boolean branchCreated = false;
for (Ref refInternal : ref) {
@@ -677,24 +712,24 @@ public class GitProducerTest extends GitTestSupport {
}
}
assertEquals(branchCreated, true);
-
+
File fileToAddDifferent = new File(gitLocalRepo, filenameBranchToAdd);
fileToAddDifferent.createNewFile();
-
+
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
-
+
template.send("direct:commit-all-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageAll);
}
});
-
+
revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
int count = 0;
for (RevCommit rev : revCommits) {
@@ -706,18 +741,18 @@ public class GitProducerTest extends GitTestSupport {
}
count++;
}
-
+
repository.close();
}
-
+
@Test
public void createTagTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -726,21 +761,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Git git = new Git(repository);
-
+
template.sendBody("direct:create-tag", "");
-
+
List<Ref> ref = git.tagList().call();
boolean tagCreated = false;
for (Ref refInternal : ref) {
@@ -751,15 +786,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(tagCreated, true);
repository.close();
}
-
+
@Test
public void deleteTagTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -768,21 +803,21 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Git git = new Git(repository);
-
+
template.sendBody("direct:create-tag", "");
-
+
List<Ref> ref = git.tagList().call();
boolean tagCreated = false;
for (Ref refInternal : ref) {
@@ -791,9 +826,9 @@ public class GitProducerTest extends GitTestSupport {
}
}
assertEquals(tagCreated, true);
-
+
template.sendBody("direct:delete-tag", "");
-
+
ref = git.tagList().call();
boolean tagExists = false;
for (Ref refInternal : ref) {
@@ -804,15 +839,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(tagExists, false);
repository.close();
}
-
+
@Test
public void showBranchesTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -821,43 +856,43 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
}
});
-
+
Git git = new Git(repository);
-
+
template.sendBody("direct:create-branch", "");
-
+
List<Ref> branches = template.requestBody("direct:show-branches", "", List.class);
-
+
Boolean branchExists = false;
-
+
for (Ref reference : branches) {
if (("refs/heads/" + branchTest).equals(reference.getName())) {
branchExists = true;
}
}
assertTrue(branchExists);
-
+
repository.close();
}
-
+
@Test
public void cherryPickTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -866,10 +901,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -879,39 +914,39 @@ public class GitProducerTest extends GitTestSupport {
Iterable<RevCommit> logs = new Git(repository).log()
.call();
int count = 0;
-
+
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
count++;
}
assertEquals(count, 1);
-
+
template.sendBody("direct:create-branch", "");
-
+
List<Ref> branches = template.requestBody("direct:show-branches", "", List.class);
-
+
Boolean branchExists = false;
-
+
for (Ref reference : branches) {
if (("refs/heads/" + branchTest).equals(reference.getName())) {
branchExists = true;
}
}
assertTrue(branchExists);
-
+
File fileToAdd1 = new File(gitLocalRepo, "filetest1test.txt");
fileToAdd1.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, "filetest1test.txt");
}
});
-
+
status = new Git(repository).status().call();
assertTrue(status.getAdded().contains("filetest1test.txt"));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -923,14 +958,14 @@ public class GitProducerTest extends GitTestSupport {
count = 0;
String id = "";
for (RevCommit rev : logs) {
- if (count == 0) {
+ if (count == 0) {
id = rev.getName();
assertEquals(rev.getShortMessage(), "Test second commit");
}
count++;
}
assertEquals(count, 2);
-
+
final String str = id;
template.send("direct:cherrypick", new Processor() {
@Override
@@ -938,7 +973,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_ID, str);
}
});
-
+
Git git = new Git(repository);
git.checkout().setCreateBranch(false).setName(branchTest).call();
logs = git.log()
@@ -953,15 +988,15 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 2);
repository.close();
}
-
+
@Test
public void cherryPickBranchToMasterTest() throws Exception {
Repository repository = getTestRepository();
-
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
-
+
template.send("direct:add", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -970,10 +1005,10 @@ public class GitProducerTest extends GitTestSupport {
});
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
-
+
Status status = new Git(repository).status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
-
+
template.send("direct:commit", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -983,29 +1018,29 @@ public class GitProducerTest extends GitTestSupport {
Iterable<RevCommit> logs = new Git(repository).log()
.call();
int count = 0;
-
+
for (RevCommit rev : logs) {
assertEquals(rev.getShortMessage(), commitMessage);
count++;
}
assertEquals(count, 1);
-
+
template.sendBody("direct:create-branch", "");
-
+
List<Ref> branches = template.requestBody("direct:show-branches", "", List.class);
-
+
Boolean branchExists = false;
-
+
for (Ref reference : branches) {
if (("refs/heads/" + branchTest).equals(reference.getName())) {
branchExists = true;
}
}
assertTrue(branchExists);
-
+
File fileToAdd1 = new File(gitLocalRepo, "filetest1test.txt");
fileToAdd1.createNewFile();
-
+
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -1016,7 +1051,7 @@ public class GitProducerTest extends GitTestSupport {
git.checkout().setCreateBranch(false).setName(branchTest).call();
status = git.status().call();
assertTrue(status.getAdded().contains("filetest1test.txt"));
-
+
template.send("direct:commit-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
@@ -1028,14 +1063,14 @@ public class GitProducerTest extends GitTestSupport {
count = 0;
String id = "";
for (RevCommit rev : logs) {
- if (count == 0) {
+ if (count == 0) {
id = rev.getName();
assertEquals(rev.getShortMessage(), "Test second commit");
}
count++;
}
assertEquals(count, 2);
-
+
final String str = id;
template.send("direct:cherrypick-master", new Processor() {
@Override
@@ -1043,7 +1078,7 @@ public class GitProducerTest extends GitTestSupport {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_ID, str);
}
});
-
+
git = new Git(repository);
git.checkout().setCreateBranch(false).setName("refs/heads/master").call();
logs = git.log()
@@ -1058,10 +1093,10 @@ public class GitProducerTest extends GitTestSupport {
assertEquals(count, 2);
repository.close();
}
-
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
+ return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:clone")
@@ -1078,6 +1113,8 @@ public class GitProducerTest extends GitTestSupport {
.to("git://" + gitLocalRepo + "?operation=add&branchName=" + branchTest);
from("direct:commit")
.to("git://" + gitLocalRepo + "?operation=commit");
+ from("direct:commit-not-allow-empty")
+ .to("git://" + gitLocalRepo + "?operation=commit&allowEmpty=false");
from("direct:commit-branch")
.to("git://" + gitLocalRepo + "?operation=commit&branchName=" + branchTest);
from("direct:commit-all")
@@ -1108,7 +1145,7 @@ public class GitProducerTest extends GitTestSupport {
.to("git://" + gitLocalRepo + "?operation=cherryPick&branchName=refs/heads/master");
from("direct:pull")
.to("git://" + gitLocalRepo + "?remoteName=origin&operation=pull");
- }
+ }
};
}