1+ /*
2+ * Copyright (C) 2025 DiffPlug
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
116package com .diffplug .webtools .flywayjooq ;
217
318import com .diffplug .common .base .Either ;
419import com .diffplug .common .base .Errors ;
520import com .diffplug .common .base .Throwables ;
621import com .diffplug .common .base .Throwing ;
22+ import com .diffplug .webtools .node .SetupCleanup ;
723import com .google .common .collect .ImmutableList ;
824import com .google .common .io .ByteStreams ;
925import com .google .common .io .Files ;
1531import com .palantir .docker .compose .execution .DockerCompose ;
1632import com .palantir .docker .compose .execution .DockerComposeExecArgument ;
1733import com .palantir .docker .compose .execution .DockerComposeExecOption ;
18- import org .flywaydb .core .Flyway ;
19- import org .gradle .api .GradleException ;
20- import org .postgresql .ds .PGSimpleDataSource ;
21- import webtools .Env ;
22- import com .diffplug .webtools .node .SetupCleanup ;
23-
2434import java .io .*;
2535import java .nio .charset .StandardCharsets ;
2636import java .nio .file .FileVisitResult ;
2939import java .nio .file .attribute .BasicFileAttributes ;
3040import java .util .*;
3141import java .util .concurrent .TimeUnit ;
42+ import org .flywaydb .core .Flyway ;
43+ import org .gradle .api .GradleException ;
44+ import org .postgresql .ds .PGSimpleDataSource ;
45+ import webtools .Env ;
3246
3347public class SetupCleanupDockerFlyway implements Serializable {
3448 private static final long serialVersionUID = -8606504827780656288L ;
@@ -71,7 +85,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
7185 }
7286 }
7387
74-
7588 void forceStop (File projectDir ) throws Exception {
7689 try {
7790 new Impl ().doStop (this );
@@ -107,8 +120,8 @@ PGSimpleDataSource getConnection() throws IOException {
107120 port = Integer .parseInt (connectionProps .getProperty ("port" ));
108121 }
109122 PGSimpleDataSource dataSource = new PGSimpleDataSource ();
110- dataSource .setServerNames (new String [] {ip });
111- dataSource .setPortNumbers (new int [] {port });
123+ dataSource .setServerNames (new String []{ip });
124+ dataSource .setPortNumbers (new int []{port });
112125 dataSource .setUser ("root" );
113126 dataSource .setPassword ("password" );
114127 dataSource .setDatabaseName ("template1" );
@@ -144,7 +157,6 @@ public static void keepTrying(Throwing.Runnable toAttempt) {
144157 }
145158 }
146159
147-
148160 DockerComposeRule rule () {
149161 return DockerComposeRule .builder ()
150162 .file (dockerComposeFile .getAbsolutePath ())
@@ -187,19 +199,19 @@ protected void doStart(SetupCleanupDockerFlyway key) throws IOException, Interru
187199 PGSimpleDataSource postgres = key .getConnection ();
188200 keepTrying (() -> {
189201 Flyway .configure ()
190- .dataSource (postgres )
191- .locations ("filesystem:" + key .flywayMigrations .getAbsolutePath ())
192- .schemas ("public" )
193- .load ()
194- .migrate ();
202+ .dataSource (postgres )
203+ .locations ("filesystem:" + key .flywayMigrations .getAbsolutePath ())
204+ .schemas ("public" )
205+ .load ()
206+ .migrate ();
195207 });
196208
197209 // write out the schema to disk
198210 String schema ;
199211 List <String > pg_dump_args = Arrays .asList ("-d" , "template1" , "-U" , postgres .getUser (), "--schema-only" , "--restrict-key=reproduciblediff" );
200212 if (rule == null ) {
201- Process process = Runtime .getRuntime ().exec (ImmutableList .<String >builder ().add (
202- "pg_dump" ,
213+ Process process = Runtime .getRuntime ().exec (ImmutableList .<String > builder ().add (
214+ "pg_dump" ,
203215 "-h" , GITHUB_IP , "-p" , Integer .toString (GITHUB_PORT ))
204216 .addAll (pg_dump_args ).build ().toArray (new String [0 ]));
205217 // swallow errors (not great...)
@@ -212,7 +224,7 @@ protected void doStart(SetupCleanupDockerFlyway key) throws IOException, Interru
212224 schema = rule .dockerCompose ().exec (DockerComposeExecOption .noOptions (),
213225 "postgres" , DockerComposeExecArgument .arguments (ImmutableList .builder ().add ("pg_dump" )
214226 .addAll (pg_dump_args )
215- .build ().toArray (new String [0 ])));
227+ .build ().toArray (new String [0 ])));
216228 }
217229 Files .createParentDirs (key .flywaySchemaDump );
218230 Files .write (schema , key .flywaySchemaDump , StandardCharsets .UTF_8 );
0 commit comments