@@ -101,6 +101,7 @@ public class EmbeddedPostgres implements Closeable
101
101
private final Map <String , String > postgresConfig ;
102
102
private final Map <String , String > localeConfig ;
103
103
private final Map <String , String > connectConfig ;
104
+ private final Map <String , String > environmentVariables ;
104
105
105
106
private volatile FileOutputStream lockStream ;
106
107
private volatile FileLock lock ;
@@ -111,14 +112,15 @@ public class EmbeddedPostgres implements Closeable
111
112
112
113
EmbeddedPostgres (File parentDirectory , File dataDirectory , boolean cleanDataDirectory ,
113
114
Map <String , String > postgresConfig , Map <String , String > localeConfig , int port , Map <String , String > connectConfig ,
114
- PgBinaryResolver pgBinaryResolver , ProcessBuilder .Redirect errorRedirector , ProcessBuilder .Redirect outputRedirector ) throws IOException
115
+ Map < String , String > environmentVariables , PgBinaryResolver pgBinaryResolver , ProcessBuilder .Redirect errorRedirector , ProcessBuilder .Redirect outputRedirector ) throws IOException
115
116
{
116
- this (parentDirectory , dataDirectory , cleanDataDirectory , postgresConfig , localeConfig , port , connectConfig ,
117
+ this (parentDirectory , dataDirectory , cleanDataDirectory , postgresConfig , localeConfig , port , connectConfig , environmentVariables ,
117
118
pgBinaryResolver , errorRedirector , outputRedirector , DEFAULT_PG_STARTUP_WAIT , null );
118
119
}
119
120
120
121
EmbeddedPostgres (File parentDirectory , File dataDirectory , boolean cleanDataDirectory ,
121
122
Map <String , String > postgresConfig , Map <String , String > localeConfig , int port , Map <String , String > connectConfig ,
123
+ Map <String , String > environmentVariables ,
122
124
PgBinaryResolver pgBinaryResolver , ProcessBuilder .Redirect errorRedirector ,
123
125
ProcessBuilder .Redirect outputRedirector , Duration pgStartupWait ,
124
126
File overrideWorkingDirectory ) throws IOException
@@ -127,6 +129,7 @@ public class EmbeddedPostgres implements Closeable
127
129
this .postgresConfig = new HashMap <>(postgresConfig );
128
130
this .localeConfig = new HashMap <>(localeConfig );
129
131
this .connectConfig = new HashMap <>(connectConfig );
132
+ this .environmentVariables = new HashMap <>(environmentVariables );
130
133
this .port = port ;
131
134
this .pgDir = prepareBinaries (pgBinaryResolver , overrideWorkingDirectory );
132
135
this .errorRedirector = errorRedirector ;
@@ -490,6 +493,7 @@ public static class Builder
490
493
private File builderDataDirectory ;
491
494
private final Map <String , String > config = new HashMap <>();
492
495
private final Map <String , String > localeConfig = new HashMap <>();
496
+ private final Map <String , String > environmentVariables = new HashMap <>();
493
497
private boolean builderCleanDataDirectory = true ;
494
498
private int builderPort = 0 ;
495
499
private final Map <String , String > connectConfig = new HashMap <>();
@@ -546,6 +550,11 @@ public Builder setConnectConfig(String key, String value) {
546
550
connectConfig .put (key , value );
547
551
return this ;
548
552
}
553
+
554
+ public Builder setEnvironmentVariable (String key , String value ) {
555
+ environmentVariables .put (key , value );
556
+ return this ;
557
+ }
549
558
550
559
public Builder setOverrideWorkingDirectory (File workingDirectory ) {
551
560
overrideWorkingDirectory = workingDirectory ;
@@ -582,7 +591,7 @@ public EmbeddedPostgres start() throws IOException {
582
591
builderDataDirectory = Files .createTempDirectory ("epg" ).toFile ();
583
592
}
584
593
return new EmbeddedPostgres (parentDirectory , builderDataDirectory , builderCleanDataDirectory , config ,
585
- localeConfig , builderPort , connectConfig , pgBinaryResolver , errRedirector , outRedirector ,
594
+ localeConfig , builderPort , connectConfig , environmentVariables , pgBinaryResolver , errRedirector , outRedirector ,
586
595
pgStartupWait , overrideWorkingDirectory );
587
596
}
588
597
@@ -602,6 +611,7 @@ public boolean equals(Object o) {
602
611
Objects .equals (config , builder .config ) &&
603
612
Objects .equals (localeConfig , builder .localeConfig ) &&
604
613
Objects .equals (connectConfig , builder .connectConfig ) &&
614
+ Objects .equals (environmentVariables , builder .environmentVariables ) &&
605
615
Objects .equals (pgBinaryResolver , builder .pgBinaryResolver ) &&
606
616
Objects .equals (pgStartupWait , builder .pgStartupWait ) &&
607
617
Objects .equals (errRedirector , builder .errRedirector ) &&
@@ -610,7 +620,7 @@ public boolean equals(Object o) {
610
620
611
621
@ Override
612
622
public int hashCode () {
613
- return Objects .hash (parentDirectory , builderDataDirectory , config , localeConfig , builderCleanDataDirectory , builderPort , connectConfig , pgBinaryResolver , pgStartupWait , errRedirector , outRedirector );
623
+ return Objects .hash (parentDirectory , builderDataDirectory , config , localeConfig , builderCleanDataDirectory , builderPort , connectConfig , environmentVariables , pgBinaryResolver , pgStartupWait , errRedirector , outRedirector );
614
624
}
615
625
}
616
626
@@ -894,6 +904,8 @@ public void applyTo(ProcessBuilder builder, List<String> arguments) {
894
904
command .addAll (arguments );
895
905
896
906
builder .command (command );
907
+
908
+ builder .environment ().putAll (environmentVariables );
897
909
}
898
910
}
899
911
}
0 commit comments