From c80b29fba02a531b4fd4088e23045edb72e60297 Mon Sep 17 00:00:00 2001 From: Geert Bevin Date: Sat, 20 Jul 2024 15:56:53 -0400 Subject: [PATCH] Added project action to clear the cache. Ensure that the project gets refreshed each time a build action is ran. --- .../rife/bld/idea/execution/BldExecution.java | 14 +++++ .../project/BldProjectClearCacheAction.java | 53 +++++++++++++++++++ .../bld/idea/project/BldProjectWindow.java | 2 + .../resources/messages/BldBundle.properties | 2 + 4 files changed, 71 insertions(+) create mode 100644 src/main/java/rife/bld/idea/project/BldProjectClearCacheAction.java diff --git a/src/main/java/rife/bld/idea/execution/BldExecution.java b/src/main/java/rife/bld/idea/execution/BldExecution.java index f2ded5c..c468873 100644 --- a/src/main/java/rife/bld/idea/execution/BldExecution.java +++ b/src/main/java/rife/bld/idea/execution/BldExecution.java @@ -88,6 +88,18 @@ public boolean hasBldProperties() { return getBldProperties() != null; } + public VirtualFile getBldCache() { + var lib = projectDir_.findChild("lib"); + if (lib == null) return null; + var bld = lib.findChild("bld"); + if (bld == null) return null; + return bld.findChild("bld.cache"); + } + + public boolean hasBldCache() { + return getBldCache() != null; + } + public void setupProject() { projectDir_ = ProjectUtil.guessProjectDir(project_); if (projectDir_ == null) { @@ -192,6 +204,8 @@ public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType process_handler.runProcess(); runningBldProcesses_.remove(project_, process); + projectDir_.refresh(true, true); + return output; } diff --git a/src/main/java/rife/bld/idea/project/BldProjectClearCacheAction.java b/src/main/java/rife/bld/idea/project/BldProjectClearCacheAction.java new file mode 100644 index 0000000..908923f --- /dev/null +++ b/src/main/java/rife/bld/idea/project/BldProjectClearCacheAction.java @@ -0,0 +1,53 @@ +package rife.bld.idea.project; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.ActionUpdateThread; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import rife.bld.idea.execution.BldExecution; +import rife.bld.idea.utils.BldBundle; + +import java.io.IOException; + +final class BldProjectClearCacheAction extends AnAction implements DumbAware { + private final Project project_; + + public BldProjectClearCacheAction(Project project) { + super(BldBundle.messagePointer("bld.action.clearCache.name"), + BldBundle.messagePointer("bld.action.clearCache.description"), AllIcons.Actions.GC); + + project_ = project; + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + var cache = BldExecution.getInstance(project_).getBldCache(); + if (cache != null) { + ApplicationManager.getApplication().runWriteAction( + () -> { + try { + cache.delete(null); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + ); + } + } + + @Override + public void update(@NotNull AnActionEvent event) { + final var presentation = event.getPresentation(); + presentation.setText(BldBundle.messagePointer("bld.action.clearCache.name")); + presentation.setEnabled(BldExecution.getInstance(project_).hasBldCache()); + } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.EDT; + } +} diff --git a/src/main/java/rife/bld/idea/project/BldProjectWindow.java b/src/main/java/rife/bld/idea/project/BldProjectWindow.java index 8adc162..0981c6d 100644 --- a/src/main/java/rife/bld/idea/project/BldProjectWindow.java +++ b/src/main/java/rife/bld/idea/project/BldProjectWindow.java @@ -133,6 +133,8 @@ private JPanel createToolbarPanel() { group.add(new BldProjectEditMainAction(project_)); group.add(new BldProjectEditPropertiesAction(project_)); group.addSeparator(); + group.add(new BldProjectClearCacheAction(project_)); + group.addSeparator(); group.add(new BldProjectOfflineAction(project_)); final var action_toolbar = ActionManager.getInstance().createActionToolbar(BldConstants.BLD_EXPLORER_TOOLBAR, group, true); diff --git a/src/main/resources/messages/BldBundle.properties b/src/main/resources/messages/BldBundle.properties index bed6421..a3cd9c1 100644 --- a/src/main/resources/messages/BldBundle.properties +++ b/src/main/resources/messages/BldBundle.properties @@ -10,6 +10,8 @@ bld.action.offline.name=Toggle Offline Mode bld.action.offline.description=Work with or without internet bld.action.properties.name=Edit Properties bld.action.properties.description=Edit the bld wrapper properties +bld.action.clearCache.name=Clear Cache +bld.action.clearCache.description=Remove the bld cache progress.text.loading.bld.config=Loading bld configuration... bld.empty.text=No bld commands found. bld.project.commands=Commands