PTP
Release 7.0

org.eclipse.ptp.ems.ui
Class LazyEnvManagerDetector

java.lang.Object
  extended by org.eclipse.ptp.ems.ui.LazyEnvManagerDetector
All Implemented Interfaces:
IEnvManager

public class LazyEnvManagerDetector
extends Object
implements IEnvManager

An implementation of IEnvManager which avoids connecting to the remote machine until it is actually necessary, then displays a progress dialog while the connection is established and subsequently forwards all method calls to the IEnvManager returned by EnvManagerRegistry.getEnvManager(IProgressMonitor, IRemoteConnection) .

When it becomes necessary to connect to the remote machine, a modal progress dialog is displayed while the connection is established. Then, EnvManagerRegistry.getEnvManager(IProgressMonitor, IRemoteConnection) is invoked to detects the environment management system on the remote machine, if any, and acquire an IEnvManager capable of interfacing with that system.

All of the IEnvManager methods delegate to the IEnvManager returned by EnvManagerRegistry.getEnvManager(IProgressMonitor, IRemoteConnection).

Since:
6.0

Field Summary
 
Fields inherited from interface org.eclipse.ptp.ems.core.IEnvManager
ENV_MANAGER_EXTENSION_POINT_ID
 
Constructor Summary
LazyEnvManagerDetector(IRemoteConnection remoteConnection)
          Constructor.
 
Method Summary
 boolean checkForCompatibleInstallation(IProgressMonitor pm)
          Returns true iff the remote machine is running an environment management system supported by this IEnvManager.
 void configure(IRemoteConnection remoteConnection)
          Sets the IRemoteConnection which will be used to run commands on a remote machine.
 String createBashScript(IProgressMonitor pm, boolean echo, IEnvManagerConfig config, String commandToExecuteAfterward)
          Creates a temporary file on the remote machine and writes a Bash shell script into that file which will configure the remote environment with the given elements, execute the given command, and then delete the temporary file (shell script).
 List<String> determineAvailableElements(IProgressMonitor pm)
          Returns the set of all environment configuration elements available on the remote machine (e.g., the result of module -t avail).
 List<String> determineDefaultElements(IProgressMonitor pm)
          Returns the set of all environment configuration elements loaded by default upon login (e.g., the result of module -t list in a login shell).
 String getBashConcatenation(String separator, boolean echo, IEnvManagerConfig config, String commandToExecuteAfterward)
          Returns a single Bash shell command which will configure the remote environment with the given elements and then execute the given command.
 Comparator<String> getComparator()
          Returns a Comparator used to sort the strings returned by IEnvManager.determineAvailableElements(IProgressMonitor) and IEnvManager.determineDefaultElements(IProgressMonitor) when displaying them to the user.
 String getDescription(IProgressMonitor pm)
          If the remote machine is running an environment management system supported by this IEnvManager, returns a short description of the environment management system (e.g., "Modules 3.2.7"); otherwise, returns null.
 String getInstructions()
          Returns a short sentence that will be displayed to the user to request that items be selected from a checklist.
 String getName()
          Returns a human-readable name for this environment management system.
 void setProgressMonitor(IProgressMonitor monitor)
          Set a progress monitor to use for long running operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyEnvManagerDetector

public LazyEnvManagerDetector(IRemoteConnection remoteConnection)
Constructor.

Parameters:
remoteConnection - IRemoteConnection used to access files and execute shell commands on the remote machine (non- null)
Method Detail

checkForCompatibleInstallation

public boolean checkForCompatibleInstallation(IProgressMonitor pm)
                                       throws RemoteConnectionException,
                                              IOException
Description copied from interface: IEnvManager
Returns true iff the remote machine is running an environment management system supported by this IEnvManager.

Specified by:
checkForCompatibleInstallation in interface IEnvManager
Parameters:
pm - progress monitor used to report the status of potentially long-running operations to the user (non- null)
Returns:
true iff the remote machine is running an environment management system supported by this IEnvManager
Throws:
RemoteConnectionException - if an remote connection error occurs
IOException - if an input/output error occurs

configure

public void configure(IRemoteConnection remoteConnection)
Description copied from interface: IEnvManager
Sets the IRemoteConnection which will be used to run commands on a remote machine.

This method must be invoked before IEnvManager.checkForCompatibleInstallation(IProgressMonitor), IEnvManager.getDescription(IProgressMonitor), IEnvManager.determineAvailableElements(IProgressMonitor), IEnvManager.determineDefaultElements(IProgressMonitor), or IEnvManager.createBashScript(IProgressMonitor, boolean, IEnvManagerConfig, String).

Specified by:
configure in interface IEnvManager
Parameters:
remoteConnection - IRemoteConnection (non-null)

createBashScript

public String createBashScript(IProgressMonitor pm,
                               boolean echo,
                               IEnvManagerConfig config,
                               String commandToExecuteAfterward)
                        throws RemoteConnectionException,
                               IOException
Description copied from interface: IEnvManager
Creates a temporary file on the remote machine and writes a Bash shell script into that file which will configure the remote environment with the given elements, execute the given command, and then delete the temporary file (shell script).

Specified by:
createBashScript in interface IEnvManager
Parameters:
pm - progress monitor used to report the status of potentially long-running operations to the user (non- null)
echo - true iff the script should "echo" each command prior to execution
config - environment manager configuration (non-null)
commandToExecuteAfterward - a Bash shell command to execute after the environment has been configured
Returns:
path to the shell script on the remote machine (non-null)
Throws:
RemoteConnectionException - if an remote connection error occurs
IOException - if an input/output error occurs

determineAvailableElements

public List<String> determineAvailableElements(IProgressMonitor pm)
                                        throws RemoteConnectionException,
                                               IOException
Description copied from interface: IEnvManager
Returns the set of all environment configuration elements available on the remote machine (e.g., the result of module -t avail).

Specified by:
determineAvailableElements in interface IEnvManager
Parameters:
pm - progress monitor used to report the status of potentially long-running operations to the user (non- null)
Returns:
unmodifiable Set (non-null)
Throws:
RemoteConnectionException - if an remote connection error occurs
IOException - if an input/output error occurs
Since:
2.0

determineDefaultElements

public List<String> determineDefaultElements(IProgressMonitor pm)
                                      throws RemoteConnectionException,
                                             IOException
Description copied from interface: IEnvManager
Returns the set of all environment configuration elements loaded by default upon login (e.g., the result of module -t list in a login shell). Note that the ordering of modules is important and must be retained.

Specified by:
determineDefaultElements in interface IEnvManager
Parameters:
pm - progress monitor used to report the status of potentially long-running operations to the user (non- null)
Returns:
unmodifiable List (non-null)
Throws:
RemoteConnectionException - if an remote connection error occurs
IOException - if an input/output error occurs
Since:
2.0

getBashConcatenation

public String getBashConcatenation(String separator,
                                   boolean echo,
                                   IEnvManagerConfig config,
                                   String commandToExecuteAfterward)
Description copied from interface: IEnvManager
Returns a single Bash shell command which will configure the remote environment with the given elements and then execute the given command.

The returned command may include sequencing, piping, I/O redirection, etc.; however, it must be possible to concatenate additional Bash commands by appending a semicolon.

Specified by:
getBashConcatenation in interface IEnvManager
Parameters:
separator - string that will be inserted between consecutive Bash commands: typically, either a semicolon or a newline
echo - true iff the script should "echo" each command prior to execution
config - environment manager configuration (non-null)
commandToExecuteAfterward - a Bash shell command to execute after the environment has been configured
Returns:
a single Bash shell command which will configure the remote environment with the given elements and then execute the given command (non-null)

getComparator

public Comparator<String> getComparator()
Description copied from interface: IEnvManager
Returns a Comparator used to sort the strings returned by IEnvManager.determineAvailableElements(IProgressMonitor) and IEnvManager.determineDefaultElements(IProgressMonitor) when displaying them to the user.

Specified by:
getComparator in interface IEnvManager
Returns:
Comparator (non-null)

getDescription

public String getDescription(IProgressMonitor pm)
                      throws RemoteConnectionException,
                             IOException
Description copied from interface: IEnvManager
If the remote machine is running an environment management system supported by this IEnvManager, returns a short description of the environment management system (e.g., "Modules 3.2.7"); otherwise, returns null.

Specified by:
getDescription in interface IEnvManager
Parameters:
pm - progress monitor used to report the status of potentially long-running operations to the user (non- null)
Returns:
a short, human-readable description of the environment configuration system (e.g., "SoftEnv 1.6.2"), or null if a compatible environment configuration system is not present on the remote machine
Throws:
RemoteConnectionException - if an remote connection error occurs
IOException - if an input/output error occurs

getInstructions

public String getInstructions()
Description copied from interface: IEnvManager
Returns a short sentence that will be displayed to the user to request that items be selected from a checklist.

For example, "Select modules to be loaded."

Specified by:
getInstructions in interface IEnvManager
Returns:
String (non-null)

getName

public String getName()
Description copied from interface: IEnvManager
Returns a human-readable name for this environment management system.

Specified by:
getName in interface IEnvManager
Returns:
String (non-null)

setProgressMonitor

public void setProgressMonitor(IProgressMonitor monitor)
Set a progress monitor to use for long running operations. If no progress monitor is set, the workbench progress service will be used

Parameters:
monitor - progress monitor

PTP
Release 7.0

Copyright (c) 2011 IBM Corporation and others. All Rights Reserved.