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
|
@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)
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -149,13 +149,15 @@ public final class TaskExecutor {
|
|||||||
try {
|
try {
|
||||||
task.setVariables(variables);
|
task.setVariables(variables);
|
||||||
|
|
||||||
try {
|
if (task.doPreExecute()) {
|
||||||
task.getScheduler().schedule(task::preExecute).get();
|
try {
|
||||||
} catch (ExecutionException e) {
|
task.getScheduler().schedule(task::preExecute).get();
|
||||||
if (e.getCause() instanceof Exception)
|
} catch (ExecutionException e) {
|
||||||
throw (Exception) e.getCause();
|
if (e.getCause() instanceof Exception)
|
||||||
else
|
throw (Exception) e.getCause();
|
||||||
throw e;
|
else
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doDependentsSucceeded = executeTasks(task.getDependents());
|
boolean doDependentsSucceeded = executeTasks(task.getDependents());
|
||||||
@@ -194,13 +196,15 @@ public final class TaskExecutor {
|
|||||||
if (doDependenciesSucceeded)
|
if (doDependenciesSucceeded)
|
||||||
task.setDependenciesSucceeded();
|
task.setDependenciesSucceeded();
|
||||||
|
|
||||||
try {
|
if (task.doPostExecute()) {
|
||||||
task.getScheduler().schedule(task::postExecute).get();
|
try {
|
||||||
} catch (ExecutionException e) {
|
task.getScheduler().schedule(task::postExecute).get();
|
||||||
if (e.getCause() instanceof Exception)
|
} catch (ExecutionException e) {
|
||||||
throw (Exception) e.getCause();
|
if (e.getCause() instanceof Exception)
|
||||||
else
|
throw (Exception) e.getCause();
|
||||||
throw e;
|
else
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = true;
|
flag = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user