Skip to content

Commit

Permalink
Merge pull request #23 from GLundh/flatten-view-switch
Browse files Browse the repository at this point in the history
Flatten View switch
  • Loading branch information
GLundh authored Jan 28, 2021
2 parents 2252b13 + 8c5b5b0 commit d49055b
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 85 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.54</version>
<version>4.15</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -58,7 +58,7 @@
</scm>

<properties>
<jenkins.version>2.73.3</jenkins.version>
<jenkins.version>2.176.4</jenkins.version>
<java.level>8</java.level>
<jenkins-test-harness.version>2.38</jenkins-test-harness.version>
<scmCommentPrefix>maven-release-plugin:</scmCommentPrefix>
Expand Down Expand Up @@ -95,7 +95,7 @@
<dependency>
<groupId>com.axis.system.jenkins.plugins.downstream</groupId>
<artifactId>downstream-build-cache</artifactId>
<version>1.5.2</version>
<version>1.6</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions scripts/codenarc_rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ruleset {

// rulesets/dry.xml
DuplicateListLiteral
DuplicateMapLiteral
// DuplicateMapLiteral Axis: Does not work for HTML-attributes in groovy
DuplicateNumberLiteral
// DuplicateStringLiteral Axis: Not very useful to us

Expand Down Expand Up @@ -230,7 +230,7 @@ ruleset {
ExplicitArrayListInstantiation
ExplicitCallToAndMethod
ExplicitCallToCompareToMethod
ExplicitCallToDivMethod
// ExplicitCallToDivMethod Axis: Because div() is used for building html pages.
ExplicitCallToEqualsMethod
ExplicitCallToGetAtMethod
ExplicitCallToLeftShiftMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public Entry(@Nullable Arrow arrow) {
this.data = null;
}

public Arrow getArrow() {
return arrow;
}

public T getData() {
return data;
}

@Override
public String toString() {
return "Entry{arrow=" + arrow + ", data=" + data + '}';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.axis.system.jenkins.plugins.downstream.yabv;

import static com.axis.system.jenkins.plugins.downstream.tree.TreeLaminator.layoutTree;

import com.axis.system.jenkins.plugins.downstream.cache.BuildCache;
import com.axis.system.jenkins.plugins.downstream.tree.Matrix;
import com.axis.system.jenkins.plugins.downstream.tree.TreeLaminator.ChildrenFunction;
Expand All @@ -13,21 +11,26 @@
import hudson.model.Job;
import hudson.model.Queue;
import hudson.model.Run;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import jenkins.model.TransientActionFactory;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static com.axis.system.jenkins.plugins.downstream.tree.TreeLaminator.layoutTree;

/**
* Produces Transient Actions for visualizing the flow of downstream builds.
*
Expand Down Expand Up @@ -56,6 +59,13 @@ private static final ChildrenFunction getChildrenFunc() {
};
}

public Run getRootUpstreamBuild() {
if (target == null) {
return null;
}
return buildFlowOptions.isShowUpstreamBuilds() ? getRootUpstreamBuild(target) : target;
}

private static Run getRootUpstreamBuild(@Nonnull Run build) {
Run parentBuild;
while ((parentBuild = getUpstreamBuild(build)) != null) {
Expand Down Expand Up @@ -92,7 +102,7 @@ public BuildFlowOptions getBuildFlowOptions() {
@Exported(visibility = 1)
public boolean isAnyBuildOngoing() {
return target != null
&& isChildrenStillBuilding(getRootUpstreamBuild(target), getChildrenFunc());
&& isChildrenStillBuilding(getRootUpstreamBuild(), getChildrenFunc());
}

private static boolean isChildrenStillBuilding(Object current, ChildrenFunction children) {
Expand Down Expand Up @@ -136,13 +146,54 @@ public Run getTarget() {
}

public Matrix buildMatrix() {
if (target == null) {
Run root = getRootUpstreamBuild();
if (root == null) {
return new Matrix();
}
Run root = buildFlowOptions.isShowUpstreamBuilds() ? getRootUpstreamBuild(target) : target;
return layoutTree(root, getChildrenFunc());
}

/**
* Returns all items in the build flow, populated from the root. Which target is root depends on
* {@link BuildFlowOptions#isShowUpstreamBuilds()}.
*
* @param lookBack number of historic build flows to fetch, based on the root target's previous
* builds.
* @return A list of sets of Objects. Each set represents all items in a flow, starting from the
* root. The first set is calculated from the root, the next set is from the root target's
* previous build and so on.
*/
public List<Set<Object>> getAllItemsInFlow(int lookBack) {
Run root = getRootUpstreamBuild();
if (root == null) {
return Collections.emptyList();
}
List<Set<Object>> result = new ArrayList<>();
for (; lookBack > 0 && root != null; lookBack--) {
Set<Object> itemsInFlow = getAllDownstreamItems(root);
itemsInFlow.add(root);
result.add(itemsInFlow);
root = root.getPreviousBuild();
}
return result;
}

private static Set<Object> getAllDownstreamItems(Run current) {
Set<Object> resultSet = new HashSet<>();
addAllDownstreamItems(resultSet, current, getChildrenFunc());
return resultSet;
}

private static void addAllDownstreamItems(
Set<Object> resultSet, Object current, ChildrenFunction children) {
Iterator childIter = children.children(current).iterator();
while (childIter.hasNext()) {
Object child = childIter.next();
resultSet.add(child);
addAllDownstreamItems(resultSet, child, children);
}
}

@Override
public String getDisplayName() {
return null;
Expand All @@ -166,6 +217,7 @@ public void doBuildFlow(StaplerRequest req, StaplerResponse rsp)
Boolean.parseBoolean(req.getParameter("showBuildHistory")));
buildFlowOptions.setShowUpstreamBuilds(
Boolean.parseBoolean(req.getParameter("showUpstreamBuilds")));
buildFlowOptions.setFlattenView(Boolean.parseBoolean(req.getParameter("flattenView")));
rsp.setContentType("text/html;charset=UTF-8");
req.getView(this, "buildFlow.groovy").forward(req, rsp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ public class BuildFlowOptions {
private boolean showBuildHistory;
private boolean showDurationInfo;
private boolean showUpstreamBuilds;
private boolean flattenView;

public BuildFlowOptions() {
showBuildHistory = false;
showDurationInfo = false;
showUpstreamBuilds = false;
flattenView = false;
}

public BuildFlowOptions(
boolean showBuildHistory, boolean showDurationInfo, boolean showUpstreamBuilds) {
boolean showBuildHistory,
boolean showDurationInfo,
boolean showUpstreamBuilds,
boolean flattenView) {
this.showBuildHistory = showBuildHistory;
this.showDurationInfo = showDurationInfo;
this.showUpstreamBuilds = showUpstreamBuilds;
this.flattenView = flattenView;
}

public boolean isShowBuildHistory() {
Expand All @@ -42,12 +48,21 @@ public void setShowUpstreamBuilds(boolean showUpstreamBuilds) {
this.showUpstreamBuilds = showUpstreamBuilds;
}

public boolean isFlattenView() {
return flattenView;
}

public void setFlattenView(boolean flattenView) {
this.flattenView = flattenView;
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("BuildFlowOptions{");
sb.append("showBuildHistory=").append(showBuildHistory);
sb.append(", showDurationInfo=").append(showDurationInfo);
sb.append(", showUpstreamBuilds=").append(showUpstreamBuilds);
sb.append(", flattenView=").append(flattenView);
sb.append('}');
return sb.toString();
}
Expand Down
Loading

0 comments on commit d49055b

Please sign in to comment.