summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-04-22 12:53:35 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2015-04-22 12:53:35 +0200
commitff798f13da5f6e57bb8480c57e8db486c9007174 (patch)
treec9a855878800e58aa4183b897fb766867348d47c /org.eclipse.jgit.pgm
parent12e38d72758b486f19ccfa6c830d1ef95dfb1d11 (diff)
downloadjgit-ff798f13da5f6e57bb8480c57e8db486c9007174.tar.gz
jgit-ff798f13da5f6e57bb8480c57e8db486c9007174.zip
Restore AwtCredentialsProvider to enable debugging pgm in Eclipse
In 6c1f7393882baf8464859136a70199ea96fcae0f the AWT based credentials provider was dropped because we don't support Java 5 any longer so we can always use the ConsoleCredentialsProvider which requires Java 6. This broke debugging org.eclipse.jgit.pgm since Eclipse doesn't support using a system console authenticator [1]. [1] see https://bugs.eclipse.org/bugs/show_bug.cgi?id=148831 Change-Id: Iba71001a7762e73d6579ba9dfa5a08ddaba777ea
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java50
1 files changed, 46 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
index 38c3a2fcd4..7151de794d 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
@@ -47,14 +47,15 @@ package org.eclipse.jgit.pgm;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.jgit.console.ConsoleAuthenticator;
-import org.eclipse.jgit.console.ConsoleCredentialsProvider;
+import org.eclipse.jgit.awtui.AwtAuthenticator;
+import org.eclipse.jgit.awtui.AwtCredentialsProvider;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
@@ -115,8 +116,10 @@ public class Main {
*/
protected void run(final String[] argv) {
try {
- ConsoleAuthenticator.install();
- ConsoleCredentialsProvider.install();
+ if (!installConsole()) {
+ AwtAuthenticator.install();
+ AwtCredentialsProvider.install();
+ }
configureHttpProxy();
execute(argv);
} catch (Die err) {
@@ -246,6 +249,45 @@ public class Main {
return rb.build();
}
+ private static boolean installConsole() {
+ try {
+ install("org.eclipse.jgit.console.ConsoleAuthenticator"); //$NON-NLS-1$
+ install("org.eclipse.jgit.console.ConsoleCredentialsProvider"); //$NON-NLS-1$
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ } catch (NoClassDefFoundError e) {
+ return false;
+ } catch (UnsupportedClassVersionError e) {
+ return false;
+
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException(CLIText.get().cannotSetupConsole, e);
+ } catch (SecurityException e) {
+ throw new RuntimeException(CLIText.get().cannotSetupConsole, e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(CLIText.get().cannotSetupConsole, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(CLIText.get().cannotSetupConsole, e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(CLIText.get().cannotSetupConsole, e);
+ }
+ }
+
+ private static void install(final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException, ClassNotFoundException {
+ try {
+ Class.forName(name).getMethod("install").invoke(null); //$NON-NLS-1$
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof RuntimeException)
+ throw (RuntimeException) e.getCause();
+ if (e.getCause() instanceof Error)
+ throw (Error) e.getCause();
+ throw e;
+ }
+ }
+
/**
* Configure the JRE's standard HTTP based on <code>http_proxy</code>.
* <p>