Author: adietish
Date: 2011-10-13 11:51:01 -0400 (Thu, 13 Oct 2011)
New Revision: 35625
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/SshPrivateKeysPreferences.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
Log:
[JBIDE-9805] moved SshPrivateKeysPreferences to org.jboss.tools.common.ui (was:
org.jboss.tools.deltacloud.ui)
Modified: trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-13
15:37:22 UTC (rev 35624)
+++ trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-10-13
15:51:01 UTC (rev 35625)
@@ -23,6 +23,7 @@
org.jboss.tools.common.ui.databinding,
org.jboss.tools.common.ui.preferences,
org.jboss.tools.common.ui.preferencevalue,
+ org.jboss.tools.common.ui.ssh,
org.jboss.tools.common.ui.widget.editor,
org.jboss.tools.common.ui.widget.field,
org.jboss.tools.common.ui.wizard
Copied:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/SshPrivateKeysPreferences.java
(from rev 35563,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/SshPrivateKeysPreferences.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/SshPrivateKeysPreferences.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/SshPrivateKeysPreferences.java 2011-10-13
15:51:01 UTC (rev 35625)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.ssh;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
+import org.jboss.tools.common.ui.preferencevalue.StringsPreferenceValue;
+
+/**
+ * @author André Dietisheim
+ */
+public class SshPrivateKeysPreferences {
+
+ private static final String JSCH_PLUGIN_ID = "org.eclipse.jsch.core";
+ /**
+ * Preference keys defined by org.eclipse.jsch.
+ *
+ * these keys are replicates from org.eclipse.jsch.internal.core.IConstants
+ */
+ private static final String PRIVATEKEY = "PRIVATEKEY";
+ private static final String SSH2HOME = "SSH2HOME";
+
+ private static final String SSH_USERHOME = ".ssh";
+ private static final String SSH_USERHOME_WIN32 = "ssh";
+
+ private static StringsPreferenceValue sshPrivateKeyPreference =
+ new StringsPreferenceValue(',', PRIVATEKEY, JSCH_PLUGIN_ID);
+ private static StringPreferenceValue sshHome = new StringPreferenceValue(SSH2HOME,
JSCH_PLUGIN_ID);
+
+ /**
+ * Adds the given keyName to the ssh-preferences
+ *
+ * @param keyName
+ * the name of the key to add
+ */
+ public static void add(String keyName) {
+ sshPrivateKeyPreference.add(keyName);
+ }
+
+ public static String[] getKeys() {
+ return sshPrivateKeyPreference.get();
+ }
+
+ /**
+ * Removes the given keyName from the ssh-preferences
+ *
+ * @param keyName
+ * the name of the key to remove
+ */
+ public static void remove(String keyName) {
+ sshPrivateKeyPreference.remove(keyName);
+ }
+
+ /**
+ * Returns the path to the folder that ssh keys get stored to. It either
+ * gets the preferences value from org.eclipse.jsch or uses a ssh folder in
+ * the user home. This code was built according to what
+ * org.eclipse.jsch.internal.core.PreferenceInitializer is doing.
+ *
+ * @return the directory to store or load the ssh keys from
+ * @throws DeltaCloudException
+ * if the directory could not be determined
+ */
+ public static String getSshKeyDirectory() throws FileNotFoundException {
+ String sshHomePath = sshHome.get();
+ if (isEmpty(sshHomePath)) {
+ sshHomePath = getSshSystemHome();
+ }
+
+ if (isEmpty(sshHomePath)) {
+ throw new FileNotFoundException("Could not determine path to ssh keys
directory.");
+ }
+ return sshHomePath;
+ }
+
+ private static String getSshSystemHome() {
+ String userHomePath = System.getProperty("user.home");
+ StringBuilder builder = new StringBuilder(userHomePath);
+ builder.append(File.separatorChar);
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ builder.append(SSH_USERHOME_WIN32); //$NON-NLS-1$
+ } else {
+ builder.append(SSH_USERHOME);
+ }
+ return builder.toString();
+ }
+
+ private static boolean isEmpty(String value) {
+ return value == null
+ || value.length() == 0;
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/ssh/SshPrivateKeysPreferences.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain