package org.jenkinsci.plugins.lucene.search.databackend;

import hudson.model.Job;

import java.util.LinkedList;
import java.util.List;

import org.apache.http.util.TextUtils;

public class ManagerProgress extends Progress {

    private List<Progress> history = new LinkedList<Progress>();

    private Progress currentProject;

    private long processedItems = 0;

    public void jobComplete() {
        if (currentProject != null) {
            currentProject.setSuccessfullyCompleted();
            currentProject.setFinished();
            this.getHistory().add(currentProject);
            setProcessedItems(getProcessedItems() + currentProject.getMax());
            this.setElapsedTime(System.currentTimeMillis() - startTime);
        }
    }

    @Override
    public void assertNoErrors() throws Exception {
        super.assertNoErrors();
        if (currentProject != null) {
            currentProject.assertNoErrors();
        }
    }

    public String getReasonsAsString() {
        if (!TextUtils.isEmpty(super.getReasonMessage())) {
            return super.getReasonMessage();
        } else if (currentProject != null) {
            return currentProject.getReasonMessage();
        }
        return "";
    }

    @Override
    public void completedWithErrors(Exception e) {
        super.completedWithErrors(e);
        currentProject.completedWithErrors(e);
        currentProject.setFinished();
        this.getHistory().add(currentProject);
    }

    public Progress beginCleanJob() {
        incCurrent();
        currentProject = new Progress("main clean");
        return currentProject;
    }

    public Progress beginJob(Job<?, ?> project) {
        StringBuilder builder = new StringBuilder();
        if (!project.getParent().getDisplayName().equalsIgnoreCase("jenkins")) {
            builder.append(project.getParent().getFullName() + " >> ");
        }
        builder.append(project.getName());
        incCurrent();
        currentProject = new Progress(builder.toString());
        return currentProject;
    }

    public List<Progress> getHistory() {
        return history;
    }

    public long getProcessedItems() {
        return processedItems;
    }

    public void setProcessedItems(long processedItems) {
        this.processedItems = processedItems;
    }
}
@@ -520,32 +520,34 @@
 .setFinished();%0A
+//
             this
@@ -1323,32 +1323,74 @@
 dWithErrors(e);%0A
+        if (currentProject != null) %7B%0A    
         currentP
@@ -1420,32 +1420,36 @@
 ors(e);%0A        
+ 
+   
 currentProject.s
@@ -1458,24 +1458,28 @@
 Finished();%0A
+    
         this
@@ -1509,24 +1509,34 @@
 ntProject);%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1633,19 +1633,65 @@
 ss(%22
-main clean%22
+clean all%22);%0A        this.getHistory().add(currentProject
 );%0A 
@@ -2113,24 +2113,71 @@
 oString());%0A
+        this.getHistory().add(currentProject);%0A
         retu

modify ManagerProgress