Skip to content

Commit

Permalink
Merge pull request #28210 from aloubyansky/remote-dev-delete-files-af…
Browse files Browse the repository at this point in the history
…ter-app-closed

In remote dev delete files after the app has been closed and before it is restarted
  • Loading branch information
aloubyansky authored Sep 28, 2022
2 parents 1188010 + 93f5b5b commit 3eaff0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.runner.DevModeMediator;
import io.quarkus.bootstrap.runner.Timing;
import io.quarkus.changeagent.ClassChangeAgent;
import io.quarkus.deployment.dev.DevModeContext.ModuleInfo;
Expand Down Expand Up @@ -602,15 +603,22 @@ public Set<String> syncState(Map<String, String> fileHashes) {
ret.add(i.getKey());
}
}
List<Path> removedFiles = List.of();
for (Map.Entry<String, String> remaining : ourHashes.entrySet()) {
String file = remaining.getKey();
if (file.endsWith("META-INF/MANIFEST.MF") || file.contains("META-INF/maven")
|| !file.contains("/")) {
//we have some filters, for files that we don't want to delete
continue;
}
log.info("Deleting removed file " + file);
Files.deleteIfExists(applicationRoot.resolve(file));
log.info("Scheduled for removal " + file);
if (removedFiles.isEmpty()) {
removedFiles = new ArrayList<>();
}
removedFiles.add(applicationRoot.resolve(file));
}
if (!removedFiles.isEmpty()) {
DevModeMediator.removedFiles.addLast(removedFiles);
}
return ret;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Deque;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.LinkedBlockingDeque;

import org.jboss.logging.Logger;

Expand All @@ -24,6 +26,8 @@ public class DevModeMediator {

protected static final Logger LOGGER = Logger.getLogger(DevModeMediator.class);

public static final Deque<List<Path>> removedFiles = new LinkedBlockingDeque<>();

static void doDevMode(Path appRoot) throws IOException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Path deploymentClassPath = appRoot.resolve(QuarkusEntryPoint.LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT);
Expand Down Expand Up @@ -88,6 +92,13 @@ public void run() {
closeable.close();
}
closeable = null;
final List<Path> pathsToDelete = removedFiles.pollFirst();
if (pathsToDelete != null) {
for (Path p : pathsToDelete) {
LOGGER.info("Deleting " + p);
Files.deleteIfExists(p);
}
}
try {
closeable = doStart(appRoot, deploymentClassPath);
} catch (Exception e) {
Expand Down

0 comments on commit 3eaff0a

Please sign in to comment.