diff options
author | Emmanuel Hugonnet <ehugonne@redhat.com> | 2020-01-13 15:45:55 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2020-01-25 15:58:47 +0100 |
commit | 54b1c7cc6a2ba6031b97d8a5c455d93ffd4ce5f5 (patch) | |
tree | 1027d69566f972c2aa68bbc8185ca3a45103be3a | |
parent | 8fa3594565d43c81d5e1a34660b29a861b81d43a (diff) | |
download | jgit-54b1c7cc6a2ba6031b97d8a5c455d93ffd4ce5f5.tar.gz jgit-54b1c7cc6a2ba6031b97d8a5c455d93ffd4ce5f5.zip |
Use ServiceLoader to define the default SSH session factory.
Use ServiceLoader and define
org.eclipse.jgit.transport.DefaultSshSessionFactory in
META-INF/services/org.eclipse.jgit.transport.SshSessionFactory so that
the legacy behavior is still the same.
Bug: 553625
Change-Id: Id1a65506140d921ed76d83699e3817f0d2ca08ed
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
3 files changed, 15 insertions, 2 deletions
diff --git a/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory b/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory new file mode 100644 index 0000000000..1f8828457b --- /dev/null +++ b/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory @@ -0,0 +1 @@ +org.eclipse.jgit.transport.DefaultSshSessionFactory diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java index 063fb6b8bd..afa0a11c24 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java @@ -24,8 +24,10 @@ import com.jcraft.jsch.Session; * <p> * If user interactivity is required by SSH (e.g. to obtain a password), the * connection will immediately fail. + * + * @since 5.7 */ -class DefaultSshSessionFactory extends JschConfigSessionFactory { +public class DefaultSshSessionFactory extends JschConfigSessionFactory { /** {@inheritDoc} */ @Override protected void configure(OpenSshConfig.Host hc, Session session) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java index 906c4ed2d8..ad04d424d7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java @@ -13,6 +13,8 @@ package org.eclipse.jgit.transport; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Iterator; +import java.util.ServiceLoader; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -31,8 +33,16 @@ import org.eclipse.jgit.util.SystemReader; * SshSessionFactory for the duration of the period they are using the Session. */ public abstract class SshSessionFactory { - private static SshSessionFactory INSTANCE = new DefaultSshSessionFactory(); + private static SshSessionFactory INSTANCE = loadSshSessionFactory(); + private static SshSessionFactory loadSshSessionFactory() { + ServiceLoader<SshSessionFactory> loader = ServiceLoader.load(SshSessionFactory.class); + Iterator<SshSessionFactory> iter = loader.iterator(); + if(iter.hasNext()) { + return iter.next(); + } + return null; + } /** * Get the currently configured JVM-wide factory. * <p> |