Author: adietish
Date: 2011-11-07 10:05:04 -0500 (Mon, 07 Nov 2011)
New Revision: 36192
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
Log:
[JBIDE-10049] migrated fix from m4 to trunk (beta1)
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2011-11-07
15:05:04 UTC (rev 36192)
@@ -4,12 +4,13 @@
Bundle-SymbolicName: org.jboss.tools.openshift.express.ui;singleton:=true
Bundle-Version: 2.3.0.qualifier
Bundle-Activator: org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator
-Require-Bundle:
org.jboss.tools.openshift.express.client;bundle-version="[2.3.0,3.0.0)",
- org.jboss.tools.openshift.egit.core;bundle-version="[2.3.0,3.0.0)",
+Require-Bundle:
org.jboss.tools.openshift.express.client;bundle-version="2.3.0",
+ org.jboss.ide.eclipse.as.egit.core;bundle-version="2.3.0",
org.eclipse.egit.ui;bundle-version="[1.0.0,2.0.0)",
org.eclipse.egit.core;bundle-version="[1.1.0,2.0.0)",
org.eclipse.jgit;bundle-version="[1.1.0,2.1.0)",
com.jcraft.jsch;bundle-version="0.1.44",
+ org.eclipse.jsch.core;bundle-version="[1.1.300,2.0.0)",
org.jboss.ide.eclipse.as.core;bundle-version="2.3.0",
org.eclipse.m2e.core;bundle-version="1.0.100",
org.eclipse.ui,
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-11-07
15:05:04 UTC (rev 36192)
@@ -20,7 +20,7 @@
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
import
org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.ide.eclipse.as.egit.core.EGitUtils;
public class ExpressPublishMethod implements IJBossServerPublishMethod {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftWizardPage.java 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenShiftWizardPage.java 2011-11-07
15:05:04 UTC (rev 36192)
@@ -20,7 +20,6 @@
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
@@ -33,10 +32,6 @@
*/
public abstract class AbstractOpenShiftWizardPage extends WizardPage {
- protected enum WizardProgressDirection {
- BACKWARD, FORWARD
- }
-
private DataBindingContext dbc;
protected AbstractOpenShiftWizardPage(String title, String description, String pageName,
IWizard wizard) {
@@ -85,46 +80,29 @@
@Override
public void handlePageChanging(PageChangingEvent event) {
if (event.getTargetPage() == AbstractOpenShiftWizardPage.this) {
- onPageWillGetActivated(getActivationDirection(event), event, dbc);
- } else if (event.getCurrentPage() == AbstractOpenShiftWizardPage.this){
- onPageWillGetDeactivated(getDeactivationDirection(event), event, dbc);
+ onPageWillGetActivated(event, dbc);
+ } else {
+ onPageWillGetDeactivated(event, dbc);
}
}
-
});
}
}
- private WizardProgressDirection getActivationDirection(PageChangingEvent event) {
- IWizardPage previousPage = getPreviousPage();
- if (previousPage == null
- || previousPage.equals(event.getCurrentPage())) {
- return WizardProgressDirection.BACKWARD;
- } else {
- return WizardProgressDirection.FORWARD;
- }
+ protected DataBindingContext getDatabindingContext() {
+ return dbc;
}
- private WizardProgressDirection getDeactivationDirection(PageChangingEvent event) {
- IWizardPage previousPage = getPreviousPage();
- if (previousPage == null
- || previousPage.equals(event.getTargetPage())) {
- return WizardProgressDirection.BACKWARD;
- } else {
- return WizardProgressDirection.FORWARD;
- }
- }
-
protected void onPageActivated(DataBindingContext dbc) {
}
protected void onPageDeactivated(DataBindingContext dbc) {
}
- protected void onPageWillGetActivated(WizardProgressDirection direction,
PageChangingEvent event, DataBindingContext dbc) {
+ protected void onPageWillGetActivated(PageChangingEvent event, DataBindingContext dbc)
{
}
- protected void onPageWillGetDeactivated(WizardProgressDirection direction,
PageChangingEvent event, DataBindingContext dbc) {
+ protected void onPageWillGetDeactivated(PageChangingEvent event, DataBindingContext dbc)
{
}
protected abstract void doCreateControls(Composite parent, DataBindingContext dbc);
@@ -132,4 +110,5 @@
protected DataBindingContext getDataBindingContext() {
return dbc;
}
+
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2011-11-07
15:05:04 UTC (rev 36192)
@@ -146,9 +146,8 @@
}
@Override
- protected void onPageWillGetDeactivated(WizardProgressDirection direction,
PageChangingEvent event, DataBindingContext dbc) {
- if (!model.areCredentialsValidated()
- && direction == WizardProgressDirection.FORWARD) {
+ protected void onPageWillGetDeactivated(PageChangingEvent event, DataBindingContext dbc)
{
+ if (!model.areCredentialsValidated()) {
try {
final ArrayBlockingQueue<IStatus> queue = new
ArrayBlockingQueue<IStatus>(1);
WizardUtils.runInWizard(
@@ -160,7 +159,7 @@
queue.offer(status);
return Status.OK_STATUS;
}
- }, getContainer(), getDataBindingContext());
+ }, getContainer(), getDatabindingContext());
queue.poll(10, TimeUnit.SECONDS);
event.doit = model.areCredentialsValid();
} catch (Exception ex) {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2011-11-07
15:05:04 UTC (rev 36192)
@@ -26,6 +26,7 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizard;
@@ -93,6 +94,16 @@
"You have to select a ssh public key")),
new UpdateValueStrategy().setAfterGetValidator(new SSHKeyValidator()));
ControlDecorationSupport.create(sshKeyTextBinding, SWT.TOP | SWT.LEFT);
+ try {
+ model.initSshKey();
+ } catch (OpenShiftException ex) {
+ IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could check your ssh keys", ex);
+ OpenShiftUIActivator.log(status);
+ ErrorDialog.openError(getShell(),
+ "Error checking your ssh keys",
+ "Could not check your ssh keys", status);
+ }
Button browseButton = new Button(container, SWT.PUSH);
browseButton.setText("Browse");
@@ -113,7 +124,6 @@
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.CENTER).applyTo(sshPrefsLink);
sshPrefsLink.addSelectionListener(onSshPrefs());
-
}
private SelectionListener onNew() {
@@ -122,26 +132,35 @@
@Override
public void widgetSelected(SelectionEvent e) {
- InputDialog dialog = new PassphraseDialog(getShell());
- if (Dialog.OK == dialog.open()) {
- try {
- String passPhrase = dialog.getValue();
- model.createSShKeyPair(passPhrase);
- } catch (FileNotFoundException ex) {
- IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not read the ssh key folder", ex);
- OpenShiftUIActivator.log(status);
- ErrorDialog.openError(getShell(),
- "Error creating a new ssh key pair",
- "Could not create a new ssh key pair", status);
- } catch (OpenShiftException ex) {
- IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not create an ssh key pair", ex);
- OpenShiftUIActivator.log(status);
- ErrorDialog.openError(getShell(),
- "Error creating a new ssh key pair",
- "Could not create a new ssh key pair", status);
+ try {
+ if (model.libraPublicKeyExists()) {
+ MessageDialog.openInformation(getShell(),
+ "Libra Key already present",
+ "You already have a key at \"" + model.getLibraPublicKey() +
"\". Please move it or use it.");
+ return;
+ }
+
+ InputDialog dialog = new PassphraseDialog(getShell());
+ if (Dialog.OK == dialog.open()) {
+ try {
+ String passPhrase = dialog.getValue();
+ model.createLibraKeyPair(passPhrase);
+ } catch (FileNotFoundException ex) {
+ IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not read the ssh key folder", ex);
+ OpenShiftUIActivator.log(status);
+ ErrorDialog.openError(getShell(),
+ "Error creating a new ssh key pair",
+ "Could not create a new ssh key pair", status);
+ }
}
+ } catch (OpenShiftException ex) {
+ IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not create an ssh key pair", ex);
+ OpenShiftUIActivator.log(status);
+ ErrorDialog.openError(getShell(),
+ "Error creating a new ssh key pair",
+ "Could not create a new ssh key pair", status);
}
}
};
@@ -177,7 +196,7 @@
SshPrivateKeysPreferences.openPreferencesPage(getShell());
// refresh warning about key
// (since user may have changed SSH2 prefs)
- getDataBindingContext().updateTargets();
+ getDatabindingContext().updateTargets();
}
};
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2011-11-07
14:57:00 UTC (rev 36191)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2011-11-07
15:05:04 UTC (rev 36192)
@@ -14,8 +14,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jsch.internal.core.IConstants;
+import org.eclipse.jsch.internal.core.JSchCorePlugin;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
-import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
import org.jboss.tools.openshift.express.client.IDomain;
import org.jboss.tools.openshift.express.client.ISSHPublicKey;
import org.jboss.tools.openshift.express.client.IUser;
@@ -29,7 +31,7 @@
*/
public class NewDomainWizardPageModel extends ObservableUIPojo {
- private static final String OPENSHIFT_KEY_PREFIX = "openshift_id_rsa_";
+ public static final String LIBRA_KEY = "libra_id_rsa";
private static final String PUBLIC_KEY_SUFFIX = ".pub";
public static final String PROPERTY_NAMESPACE = "namespace";
@@ -46,6 +48,40 @@
this.user = user;
}
+ public void initSshKey() throws OpenShiftException {
+ if (!libraPublicKeyExists()) {
+ return;
+ }
+ File libraPublicKey = getLibraPublicKey();
+ setSshKey(libraPublicKey.getAbsolutePath());
+ }
+
+ /**
+ * Returns the file of the libra public key. It is not checking if the file exists.
+ *
+ * @return the libra public key
+ * @throws OpenShiftException
+ */
+ public File getLibraPublicKey() throws OpenShiftException {
+ File libraPrivateKey = getLibraPrivateKey();
+ return new File(libraPrivateKey.getParent(),
getPublicKeyPath(libraPrivateKey.getName()));
+ }
+
+ private String getPublicKeyPath(String privateKeyPath) {
+ return privateKeyPath + PUBLIC_KEY_SUFFIX;
+ }
+
+ public File getLibraPrivateKey() throws OpenShiftException {
+ Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
+ String ssh2Home = preferences.getString(IConstants.KEY_SSH2HOME);
+ if (ssh2Home == null
+ || ssh2Home.trim().length() == 0) {
+ throw new OpenShiftException("Could not determine your ssh2 home
directory");
+ }
+
+ return new File(ssh2Home, LIBRA_KEY);
+ }
+
public String getNamespace() {
return this.namespace;
}
@@ -58,34 +94,37 @@
public String getSshKey() {
return sshKey;
}
+
+ public boolean libraPublicKeyExists() throws OpenShiftException {
+ return FileUtils.canRead(getLibraPublicKey());
+ }
- public void createSShKeyPair(String passPhrase) throws FileNotFoundException,
OpenShiftException {
- String sshKeysDirectory = SshPrivateKeysPreferences.getSshKeyDirectory();
- SSHKeyPair keyPair = createSshKeyPair(passPhrase, sshKeysDirectory);
- SshPrivateKeysPreferences.add(keyPair.getPrivateKeyPath());
+ public void createLibraKeyPair(String passPhrase) throws FileNotFoundException,
OpenShiftException {
+ File libraPublicKey = getLibraPublicKey();
+ if (libraPublicKey.canRead()) {
+ // key already exists
+ return;
+ }
+ File libraPrivateKey = getLibraPrivateKey();
+ SSHKeyPair keyPair = SSHKeyPair.create(passPhrase, libraPrivateKey.getAbsolutePath(),
libraPublicKey.getAbsolutePath());
+ addToPrivateKeysPreferences(keyPair);
setSshKey(keyPair.getPublicKeyPath());
}
- private SSHKeyPair createSshKeyPair(String passPhrase, String sshKeysDirectory) throws
OpenShiftException {
- String privateKeyPath = getKeyPairFileName(sshKeysDirectory);
- String publicKeyPath = getPublicKeyPath(privateKeyPath);
- return SSHKeyPair.create(passPhrase, privateKeyPath, publicKeyPath);
- }
-
- private String getKeyPairFileName(String sshKeysDirectory) {
- int i = 0;
- File privateKey = null;
- while (FileUtils.canRead(privateKey = new File(sshKeysDirectory, OPENSHIFT_KEY_PREFIX +
i))
- || FileUtils.canRead(new File(sshKeysDirectory,
getPublicKeyPath(privateKey.getName())))) {
- i++;
+ private void addToPrivateKeysPreferences(SSHKeyPair keyPair) {
+ Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
+ String privateKeys = preferences.getString(IConstants.KEY_PRIVATEKEY);
+ if (privateKeys != null
+ && privateKeys.trim().length() > 0) {
+ privateKeys = privateKeys + "," + keyPair.getPrivateKeyPath();
+ } else {
+ privateKeys = keyPair.getPrivateKeyPath();
}
- return privateKey.getAbsolutePath();
+ preferences.setValue(IConstants.KEY_PRIVATEKEY, privateKeys);
+ JSchCorePlugin.getPlugin().setNeedToLoadKeys(true);
+ JSchCorePlugin.getPlugin().savePluginPreferences();
}
-
- private String getPublicKeyPath(String privateKeyPath) {
- return privateKeyPath + PUBLIC_KEY_SUFFIX;
- }
-
+
public void setSshKey(String sshKey) {
firePropertyChange(PROPERTY_SSHKEY, this.sshKey, this.sshKey = sshKey);
}