Do not schedule task if preExecute and postExecute are not overrided.
This commit is contained in:
@@ -104,6 +104,11 @@ public class LibraryDownloadTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPreExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preExecute() throws Exception {
|
||||
Optional<Path> libPath = cacheRepository.getLibrary(originalLibrary);
|
||||
@@ -135,6 +140,11 @@ public class LibraryDownloadTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPostExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postExecute() throws Exception {
|
||||
if (!cached)
|
||||
|
||||
@@ -64,6 +64,11 @@ public class ModpackUpdateTask extends Task {
|
||||
FileUtils.copyDirectory(repository.getVersionRoot(id).toPath(), backupFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPostExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postExecute() throws Exception {
|
||||
if (isDependenciesSucceeded()) {
|
||||
|
||||
@@ -96,6 +96,11 @@ public final class MultiMCModpackInstallTask extends Task {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPreExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preExecute() throws Exception {
|
||||
File run = repository.getRunDirectory(name);
|
||||
|
||||
@@ -145,6 +145,10 @@ public abstract class Task {
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public boolean doPreExecute() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
@@ -157,6 +161,10 @@ public abstract class Task {
|
||||
*/
|
||||
public abstract void execute() throws Exception;
|
||||
|
||||
public boolean doPostExecute() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InterruptedException if current thread is interrupted
|
||||
* @see Thread#isInterrupted
|
||||
|
||||
@@ -149,13 +149,15 @@ public final class TaskExecutor {
|
||||
try {
|
||||
task.setVariables(variables);
|
||||
|
||||
try {
|
||||
task.getScheduler().schedule(task::preExecute).get();
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof Exception)
|
||||
throw (Exception) e.getCause();
|
||||
else
|
||||
throw e;
|
||||
if (task.doPreExecute()) {
|
||||
try {
|
||||
task.getScheduler().schedule(task::preExecute).get();
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof Exception)
|
||||
throw (Exception) e.getCause();
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
boolean doDependentsSucceeded = executeTasks(task.getDependents());
|
||||
@@ -194,13 +196,15 @@ public final class TaskExecutor {
|
||||
if (doDependenciesSucceeded)
|
||||
task.setDependenciesSucceeded();
|
||||
|
||||
try {
|
||||
task.getScheduler().schedule(task::postExecute).get();
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof Exception)
|
||||
throw (Exception) e.getCause();
|
||||
else
|
||||
throw e;
|
||||
if (task.doPostExecute()) {
|
||||
try {
|
||||
task.getScheduler().schedule(task::postExecute).get();
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof Exception)
|
||||
throw (Exception) e.getCause();
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
flag = true;
|
||||
|
||||
Reference in New Issue
Block a user