Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class KeyboardInteractiveDialog extends TrayDialog {
protected String lang;
protected String[] prompt;
protected boolean[] echo;
private String message;
private final String message;
private String[] result;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ protected SshConnection(SshConnector conn, ITerminalControl control) {
protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI,
IProgressMonitor monitor) throws JSchException {
IJSchService service = UIPlugin.getDefault().getJSchService();
if (service == null)
if (service == null) {
return null;
}
Session session = service.createSession(hostname, port, username);
//session.setTimeout(getSshTimeoutInMillis());
session.setTimeout(0); //never time out on the session
session.setServerAliveCountMax(6); //give up after 6 tries (remote will be dead after 30 min)
if (password != null)
if (password != null) {
session.setPassword(password);
}
session.setUserInfo(wrapperUI);
return session;
}
Expand Down Expand Up @@ -125,14 +127,16 @@ public void run() {
}
// dont try to connect if disconnect has been requested already
synchronized (this) {
if (fDisconnectHasBeenCalled)
if (fDisconnectHasBeenCalled) {
return;
}
}

session.connect(nTimeout); // making connection with timeout.
// if we got disconnected, do not continue
if (!isSessionConnected())
if (!isSessionConnected()) {
return;
}
ChannelShell channel = (ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
channel.setPtyType("xterm"); //$NON-NLS-1$
// TERM=xterm implies VT100 line wrapping mode
Expand Down Expand Up @@ -360,8 +364,9 @@ public void run() {
}
});
String[] result = finResult[0];
if (result == null)
if (result == null) {
return null; // cancelled
}
if (result.length == 1 && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$
fPassword = result[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public static String getMessage(String key) {
try {
Field f = SshMessages.class.getDeclaredField(key);
Object o = f.get(null);
if (o instanceof String)
if (o instanceof String) {
return (String) o;
}
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public void loadSettings() {
}

String get(String value, String def) {
if (value == null || value.length() == 0)
if (value == null || value.length() == 0) {
return def;
}
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public void setupPanel(Composite parent) {
panel.setLayoutData(data);

// Create the host selection combo
if (isWithoutSelection())
if (isWithoutSelection()) {
createHostsUI(panel, true);
}

SshConnector conn = new SshConnector();
sshSettings = (SshSettings) conn.getSshSettings();
Expand All @@ -90,8 +91,9 @@ public void setupPanel(Composite parent) {
sshSettingsPage.addListener(new ISettingsPage.Listener() {
@Override
public void onSettingsPageChanged(Control control) {
if (getContainer() != null)
if (getContainer() != null) {
getContainer().validate();
}
}
});

Expand All @@ -106,39 +108,47 @@ public void onSettingsPageChanged(Control control) {

@Override
public void setupData(Map<String, Object> data) {
if (data == null || sshSettings == null || sshSettingsPage == null)
if (data == null || sshSettings == null || sshSettingsPage == null) {
return;
}

String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
if (value != null)
if (value != null) {
sshSettings.setHost(value);
}

Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT);
value = v != null ? v.toString() : null;
if (value != null)
if (value != null) {
sshSettings.setPort(value);
}

v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
value = v != null ? v.toString() : null;
if (value != null)
if (value != null) {
sshSettings.setTimeout(value);
}

v = data.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
value = v != null ? v.toString() : null;
if (value != null)
if (value != null) {
sshSettings.setKeepalive(value);
}

value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
if (value != null)
if (value != null) {
sshSettings.setPassword(value);
}

value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_USER);
if (value != null)
if (value != null) {
sshSettings.setUser(value);
}

value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
if (value != null)
if (value != null) {
setEncoding(value);
}

sshSettingsPage.loadSettings();
}
Expand All @@ -155,8 +165,9 @@ private String getDefaultUser() {
ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element);
if (provider != null) {
Object user = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_USER);
if (user instanceof String)
if (user instanceof String) {
return ((String) user).trim();
}
}
}

Expand All @@ -165,8 +176,9 @@ private String getDefaultUser() {

@Override
public void extractData(Map<String, Object> data) {
if (data == null)
if (data == null) {
return;
}

// set the terminal connector id for ssh
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
Expand Down Expand Up @@ -281,8 +293,9 @@ protected void saveSettingsForHost(boolean add) {
}

// maybe unchecked the password button - so try to remove a saved password - if any
if (!savePassword)
if (!savePassword) {
removeSecurePassword(host);
}
} else if (add) {
Map<String, String> hostSettings = new HashMap<>();
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
private String getTerminalTitle(Map<String, Object> properties) {
// Try to see if the user set a title explicitly via the properties map.
String title = getDefaultTerminalTitle(properties);
if (title != null)
if (title != null) {
return title;
}

//No title,try to calculate the title
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
Expand All @@ -100,9 +101,9 @@ private String getTerminalTitle(Map<String, Object> properties) {
String date = format.format(new Date(System.currentTimeMillis()));
if (port != null && Integer.valueOf(port).intValue() != ISshSettings.DEFAULT_SSH_PORT) {
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle_port,
new String[] { user, host, port, date });
user, host, port, date);
}
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[] { user, host, date });
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, user, host, date);
}

return Messages.SshLauncherDelegate_terminalTitle_default;
Expand All @@ -125,8 +126,9 @@ public ITerminalConnector createTerminalConnector(Map<String, Object> properties

// Check for the terminal connector id
String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
if (connectorId == null)
if (connectorId == null) {
connectorId = "org.eclipse.terminal.connector.ssh.SshConnector"; //$NON-NLS-1$
}

// Extract the ssh properties
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
Expand All @@ -142,8 +144,9 @@ public ITerminalConnector createTerminalConnector(Map<String, Object> properties
int portOffset = 0;
if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
if (portOffset < 0)
if (portOffset < 0) {
portOffset = 0;
}
}

// The real port to connect to is port + portOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public void saveState(IMemento memento, Map<String, Object> properties) {
(String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT,
value instanceof Integer ? ((Integer) value).intValue() : -1);
value instanceof Integer i ? i.intValue() : -1);
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT,
value instanceof Integer ? ((Integer) value).intValue() : -1);
value instanceof Integer i ? i.intValue() : -1);
value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
value instanceof Integer ? ((Integer) value).intValue() : -1);
value instanceof Integer i ? i.intValue() : -1);
memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER,
(String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER));
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,
Expand Down
Loading