mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Proper handling of progress monitor in TeaVMBuilder
This commit is contained in:
parent
b7c07886a6
commit
ac2ffa42ff
|
@ -41,13 +41,17 @@ public class TeaVMBuilder extends IncrementalProjectBuilder {
|
|||
tool.setRuntime(RuntimeCopyOperation.SEPARATE);
|
||||
tool.setMinifying(false);
|
||||
tool.setMainClass(projectSettings.getMainClass());
|
||||
tool.setProgressListener(new TeaVMEclipseProgressListener(monitor));
|
||||
tool.setProgressListener(new TeaVMEclipseProgressListener(this, monitor, 10000));
|
||||
try {
|
||||
monitor.beginTask("Running TeaVM", 10000);
|
||||
tool.generate();
|
||||
removeMarkers();
|
||||
if (tool.getDependencyViolations().hasMissingItems()) {
|
||||
putMarkers(tool.getDependencyViolations());
|
||||
}
|
||||
if (!monitor.isCanceled()) {
|
||||
monitor.done();
|
||||
}
|
||||
} catch (TeaVMToolException e) {
|
||||
throw new CoreException(TeaVMEclipsePlugin.makeError(e));
|
||||
}
|
||||
|
|
|
@ -9,40 +9,82 @@ import org.teavm.vm.TeaVMProgressListener;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class TeaVMEclipseProgressListener implements TeaVMProgressListener {
|
||||
class TeaVMEclipseProgressListener implements TeaVMProgressListener {
|
||||
private TeaVMBuilder builder;
|
||||
private IProgressMonitor progressMonitor;
|
||||
private TeaVMPhase currentPhase;
|
||||
private int currentProgress;
|
||||
private int currentPhaseTotal;
|
||||
private int total;
|
||||
private int last;
|
||||
|
||||
public TeaVMEclipseProgressListener(IProgressMonitor progressMonitor) {
|
||||
public TeaVMEclipseProgressListener(TeaVMBuilder builder, IProgressMonitor progressMonitor, int total) {
|
||||
this.builder = builder;
|
||||
this.progressMonitor = progressMonitor;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) {
|
||||
String taskName = "Building";
|
||||
switch (phase) {
|
||||
case DECOMPILATION:
|
||||
taskName = "Decompiling";
|
||||
break;
|
||||
case DEPENDENCY_CHECKING:
|
||||
taskName = "Dependency checking";
|
||||
break;
|
||||
case DEVIRTUALIZATION:
|
||||
taskName = "Applying devirtualization";
|
||||
break;
|
||||
case LINKING:
|
||||
taskName = "Linking";
|
||||
break;
|
||||
case RENDERING:
|
||||
taskName = "Rendering";
|
||||
break;
|
||||
if (phase != currentPhase) {
|
||||
String taskName = "Building";
|
||||
switch (phase) {
|
||||
case DECOMPILATION:
|
||||
taskName = "Decompiling";
|
||||
break;
|
||||
case DEPENDENCY_CHECKING:
|
||||
taskName = "Dependency checking";
|
||||
break;
|
||||
case DEVIRTUALIZATION:
|
||||
taskName = "Applying devirtualization";
|
||||
break;
|
||||
case LINKING:
|
||||
taskName = "Linking";
|
||||
break;
|
||||
case RENDERING:
|
||||
taskName = "Rendering";
|
||||
break;
|
||||
}
|
||||
progressMonitor.subTask(taskName);
|
||||
}
|
||||
progressMonitor.beginTask(taskName, count);
|
||||
currentPhase = phase;
|
||||
currentProgress = 0;
|
||||
currentPhaseTotal = count;
|
||||
if (builder.isInterrupted()) {
|
||||
progressMonitor.setCanceled(true);
|
||||
}
|
||||
update();
|
||||
return progressMonitor.isCanceled() ? TeaVMProgressFeedback.CANCEL : TeaVMProgressFeedback.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeaVMProgressFeedback progressReached(int progress) {
|
||||
progressMonitor.worked(progress);
|
||||
currentProgress = progress;
|
||||
update();
|
||||
if (builder.isInterrupted()) {
|
||||
progressMonitor.setCanceled(true);
|
||||
}
|
||||
return progressMonitor.isCanceled() ? TeaVMProgressFeedback.CANCEL : TeaVMProgressFeedback.CONTINUE;
|
||||
}
|
||||
|
||||
private int getActual() {
|
||||
if (currentPhase == null) {
|
||||
return 0;
|
||||
}
|
||||
int totalPhases = TeaVMPhase.values().length;
|
||||
int min = total * currentPhase.ordinal() / totalPhases;
|
||||
if (currentPhaseTotal <= 0) {
|
||||
return min;
|
||||
}
|
||||
int max = total * (currentPhase.ordinal() + 1) / totalPhases - 1;
|
||||
return Math.min(max, min + (max - min) * currentProgress / currentPhaseTotal);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
int actual = getActual();
|
||||
if (actual > last) {
|
||||
progressMonitor.worked(actual - last);
|
||||
last = actual;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user