From f48bd5faa01c191f355fd5ebdc2e98f0579b591f Mon Sep 17 00:00:00 2001 From: zeapo Date: Wed, 17 Dec 2014 22:55:45 +0100 Subject: git tasks refactoring (clone working) --- .../com/zeapo/pwdstore/git/CloneOperation.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java (limited to 'app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java new file mode 100644 index 00000000..0445b114 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -0,0 +1,54 @@ +package com.zeapo.pwdstore.git; + +import android.app.Activity; + +import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; + +import java.io.File; + +public class CloneOperation extends GitOperation { + private static final String TAG = "CLONEOPT"; + + /** + * Creates a new clone operation + * @param fileDir the git working tree directory + * @param callingActivity the calling activity + */ + public CloneOperation(File fileDir, Activity callingActivity) { + super(fileDir, callingActivity); + } + + /** + * Sets the command using the repository uri + * @param uri the uri of the repository + * @return the current object + */ + public CloneOperation setCommand(String uri) { + this.command = Git.cloneRepository(). + setCredentialsProvider(provider). + setCloneAllBranches(true). + setDirectory(repository.getWorkTree()). + setURI(uri); + return this; + } + + /** + * sets the authentication for user/pwd scheme + * @param username the username + * @param password the password + * @return the current object + */ + @Override + public CloneOperation setAuthentication(String username, String password) { + super.setAuthentication(username, password); + return this; + } + + @Override + public CloneOperation setAuthentication(File sshKey, String username, String passphrase) { + super.setAuthentication(sshKey, username, passphrase); + return this; + } +} -- cgit v1.2.3 From d29f308848d4ad5ae277e3d8c032fab0a0ee7401 Mon Sep 17 00:00:00 2001 From: zeapo Date: Wed, 17 Dec 2014 23:32:35 +0100 Subject: add documentation --- app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java index 0445b114..3c5c20c6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -46,6 +46,13 @@ public class CloneOperation extends GitOperation { return this; } + /** + * sets the authentication for the ssh-key scheme + * @param sshKey the ssh-key file + * @param username the username + * @param passphrase the passphrase + * @return the current object + */ @Override public CloneOperation setAuthentication(File sshKey, String username, String passphrase) { super.setAuthentication(sshKey, username, passphrase); -- cgit v1.2.3 From 3ca806d699182f3233c2425bd407988540083758 Mon Sep 17 00:00:00 2001 From: zeapo Date: Thu, 18 Dec 2014 21:52:38 +0100 Subject: set credential after they've been intialized --- .../main/java/com/zeapo/pwdstore/git/CloneOperation.java | 10 ++++++++-- app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java | 4 +--- .../main/java/com/zeapo/pwdstore/git/PullOperation.java | 14 ++++++++++---- .../main/java/com/zeapo/pwdstore/git/PushOperation.java | 12 ++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java index 3c5c20c6..dc94ce3b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -4,7 +4,6 @@ import android.app.Activity; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import java.io.File; @@ -27,7 +26,6 @@ public class CloneOperation extends GitOperation { */ public CloneOperation setCommand(String uri) { this.command = Git.cloneRepository(). - setCredentialsProvider(provider). setCloneAllBranches(true). setDirectory(repository.getWorkTree()). setURI(uri); @@ -58,4 +56,12 @@ public class CloneOperation extends GitOperation { super.setAuthentication(sshKey, username, passphrase); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((CloneCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, CloneCommand.class).execute(this.command); + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java index 65436969..60112c90 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java @@ -78,9 +78,7 @@ public abstract class GitOperation { * * @throws Exception */ - public void execute() throws Exception { - new GitAsyncTask(callingActivity, true, false, GitCommand.class).execute(command); - } + public abstract void execute() throws Exception; /** * Executes the GitCommand in an async task after creating the authentication diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java index 0d43216d..2d499b4e 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -2,9 +2,8 @@ package com.zeapo.pwdstore.git; import android.app.Activity; -import com.zeapo.pwdstore.utils.PasswordRepository; - import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PullCommand; import java.io.File; @@ -29,8 +28,15 @@ public class PullOperation extends GitOperation { this.command = new Git(repository) .pull() .setRebase(true) - .setRemote("origin") - .setCredentialsProvider(provider); + .setRemote("origin"); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((PullCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, PullCommand.class).execute(this.command); + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java index fa3e4dd9..fd4fb229 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java @@ -3,6 +3,7 @@ package com.zeapo.pwdstore.git; import android.app.Activity; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PushCommand; import java.io.File; @@ -27,8 +28,15 @@ public class PushOperation extends GitOperation { this.command = new Git(repository) .push() .setPushAll() - .setRemote("origin") - .setCredentialsProvider(provider); + .setRemote("origin"); return this; } + + @Override + public void execute() throws Exception { + if (this.provider != null) { + ((PushCommand) this.command).setCredentialsProvider(this.provider); + } + new GitAsyncTask(callingActivity, true, false, PushCommand.class).execute(this.command); + } } -- cgit v1.2.3