Skip to content

Commit

Permalink
Order builds by build number for graph show in project page
Browse files Browse the repository at this point in the history
  • Loading branch information
froque committed Feb 8, 2023
1 parent 1b1f8c1 commit a53a6a6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/hudson/plugins/disk_usage/ProjectDiskUsageAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jenkins.model.Jenkins;
import org.jfree.data.category.DefaultCategoryDataset;
import org.kohsuke.stapler.export.ExportedBean;
Expand Down Expand Up @@ -302,8 +304,10 @@ public Graph getGraph() throws IOException {
Long jobRootDirDiskUsage = getJobRootDirDiskUsage();
maxValue = jobRootDirDiskUsage;
// First iteration just to get scale of the y-axis
ArrayList<DiskUsageBuildInformation> builds = new ArrayList<>();
builds.addAll(property.getDiskUsageOfBuilds());
final var builds = property.getDiskUsageOfBuilds()
.stream()
.sorted((a, b) -> b.getNumber() - a.getNumber())
.collect(Collectors.toList());
// do it in reverse order
for(int i = builds.size() - 1; i >= 0; i--) {
DiskUsageBuildInformation build = builds.get(i);
Expand All @@ -320,16 +324,12 @@ public Graph getGraph() throws IOException {
double workspaceBase = Math.pow(1024, workspaceFloor);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
for(Object[] usage: usages) {
Integer label = (Integer) usage[0];
dataset.addValue(((Long) usage[1]) / base,
Messages.DiskUsage_Graph_JobDirectory(), label);
dataset.addValue(((Long) usage[2]) / base,
Messages.DiskUsage_Graph_BuildDirectory(), label);
dataset2.addValue(((Long) usage[3]) / workspaceBase,
Messages.DiskUsage_Graph_AgentWorkspaces(), label);
dataset2.addValue(((Long) usage[4]) / workspaceBase,
Messages.DiskUsage_Graph_NonAgentWorkspaces(), label);
for (Object[] usage : usages) {
String label = "#" + (Integer) usage[0];
dataset.addValue(((Long) usage[1]) / base, Messages.DiskUsage_Graph_JobDirectory(), label);
dataset.addValue(((Long) usage[2]) / base, Messages.DiskUsage_Graph_BuildDirectory(), label);
dataset2.addValue(((Long) usage[3]) / workspaceBase, Messages.DiskUsage_Graph_AgentWorkspaces(), label);
dataset2.addValue(((Long) usage[4]) / workspaceBase, Messages.DiskUsage_Graph_NonAgentWorkspaces(), label);
}
return new DiskUsageGraph(dataset, unit, dataset2, workspaceUnit);
}
Expand Down

0 comments on commit a53a6a6

Please sign in to comment.