Skip to content

Commit

Permalink
Added project action to clear the cache.
Browse files Browse the repository at this point in the history
Ensure that the project gets refreshed each time a build action is ran.
  • Loading branch information
gbevin committed Jul 20, 2024
1 parent e06a197 commit c80b29f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/rife/bld/idea/execution/BldExecution.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/java/rife/bld/idea/project/BldProjectWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/BldBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c80b29f

Please sign in to comment.