From ce99b48384bd7a7ee42942653b5659787d3f1d48 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 10 Nov 2010 14:15:50 -0800 Subject: [PATCH] Define a default CredentialsProvider This permits applications to set their preferred credentials UI implementation once, rather than needing to define it on every single Transport instance they open. Change-Id: I010550de1a6becab27f7aa5a9901df5a1c7e74bd Signed-off-by: Shawn O. Pearce --- .../jgit/transport/CredentialsProvider.java | 17 +++++++++++++++++ .../org/eclipse/jgit/transport/Transport.java | 1 + 2 files changed, 18 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/CredentialsProvider.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/CredentialsProvider.java index d2130ad30..ca83c6904 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/CredentialsProvider.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/CredentialsProvider.java @@ -63,6 +63,23 @@ import org.eclipse.jgit.errors.UnsupportedCredentialItem; * @see UsernamePasswordCredentialsProvider */ public abstract class CredentialsProvider { + private static volatile CredentialsProvider defaultProvider; + + /** @return the default credentials provider, or null. */ + public static CredentialsProvider getDefault() { + return defaultProvider; + } + + /** + * Set the default credentials provider. + * + * @param p + * the new default provider, may be null to select no default. + */ + public static void setDefault(CredentialsProvider p) { + defaultProvider = p; + } + /** * Check if the provider can supply the necessary {@link CredentialItem}s. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 5895f7f37..69eea0c22 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -577,6 +577,7 @@ public abstract class Transport { this.local = local; this.uri = uri; this.checkFetchedObjects = tc.isFsckObjects(); + this.credentialsProvider = CredentialsProvider.getDefault(); } /**