[jbosstools-commits] JBoss Tools SVN: r43926 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Sep 21 09:16:58 EDT 2012


Author: adietish
Date: 2012-09-21 09:16:57 -0400 (Fri, 21 Sep 2012)
New Revision: 43926

Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
Log:
[JBIDE-10118] adding key with name only, if it's stored in ssh2 home, full path otherwise

Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java	2012-09-21 13:14:46 UTC (rev 43925)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SSHUtils.java	2012-09-21 13:16:57 UTC (rev 43926)
@@ -80,22 +80,37 @@
 	public static void addToPrivateKeysPreferences(File privateKey) {
 		Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
 		String privateKeys = preferences.getString(IConstants.KEY_PRIVATEKEY);
+		String privateKeyPath = getKeyPath(privateKey);
+		
 		if (privateKeys != null
 				&& privateKeys.trim().length() > 0) {
-			privateKeys = privateKeys + "," + privateKey.getAbsolutePath();
+			privateKeys = privateKeys + "," + privateKeyPath;
 		} else {
-			privateKeys = privateKey.getAbsolutePath();
+			privateKeys = privateKeyPath;
 		}
 		preferences.setValue(IConstants.KEY_PRIVATEKEY, privateKeys);
 		JSchCorePlugin.getPlugin().setNeedToLoadKeys(true);
 		JSchCorePlugin.getPlugin().savePluginPreferences();
 	}
 
+	private static String getKeyPath(File privateKey) {
+		String ssh2Home = getSSH2Home();
+		if (ssh2Home == null
+				|| ssh2Home.isEmpty()) {
+			return privateKey.getAbsolutePath();
+		}
+		
+		if (!privateKey.getAbsolutePath().startsWith(ssh2Home)) {
+			return privateKey.getAbsolutePath(); 
+		}
+		
+		return privateKey.getName();
+	}
+
 	public static int openPreferencesPage(Shell shell) {
 		PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(
 				shell, SSH_PREFERENCE_PAGE_ID, null, null);
 		return dialog.open();
-
 	}
 
 	/**



More information about the jbosstools-commits mailing list