summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2009-10-31 19:39:18 -0700
committerShawn O. Pearce <spearce@spearce.org>2009-11-02 17:55:55 -0800
commit7e8dc53881a4f7babbab9cd9979a49edb7ad03f1 (patch)
tree454ee570ae7863ac3f48ecf7cc3aa2052dc3806f /org.eclipse.jgit.pgm
parent27a497f83e683d384d379ee75570f8c25a7aa624 (diff)
downloadjgit-7e8dc53881a4f7babbab9cd9979a49edb7ad03f1.tar.gz
jgit-7e8dc53881a4f7babbab9cd9979a49edb7ad03f1.zip
Prompt for passwords from the console in jgit command line tools
If we are on a Java 6 JVM we should have the Console class available, unless the user has redirected /dev/null to stdin. When there is a console present we would prefer to use that for command line prompts as that is what the user expects from a command line tool. Change-Id: Ibaf87bb5540371d94d96d1b7e94ca002f752e5bd Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/pom.xml16
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java46
2 files changed, 60 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml
index 8f2312b85e..e06dbc2d02 100644
--- a/org.eclipse.jgit.pgm/pom.xml
+++ b/org.eclipse.jgit.pgm/pom.xml
@@ -77,6 +77,22 @@
</dependency>
</dependencies>
+ <profiles>
+ <profile>
+ <id>java6</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jgit</groupId>
+ <artifactId>org.eclipse.jgit.console</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
<build>
<sourceDirectory>src/</sourceDirectory>
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 3579b65e31..18cf8be467 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
@@ -45,6 +45,7 @@
package org.eclipse.jgit.pgm;
import java.io.File;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -88,8 +89,10 @@ public class Main {
public static void main(final String[] argv) {
final Main me = new Main();
try {
- AwtAuthenticator.install();
- AwtSshSessionFactory.install();
+ if (!installConsole()) {
+ AwtAuthenticator.install();
+ AwtSshSessionFactory.install();
+ }
configureHttpProxy();
me.execute(argv);
} catch (Die err) {
@@ -184,6 +187,45 @@ public class Main {
return null;
}
+ private static boolean installConsole() {
+ try {
+ install("org.eclipse.jgit.console.ConsoleAuthenticator");
+ install("org.eclipse.jgit.console.ConsoleSshSessionFactory");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ } catch (NoClassDefFoundError e) {
+ return false;
+ } catch (UnsupportedClassVersionError e) {
+ return false;
+
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Cannot setup console", e);
+ } catch (SecurityException e) {
+ throw new RuntimeException("Cannot setup console", e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Cannot setup console", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Cannot setup console", e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Cannot setup console", e);
+ }
+ }
+
+ private static void install(final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException, ClassNotFoundException {
+ try {
+ Class.forName(name).getMethod("install").invoke(null);
+ } 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>