Now you cannot run tasks second time or if requirements are not met
This commit is contained in:
		@@ -17,6 +17,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package ru.windcorp.progressia.common.modules;
 | 
			
		||||
 | 
			
		||||
import ru.windcorp.jputil.chars.StringUtil;
 | 
			
		||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
 | 
			
		||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
 | 
			
		||||
 | 
			
		||||
@@ -43,10 +44,26 @@ public abstract class Task
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void run() {
 | 
			
		||||
		if (!canRun()) {
 | 
			
		||||
			ArrayList<Task> undoneTasks = new ArrayList<>();
 | 
			
		||||
			for (Task j : requiredTasks) {
 | 
			
		||||
				if (!j.isDone()) {
 | 
			
		||||
					undoneTasks.add(j);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			throw CrashReports.report(new Throwable(),
 | 
			
		||||
					"The following required Tasks are not done:\n%s",
 | 
			
		||||
					StringUtil.iterableToString(undoneTasks, "\n"));
 | 
			
		||||
		} else if (isDone()) {
 | 
			
		||||
			throw CrashReports.report(new Throwable(),
 | 
			
		||||
					"The task cannot be performed second time");
 | 
			
		||||
		} else {
 | 
			
		||||
			isActive = true;
 | 
			
		||||
			perform();
 | 
			
		||||
			isDone = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//This method will be invoked by Run()
 | 
			
		||||
	protected abstract void perform();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user