Author: xcoulon
Date: 2012-04-27 21:32:19 -0400 (Fri, 27 Apr 2012)
New Revision: 40607
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogWorker.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftSshSessionFactory.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/actionProvider/ShowEnvironmentActionProvider.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/OpenShiftSshSessionFactory.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/TailServerLogWorker.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogAction.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties
Log:
Fixed - JBIDE-11632
Add a "Show environment" to openshift console
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2012-04-28
00:48:19 UTC (rev 40606)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/plugin.xml 2012-04-28
01:32:19 UTC (rev 40607)
@@ -491,7 +491,18 @@
</or>
</enablement>
</actionProvider>
-
+ <actionProvider
+
appearsBefore="org.jboss.tools.openshift.express.internal.ui.viewer.actionProvider.showPropertiesActionProvider"
+
class="org.jboss.tools.openshift.express.internal.ui.viewer.actionProvider.ShowEnvironmentActionProvider"
+
id="org.jboss.tools.openshift.express.internal.ui.viewer.actionProvider.showEnvironmentActionProvider">
+ <enablement>
+ <or>
+ <instanceof
+ value="com.openshift.client.IApplication">
+ </instanceof>
+ </or>
+ </enablement>
+ </actionProvider>
</extension>
<extension
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/ApplicationPortForwardingWizardPage.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -21,7 +21,6 @@
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jgit.transport.URIish;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -34,11 +33,11 @@
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
+import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftSshSessionFactory;
import org.jboss.tools.openshift.express.internal.ui.wizard.AbstractOpenShiftWizardPage;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
-import com.openshift.client.IApplication;
import com.openshift.client.IApplicationPortForwarding;
import com.openshift.client.OpenShiftSSHOperationException;
@@ -224,14 +223,6 @@
};
}
- static URIish getSshUri(IApplication application) {
- final String host = application.getName() + "-" +
application.getDomain().getId() + "."
- + application.getDomain().getSuffix();
- final String user = application.getUUID();
- final URIish uri = new URIish().setHost(host).setPort(22).setUser(user);
- return uri;
- }
-
private SelectionListener onStopPortForwarding() {
return new SelectionAdapter() {
@Override
@@ -371,7 +362,7 @@
if (!hasSSHSession) {
Logger.debug("Opening a new SSH Session for application '" +
wizardModel.getApplication().getName() + "'");
final Session session = OpenShiftSshSessionFactory.getInstance().createSession(
- getSshUri(wizardModel.getApplication()));
+ wizardModel.getApplication());
wizardModel.getApplication().setSSHSession(session);
}
}
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/OpenShiftSshSessionFactory.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/OpenShiftSshSessionFactory.java 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/OpenShiftSshSessionFactory.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -1,131 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.openshift.express.internal.core.portforward;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider;
-import org.eclipse.jgit.transport.CredentialsProviderUserInfo;
-import org.eclipse.jgit.transport.JschConfigSessionFactory;
-import org.eclipse.jgit.transport.OpenSshConfig;
-import org.eclipse.jgit.transport.URIish;
-import org.eclipse.jgit.util.FS;
-import org.eclipse.jsch.core.IJSchService;
-import org.eclipse.jsch.ui.UserInfoPrompter;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-import org.jboss.tools.openshift.express.internal.ui.console.JschToEclipseLogger;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.UserInfo;
-
-/**
- * Same as EclipseSshSessinFactory, but provides a mean to retrieve the pure Jsch
Session, not a RemoteSession.
- *
- * @author Xavier Coulon
- *
- */
-public class OpenShiftSshSessionFactory extends JschConfigSessionFactory {
-
- private static OpenShiftSshSessionFactory INSTANCE = new OpenShiftSshSessionFactory();
-
- /**
- * Get the currently configured JVM-wide factory.
- * <p>
- * A factory is always available. By default the factory will read from the user's
<code>$HOME/.ssh</code> and
- * assume OpenSSH compatibility.
- *
- * @return factory the current factory for this JVM.
- */
- public static OpenShiftSshSessionFactory getInstance() {
- return INSTANCE;
- }
-
- private final IJSchService provider;
-
- private OpenSshConfig config;
-
- private final Map<URIish, Session> cache = new HashMap<URIish, Session>();
-
- OpenShiftSshSessionFactory() {
- final BundleContext context =
OpenShiftUIActivator.getDefault().getBundle().getBundleContext();
- final ServiceReference<?> ssh =
context.getServiceReference(IJSchService.class.getName());
- this.provider = (IJSchService) context.getService(ssh);
- }
-
- public Session createSession(final URIish uri) throws JSchException {
- final Session session = cache.get(uri);
- if (session == null || !session.isConnected()) {
- final FS fs = FS.DETECTED;
- if (config == null) {
- config = OpenSshConfig.get(fs);
- }
- String user = uri.getUser();
- String host = uri.getHost();
- int port = uri.getPort();
- JSch.setLogger(new JschToEclipseLogger());
- final OpenSshConfig.Host hc = config.lookup(host);
- cache.put(uri, createSession(hc, user, host, port, fs));
- }
- return cache.get(uri);
- }
-
- @Override
- protected Session createSession(final OpenSshConfig.Host hc, final String user, final
String host, final int port,
- FS fs) throws JSchException {
- final JSch jsch = getJSch(hc, FS.DETECTED);
- if (jsch == provider.getJSch()) {
- // If its the default JSch desired, let the provider
- // manage the session creation for us.
- //
- final Session session = provider.createSession(host, port, user);
- configure(hc, session);
- session.connect();
- return session;
- } else {
- // This host configuration is using a different IdentityFile,
- // one that is not available through the default JSch.
- //
- final Session session = jsch.getSession(user, host, port);
- configure(hc, session);
- session.connect(0);
- return session;
- }
- }
-
- @Override
- protected JSch createDefaultJSch(FS fs) throws JSchException {
- // Forcing a dummy session to be created will cause the known hosts
- // and configured private keys to be initialized. This is needed by
- // our parent class in case non-default JSch instances need to be made.
- //
- provider.createSession("127.0.0.1", 0, "eclipse"); //$NON-NLS-1$
//$NON-NLS-2$
- return provider.getJSch();
- }
-
- @Override
- protected void configure(final OpenSshConfig.Host hc, final Session session) {
- final EGitCredentialsProvider credentialsProvider = new EGitCredentialsProvider();
- if ((!hc.isBatchMode() || !credentialsProvider.isInteractive())) {
- session.setUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider));
- } else {
- UserInfo userInfo = session.getUserInfo();
-
- if (!hc.isBatchMode() && userInfo == null)
- new UserInfoPrompter(session);
- }
- }
-
-}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.action;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.console.ConsoleUtils;
+import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
+import org.jboss.tools.openshift.express.internal.ui.utils.OpenShiftSshSessionFactory;
+
+import com.openshift.client.IApplication;
+
+/**
+ * @author Xavier Coulon
+ */
+public class ShowEnvironmentAction extends AbstractAction {
+
+ public ShowEnvironmentAction() {
+ super(OpenShiftExpressUIMessages.SHOW_ENVIRONMENT_ACTION, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ try {
+ final ITreeSelection treeSelection = (ITreeSelection) selection;
+ if (selection instanceof ITreeSelection && treeSelection.getFirstElement()
instanceof IApplication) {
+ final IApplication application = (IApplication) treeSelection.getFirstElement();
+ if(!application.hasSSHSession()) {
+ application.setSSHSession(OpenShiftSshSessionFactory.getInstance().createSession(application));
+ }
+ List<String> props = application.getEnvironmentProperties();
+ final MessageConsole console =
ConsoleUtils.findMessageConsole(getMessageConsoleName(application));
+ MessageConsoleStream stream = console.newMessageStream();
+ for (String prop : props) {
+ stream.println(prop);
+ }
+ ConsoleUtils.displayConsoleView(console);
+
+ }
+ } catch (Exception e) {
+ OpenShiftUIActivator.createErrorStatus("Failed to display remote environment
variables", e);
+ }
+
+ }
+
+ /**
+ * @return
+ */
+ private String getMessageConsoleName(final IApplication application) {
+ return "Environment Variables for application '" + application.getName()
+ "' (" + application.getDomain().getId() + ")";
+ }
+
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/ShowEnvironmentAction.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/TailServerLogWorker.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/TailServerLogWorker.java 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/TailServerLogWorker.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -1,74 +0,0 @@
-package org.jboss.tools.openshift.express.internal.ui.action;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.eclipse.jgit.transport.RemoteSession;
-import org.eclipse.ui.console.MessageConsole;
-
-
-/**
- * The underlying 'Tail' worker, that uses an established RemoteSession (with
- * the help of JGit), runs in a dedicated process and displays the outputstream
- * into a specific console. This worker is a <code>java.lang.Runnable</code>
in
- * order to run in a separate thread
- *
- * @author Xavier Coulon
- *
- */
-public class TailServerLogWorker implements Runnable {
-
- /** the remote 'tail' process. */
- private final Process process;
-
- /** the output message console. */
- private final MessageConsole console;
-
- /** the SSH session. */
- private final RemoteSession remoteSession;
-
- /**
- * Constructor.
- *
- * @param console
- * @param process
- * @param remoteSession
- */
- public TailServerLogWorker(final MessageConsole console, final Process process, final
RemoteSession remoteSession) {
- this.console = console;
- this.process = process;
- this.remoteSession = remoteSession;
- }
-
- @Override
- public void run() {
- try {
- // get I/O streams for remote tail
- final InputStream in = process.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- String line;
- // Read File Line By Line
- while ((line = reader.readLine()) != null) {
- console.newMessageStream().println(line);
- }
- } catch (Throwable e) {
- org.jboss.tools.openshift.express.internal.ui.utils.Logger.error(
- "Error while receiving the remote server log", e);
- console.newMessageStream().println("Error while receiving the remote server log:
" + e.getMessage());
- } finally {
-
- }
- }
-
- /**
- * Method called when the overall 'tail' process should be stopped: the
- * underlying ssh remote session must be disconnected and the running
- * process must be destroyed.
- */
- public void stop() {
- this.remoteSession.disconnect();
- this.process.destroy();
- }
-
-}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogAction.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogAction.java 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogAction.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -28,7 +28,6 @@
import org.eclipse.wst.server.ui.IServerModule;
import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
import org.jboss.tools.openshift.express.internal.ui.action.AbstractAction;
-import org.jboss.tools.openshift.express.internal.ui.action.TailServerLogWorker;
import
org.jboss.tools.openshift.express.internal.ui.messages.OpenShiftExpressUIMessages;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogWorker.java
(from rev 40548,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/action/TailServerLogWorker.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogWorker.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogWorker.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -0,0 +1,74 @@
+package org.jboss.tools.openshift.express.internal.ui.console;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.eclipse.jgit.transport.RemoteSession;
+import org.eclipse.ui.console.MessageConsole;
+
+
+/**
+ * The underlying 'Tail' worker, that uses an established RemoteSession (with
+ * the help of JGit), runs in a dedicated process and displays the outputstream
+ * into a specific console. This worker is a <code>java.lang.Runnable</code>
in
+ * order to run in a separate thread
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class TailServerLogWorker implements Runnable {
+
+ /** the remote 'tail' process. */
+ private final Process process;
+
+ /** the output message console. */
+ private final MessageConsole console;
+
+ /** the SSH session. */
+ private final RemoteSession remoteSession;
+
+ /**
+ * Constructor.
+ *
+ * @param console
+ * @param process
+ * @param remoteSession
+ */
+ public TailServerLogWorker(final MessageConsole console, final Process process, final
RemoteSession remoteSession) {
+ this.console = console;
+ this.process = process;
+ this.remoteSession = remoteSession;
+ }
+
+ @Override
+ public void run() {
+ try {
+ // get I/O streams for remote tail
+ final InputStream in = process.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ String line;
+ // Read File Line By Line
+ while ((line = reader.readLine()) != null) {
+ console.newMessageStream().println(line);
+ }
+ } catch (Throwable e) {
+ org.jboss.tools.openshift.express.internal.ui.utils.Logger.error(
+ "Error while receiving the remote server log", e);
+ console.newMessageStream().println("Error while receiving the remote server log:
" + e.getMessage());
+ } finally {
+
+ }
+ }
+
+ /**
+ * Method called when the overall 'tail' process should be stopped: the
+ * underlying ssh remote session must be disconnected and the running
+ * process must be destroyed.
+ */
+ public void stop() {
+ this.remoteSession.disconnect();
+ this.process.destroy();
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/console/TailServerLogWorker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -40,6 +40,8 @@
public static String MAKE_SNAPSHOT_ACTION;
public static String SHOW_PROPERTIES_VIEW_ACTION;
+
+ public static String SHOW_ENVIRONMENT_ACTION;
public static String REFRESH_VIEWER_ACTION;
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties 2012-04-28
00:48:19 UTC (rev 40606)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/messages/OpenShiftExpressUIMessages.properties 2012-04-28
01:32:19 UTC (rev 40607)
@@ -16,7 +16,9 @@
SHOW_PROPERTIES_VIEW_ACTION=Properties
REFRESH_VIEWER_ACTION=Refresh
+SHOW_ENVIRONMENT_ACTION=Show Environment Variables
+
DELETE_CONNECTION_ACTION=Disconnect
USER_NOT_CONNECTED_LABEL=<User is not connected>
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftSshSessionFactory.java
(from rev 40595,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/portforward/OpenShiftSshSessionFactory.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftSshSessionFactory.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftSshSessionFactory.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.openshift.express.internal.ui.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider;
+import org.eclipse.jgit.transport.CredentialsProviderUserInfo;
+import org.eclipse.jgit.transport.JschConfigSessionFactory;
+import org.eclipse.jgit.transport.OpenSshConfig;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.jsch.core.IJSchService;
+import org.eclipse.jsch.ui.UserInfoPrompter;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.console.JschToEclipseLogger;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UserInfo;
+import com.openshift.client.IApplication;
+
+/**
+ * Same as EclipseSshSessinFactory, but provides a mean to retrieve the pure Jsch
Session, not a RemoteSession.
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class OpenShiftSshSessionFactory extends JschConfigSessionFactory {
+
+ private static OpenShiftSshSessionFactory INSTANCE = new OpenShiftSshSessionFactory();
+
+ /**
+ * Get the currently configured JVM-wide factory.
+ * <p>
+ * A factory is always available. By default the factory will read from the user's
<code>$HOME/.ssh</code> and
+ * assume OpenSSH compatibility.
+ *
+ * @return factory the current factory for this JVM.
+ */
+ public static OpenShiftSshSessionFactory getInstance() {
+ return INSTANCE;
+ }
+
+ private final IJSchService provider;
+
+ private OpenSshConfig config;
+
+ private final Map<URIish, Session> cache = new HashMap<URIish, Session>();
+
+ OpenShiftSshSessionFactory() {
+ final BundleContext context =
OpenShiftUIActivator.getDefault().getBundle().getBundleContext();
+ final ServiceReference<?> ssh =
context.getServiceReference(IJSchService.class.getName());
+ this.provider = (IJSchService) context.getService(ssh);
+ }
+
+ public Session createSession(final IApplication application) throws JSchException {
+ final URIish uri = getSshUri(application);
+ final Session session = cache.get(uri);
+ if (session == null || !session.isConnected()) {
+ final FS fs = FS.DETECTED;
+ if (config == null) {
+ config = OpenSshConfig.get(fs);
+ }
+ String user = uri.getUser();
+ String host = uri.getHost();
+ int port = uri.getPort();
+ JSch.setLogger(new JschToEclipseLogger());
+ final OpenSshConfig.Host hc = config.lookup(host);
+ cache.put(uri, createSession(hc, user, host, port, fs));
+ }
+ return cache.get(uri);
+ }
+
+ static URIish getSshUri(IApplication application) {
+ final String host = application.getName() + "-" +
application.getDomain().getId() + "."
+ + application.getDomain().getSuffix();
+ final String user = application.getUUID();
+ final URIish uri = new URIish().setHost(host).setPort(22).setUser(user);
+ return uri;
+ }
+
+ @Override
+ protected Session createSession(final OpenSshConfig.Host hc, final String user, final
String host, final int port,
+ FS fs) throws JSchException {
+ final JSch jsch = getJSch(hc, FS.DETECTED);
+ if (jsch == provider.getJSch()) {
+ // If its the default JSch desired, let the provider
+ // manage the session creation for us.
+ //
+ final Session session = provider.createSession(host, port, user);
+ configure(hc, session);
+ session.connect();
+ return session;
+ } else {
+ // This host configuration is using a different IdentityFile,
+ // one that is not available through the default JSch.
+ //
+ final Session session = jsch.getSession(user, host, port);
+ configure(hc, session);
+ session.connect(0);
+ return session;
+ }
+ }
+
+ @Override
+ protected JSch createDefaultJSch(FS fs) throws JSchException {
+ // Forcing a dummy session to be created will cause the known hosts
+ // and configured private keys to be initialized. This is needed by
+ // our parent class in case non-default JSch instances need to be made.
+ //
+ provider.createSession("127.0.0.1", 0, "eclipse"); //$NON-NLS-1$
//$NON-NLS-2$
+ return provider.getJSch();
+ }
+
+ @Override
+ protected void configure(final OpenSshConfig.Host hc, final Session session) {
+ final EGitCredentialsProvider credentialsProvider = new EGitCredentialsProvider();
+ if ((!hc.isBatchMode() || !credentialsProvider.isInteractive())) {
+ session.setUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider));
+ } else {
+ UserInfo userInfo = session.getUserInfo();
+
+ if (!hc.isBatchMode() && userInfo == null)
+ new UserInfoPrompter(session);
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftSshSessionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/actionProvider/ShowEnvironmentActionProvider.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/actionProvider/ShowEnvironmentActionProvider.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/actionProvider/ShowEnvironmentActionProvider.java 2012-04-28
01:32:19 UTC (rev 40607)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.viewer.actionProvider;
+
+import org.jboss.tools.openshift.express.internal.ui.action.ShowEnvironmentAction;
+
+/**
+ * @author Xavier Coulon
+ */
+public class ShowEnvironmentActionProvider extends AbstractActionProvider {
+
+ public ShowEnvironmentActionProvider() {
+ super(new ShowEnvironmentAction(), "group.properties");
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/viewer/actionProvider/ShowEnvironmentActionProvider.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain