Do not schedule task if preExecute and postExecute are not overrided.

This commit is contained in:
huanghongxun
2019-01-22 16:46:11 +08:00
parent 78fcc69d29
commit 28d002f6d3
5 changed files with 46 additions and 14 deletions

View File

@@ -104,6 +104,11 @@ public class LibraryDownloadTask extends Task {
} }
} }
@Override
public boolean doPreExecute() {
return true;
}
@Override @Override
public void preExecute() throws Exception { public void preExecute() throws Exception {
Optional<Path> libPath = cacheRepository.getLibrary(originalLibrary); Optional<Path> libPath = cacheRepository.getLibrary(originalLibrary);
@@ -135,6 +140,11 @@ public class LibraryDownloadTask extends Task {
} }
} }
@Override
public boolean doPostExecute() {
return true;
}
@Override @Override
public void postExecute() throws Exception { public void postExecute() throws Exception {
if (!cached) if (!cached)

View File

@@ -64,6 +64,11 @@ public class ModpackUpdateTask extends Task {
FileUtils.copyDirectory(repository.getVersionRoot(id).toPath(), backupFolder); FileUtils.copyDirectory(repository.getVersionRoot(id).toPath(), backupFolder);
} }
@Override
public boolean doPostExecute() {
return true;
}
@Override @Override
public void postExecute() throws Exception { public void postExecute() throws Exception {
if (isDependenciesSucceeded()) { if (isDependenciesSucceeded()) {

View File

@@ -96,6 +96,11 @@ public final class MultiMCModpackInstallTask extends Task {
return dependencies; return dependencies;
} }
@Override
public boolean doPreExecute() {
return true;
}
@Override @Override
public void preExecute() throws Exception { public void preExecute() throws Exception {
File run = repository.getRunDirectory(name); File run = repository.getRunDirectory(name);

View File

@@ -145,6 +145,10 @@ public abstract class Task {
this.variables = variables; this.variables = variables;
} }
public boolean doPreExecute() {
return false;
}
/** /**
* @throws InterruptedException if current thread is interrupted * @throws InterruptedException if current thread is interrupted
* @see Thread#isInterrupted * @see Thread#isInterrupted
@@ -157,6 +161,10 @@ public abstract class Task {
*/ */
public abstract void execute() throws Exception; public abstract void execute() throws Exception;
public boolean doPostExecute() {
return false;
}
/** /**
* @throws InterruptedException if current thread is interrupted * @throws InterruptedException if current thread is interrupted
* @see Thread#isInterrupted * @see Thread#isInterrupted

View File

@@ -149,6 +149,7 @@ public final class TaskExecutor {
try { try {
task.setVariables(variables); task.setVariables(variables);
if (task.doPreExecute()) {
try { try {
task.getScheduler().schedule(task::preExecute).get(); task.getScheduler().schedule(task::preExecute).get();
} catch (ExecutionException e) { } catch (ExecutionException e) {
@@ -157,6 +158,7 @@ public final class TaskExecutor {
else else
throw e; throw e;
} }
}
boolean doDependentsSucceeded = executeTasks(task.getDependents()); boolean doDependentsSucceeded = executeTasks(task.getDependents());
if (!doDependentsSucceeded && task.isRelyingOnDependents() || canceled) if (!doDependentsSucceeded && task.isRelyingOnDependents() || canceled)
@@ -194,6 +196,7 @@ public final class TaskExecutor {
if (doDependenciesSucceeded) if (doDependenciesSucceeded)
task.setDependenciesSucceeded(); task.setDependenciesSucceeded();
if (task.doPostExecute()) {
try { try {
task.getScheduler().schedule(task::postExecute).get(); task.getScheduler().schedule(task::postExecute).get();
} catch (ExecutionException e) { } catch (ExecutionException e) {
@@ -202,6 +205,7 @@ public final class TaskExecutor {
else else
throw e; throw e;
} }
}
flag = true; flag = true;
if (task.getSignificance().shouldLog()) { if (task.getSignificance().shouldLog()) {