Skip to content

Commit 56b485a

Browse files
eclipse-platform-botlaeubi
authored andcommitted
Perform clean code of terminal/bundles/org.eclipse.terminal.connector.ssh
1 parent 3082b75 commit 56b485a

File tree

7 files changed

+52
-29
lines changed

7 files changed

+52
-29
lines changed

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/connector/KeyboardInteractiveDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class KeyboardInteractiveDialog extends TrayDialog {
4343
protected String lang;
4444
protected String[] prompt;
4545
protected boolean[] echo;
46-
private String message;
46+
private final String message;
4747
private String[] result;
4848

4949
/**

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/connector/SshConnection.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ protected SshConnection(SshConnector conn, ITerminalControl control) {
7676
protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI,
7777
IProgressMonitor monitor) throws JSchException {
7878
IJSchService service = UIPlugin.getDefault().getJSchService();
79-
if (service == null)
79+
if (service == null) {
8080
return null;
81+
}
8182
Session session = service.createSession(hostname, port, username);
8283
//session.setTimeout(getSshTimeoutInMillis());
8384
session.setTimeout(0); //never time out on the session
8485
session.setServerAliveCountMax(6); //give up after 6 tries (remote will be dead after 30 min)
85-
if (password != null)
86+
if (password != null) {
8687
session.setPassword(password);
88+
}
8789
session.setUserInfo(wrapperUI);
8890
return session;
8991
}
@@ -125,14 +127,16 @@ public void run() {
125127
}
126128
// dont try to connect if disconnect has been requested already
127129
synchronized (this) {
128-
if (fDisconnectHasBeenCalled)
130+
if (fDisconnectHasBeenCalled) {
129131
return;
132+
}
130133
}
131134

132135
session.connect(nTimeout); // making connection with timeout.
133136
// if we got disconnected, do not continue
134-
if (!isSessionConnected())
137+
if (!isSessionConnected()) {
135138
return;
139+
}
136140
ChannelShell channel = (ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
137141
channel.setPtyType("xterm"); //$NON-NLS-1$
138142
// TERM=xterm implies VT100 line wrapping mode
@@ -360,8 +364,9 @@ public void run() {
360364
}
361365
});
362366
String[] result = finResult[0];
363-
if (result == null)
367+
if (result == null) {
364368
return null; // cancelled
369+
}
365370
if (result.length == 1 && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$
366371
fPassword = result[0];
367372
}

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/connector/SshMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public static String getMessage(String key) {
8484
try {
8585
Field f = SshMessages.class.getDeclaredField(key);
8686
Object o = f.get(null);
87-
if (o instanceof String)
87+
if (o instanceof String) {
8888
return (String) o;
89+
}
8990
} catch (SecurityException e) {
9091
} catch (NoSuchFieldException e) {
9192
} catch (IllegalArgumentException e) {

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/connector/SshSettingsPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ public void loadSettings() {
6363
}
6464

6565
String get(String value, String def) {
66-
if (value == null || value.length() == 0)
66+
if (value == null || value.length() == 0) {
6767
return def;
68+
}
6869
return value;
6970
}
7071

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/controls/SshWizardConfigurationPanel.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ public void setupPanel(Composite parent) {
7272
panel.setLayoutData(data);
7373

7474
// Create the host selection combo
75-
if (isWithoutSelection())
75+
if (isWithoutSelection()) {
7676
createHostsUI(panel, true);
77+
}
7778

7879
SshConnector conn = new SshConnector();
7980
sshSettings = (SshSettings) conn.getSshSettings();
@@ -90,8 +91,9 @@ public void setupPanel(Composite parent) {
9091
sshSettingsPage.addListener(new ISettingsPage.Listener() {
9192
@Override
9293
public void onSettingsPageChanged(Control control) {
93-
if (getContainer() != null)
94+
if (getContainer() != null) {
9495
getContainer().validate();
96+
}
9597
}
9698
});
9799

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

107109
@Override
108110
public void setupData(Map<String, Object> data) {
109-
if (data == null || sshSettings == null || sshSettingsPage == null)
111+
if (data == null || sshSettings == null || sshSettingsPage == null) {
110112
return;
113+
}
111114

112115
String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
113-
if (value != null)
116+
if (value != null) {
114117
sshSettings.setHost(value);
118+
}
115119

116120
Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT);
117121
value = v != null ? v.toString() : null;
118-
if (value != null)
122+
if (value != null) {
119123
sshSettings.setPort(value);
124+
}
120125

121126
v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
122127
value = v != null ? v.toString() : null;
123-
if (value != null)
128+
if (value != null) {
124129
sshSettings.setTimeout(value);
130+
}
125131

126132
v = data.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
127133
value = v != null ? v.toString() : null;
128-
if (value != null)
134+
if (value != null) {
129135
sshSettings.setKeepalive(value);
136+
}
130137

131138
value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
132-
if (value != null)
139+
if (value != null) {
133140
sshSettings.setPassword(value);
141+
}
134142

135143
value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_USER);
136-
if (value != null)
144+
if (value != null) {
137145
sshSettings.setUser(value);
146+
}
138147

139148
value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
140-
if (value != null)
149+
if (value != null) {
141150
setEncoding(value);
151+
}
142152

143153
sshSettingsPage.loadSettings();
144154
}
@@ -155,8 +165,9 @@ private String getDefaultUser() {
155165
ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element);
156166
if (provider != null) {
157167
Object user = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_USER);
158-
if (user instanceof String)
168+
if (user instanceof String) {
159169
return ((String) user).trim();
170+
}
160171
}
161172
}
162173

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

166177
@Override
167178
public void extractData(Map<String, Object> data) {
168-
if (data == null)
179+
if (data == null) {
169180
return;
181+
}
170182

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

283295
// maybe unchecked the password button - so try to remove a saved password - if any
284-
if (!savePassword)
296+
if (!savePassword) {
285297
removeSecurePassword(host);
298+
}
286299
} else if (add) {
287300
Map<String, String> hostSettings = new HashMap<>();
288301
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
8686
private String getTerminalTitle(Map<String, Object> properties) {
8787
// Try to see if the user set a title explicitly via the properties map.
8888
String title = getDefaultTerminalTitle(properties);
89-
if (title != null)
89+
if (title != null) {
9090
return title;
91+
}
9192

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

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

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

131133
// Extract the ssh properties
132134
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
@@ -142,8 +144,9 @@ public ITerminalConnector createTerminalConnector(Map<String, Object> properties
142144
int portOffset = 0;
143145
if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
144146
portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
145-
if (portOffset < 0)
147+
if (portOffset < 0) {
146148
portOffset = 0;
149+
}
147150
}
148151

149152
// The real port to connect to is port + portOffset

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshMementoHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public void saveState(IMemento memento, Map<String, Object> properties) {
3737
(String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
3838
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
3939
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT,
40-
value instanceof Integer ? ((Integer) value).intValue() : -1);
40+
value instanceof Integer i ? i.intValue() : -1);
4141
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
4242
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT,
43-
value instanceof Integer ? ((Integer) value).intValue() : -1);
43+
value instanceof Integer i ? i.intValue() : -1);
4444
value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
4545
memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
46-
value instanceof Integer ? ((Integer) value).intValue() : -1);
46+
value instanceof Integer i ? i.intValue() : -1);
4747
memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER,
4848
(String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER));
4949
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,

0 commit comments

Comments
 (0)