7171import java .util .concurrent .atomic .AtomicBoolean ;
7272import java .util .concurrent .locks .Lock ;
7373import java .util .concurrent .locks .ReentrantLock ;
74+ import java .util .function .Consumer ;
7475import java .util .stream .Stream ;
7576
7677import static java .nio .file .StandardOpenOption .CREATE ;
@@ -114,14 +115,14 @@ public class EmbeddedPostgres implements Closeable
114115 PgBinaryResolver pgBinaryResolver , ProcessBuilder .Redirect errorRedirector , ProcessBuilder .Redirect outputRedirector ) throws IOException
115116 {
116117 this (parentDirectory , dataDirectory , cleanDataDirectory , postgresConfig , localeConfig , port , connectConfig ,
117- pgBinaryResolver , errorRedirector , outputRedirector , DEFAULT_PG_STARTUP_WAIT , null );
118+ pgBinaryResolver , errorRedirector , outputRedirector , DEFAULT_PG_STARTUP_WAIT , null , null );
118119 }
119120
120121 EmbeddedPostgres (File parentDirectory , File dataDirectory , boolean cleanDataDirectory ,
121122 Map <String , String > postgresConfig , Map <String , String > localeConfig , int port , Map <String , String > connectConfig ,
122123 PgBinaryResolver pgBinaryResolver , ProcessBuilder .Redirect errorRedirector ,
123124 ProcessBuilder .Redirect outputRedirector , Duration pgStartupWait ,
124- File overrideWorkingDirectory ) throws IOException
125+ File overrideWorkingDirectory , Consumer < File > dataDirectoryCustomizer ) throws IOException
125126 {
126127 this .cleanDataDirectory = cleanDataDirectory ;
127128 this .postgresConfig = new HashMap <>(postgresConfig );
@@ -158,6 +159,11 @@ public class EmbeddedPostgres implements Closeable
158159 }
159160
160161 lock ();
162+
163+ if (dataDirectoryCustomizer != null ) {
164+ dataDirectoryCustomizer .accept (dataDirectory );
165+ }
166+
161167 startPostmaster ();
162168 }
163169
@@ -495,6 +501,7 @@ public static class Builder
495501 private final Map <String , String > connectConfig = new HashMap <>();
496502 private PgBinaryResolver pgBinaryResolver = DefaultPostgresBinaryResolver .INSTANCE ;
497503 private Duration pgStartupWait = DEFAULT_PG_STARTUP_WAIT ;
504+ private Consumer <File > dataDirectoryCustomizer ;
498505
499506 private ProcessBuilder .Redirect errRedirector = ProcessBuilder .Redirect .PIPE ;
500507 private ProcessBuilder .Redirect outRedirector = ProcessBuilder .Redirect .PIPE ;
@@ -573,6 +580,11 @@ public Builder setPgBinaryResolver(PgBinaryResolver pgBinaryResolver) {
573580 return this ;
574581 }
575582
583+ public Builder setDataDirectoryCustomizer (final Consumer <File > dataDirectoryCustomizer ) {
584+ this .dataDirectoryCustomizer = dataDirectoryCustomizer ;
585+ return this ;
586+ }
587+
576588 public EmbeddedPostgres start () throws IOException {
577589 if (builderPort == 0 )
578590 {
@@ -583,7 +595,7 @@ public EmbeddedPostgres start() throws IOException {
583595 }
584596 return new EmbeddedPostgres (parentDirectory , builderDataDirectory , builderCleanDataDirectory , config ,
585597 localeConfig , builderPort , connectConfig , pgBinaryResolver , errRedirector , outRedirector ,
586- pgStartupWait , overrideWorkingDirectory );
598+ pgStartupWait , overrideWorkingDirectory , dataDirectoryCustomizer );
587599 }
588600
589601 @ Override
0 commit comments