Skip to content

Commit

Permalink
bugfix: remove stale empty /.mvn directory from starter
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Dec 13, 2024
1 parent 5b23fb7 commit c52de84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
Expand All @@ -54,9 +55,8 @@ public class ArchetypeGenerator {
public record Parameter(@NonNull String key, String value) { }
public record ReturnValue(Path temporaryPath, int status, String output) implements AutoCloseable {
@Override
@SneakyThrows(IOException.class)
public void close() {
cleanup(this);
cleanup(temporaryPath);
}
}

Expand All @@ -78,9 +78,11 @@ public ArchetypeGenerator(@ConfigProperty(name = "com.flowlogix.starter.generato
public ReturnValue generateArchetype(Parameter[] inputParameters) {
log.debug("Available Permits: {}", semaphore.availablePermits());
semaphore.acquire();
Optional<Path> rootMavenPath = Optional.empty();
try {
Path temporaryPath = getTemporaryPath();
Files.writeString(temporaryPath.resolve(".mvn").resolve("jvm.config"),
rootMavenPath = Optional.of(temporaryPath.resolve(".mvn"));
Files.writeString(rootMavenPath.get().resolve("jvm.config"),
jvmOptions + System.lineSeparator());
String projectDirectory = temporaryPath.toString();
List<String> options = generateMavenCommandLine(inputParameters, projectDirectory);
Expand All @@ -93,6 +95,7 @@ public ReturnValue generateArchetype(Parameter[] inputParameters) {
return new ReturnValue(temporaryPath, -1, e.getMessage());
}
} finally {
rootMavenPath.ifPresent(ArchetypeGenerator::cleanup);
semaphore.release();
}
}
Expand Down Expand Up @@ -163,8 +166,9 @@ private static ReturnValue zipToStream(ReturnValue returnValue, OutputStream zip
return returnValue;
}

private static void cleanup(ReturnValue returnValue) throws IOException {
try (var paths = Files.walk(returnValue.temporaryPath)) {
@SneakyThrows(IOException.class)
private static void cleanup(Path path) {
try (var paths = Files.walk(path)) {
paths.sorted(Comparator.reverseOrder()).forEach(ArchetypeGenerator::deleteFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void generateArchetype() throws IOException, ExecutionException, InterruptedExce
temporaryPath = result.temporaryPath();
log.debug("Generated project: {}", result.output());
assertThat(temporaryPath).isNotEmptyDirectory();
assertThat(temporaryPath.resolve(".mvn")).doesNotExist();
}
assertThat(temporaryPath).doesNotExist();
}
Expand Down

0 comments on commit c52de84

Please sign in to comment.