mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-2376: more code review fixes; changed 'release' method to 'finished'
This commit is contained in:
parent
ea9e1c2dda
commit
d8740850e4
5 changed files with 56 additions and 15 deletions
|
@ -33,8 +33,7 @@ import ghidra.program.model.listing.Program;
|
|||
import ghidra.util.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.exception.VersionException;
|
||||
import ghidra.util.task.Task;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import ghidra.util.task.*;
|
||||
|
||||
public class OpenProgramTask extends Task {
|
||||
|
||||
|
@ -108,7 +107,7 @@ public class OpenProgramTask extends Task {
|
|||
|
||||
@Override
|
||||
public void run(TaskMonitor taskMonitor) {
|
||||
this.monitor = taskMonitor;
|
||||
this.monitor = TaskMonitorService.getMonitor();
|
||||
|
||||
if (domainFileInfoList.size() > 1) {
|
||||
monitor.initialize(domainFileInfoList.size());
|
||||
|
|
|
@ -313,11 +313,35 @@ public class TaskMonitorServiceTest extends AbstractGhidraHeadedIntegrationTest
|
|||
}
|
||||
|
||||
/**
|
||||
* Verifies that once a monitor has been reset, the next call to retrieve a monitor will
|
||||
* return it as a primary
|
||||
* Verifies that calling finish on a primary monitor will cause it to
|
||||
* be set back to an uninitialized state.
|
||||
*/
|
||||
@Test
|
||||
public void testMonitorReset() {
|
||||
public void testMonitorFinishPrimary() {
|
||||
|
||||
TaskLauncher.launch(new Task("task") {
|
||||
@Override
|
||||
public void run(TaskMonitor monitor) throws CancelledException {
|
||||
|
||||
TaskMonitor monitor1 = TaskMonitorService.getMonitor();
|
||||
assertTrue(monitor1 instanceof TaskDialog);
|
||||
|
||||
monitor1.finished();
|
||||
|
||||
monitor1 = TaskMonitorService.getMonitor();
|
||||
assertTrue(monitor1 instanceof TaskDialog);
|
||||
}
|
||||
});
|
||||
|
||||
waitForTasks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that calling finish on a secondary monitor will NOT cause
|
||||
* it to be uninitialized (only primary monitors can reset this state)
|
||||
*/
|
||||
@Test
|
||||
public void testMonitorFinishSecondary() {
|
||||
|
||||
TaskLauncher.launch(new Task("task") {
|
||||
@Override
|
||||
|
@ -329,10 +353,10 @@ public class TaskMonitorServiceTest extends AbstractGhidraHeadedIntegrationTest
|
|||
monitor1 = TaskMonitorService.getMonitor();
|
||||
assertTrue(monitor1 instanceof SecondaryTaskMonitor);
|
||||
|
||||
monitor1.release();
|
||||
monitor1.finished();
|
||||
|
||||
monitor1 = TaskMonitorService.getMonitor();
|
||||
assertTrue(monitor1 instanceof TaskDialog);
|
||||
assertTrue(monitor1 instanceof SecondaryTaskMonitor);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -65,6 +65,17 @@ public class SecondaryTaskMonitor implements TaskMonitor {
|
|||
parentMonitor.setInitialized(init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Secondary monitors should not be able to reset progress or revert back
|
||||
* to an uninitialized state; hence the override.
|
||||
*/
|
||||
@Override
|
||||
public void finished() {
|
||||
synchronized (this) {
|
||||
setMessage("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelEnabled() {
|
||||
return parentMonitor.isCancelEnabled();
|
||||
|
|
|
@ -86,11 +86,19 @@ public class DefaultLanguageService implements LanguageService, ChangeListener {
|
|||
}
|
||||
|
||||
private void searchForProviders() {
|
||||
TaskMonitor monitor = TaskMonitorService.getMonitor();
|
||||
monitor.setMessage("Searching for language providers");
|
||||
try {
|
||||
Set<LanguageProvider> languageProviders =
|
||||
ClassSearcher.getInstances(LanguageProvider.class);
|
||||
|
||||
searchCompleted = true;
|
||||
processProviders(languageProviders);
|
||||
}
|
||||
finally {
|
||||
monitor.finished();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.lang.LanguageService#getLanguage(ghidra.program.model.lang.LanguageID)
|
||||
|
@ -100,7 +108,6 @@ public class DefaultLanguageService implements LanguageService, ChangeListener {
|
|||
|
||||
TaskMonitor monitor = TaskMonitorService.getMonitor();
|
||||
monitor.setMessage("Retrieving language: " + languageID);
|
||||
|
||||
try {
|
||||
LanguageInfo info = languageMap.get(languageID);
|
||||
|
||||
|
@ -112,7 +119,7 @@ public class DefaultLanguageService implements LanguageService, ChangeListener {
|
|||
return lang;
|
||||
}
|
||||
finally {
|
||||
monitor.release();
|
||||
monitor.finished();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public interface TaskMonitor {
|
|||
* monitor being returned from the {@link TaskMonitorService} on the next
|
||||
* invocation.
|
||||
*/
|
||||
public default void release() {
|
||||
public default void finished() {
|
||||
synchronized (this) {
|
||||
setMessage("");
|
||||
setProgress(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue