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 <[email protected]> Authored: Mon Nov 21 11:31:28 2016 +0100 Committer: Andrea Cosentino <[email protected]> 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"); + } }; }
