1
1
package org .jabref .logic .search ;
2
2
3
- import com .fasterxml .jackson .databind .ObjectMapper ;
4
- import org .slf4j .Logger ;
5
- import org .slf4j .LoggerFactory ;
6
-
7
3
import java .io .BufferedReader ;
8
4
import java .io .IOException ;
9
5
import java .io .InputStreamReader ;
13
9
import java .util .Map ;
14
10
import java .util .Optional ;
15
11
12
+ import com .fasterxml .jackson .databind .ObjectMapper ;
13
+ import org .slf4j .Logger ;
14
+ import org .slf4j .LoggerFactory ;
15
+
16
16
import static org .jabref .logic .os .OS .getHostName ;
17
17
import static org .jabref .logic .search .PostgreServer .POSTGRES_METADATA_FILE ;
18
18
@@ -27,13 +27,14 @@ public static PostgreProcessCleaner getInstance() {
27
27
}
28
28
29
29
public void checkAndCleanupOldInstance () {
30
- if (!Files .exists (POSTGRES_METADATA_FILE ))
30
+ if (!Files .exists (POSTGRES_METADATA_FILE )) {
31
31
return ;
32
+ }
32
33
33
34
try {
34
35
Map <String , Object > metadata = new HashMap <>(new ObjectMapper ()
35
36
.readValue (Files .readAllBytes (POSTGRES_METADATA_FILE ), HashMap .class ));
36
- if (!metadata .isEmpty ()) {
37
+ if (!metadata .isEmpty ()) {
37
38
int port = ((Number ) metadata .get ("postgresPort" )).intValue ();
38
39
destroyPreviousJavaProcess (metadata );
39
40
destroyPostgresProcess (port );
@@ -97,7 +98,6 @@ private long getPidUsingPort(int port) {
97
98
} catch (Exception e ) {
98
99
LOGGER .warn ("Failed to get PID for port {}: {}" , port , e .getMessage ());
99
100
}
100
-
101
101
return -1 ;
102
102
}
103
103
@@ -128,16 +128,17 @@ private long extractPidFromOutput(String os, BufferedReader reader) throws IOExc
128
128
129
129
private Long parseUnixPidFromLine (String line ) {
130
130
String [] parts = line .trim ().split ("\\ s+" );
131
- if (parts .length > 1 && parts [1 ].matches ("\\ d+" ))
131
+ if (parts .length > 1 && parts [1 ].matches ("\\ d+" )) {
132
132
return Long .parseLong (parts [1 ]);
133
+ }
133
134
return null ;
134
135
}
135
136
136
137
private Long parseWindowsPidFromLine (String line ) {
137
138
String [] parts = line .trim ().split ("\\ s+" );
138
- if (parts .length >= 5 && parts [parts .length - 1 ].matches ("\\ d+" ))
139
+ if (parts .length >= 5 && parts [parts .length - 1 ].matches ("\\ d+" )) {
139
140
return Long .parseLong (parts [parts .length - 1 ]);
141
+ }
140
142
return null ;
141
143
}
142
-
143
144
}
0 commit comments