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.setRuntime(RuntimeCopyOperation.SEPARATE);
|
||||||
tool.setMinifying(false);
|
tool.setMinifying(false);
|
||||||
tool.setMainClass(projectSettings.getMainClass());
|
tool.setMainClass(projectSettings.getMainClass());
|
||||||
tool.setProgressListener(new TeaVMEclipseProgressListener(monitor));
|
tool.setProgressListener(new TeaVMEclipseProgressListener(this, monitor, 10000));
|
||||||
try {
|
try {
|
||||||
|
monitor.beginTask("Running TeaVM", 10000);
|
||||||
tool.generate();
|
tool.generate();
|
||||||
removeMarkers();
|
removeMarkers();
|
||||||
if (tool.getDependencyViolations().hasMissingItems()) {
|
if (tool.getDependencyViolations().hasMissingItems()) {
|
||||||
putMarkers(tool.getDependencyViolations());
|
putMarkers(tool.getDependencyViolations());
|
||||||
}
|
}
|
||||||
|
if (!monitor.isCanceled()) {
|
||||||
|
monitor.done();
|
||||||
|
}
|
||||||
} catch (TeaVMToolException e) {
|
} catch (TeaVMToolException e) {
|
||||||
throw new CoreException(TeaVMEclipsePlugin.makeError(e));
|
throw new CoreException(TeaVMEclipsePlugin.makeError(e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,40 +9,82 @@ import org.teavm.vm.TeaVMProgressListener;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class TeaVMEclipseProgressListener implements TeaVMProgressListener {
|
class TeaVMEclipseProgressListener implements TeaVMProgressListener {
|
||||||
|
private TeaVMBuilder builder;
|
||||||
private IProgressMonitor progressMonitor;
|
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.progressMonitor = progressMonitor;
|
||||||
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) {
|
public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) {
|
||||||
String taskName = "Building";
|
if (phase != currentPhase) {
|
||||||
switch (phase) {
|
String taskName = "Building";
|
||||||
case DECOMPILATION:
|
switch (phase) {
|
||||||
taskName = "Decompiling";
|
case DECOMPILATION:
|
||||||
break;
|
taskName = "Decompiling";
|
||||||
case DEPENDENCY_CHECKING:
|
break;
|
||||||
taskName = "Dependency checking";
|
case DEPENDENCY_CHECKING:
|
||||||
break;
|
taskName = "Dependency checking";
|
||||||
case DEVIRTUALIZATION:
|
break;
|
||||||
taskName = "Applying devirtualization";
|
case DEVIRTUALIZATION:
|
||||||
break;
|
taskName = "Applying devirtualization";
|
||||||
case LINKING:
|
break;
|
||||||
taskName = "Linking";
|
case LINKING:
|
||||||
break;
|
taskName = "Linking";
|
||||||
case RENDERING:
|
break;
|
||||||
taskName = "Rendering";
|
case RENDERING:
|
||||||
break;
|
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;
|
return progressMonitor.isCanceled() ? TeaVMProgressFeedback.CANCEL : TeaVMProgressFeedback.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TeaVMProgressFeedback progressReached(int progress) {
|
public TeaVMProgressFeedback progressReached(int progress) {
|
||||||
progressMonitor.worked(progress);
|
currentProgress = progress;
|
||||||
|
update();
|
||||||
|
if (builder.isInterrupted()) {
|
||||||
|
progressMonitor.setCanceled(true);
|
||||||
|
}
|
||||||
return progressMonitor.isCanceled() ? TeaVMProgressFeedback.CANCEL : TeaVMProgressFeedback.CONTINUE;
|
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