generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete clients that no longer exist (#4741)
Fixes: #4734 Note that this does not fix the 'leftover kotlin .class files' problem, this needs to be fixed in Quarkus itself.
- Loading branch information
1 parent
44b906c
commit 379ffbd
Showing
4 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...e/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/PackageOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package xyz.block.ftl.deployment; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.deployment.util.FileUtil; | ||
|
||
public class PackageOutput implements AutoCloseable { | ||
|
||
private static final Logger log = Logger.getLogger(PackageOutput.class); | ||
|
||
private final Path outputDir; | ||
private final String packageName; | ||
private final Map<String, StringBuilder> files = new HashMap<>(); | ||
|
||
public PackageOutput(Path outputDir, String packageName) { | ||
this.outputDir = outputDir; | ||
this.packageName = packageName.replaceAll("\\.", "/"); | ||
} | ||
|
||
public StringBuilder writeKotlin(String fileName) throws IOException { | ||
StringBuilder value = new StringBuilder(); | ||
files.put(packageName + "/" + fileName + ".kt", value); | ||
return value; | ||
} | ||
|
||
public StringBuilder writeJava(String fileName) throws IOException { | ||
StringBuilder value = new StringBuilder(); | ||
files.put(fileName, value); | ||
return value; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
Path packageDir = outputDir.resolve(packageName); | ||
if (Files.exists(packageDir)) { | ||
try (var s = Files.list(packageDir)) { | ||
s.forEach(path -> { | ||
if (!files.containsKey(path.getFileName().toString())) { | ||
try { | ||
FileUtil.deleteIfExists(path); | ||
} catch (IOException e) { | ||
log.errorf(e, "Failed to delete path: %s", path); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
Files.createDirectories(packageDir); | ||
for (var e : files.entrySet()) { | ||
Path target = outputDir.resolve(e.getKey()); | ||
byte[] fileBytes = e.getValue().toString().getBytes(StandardCharsets.UTF_8); | ||
if (Files.exists(target)) { | ||
var existing = Files.readAllBytes(target); | ||
if (Arrays.equals(fileBytes, existing)) { | ||
continue; | ||
} | ||
} | ||
Files.write(target, fileBytes); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.