]> source.dussan.org Git - jgit.git/commitdiff
Define a default CredentialsProvider 79/1879/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 10 Nov 2010 22:15:50 +0000 (14:15 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 10 Nov 2010 22:58:45 +0000 (14:58 -0800)
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 <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/transport/CredentialsProvider.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java

index d2130ad30f1a5f9f074bc10b3894db62a126ad6f..ca83c690427dad550a5d0fd4882e7866dfa640af 100644 (file)
@@ -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.
         *
index 5895f7f37fb49f2b74c12ff2db0bbef29750897f..69eea0c223246ed9247a18abf47ff3cf4f16f25c 100644 (file)
@@ -577,6 +577,7 @@ public abstract class Transport {
                this.local = local;
                this.uri = uri;
                this.checkFetchedObjects = tc.isFsckObjects();
+               this.credentialsProvider = CredentialsProvider.getDefault();
        }
 
        /**