mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-10-23 05:31:02 +00:00
Merge remote-tracking branch 'origin/GP-3554_dev747368_upwtm_1L_checkCancelled'
This commit is contained in:
commit
231c56d328
|
@ -89,7 +89,7 @@ public class DtbAnalyzer extends FileFormatAnalyzer {
|
|||
|
||||
monitor.initialize(header.getEntries().size());
|
||||
for (int i = 0; i < header.getEntries().size(); ++i) {
|
||||
monitor.checkCanceled();
|
||||
monitor.checkCancelled();
|
||||
monitor.incrementProgress(1);
|
||||
|
||||
DtTableEntry entry = header.getEntries().get(i);
|
||||
|
|
|
@ -79,7 +79,7 @@ public class FdtAnalyzer extends FileFormatAnalyzer {
|
|||
Address address = program.getMinAddress();
|
||||
|
||||
while (true) {
|
||||
monitor.checkCanceled();
|
||||
monitor.checkCancelled();
|
||||
|
||||
if (address.compareTo(program.getMaxAddress()) >= 0) {
|
||||
break;
|
||||
|
|
|
@ -24,6 +24,9 @@ import ghidra.util.exception.CancelledException;
|
|||
* <p>
|
||||
* This class supports cancelling and cancel listener notification. Cancelling must be enabled
|
||||
* via {@link #setCancelEnabled(boolean)}.
|
||||
* <p>
|
||||
* Use {@link WrappingTaskMonitor} if you need to override an existing TaskMonitor
|
||||
* instance's behavior.
|
||||
*/
|
||||
public class TaskMonitorAdapter implements TaskMonitor {
|
||||
|
||||
|
@ -54,6 +57,7 @@ public class TaskMonitorAdapter implements TaskMonitor {
|
|||
return cancelled;
|
||||
}
|
||||
|
||||
@Deprecated(since = "10.3")
|
||||
@Override
|
||||
public void checkCanceled() throws CancelledException {
|
||||
if (cancelled) {
|
||||
|
@ -61,6 +65,13 @@ public class TaskMonitorAdapter implements TaskMonitor {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCancelled() throws CancelledException {
|
||||
if (cancelled) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
// do nothing
|
||||
|
|
|
@ -133,11 +133,17 @@ public class WrappingTaskMonitor implements TaskMonitor {
|
|||
return delegate.isIndeterminate();
|
||||
}
|
||||
|
||||
@Deprecated(since = "10.3")
|
||||
@Override
|
||||
public void checkCanceled() throws CancelledException {
|
||||
delegate.checkCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCancelled() throws CancelledException {
|
||||
delegate.checkCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementProgress(long incrementAmount) {
|
||||
delegate.incrementProgress(incrementAmount);
|
||||
|
|
|
@ -15,48 +15,29 @@
|
|||
*/
|
||||
package ghidra.util.task;
|
||||
|
||||
import ghidra.util.exception.CancelledException;
|
||||
|
||||
/**
|
||||
* A class that is meant to wrap a {@link TaskMonitor} when you do not know the maximum value
|
||||
* of the progress.
|
||||
*/
|
||||
public class UnknownProgressWrappingTaskMonitor extends TaskMonitorAdapter {
|
||||
|
||||
private TaskMonitor delegate;
|
||||
public class UnknownProgressWrappingTaskMonitor extends WrappingTaskMonitor {
|
||||
|
||||
public UnknownProgressWrappingTaskMonitor(TaskMonitor delegate, long startMaximum) {
|
||||
this.delegate = delegate;
|
||||
super(delegate);
|
||||
delegate.setMaximum(startMaximum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
delegate.setMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgress(long value) {
|
||||
delegate.setProgress(value);
|
||||
super.setProgress(value);
|
||||
maybeUpdateMaximum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementProgress(long incrementAmount) {
|
||||
delegate.incrementProgress(incrementAmount);
|
||||
super.incrementProgress(incrementAmount);
|
||||
maybeUpdateMaximum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isCancelled() {
|
||||
return delegate.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCancelled() throws CancelledException {
|
||||
delegate.checkCancelled();
|
||||
}
|
||||
|
||||
private void maybeUpdateMaximum() {
|
||||
long currentMaximum = delegate.getMaximum();
|
||||
long progress = delegate.getProgress();
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.util.task;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import generic.test.AbstractGenericTest;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
|
||||
public class UnknownProgressWrappingTaskMonitorTest extends AbstractGenericTest {
|
||||
|
||||
@Test
|
||||
public void testUPWTM_checkCanceled_1L_vs_2L() {
|
||||
TaskMonitorAdapter monitor = new TaskMonitorAdapter(true);
|
||||
monitor.cancel();
|
||||
UnknownProgressWrappingTaskMonitor upwtm =
|
||||
new UnknownProgressWrappingTaskMonitor(monitor, 100);
|
||||
try {
|
||||
upwtm.checkCanceled();
|
||||
fail();
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
// good
|
||||
}
|
||||
|
||||
try {
|
||||
upwtm.checkCancelled();
|
||||
fail();
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
// good
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user