// Path: src/main/java/hudson/plugins/disk_usage/unused/DiskUsageNotUsedDataCalculationThread.java
// @Extension
// public class DiskUsageNotUsedDataCalculationThread extends DiskUsageCalculation {
//     
//     //last scheduled task;
//     private static DiskUsageCalculation currentTask;
//     
//     public DiskUsageNotUsedDataCalculationThread(){        
//         super("Calculation of not used data"); 
//     } 
// 
//     @Override
//     public DiskUsageCalculation getLastTask() {
//         return currentTask;
//     }
// 
//     public CronTab getCronTab() throws ANTLRException{
//         if(!DiskUsageProjectActionFactory.DESCRIPTOR.isCalculationNotUsedDataEnabled()){
//             return new CronTab("0 1 * * 7");
//         }
//         String cron = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getCountIntervalForNotUsedData();
//         CronTab tab = new CronTab(cron);
//         return tab;
//     }
// 
//     @Override
//     protected void execute(TaskListener tl) throws IOException, InterruptedException {
//         if(!isCancelled() && startExecution()){
//             for(Item item : Jenkins.getInstance().getItems()){
//                 if(item instanceof AbstractProject){
//                     ProjectBuildChecker.valideBuildData((AbstractProject)item);
//                 }
//             }
//         }
//         DiskUsageUtil.calculateDiskUsageNotLoadedJobs(Jenkins.getInstance());
//         DiskUsageJenkinsAction.getInstance().actualizeCashedNotLoadedJobsData();
// //        plugin.getNotUsedDataDiskUsage().save();
//     }
//     
//     
// 
//     @Override
//     public AperiodicWork getNewInstance() {   
//         if(currentTask!=null){
//             currentTask.cancel();
//         }
//         else{
//             cancel();
//         }
//         currentTask = new DiskUsageNotUsedDataCalculationThread();
//         return currentTask;
//     }
//     
//     private boolean startExecution(){
//         DiskUsagePlugin plugin = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class);
//         if(!plugin.getConfiguration().isCalculationNotUsedDataEnabled())
//           return false;
//         return !isExecutingMoreThenOneTimes();
//     }
//     
//     
//     
// }


import hudson.Extension;
import hudson.model.Action;
import hudson.model.AperiodicWork;
import hudson.model.RootAction;
import hudson.plugins.disk_usage.unused.DiskUsageNotUsedDataCalculationThread;
import hudson.util.Graph;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import org.jfree.data.category.DefaultCategoryDataset;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
            datasetW.addValue(((Long) usage.getNonSlaveWorkspacesUsage()) / baseWorkspace, "non slave workspaces", label); 
        }
        
        //add current state
        if(getConfiguration().getShowFreeSpaceForJobDirectory()){
                dataset.addValue(((Long) jobsDir.getTotalSpace()) / base, "space for jobs directory", "current");
        }
        dataset.addValue(((Long) getAllDiskUsage(true)) / base, "all jobs", "current");
        dataset.addValue(((Long) getBuildsDiskUsage(null, null, true).get("all")) / base, "all builds", "current");
        datasetW.addValue(((Long) getAllDiskUsageWorkspace(true)) / baseWorkspace, "slave workspaces", "current");
        datasetW.addValue(((Long) getAllCustomOrNonSlaveWorkspaces(true)) / baseWorkspace, "non slave workspaces", "current");
        return  new DiskUsageGraph(dataset, unit, datasetW, unitWorkspace);
    }  

    public DiskUsageProjectActionFactory.DescriptorImpl getConfiguration(){
        return DiskUsageProjectActionFactory.DESCRIPTOR;
    }
    
    public BuildDiskUsageCalculationThread getBuildsDiskUsageThread(){
        return AperiodicWork.all().get(BuildDiskUsageCalculationThread.class);
    }
    
    public JobWithoutBuildsDiskUsageCalculation getJobsDiskUsageThread(){
        return AperiodicWork.all().get(JobWithoutBuildsDiskUsageCalculation.class);
    }
    
    public WorkspaceDiskUsageCalculationThread getWorkspaceDiskUsageThread(){
       return AperiodicWork.all().get(WorkspaceDiskUsageCalculationThread.class); 
    }
    
// Path: src/main/java/hudson/plugins/disk_usage/unused/DiskUsageNotUsedDataCalculationThread.java
// @Extension
// public class DiskUsageNotUsedDataCalculationThread extends DiskUsageCalculation {
//     
//     //last scheduled task;
//     private static DiskUsageCalculation currentTask;
//     
//     public DiskUsageNotUsedDataCalculationThread(){        
//         super("Calculation of not used data"); 
//     } 
// 
//     @Override
//     public DiskUsageCalculation getLastTask() {
//         return currentTask;
//     }
// 
//     public CronTab getCronTab() throws ANTLRException{
//         if(!DiskUsageProjectActionFactory.DESCRIPTOR.isCalculationNotUsedDataEnabled()){
//             return new CronTab("0 1 * * 7");
//         }
//         String cron = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class).getConfiguration().getCountIntervalForNotUsedData();
//         CronTab tab = new CronTab(cron);
//         return tab;
//     }
// 
//     @Override
//     protected void execute(TaskListener tl) throws IOException, InterruptedException {
//         if(!isCancelled() && startExecution()){
//             for(Item item : Jenkins.getInstance().getItems()){
//                 if(item instanceof AbstractProject){
//                     ProjectBuildChecker.valideBuildData((AbstractProject)item);
//                 }
//             }
//         }
//         DiskUsageUtil.calculateDiskUsageNotLoadedJobs(Jenkins.getInstance());
//         DiskUsageJenkinsAction.getInstance().actualizeCashedNotLoadedJobsData();
// //        plugin.getNotUsedDataDiskUsage().save();
//     }
//     
//     
// 
//     @Override
//     public AperiodicWork getNewInstance() {   
//         if(currentTask!=null){
//             currentTask.cancel();
//         }
//         else{
//             cancel();
//         }
//         currentTask = new DiskUsageNotUsedDataCalculationThread();
//         return currentTask;
//     }
//     
//     private boolean startExecution(){
//         DiskUsagePlugin plugin = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class);
//         if(!plugin.getConfiguration().isCalculationNotUsedDataEnabled())
//           return false;
//         return !isExecutingMoreThenOneTimes();
//     }
//     
//     
//     
// }


// Path: src/main/java/hudson/plugins/disk_usage/DiskUsageJenkinsAction.java
import hudson.Extension;
import hudson.model.Action;
import hudson.model.AperiodicWork;
import hudson.model.RootAction;
import hudson.plugins.disk_usage.unused.DiskUsageNotUsedDataCalculationThread;
import hudson.util.Graph;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import org.jfree.data.category.DefaultCategoryDataset;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

            datasetW.addValue(((Long) usage.getNonSlaveWorkspacesUsage()) / baseWorkspace, "non slave workspaces", label); 
        }
        
        //add current state
        if(getConfiguration().getShowFreeSpaceForJobDirectory()){
                dataset.addValue(((Long) jobsDir.getTotalSpace()) / base, "space for jobs directory", "current");
        }
        dataset.addValue(((Long) getAllDiskUsage(true)) / base, "all jobs", "current");
        dataset.addValue(((Long) getBuildsDiskUsage(null, null, true).get("all")) / base, "all builds", "current");
        datasetW.addValue(((Long) getAllDiskUsageWorkspace(true)) / baseWorkspace, "slave workspaces", "current");
        datasetW.addValue(((Long) getAllCustomOrNonSlaveWorkspaces(true)) / baseWorkspace, "non slave workspaces", "current");
        return  new DiskUsageGraph(dataset, unit, datasetW, unitWorkspace);
    }  

    public DiskUsageProjectActionFactory.DescriptorImpl getConfiguration(){
        return DiskUsageProjectActionFactory.DESCRIPTOR;
    }
    
    public BuildDiskUsageCalculationThread getBuildsDiskUsageThread(){
        return AperiodicWork.all().get(BuildDiskUsageCalculationThread.class);
    }
    
    public JobWithoutBuildsDiskUsageCalculation getJobsDiskUsageThread(){
        return AperiodicWork.all().get(JobWithoutBuildsDiskUsageCalculation.class);
    }
    
    public WorkspaceDiskUsageCalculationThread getWorkspaceDiskUsageThread(){
       return AperiodicWork.all().get(WorkspaceDiskUsageCalculationThread.class); 
    }
    
    public DiskUsageNotUsedDataCalculationThread getNotUsedDataDiskUsageThread(){