1
1
package org .jabref .logic .search ;
2
2
3
3
import java .io .IOException ;
4
- import java .nio .file .Path ;
5
4
import java .sql .Connection ;
6
5
import java .sql .SQLException ;
7
- import java .time .Instant ;
8
- import java .time .format .DateTimeFormatter ;
9
- import java .util .HashMap ;
10
- import java .util .Map ;
11
6
12
7
import javax .sql .DataSource ;
13
8
14
9
import org .jabref .model .search .PostgreConstants ;
15
10
16
- import com .fasterxml .jackson .databind .ObjectMapper ;
17
11
import io .zonky .test .db .postgres .embedded .EmbeddedPostgres ;
18
12
import org .slf4j .Logger ;
19
13
import org .slf4j .LoggerFactory ;
22
16
23
17
public class PostgreServer {
24
18
private static final Logger LOGGER = LoggerFactory .getLogger (PostgreServer .class );
25
- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
26
- private static final Path POSTGRES_METADATA_FILE = Path .of (
27
- System .getProperty ("java.io.tmpdir" ),
28
- "jabref-postgres-info-" + ProcessHandle .current ().pid () + ".json"
29
- );
30
19
31
20
private final EmbeddedPostgres embeddedPostgres ;
32
21
private final DataSource dataSource ;
@@ -38,7 +27,7 @@ public PostgreServer() {
38
27
.setOutputRedirector (ProcessBuilder .Redirect .DISCARD )
39
28
.start ();
40
29
LOGGER .info ("Postgres server started, connection port: {}" , embeddedPostgres .getPort ());
41
- writeMetadataToFile (embeddedPostgres .getPort ());
30
+ PostgresMetadataWriter . write (embeddedPostgres .getPort ());
42
31
} catch (IOException e ) {
43
32
LOGGER .error ("Could not start Postgres server" , e );
44
33
this .embeddedPostgres = null ;
@@ -109,23 +98,4 @@ public void shutdown() {
109
98
}
110
99
}
111
100
}
112
-
113
- private void writeMetadataToFile (int port ) {
114
- try {
115
- Map <String , Object > meta = createPostgresMetadata (port );
116
- OBJECT_MAPPER .writerWithDefaultPrettyPrinter ().writeValue (POSTGRES_METADATA_FILE .toFile (), meta );
117
- LOGGER .info ("Postgres metadata file path: {}" , POSTGRES_METADATA_FILE );
118
- } catch (IOException e ) {
119
- LOGGER .warn ("Failed to write Postgres metadata file" , e );
120
- }
121
- }
122
-
123
- private Map <String , Object > createPostgresMetadata (int port ) {
124
- Map <String , Object > meta = new HashMap <>();
125
- meta .put ("javaPid" , ProcessHandle .current ().pid ());
126
- meta .put ("postgresPort" , port );
127
- meta .put ("startedBy" , "jabref" );
128
- meta .put ("startedAt" , DateTimeFormatter .ISO_INSTANT .format (Instant .now ()));
129
- return meta ;
130
- }
131
101
}
0 commit comments