Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Feb 7, 2024
1 parent 1c95818 commit 730d651
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public interface AppLandCommandLineService extends Disposable {

/**
* Launches the AppLand CLI tools for the given directory.
* It'll stop any running service, which is serving a subdirectory the given path.
*
* @param directory Directory, where the service should be launched.
* @param waitForProcessTermination Wait for termination of processes, which are no longer needed. This is mostly useful for test cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,9 @@ public synchronized void start(@NotNull VirtualFile directory, boolean waitForPr
return;
}

for (var it = processes.entrySet().iterator(); it.hasNext(); ) {
var dirAndProcesses = it.next();

// stop early, if there are already processes for exactly the directory.
if (directory.equals(dirAndProcesses.getKey())) {
return;
}

// stop processes serving for subdirectories of the new directory
if (VfsUtilCore.isAncestor(directory, dirAndProcesses.getKey(), false)) {
it.remove();
stopLocked(dirAndProcesses.getValue(), waitForProcessTermination);
}
}

// verify that no other process is serving a parent directory
// stop early, if there are already processes for exactly this directory.
for (var entry : processes.entrySet()) {
if (VfsUtilCore.isAncestor(entry.getKey(), directory, true)) {
LOG.error("Attempted to launch a new service for a directory, which is already being processed");
if (directory.equals(entry.getKey())) {
return;
}
}
Expand Down Expand Up @@ -356,20 +340,6 @@ private void doRefreshForOpenProjectsLocked() {
}
}

// remove processes of roots, which no longer have a matching content root in a project
// or which don't match the settings anymore. We need to launch the scanner when "enableFindings" changes.
// We're iterating on a copy, because stop() is called inside the loop and modifies "processes"
for (var entry : List.copyOf(processes.entrySet())) {
var activeRoot = entry.getKey();
if (!topLevelRoots.contains(activeRoot)) {
try {
stop(activeRoot, false);
} catch (Exception e) {
LOG.warn("Error stopping processes for root: " + activeRoot.getPath());
}
}
}

// launch missing cli processes
for (var root : topLevelRoots) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,28 @@ public void setupListener() {
public void directoryTree() throws Exception {
var service = AppLandCommandLineService.getInstance();

var tempFile = myFixture.createFile("test.txt", "");
var parentDir = tempFile.getParent();
var parentDir = myFixture.createFile("test.txt", "").getParent();
assertNotNull(parentDir);

var nestedFile = myFixture.addFileToProject("parent/child/file.txt", "");
assertNotNull(nestedFile.getParent());

var nestedDir = nestedFile.getParent().getVirtualFile();
var nestedDir = myFixture.addFileToProject("parent/child/file.txt", "").getParent().getVirtualFile();
assertNotNull(nestedDir);

addContentRootAndLaunchService(nestedDir);
assertEmptyRoots();

// creating an appmap.yml file must trigger launch of the AppMap processes
createAppMapYaml(nestedDir);
assertActiveRoots(nestedDir);

addContentRootAndLaunchService(parentDir);
assertFalse(service.isRunning(parentDir, false));
assertFalse("Service must not execute for a directory without appmap.yaml", service.isRunning(parentDir, false));

createAppMapYaml(parentDir);
addContentRootAndLaunchService(parentDir);
assertTrue("Service must launch with appmap.yaml present", service.isRunning(parentDir, true));
assertTrue("Service must launch with appmap.yaml present", service.isRunning(parentDir, false));
assertActiveRoots(parentDir, nestedDir);

assertTrue(service.isRunning(parentDir, true));
assertTrue(service.isRunning(parentDir, false));
assertTrue("Processes of child directories must keep running", service.isRunning(nestedDir, true));
assertTrue(service.isRunning(nestedDir, false));
assertActiveRoots(parentDir, nestedDir);
Expand Down

0 comments on commit 730d651

Please sign in to comment.