Skip to content

Commit 1d59196

Browse files
committed
Get project root for gradle
stop compose project when start has failed
1 parent 22d7377 commit 1d59196

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

extensions/devservices/deployment/src/main/java/io/quarkus/devservices/deployment/compose/ComposeDevServicesProcessor.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,20 @@ private ComposeRunningService startCompose(Executor buildExecutor, ComposeDevSer
250250
}
251251

252252
// Start compose
253-
compose.startAndWaitUntilServicesReady(buildExecutor);
253+
try {
254+
compose.start();
255+
} catch (Exception e) {
256+
if (cfg.stopServices) {
257+
try {
258+
compose.stop();
259+
} catch (Exception e1) {
260+
log.error("Failed to stop Compose dev services", e1);
261+
}
262+
}
263+
throw e;
264+
}
265+
// Wait for services to be ready
266+
compose.waitUntilServicesReady(buildExecutor);
254267
return new ComposeRunningService(compose, true);
255268
}
256269

@@ -294,15 +307,24 @@ static boolean isComposeFile(Path p) {
294307
return COMPOSE_FILE.matcher(p.getFileName().toString()).matches();
295308
}
296309

310+
static Path getProjectRoot() {
311+
String gradlePath = System.getProperty("gradle.project.path");
312+
if (gradlePath != null) {
313+
return Path.of(gradlePath);
314+
} else {
315+
return Paths.get(System.getProperty("user.dir", ".")).toAbsolutePath().normalize();
316+
}
317+
}
318+
297319
static List<File> filesFromConfigList(List<String> l) {
298320
return l.stream()
299-
.map(f -> Paths.get(f).toAbsolutePath().normalize())
321+
.map(f -> getProjectRoot().resolve(f).toAbsolutePath().normalize())
300322
.map(Path::toFile)
301323
.collect(Collectors.toList());
302324
}
303325

304326
static List<File> collectComposeFilesFromProjectRoot() throws RuntimeException {
305-
try (Stream<Path> list = Files.list(Paths.get(".").toAbsolutePath().normalize())) {
327+
try (Stream<Path> list = Files.list(getProjectRoot().toAbsolutePath().normalize())) {
306328
return list
307329
.filter(ComposeDevServicesProcessor::isComposeFile)
308330
.map(Path::toFile)

0 commit comments

Comments
 (0)