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 2015/07/18 11:09:35 UTC
[18/23] camel git commit: Fixed CS
Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/46535261
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/46535261
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/46535261
Branch: refs/heads/master
Commit: 465352619d40f9bc35c3a3cd8fa087eb221124ba
Parents: 69fdbd1
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sat Jul 18 11:07:24 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sat Jul 18 11:08:16 2015 +0200
----------------------------------------------------------------------
.../camel/component/git/GitConstants.java | 8 +-
.../apache/camel/component/git/GitEndpoint.java | 176 ++++---
.../git/consumer/AbstractGitConsumer.java | 40 +-
.../git/consumer/GitBranchConsumer.java | 35 +-
.../git/consumer/GitCommitConsumer.java | 34 +-
.../component/git/consumer/GitTagConsumer.java | 35 +-
.../component/git/producer/GitOperation.java | 28 +-
.../component/git/producer/GitProducer.java | 453 ++++++++++---------
.../component/git/consumer/GitConsumerTest.java | 2 +-
.../component/git/producer/GitProducerTest.java | 44 +-
.../git/producer/GitRemoteProducerTest.java | 2 +-
11 files changed, 463 insertions(+), 394 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/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 0ec6856..ce90b82 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
@@ -17,7 +17,9 @@
package org.apache.camel.component.git;
public interface GitConstants {
- public static final String GIT_OPERATION = "CamelGitOperation";
- public static final String GIT_FILE_NAME = "CamelGitFilename";
- public static final String GIT_COMMIT_MESSAGE = "CamelGitCommitMessage";
+ String GIT_OPERATION = "CamelGitOperation";
+
+ String GIT_FILE_NAME = "CamelGitFilename";
+
+ String GIT_COMMIT_MESSAGE = "CamelGitCommitMessage";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/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 ce1a325..261c6ce 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
@@ -33,94 +33,127 @@ import org.apache.camel.spi.UriPath;
@UriEndpoint(scheme = "git", title = "Git", syntax = "git://localpath", label = "api,file")
public class GitEndpoint extends DefaultEndpoint {
- @UriPath @Metadata(required = "true")
+ @UriPath
+ @Metadata(required = "true")
private String localPath;
+
@UriPath
private String branchName;
+
@UriPath
private String tagName;
+
@UriPath(label = "consumer")
private GitType type;
+
@UriParam
private String username;
+
@UriParam
private String password;
+
@UriParam
private String remotePath;
- @UriParam
+
+ @UriParam(label = "producer")
private String operation;
public GitEndpoint(String uri, GitComponent component) {
super(uri, component);
}
-
- @Override
- public Producer createProducer() throws Exception {
- return new GitProducer(this);
- }
-
- @Override
- public Consumer createConsumer(Processor processor) throws Exception {
- if (type == GitType.COMMIT) return new GitCommitConsumer(this, processor);
- else if (type == GitType.TAG) return new GitTagConsumer(this, processor);
- else if (type == GitType.BRANCH) return new GitBranchConsumer(this, processor);
- else throw new IllegalArgumentException("Cannot create producer with type " + type);
- }
-
- @Override
- public boolean isSingleton() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public String getRemotePath() {
- return remotePath;
- }
-
- public void setRemotePath(String remotePath) {
- this.remotePath = remotePath;
- }
-
- public String getBranchName() {
- return branchName;
- }
-
- public void setBranchName(String branchName) {
- this.branchName = branchName;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getLocalPath() {
- return localPath;
- }
-
- public void setLocalPath(String localPath) {
- this.localPath = localPath;
- }
-
- public String getOperation() {
- return operation;
- }
-
- public void setOperation(String operation) {
- this.operation = operation;
- }
+ @Override
+ public Producer createProducer() throws Exception {
+ return new GitProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ if (type == GitType.COMMIT) {
+ return new GitCommitConsumer(this, processor);
+ } else if (type == GitType.TAG) {
+ return new GitTagConsumer(this, processor);
+ } else if (type == GitType.BRANCH) {
+ return new GitBranchConsumer(this, processor);
+ } else {
+ throw new IllegalArgumentException("Cannot create producer with type " + type);
+ }
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ /**
+ * The remote repository path
+ */
+ public String getRemotePath() {
+ return remotePath;
+ }
+
+ public void setRemotePath(String remotePath) {
+ this.remotePath = remotePath;
+ }
+
+ /**
+ * The branch name to work on
+ */
+ public String getBranchName() {
+ return branchName;
+ }
+
+ public void setBranchName(String branchName) {
+ this.branchName = branchName;
+ }
+
+ /**
+ * Remote repository username
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ /**
+ * Remote repository password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Local repository path
+ */
+ public String getLocalPath() {
+ return localPath;
+ }
+
+ public void setLocalPath(String localPath) {
+ this.localPath = localPath;
+ }
+
+ /**
+ * The operation to do on the repository
+ */
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ /**
+ * The consumer type
+ */
public GitType getType() {
return type;
}
@@ -129,6 +162,9 @@ public class GitEndpoint extends DefaultEndpoint {
this.type = type;
}
+ /**
+ * The tag name to work on
+ */
public String getTagName() {
return tagName;
}
@@ -136,5 +172,5 @@ public class GitEndpoint extends DefaultEndpoint {
public void setTagName(String tagName) {
this.tagName = tagName;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
index ca58dcf..60b98f6 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
@@ -21,7 +21,6 @@ import java.io.IOException;
import org.apache.camel.Processor;
import org.apache.camel.component.git.GitEndpoint;
-import org.apache.camel.component.git.producer.GitProducer;
import org.apache.camel.impl.ScheduledPollConsumer;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
@@ -30,20 +29,20 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractGitConsumer extends ScheduledPollConsumer {
-
+
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractGitConsumer.class);
+
private final GitEndpoint endpoint;
-
+
private Repository repo;
-
+
private Git git;
-
- private static final Logger LOG = LoggerFactory.getLogger(AbstractGitConsumer.class);
public AbstractGitConsumer(GitEndpoint endpoint, Processor processor) {
super(endpoint, processor);
this.endpoint = endpoint;
}
-
+
@Override
protected void doStart() throws Exception {
super.doStart();
@@ -58,28 +57,27 @@ public abstract class AbstractGitConsumer extends ScheduledPollConsumer {
git.close();
}
- private Repository getLocalRepository() throws IOException{
+ private Repository getLocalRepository() throws IOException {
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();
- } catch (IOException e) {
- LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
- throw e;
- }
- return repo;
+ try {
+ 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;
+ }
+ return repo;
}
-
+
protected Repository getRepository() {
return repo;
}
-
+
protected Git getGit() {
return git;
}
-
+
protected abstract int poll() throws Exception;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitBranchConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitBranchConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitBranchConsumer.java
index d906d7a..dc64012 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitBranchConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitBranchConsumer.java
@@ -23,30 +23,29 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.git.GitEndpoint;
import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.revwalk.RevCommit;
public class GitBranchConsumer extends AbstractGitConsumer {
-
- private List used = new ArrayList();
- public GitBranchConsumer(GitEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
+ private List used = new ArrayList();
- @Override
- protected int poll() throws Exception {
- int count = 0;
- List<Ref> call = getGit().branchList().call();
+ public GitBranchConsumer(GitEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int count = 0;
+ List<Ref> call = getGit().branchList().call();
for (Ref ref : call) {
- if (!used.contains(ref.getName())) {
- Exchange e = getEndpoint().createExchange();
- e.getOut().setBody(ref);
- getProcessor().process(e);
- used.add(ref.getName());
- count++;
- }
+ if (!used.contains(ref.getName())) {
+ Exchange e = getEndpoint().createExchange();
+ e.getOut().setBody(ref);
+ getProcessor().process(e);
+ used.add(ref.getName());
+ count++;
+ }
}
return count;
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
index c837adc..6a4600e 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
@@ -25,27 +25,27 @@ import org.apache.camel.component.git.GitEndpoint;
import org.eclipse.jgit.revwalk.RevCommit;
public class GitCommitConsumer extends AbstractGitConsumer {
-
- private List used = new ArrayList();
- public GitCommitConsumer(GitEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
+ private List used = new ArrayList();
- @Override
- protected int poll() throws Exception {
- int count = 0;
- Iterable<RevCommit> commits = getGit().log().all().call();
+ public GitCommitConsumer(GitEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int count = 0;
+ Iterable<RevCommit> commits = getGit().log().all().call();
for (RevCommit commit : commits) {
- if (!used.contains(commit.getId())) {
- Exchange e = getEndpoint().createExchange();
- e.getOut().setBody(commit);
- getProcessor().process(e);
- used.add(commit.getId());
- count++;
- }
+ if (!used.contains(commit.getId())) {
+ Exchange e = getEndpoint().createExchange();
+ e.getOut().setBody(commit);
+ getProcessor().process(e);
+ used.add(commit.getId());
+ count++;
+ }
}
return count;
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
index ca063f3..88832b7 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
@@ -23,30 +23,29 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.git.GitEndpoint;
import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.revwalk.RevCommit;
public class GitTagConsumer extends AbstractGitConsumer {
-
- private List used = new ArrayList();
- public GitTagConsumer(GitEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
+ private List used = new ArrayList();
- @Override
- protected int poll() throws Exception {
- int count = 0;
- List<Ref> call = getGit().tagList().call();
+ public GitTagConsumer(GitEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int count = 0;
+ List<Ref> call = getGit().tagList().call();
for (Ref ref : call) {
- if (!used.contains(ref.getName())) {
- Exchange e = getEndpoint().createExchange();
- e.getOut().setBody(ref);
- getProcessor().process(e);
- used.add(ref.getName());
- count++;
- }
+ if (!used.contains(ref.getName())) {
+ Exchange e = getEndpoint().createExchange();
+ e.getOut().setBody(ref);
+ getProcessor().process(e);
+ used.add(ref.getName());
+ count++;
+ }
}
return count;
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitOperation.java
index dbd9813..f5f07f2 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
@@ -18,18 +18,18 @@ package org.apache.camel.component.git.producer;
public interface GitOperation {
- public final static String CLONE_OPERATION = "clone";
- public final static String INIT_OPERATION = "init";
- public final static String ADD_OPERATION = "add";
- public final static String REMOVE_OPERATION = "remove";
- public final static String COMMIT_OPERATION = "commit";
- public final static String COMMIT_ALL_OPERATION = "commitAll";
- public final static String CREATE_BRANCH_OPERATION = "createBranch";
- public final static String DELETE_BRANCH_OPERATION = "deleteBranch";
- public final static String CREATE_TAG_OPERATION = "createTag";
- public final static String DELETE_TAG_OPERATION = "deleteTag";
- public final static String STATUS_OPERATION = "status";
- public final static String LOG_OPERATION = "log";
- public final static String PUSH_OPERATION = "push";
- public final static String PULL_OPERATION = "pull";
+ String CLONE_OPERATION = "clone";
+ String INIT_OPERATION = "init";
+ String ADD_OPERATION = "add";
+ String REMOVE_OPERATION = "remove";
+ String COMMIT_OPERATION = "commit";
+ String COMMIT_ALL_OPERATION = "commitAll";
+ String CREATE_BRANCH_OPERATION = "createBranch";
+ String DELETE_BRANCH_OPERATION = "deleteBranch";
+ String CREATE_TAG_OPERATION = "createTag";
+ String DELETE_TAG_OPERATION = "deleteTag";
+ String STATUS_OPERATION = "status";
+ String LOG_OPERATION = "log";
+ String PUSH_OPERATION = "push";
+ String PULL_OPERATION = "pull";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/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 a397801..57a6e01 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
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.camel.component.git.producer;
import java.io.File;
@@ -15,221 +31,225 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.PushResult;
-import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class GitProducer extends DefaultProducer{
+public class GitProducer extends DefaultProducer {
private static final Logger LOG = LoggerFactory.getLogger(GitProducer.class);
+
private final GitEndpoint endpoint;
-
+
private Repository repo;
-
+
private Git git;
-
- public GitProducer(GitEndpoint endpoint) {
- super(endpoint);
- this.endpoint = endpoint;
- }
-
- @Override
- protected void doStart() throws Exception {
- super.doStart();
- this.repo = getLocalRepository();
- this.git = new Git(repo);
- }
-
- @Override
- protected void doStop() throws Exception {
- super.doStop();
- repo.close();
- git.close();
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- String operation;
- if (ObjectHelper.isEmpty(endpoint.getOperation())) {
- operation = exchange.getIn().getHeader(GitConstants.GIT_OPERATION, String.class);
- } else {
- operation = endpoint.getOperation();
- }
- if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
- throw new IllegalArgumentException("Local path must specified to execute " + operation);
- }
-
- switch (operation) {
- case GitOperation.CLONE_OPERATION:
- doClone(exchange, operation);
- break;
-
- case GitOperation.INIT_OPERATION:
- doInit(exchange, operation);
- break;
-
- case GitOperation.ADD_OPERATION:
- doAdd(exchange, operation);
- break;
-
- case GitOperation.REMOVE_OPERATION:
- doRemove(exchange, operation);
- break;
-
- case GitOperation.COMMIT_OPERATION:
- doCommit(exchange, operation);
- break;
-
- case GitOperation.COMMIT_ALL_OPERATION:
- doCommitAll(exchange, operation);
- break;
-
- case GitOperation.CREATE_BRANCH_OPERATION:
- doCreateBranch(exchange, operation);
- break;
-
- case GitOperation.DELETE_BRANCH_OPERATION:
- doDeleteBranch(exchange, operation);
- break;
-
- case GitOperation.STATUS_OPERATION:
- doStatus(exchange, operation);
- break;
-
- case GitOperation.LOG_OPERATION:
- doLog(exchange, operation);
- break;
-
- case GitOperation.PUSH_OPERATION:
- doPush(exchange, operation);
- break;
-
- case GitOperation.PULL_OPERATION:
- doPull(exchange, operation);
- break;
-
- case GitOperation.CREATE_TAG_OPERATION:
- doCreateTag(exchange, operation);
- break;
+
+ public GitProducer(GitEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ this.repo = getLocalRepository();
+ this.git = new Git(repo);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ repo.close();
+ git.close();
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String operation;
+ if (ObjectHelper.isEmpty(endpoint.getOperation())) {
+ operation = exchange.getIn().getHeader(GitConstants.GIT_OPERATION, String.class);
+ } else {
+ operation = endpoint.getOperation();
+ }
+ if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
+ throw new IllegalArgumentException("Local path must specified to execute " + operation);
+ }
+
+ switch (operation) {
+
+ case GitOperation.CLONE_OPERATION:
+ doClone(exchange, operation);
+ break;
+
+ case GitOperation.INIT_OPERATION:
+ doInit(exchange, operation);
+ break;
+
+ case GitOperation.ADD_OPERATION:
+ doAdd(exchange, operation);
+ break;
+
+ case GitOperation.REMOVE_OPERATION:
+ doRemove(exchange, operation);
+ break;
+
+ case GitOperation.COMMIT_OPERATION:
+ doCommit(exchange, operation);
+ break;
+
+ case GitOperation.COMMIT_ALL_OPERATION:
+ doCommitAll(exchange, operation);
+ break;
+
+ case GitOperation.CREATE_BRANCH_OPERATION:
+ doCreateBranch(exchange, operation);
+ break;
+
+ case GitOperation.DELETE_BRANCH_OPERATION:
+ doDeleteBranch(exchange, operation);
+ break;
+
+ case GitOperation.STATUS_OPERATION:
+ doStatus(exchange, operation);
+ break;
+
+ case GitOperation.LOG_OPERATION:
+ doLog(exchange, operation);
+ break;
+
+ case GitOperation.PUSH_OPERATION:
+ doPush(exchange, operation);
+ break;
+
+ case GitOperation.PULL_OPERATION:
+ doPull(exchange, operation);
+ break;
+
+ case GitOperation.CREATE_TAG_OPERATION:
+ doCreateTag(exchange, operation);
+ break;
+
+ case GitOperation.DELETE_TAG_OPERATION:
+ doDeleteTag(exchange, operation);
+ break;
- case GitOperation.DELETE_TAG_OPERATION:
- doDeleteTag(exchange, operation);
- break;
- }
- }
-
+ default:
+ throw new IllegalArgumentException("Local path must specified to execute " + operation);
+ }
+ }
+
protected void doClone(Exchange exchange, String operation) throws Exception {
- Git result = null;
- if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
- throw new IllegalArgumentException("Local path must specified to execute " + operation);
- }
- try {
- File localRepo = new File(endpoint.getLocalPath(), "");
- if (!localRepo.exists()) {
- result = Git.cloneRepository().setURI(endpoint.getRemotePath()).setDirectory(new File(endpoint.getLocalPath(),"")).call();
- } else {
- throw new IllegalArgumentException("The local repository directory already exists");
- }
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- } finally {
- result.close();
- }
+ Git result = null;
+ if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
+ throw new IllegalArgumentException("Local path must specified to execute " + operation);
+ }
+ try {
+ File localRepo = new File(endpoint.getLocalPath(), "");
+ if (!localRepo.exists()) {
+ result = Git.cloneRepository().setURI(endpoint.getRemotePath()).setDirectory(new File(endpoint.getLocalPath(), "")).call();
+ } else {
+ throw new IllegalArgumentException("The local repository directory already exists");
+ }
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ } finally {
+ result.close();
+ }
}
protected void doInit(Exchange exchange, String operation) throws Exception {
- Git result = null;
- if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
- throw new IllegalArgumentException("Local path must specified to execute " + operation);
- }
- try {
- result = Git.init().setDirectory(new File(endpoint.getLocalPath(),"")).setBare(false).call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- } finally {
- result.close();
- }
+ Git result = null;
+ if (ObjectHelper.isEmpty(endpoint.getLocalPath())) {
+ throw new IllegalArgumentException("Local path must specified to execute " + operation);
+ }
+ try {
+ result = Git.init().setDirectory(new File(endpoint.getLocalPath(), "")).setBare(false).call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ } finally {
+ result.close();
+ }
}
-
+
protected void doAdd(Exchange exchange, String operation) throws Exception {
- String fileName = null;
- if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME))) {
- fileName = exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME, String.class);
- } else {
- throw new IllegalArgumentException("File name must be specified to execute " + operation);
- }
- try {
- if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
- git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
- }
- git.add().addFilepattern(fileName).call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ String fileName = null;
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME))) {
+ fileName = exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME, String.class);
+ } else {
+ throw new IllegalArgumentException("File name must be specified to execute " + operation);
+ }
+ try {
+ if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
+ git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
+ }
+ git.add().addFilepattern(fileName).call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
}
-
+
protected void doRemove(Exchange exchange, String operation) throws Exception {
String fileName = null;
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME))) {
- fileName = exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME, String.class);
+ fileName = exchange.getIn().getHeader(GitConstants.GIT_FILE_NAME, String.class);
} else {
- throw new IllegalArgumentException("File name must be specified to execute " + operation);
+ throw new IllegalArgumentException("File name must be specified to execute " + operation);
}
try {
- if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
- git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
- }
- git.rm().addFilepattern(fileName).call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
+ git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
+ }
+ git.rm().addFilepattern(fileName).call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
}
-
+
protected void doCommit(Exchange exchange, String operation) throws Exception {
- String commitMessage = null;
- if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE))) {
- commitMessage = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE, String.class);
- } else {
- throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
- }
- try {
+ String commitMessage = null;
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE))) {
+ commitMessage = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE, String.class);
+ } else {
+ throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
+ }
+ try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
- git.commit().setMessage(commitMessage).call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ git.commit().setMessage(commitMessage).call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
}
-
+
protected void doCommitAll(Exchange exchange, String operation) throws Exception {
String commitMessage = null;
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE))) {
- commitMessage = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE, String.class);
+ commitMessage = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_MESSAGE, String.class);
} else {
- throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
+ throw new IllegalArgumentException("Commit message must be specified to execute " + operation);
}
try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
- git.commit().setAll(true).setMessage(commitMessage).call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ git.commit().setAll(true).setMessage(commitMessage).call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
}
-
+
protected void doCreateBranch(Exchange exchange, String operation) throws Exception {
if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
throw new IllegalArgumentException("Branch Name must be specified to execute " + operation);
- }
+ }
try {
git.branchCreate().setName(endpoint.getBranchName()).call();
} catch (Exception e) {
@@ -237,11 +257,11 @@ public class GitProducer extends DefaultProducer{
throw e;
}
}
-
+
protected void doDeleteBranch(Exchange exchange, String operation) throws Exception {
if (ObjectHelper.isEmpty(endpoint.getBranchName())) {
throw new IllegalArgumentException("Branch Name must be specified to execute " + operation);
- }
+ }
try {
git.branchDelete().setBranchNames(endpoint.getBranchName()).call();
} catch (Exception e) {
@@ -249,83 +269,83 @@ public class GitProducer extends DefaultProducer{
throw e;
}
}
-
+
protected void doStatus(Exchange exchange, String operation) throws Exception {
Status status = null;
try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
- status = git.status().call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ status = git.status().call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
exchange.getOut().setBody(status);
}
-
+
protected void doLog(Exchange exchange, String operation) throws Exception {
Iterable<RevCommit> revCommit = null;
try {
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
- revCommit = git.log().call();
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ revCommit = git.log().call();
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
exchange.getOut().setBody(revCommit);
}
-
+
protected void doPush(Exchange exchange, String operation) throws Exception {
Iterable<PushResult> result = null;
try {
if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
throw new IllegalArgumentException("Remote path must be specified to execute " + operation);
- }
+ }
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
- }
+ }
if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call();
} else {
result = git.push().setRemote(endpoint.getRemotePath()).call();
}
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
exchange.getOut().setBody(result);
}
-
+
protected void doPull(Exchange exchange, String operation) throws Exception {
PullResult result = null;
try {
if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
throw new IllegalArgumentException("Remote path must be specified to execute " + operation);
- }
+ }
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
- }
+ }
if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
result = git.pull().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call();
} else {
result = git.pull().setRemote(endpoint.getRemotePath()).call();
}
- } catch (Exception e) {
- LOG.error("There was an error in Git " + operation + " operation");
- throw e;
- }
+ } catch (Exception e) {
+ LOG.error("There was an error in Git " + operation + " operation");
+ throw e;
+ }
exchange.getOut().setBody(result);
}
-
+
protected void doCreateTag(Exchange exchange, String operation) throws Exception {
if (ObjectHelper.isEmpty(endpoint.getTagName())) {
throw new IllegalArgumentException("Tag Name must be specified to execute " + operation);
- }
+ }
try {
git.tag().setName(endpoint.getTagName()).call();
} catch (Exception e) {
@@ -333,11 +353,11 @@ public class GitProducer extends DefaultProducer{
throw e;
}
}
-
+
protected void doDeleteTag(Exchange exchange, String operation) throws Exception {
if (ObjectHelper.isEmpty(endpoint.getTagName())) {
throw new IllegalArgumentException("Tag Name must be specified to execute " + operation);
- }
+ }
try {
git.tagDelete().setTags(endpoint.getTagName()).call();
} catch (Exception e) {
@@ -345,19 +365,18 @@ public class GitProducer extends DefaultProducer{
throw e;
}
}
-
- private Repository getLocalRepository() throws IOException{
+
+ private Repository getLocalRepository() throws IOException {
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();
- } catch (IOException e) {
- LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
- throw e;
- }
- return repo;
+ try {
+ 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;
+ }
+ return repo;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
index 2bde385..a36c746 100644
--- a/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
@@ -37,7 +37,7 @@ public class GitConsumerTest extends GitTestSupport {
@Test
public void commitConsumerTest() throws Exception {
- Repository repository = getTestRepository();
+ Repository repository = getTestRepository();
MockEndpoint added = getMockEndpoint("mock:result-commit");
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/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 212be8f..f45d503 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
@@ -36,14 +36,14 @@ public class GitProducerTest extends GitTestSupport {
@Test
public void cloneTest() throws Exception {
- template.sendBody("direct:clone","");
+ template.sendBody("direct:clone", "");
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
}
@Test
public void initTest() throws Exception {
- template.sendBody("direct:init","");
+ template.sendBody("direct:init", "");
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
}
@@ -51,8 +51,8 @@ public class GitProducerTest extends GitTestSupport {
@Test
public void addTest() throws Exception {
- Repository repository = getTestRepository();
-
+ Repository repository = getTestRepository();
+
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
@@ -124,7 +124,7 @@ public class GitProducerTest extends GitTestSupport {
@Test
public void commitTest() throws Exception {
- Repository repository = getTestRepository();
+ Repository repository = getTestRepository();
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
@@ -161,7 +161,7 @@ public class GitProducerTest extends GitTestSupport {
@Test
public void commitBranchTest() throws Exception {
- Repository repository = getTestRepository();
+ Repository repository = getTestRepository();
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
@@ -206,8 +206,12 @@ public class GitProducerTest extends GitTestSupport {
logs = git.log().call();
count = 0;
for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), commitMessageBranch);
- if (count == 1) assertEquals(rev.getShortMessage(), commitMessage);
+ if (count == 0) {
+ assertEquals(rev.getShortMessage(), commitMessageBranch);
+ }
+ if (count == 1) {
+ assertEquals(rev.getShortMessage(), commitMessage);
+ }
count++;
}
assertEquals(count, 2);
@@ -306,8 +310,12 @@ public class GitProducerTest extends GitTestSupport {
logs = git.log().call();
count = 0;
for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), commitMessageAll);
- if (count == 1) assertEquals(rev.getShortMessage(), commitMessage);
+ if (count == 0) {
+ assertEquals(rev.getShortMessage(), commitMessageAll);
+ }
+ if (count == 1) {
+ assertEquals(rev.getShortMessage(), commitMessage);
+ }
count++;
}
assertEquals(count, 2);
@@ -372,8 +380,12 @@ public class GitProducerTest extends GitTestSupport {
logs = git.log().call();
count = 0;
for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), commitMessageAll);
- if (count == 1) assertEquals(rev.getShortMessage(), commitMessage);
+ if (count == 0) {
+ assertEquals(rev.getShortMessage(), commitMessageAll);
+ }
+ if (count == 1) {
+ assertEquals(rev.getShortMessage(), commitMessage);
+ }
count++;
}
assertEquals(count, 2);
@@ -667,8 +679,12 @@ public class GitProducerTest extends GitTestSupport {
revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
int count = 0;
for (RevCommit rev : revCommits) {
- if (count == 0) assertEquals(rev.getShortMessage(), commitMessageAll);
- if (count == 1) assertEquals(rev.getShortMessage(), commitMessage);
+ if (count == 0) {
+ assertEquals(rev.getShortMessage(), commitMessageAll);
+ }
+ if (count == 1) {
+ assertEquals(rev.getShortMessage(), commitMessage);
+ }
count++;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46535261/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 36c33bd..abdd7c9 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
@@ -75,7 +75,7 @@ public class GitRemoteProducerTest extends GitTestSupport {
from("direct:commit")
.to("git://" + gitLocalRepo + "?operation=commit");
from("direct:push")
- .to("git://" + gitLocalRepo + "?operation=push&remotePath=remoteURL&username=xxx&password=xxx" );
+ .to("git://" + gitLocalRepo + "?operation=push&remotePath=remoteURL&username=xxx&password=xxx");
}
};
}