Skip to content

Commit abbcce8

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of team/bundles/org.eclipse.jsch.core
1 parent bc98892 commit abbcce8

File tree

8 files changed

+92
-47
lines changed

8 files changed

+92
-47
lines changed

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ public synchronized void setIdentityRepository(){
128128
break;
129129
}
130130
}
131-
if(irepo!=null)
131+
if(irepo!=null){
132132
break;
133+
}
133134
}
134135

135136
if(irepo!=null){
@@ -147,8 +148,9 @@ public IdentityRepository[] getPluggedInIdentityRepositries(){
147148
IExtension[] extensions=Platform.getExtensionRegistry().getExtensionPoint(
148149
JSchCorePlugin.ID, JSchCorePlugin.PT_IDENTITYREPOSITORY).getExtensions();
149150

150-
if(extensions.length==0)
151+
if(extensions.length==0){
151152
return new IdentityRepository[0];
153+
}
152154

153155
ArrayList<IdentityRepository> tmp = new ArrayList<>();
154156
for(IExtension extension : extensions) {
@@ -189,8 +191,9 @@ public void loadKnownHosts(){
189191
Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences();
190192
String ssh_home=preferences.getString(IConstants.KEY_SSH2HOME);
191193

192-
if(ssh_home.length()==0)
194+
if(ssh_home.length()==0){
193195
ssh_home=PreferenceInitializer.SSH_HOME_DEFAULT;
196+
}
194197

195198
java.io.File file=new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$
196199
try{

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchLocation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public int getPort(){
6060

6161
@Override
6262
public void setUsername(String user){
63-
if(userFixed)
63+
if(userFixed){
6464
throw new UnsupportedOperationException();
65+
}
6566
this.user=user;
6667
}
6768

@@ -72,8 +73,9 @@ public String getUsername(){
7273

7374
@Override
7475
public void setPassword(String password){
75-
if(password!=null)
76+
if(password!=null){
7677
this.password=password;
78+
}
7779
}
7880

7981
@Override

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchProvider.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ public Session createSession(IJSchLocation location, UserInfo uinfo) throws JSch
5656

5757
if(uinfo==null){
5858
IUserAuthenticator authenticator=getPluggedInAuthenticator();
59-
if(authenticator==null)
59+
if(authenticator==null){
6060
authenticator=new NullUserAuthenticator();
61+
}
6162
uinfo=new UserInfoImpl(location, authenticator, (JSchCorePlugin.getPlugin().getTimeout() * 1000));
6263
}
63-
if(uinfo!=null)
64+
if(uinfo!=null){
6465
session.setUserInfo(uinfo);
66+
}
6567

6668
return session;
6769
}
@@ -77,8 +79,9 @@ public void connect(Session session, int timeout,
7779

7880
UserInfo ui=session.getUserInfo();
7981

80-
if(ui!=null && (ui instanceof UserInfoImpl))
82+
if(ui!=null && (ui instanceof UserInfoImpl)){
8183
((UserInfoImpl)ui).aboutToConnect();
84+
}
8285

8386
try{
8487
session.connect();
@@ -107,13 +110,15 @@ public void connect(Session session, int timeout,
107110
return;
108111
}
109112

110-
if(session.isConnected())
113+
if(session.isConnected()){
111114
session.disconnect();
115+
}
112116
throw e;
113117
}
114118

115-
if(ui!=null && (ui instanceof UserInfoImpl))
119+
if(ui!=null && (ui instanceof UserInfoImpl)){
116120
((UserInfoImpl)ui).connectionMade();
121+
}
117122
}
118123

119124
@Override
@@ -122,8 +127,9 @@ public Proxy getProxyForHost(String host, String proxyType) {
122127
}
123128

124129
public static IJSchService getInstance(){
125-
if (instance == null)
130+
if (instance == null){
126131
instance = new JSchProvider();
132+
}
127133
return instance;
128134
}
129135

@@ -149,8 +155,9 @@ public void connect(Proxy proxy, String host, int port, int timeout,
149155
private IUserAuthenticator getPluggedInAuthenticator(){
150156
IExtension[] extensions=Platform.getExtensionRegistry().getExtensionPoint(
151157
JSchCorePlugin.ID, JSchCorePlugin.PT_AUTHENTICATOR).getExtensions();
152-
if(extensions.length==0)
158+
if(extensions.length==0){
153159
return null;
160+
}
154161
IExtension extension=extensions[0];
155162
IConfigurationElement[] configs=extension.getConfigurationElements();
156163
if(configs.length==0){
@@ -187,8 +194,9 @@ private boolean isAuthenticationFailure(JSchException ee){
187194
}
188195

189196
private boolean hasPromptExceededTimeout(Session session){
190-
if(session.getUserInfo()==null || !(session.getUserInfo() instanceof UserInfoImpl))
197+
if(session.getUserInfo()==null || !(session.getUserInfo() instanceof UserInfoImpl)){
191198
return false;
199+
}
192200
return ((UserInfoImpl)session.getUserInfo()).hasPromptExceededTimeout();
193201
}
194202

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Policy.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@
1818
public class Policy{
1919

2020
public static void checkCanceled(IProgressMonitor monitor){
21-
if(monitor.isCanceled())
21+
if(monitor.isCanceled()){
2222
throw new OperationCanceledException();
23+
}
2324
}
2425

2526
public static IProgressMonitor monitorFor(IProgressMonitor monitor){
26-
if(monitor==null)
27+
if(monitor==null){
2728
return new NullProgressMonitor();
29+
}
2830
return monitor;
2931
}
3032

3133
public static IProgressMonitor subMonitorFor(IProgressMonitor monitor,
3234
int ticks){
33-
if(monitor==null)
35+
if(monitor==null){
3436
return new NullProgressMonitor();
35-
if(monitor instanceof NullProgressMonitor)
37+
}
38+
if(monitor instanceof NullProgressMonitor){
3639
return monitor;
40+
}
3741
return SubMonitor.convert(monitor, ticks);
3842
}
3943

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/PreferenceInitializer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer{
4545
public void initializeDefaultPreferences(){
4646
IEclipsePreferences defaultNode=DefaultScope.INSTANCE
4747
.getNode(JSchCorePlugin.ID);
48-
if(SSH_HOME_DEFAULT!=null)
48+
if(SSH_HOME_DEFAULT!=null){
4949
defaultNode.put(IConstants.KEY_SSH2HOME, SSH_HOME_DEFAULT);
50+
}
5051
defaultNode.put(IConstants.KEY_PRIVATEKEY, IConstants.PRIVATE_KEYS_DEFAULT);
5152
changeDefaultWin32SshHome();
5253
Utils.migrateSSH2Preferences();
5354
}
5455

5556
private void changeDefaultWin32SshHome(){
56-
if(!Platform.getOS().equals(Platform.OS_WIN32))
57+
if(!Platform.getOS().equals(Platform.OS_WIN32)){
5758
return;
59+
}
5860

5961
IEclipsePreferences preferences=InstanceScope.INSTANCE
6062
.getNode(JSchCorePlugin.ID);
@@ -72,9 +74,10 @@ private void changeDefaultWin32SshHome(){
7274
if(SSH_OLD_WIN32_HOME_DEFAULT!=null
7375
&&new File(SSH_OLD_WIN32_HOME_DEFAULT).exists()){
7476
if(!(SSH_HOME_DEFAULT!=null&&new File(SSH_HOME_DEFAULT).exists())
75-
||existingWorkspace)
77+
||existingWorkspace){
7678
preferences
7779
.put(IConstants.KEY_SSH2HOME, SSH_OLD_WIN32_HOME_DEFAULT);
80+
}
7881
}
7982
}
8083

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/ResponsiveSocketFactory.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,24 @@ public class ResponsiveSocketFactory implements SocketFactory {
4141
private static Class<?> proxyClass;
4242
private static boolean hasProxyClass = true;
4343
public ResponsiveSocketFactory(IProgressMonitor monitor, int timeout) {
44-
if (monitor == null)
44+
if (monitor == null){
4545
monitor = new NullProgressMonitor();
46+
}
4647
this.monitor = monitor;
4748
this.timeout=timeout;
4849
}
4950
@Override
5051
public InputStream getInputStream(Socket socket) throws IOException {
51-
if (in == null)
52+
if (in == null){
5253
in = socket.getInputStream();
54+
}
5355
return in;
5456
}
5557
@Override
5658
public OutputStream getOutputStream(Socket socket) throws IOException {
57-
if (out == null)
59+
if (out == null){
5860
out = socket.getOutputStream();
61+
}
5962
return out;
6063
}
6164
@Override
@@ -101,7 +104,9 @@ private Socket createSocket(final String host, final int port, int timeout, IPro
101104
thread.start();
102105

103106
// Wait the appropriate number of seconds
104-
if (timeout == 0) timeout = DEFAULT_TIMEOUT;
107+
if (timeout == 0){
108+
timeout = DEFAULT_TIMEOUT;
109+
}
105110
for (int i = 0; i < timeout; i++) {
106111
try {
107112
// wait for the thread to complete or 1 second, which ever comes first
@@ -131,10 +136,12 @@ private Socket createSocket(final String host, final int port, int timeout, IPro
131136
}
132137
}
133138
if (exception[0] != null) {
134-
if (exception[0] instanceof UnknownHostException)
139+
if (exception[0] instanceof UnknownHostException){
135140
throw (UnknownHostException)exception[0];
136-
else
141+
}
142+
else{
137143
throw (IOException)exception[0];
144+
}
138145
}
139146
if (socket[0] == null) {
140147
throw new InterruptedIOException(NLS.bind(Messages.Util_timeout, host));
@@ -154,8 +161,7 @@ private Socket createSocket(final String host, final int port, int timeout, IPro
154161
Object noProxyObject = field.get(null);
155162
Constructor<Socket> constructor = Socket.class.getConstructor(proxyClass);
156163
Object o = constructor.newInstance(noProxyObject);
157-
if(o instanceof Socket){
158-
Socket socket=(Socket)o;
164+
if(o instanceof Socket socket){
159165
socket.connect(new InetSocketAddress(host, port), timeout * 1000);
160166
return socket;
161167
}

team/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/UserInfoImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ public boolean promptPassword(String message){
131131
if(_password!=null){
132132
password=_password;
133133
// Cache the password with the repository location on the memory.
134-
if(location!=null)
134+
if(location!=null){
135135
location.setPassword(password);
136+
}
136137
}
137138
return _password!=null;
138139
}
@@ -166,8 +167,9 @@ public String[] promptKeyboardInteractive(String destination, String name,
166167
}
167168
String[] result=authenticator.promptForKeyboradInteractive(location,
168169
destination, name, instruction, prompt, echo);
169-
if(result==null)
170+
if(result==null){
170171
return null; // canceled
172+
}
171173
if(result.length==1&&prompt.length==1
172174
&&prompt[0].trim().equalsIgnoreCase("password:")){ //$NON-NLS-1$
173175
password=result[0];

0 commit comments

Comments
 (0)