Skip to content
Permalink
Browse files
[JENKINS-46350] Feature/graphs (#38)
* Enabling Graph visualisation of the overall Lints

Change-Id: I654aa0b41197bf9b0bdae52ac76b13effdd01984

* Added PieCharts and refactored previous implementation

Change-Id: I2271d13b8eb682f7fdebf0e460ac8faba7e8d6cc

* Fixed synchronised issues

Change-Id: I4741c22f73389b82d05b9c7f0e16d5f6836b27e6

* [JENKINS-46424] Added testcases

* Added further test cases to test the current label
classcastexception

Apparently this is just caused with a combination of plugins which I've
not found yet which it's the culprit

* [JENKINS-46424] Fixed NullPointerException

Missing Unit Tests

Change-Id: I6f65be3b44815e655c32b8f0e88bb5b85bcb8513

* [JENKINS-46383] using getAssignedLabel since .getAssignedLabelString causes issues when using wrong formatted doublequote restriction labels within the WebUI

Change-Id: I7a5703ec2ae3964e946e3cf883bc6531537b08a7

* Using different colours to show the severities and minor cosmetic changes

Change-Id: I71e49b08105c4b5f1485344ae8f2b2e57ba3deb0

* Removed unused imports

Change-Id: I6a23e05bfffa2632a1c72f90354b14bc11481273

* Unfortunately when empty it uses the default agent 'master'

Change-Id: I7d3f610c91550fe5af53a8ee6fc46c0cd3d14d67
  • Loading branch information
v1v committed Aug 24, 2017
1 parent 50067b8 commit 61abe7c4815d3e4bed0d512b3bca3e92eb3956f4
@@ -216,6 +216,13 @@
<version>1.24</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jenkins-multijob-plugin</artifactId>
<version>1.21</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
@@ -3,8 +3,17 @@
import hudson.Extension;
import hudson.model.Node;
import hudson.model.RootAction;
import hudson.util.ChartUtil;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.*;
import org.jenkins.ci.plugins.jenkinslint.graph.JenkinsLintGraph;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractAction;
import org.jenkins.ci.plugins.jenkinslint.model.InterfaceCheck;
import org.jenkins.ci.plugins.jenkinslint.model.InterfaceSlaveCheck;
import org.jenkins.ci.plugins.jenkinslint.model.Job;
import org.jenkins.ci.plugins.jenkinslint.model.Lint;
import org.jenkins.ci.plugins.jenkinslint.model.Slave;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@@ -23,8 +32,8 @@ public final class JenkinsLintAction extends AbstractAction implements RootActio

public void getData() throws IOException {
LOG.log(Level.FINE, "getData()");
jobSet.clear();
slaveSet.clear();
this.getJobSet().clear();
this.getSlaveSet().clear();

this.reloadCheckList();
this.reloadSlaveCheckList();
@@ -39,14 +48,13 @@ public void getData() throws IOException {
// Lint is disabled when is ignored or globally disabled
newJob.addLint(new Lint(checker.getName(), checker.executeCheck(item), checker.isIgnored(item.getDescription()), checker.isEnabled()));
}
jobSet.put(item.getName(), newJob);
this.getJobSet().put(item.getName(), newJob);
LOG.log(Level.FINER, newJob.toString());
} else {
LOG.log(Level.FINER, "Excluded MatrixConfiguration " + item.getName());
}
}


for (Node node : Jenkins.getInstance().getNodes()) {
LOG.log(Level.FINER, "querySlaveCheck " + node.getDisplayName());
Slave newSlave = new Slave(node.getNodeName(), node.getSearchUrl());
@@ -55,18 +63,18 @@ public void getData() throws IOException {
LOG.log(Level.FINER, checker.getName() + " " + node.getDisplayName() + " " + status);
newSlave.addLint(new Lint(checker.getName(), status, checker.isIgnored(node.getNodeDescription()), checker.isEnabled()));
}
slaveSet.put(newSlave.getName(), newSlave);
this.getSlaveSet().put(newSlave.getName(), newSlave);
LOG.log(Level.FINER, newSlave.toString());
}
}

@Exported
public Hashtable<String, Job> getJobSet() {
public synchronized Hashtable<String, Job> getJobSet() {
return jobSet;
}

@Exported
public Hashtable<String, InterfaceCheck> getCheckSet() {
public synchronized Hashtable<String, InterfaceCheck> getCheckSet() {
Hashtable<String, InterfaceCheck> temp = new Hashtable<String, InterfaceCheck>();
for (InterfaceCheck check : this.getCheckList()) {
temp.put(check.getName(), check);
@@ -75,16 +83,44 @@ public Hashtable<String, InterfaceCheck> getCheckSet() {
}

@Exported
public Hashtable<String, Slave> getSlaveSet() {
public synchronized Hashtable<String, Slave> getSlaveSet() {
return slaveSet;
}

@Exported
public Hashtable<String, InterfaceSlaveCheck> getSlaveCheckSet() {
public synchronized Hashtable<String, InterfaceSlaveCheck> getSlaveCheckSet() {
Hashtable<String, InterfaceSlaveCheck> temp = new Hashtable<String, InterfaceSlaveCheck>();
for (InterfaceSlaveCheck check : this.getSlaveCheckList()) {
temp.put(check.getName(), check);
}
return temp;
}

public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if(ChartUtil.awtProblemCause != null) {
// not available. send out error message
rsp.sendRedirect2(req.getContextPath()+"/images/headless.png");
return;
}
ChartUtil.generateGraph(req,rsp, JenkinsLintGraph.createChart(this.getJobSet().elements()),1024,768);
}

public void doPieGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if(ChartUtil.awtProblemCause != null) {
// not available. send out error message
rsp.sendRedirect2(req.getContextPath()+"/images/headless.png");
return;
}
ChartUtil.generateGraph(req,rsp, JenkinsLintGraph.createPieChart(this.getJobSet().elements()),512,384);
}


public void doSeverityPieGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if(ChartUtil.awtProblemCause != null) {
// not available. send out error message
rsp.sendRedirect2(req.getContextPath()+"/images/headless.png");
return;
}
ChartUtil.generateGraph(req,rsp, JenkinsLintGraph.createSeverityPieChart(this.getJobSet().elements(), this.getCheckSet()),512,384);
}
}
@@ -118,18 +118,20 @@ private boolean isSystemSandbox(List<Builder> builders) {

private boolean isSandboxInPublisher(DescribableList<Publisher, Descriptor<Publisher>> publishersList) {
boolean status = true;
for (Publisher publisher : publishersList) {
if (publisher.getClass().getName().endsWith("GroovyPostbuildRecorder")) {
LOG.log(Level.FINEST, "GroovyPostbuildRecorder " + publisher);
try {
Object scriptSource = publisher.getClass().getMethod("getScript",null).invoke(publisher);
if (scriptSource.getClass().getName().endsWith("SecureGroovyScript")) {
if (!isSandbox(scriptSource.getClass().getMethod("isSandbox",null).invoke(scriptSource))) {
status = false;
if (publishersList != null) {
for (Publisher publisher : publishersList) {
if (publisher.getClass().getName().endsWith("GroovyPostbuildRecorder")) {
LOG.log(Level.FINEST, "GroovyPostbuildRecorder " + publisher);
try {
Object scriptSource = publisher.getClass().getMethod("getScript", null).invoke(publisher);
if (scriptSource.getClass().getName().endsWith("SecureGroovyScript")) {
if (!isSandbox(scriptSource.getClass().getMethod("isSandbox", null).invoke(scriptSource))) {
status = false;
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
}
}
@@ -138,23 +140,25 @@ private boolean isSandboxInPublisher(DescribableList<Publisher, Descriptor<Publi

private boolean isSandboxParameters(List<ParameterDefinition> properties) {
boolean status = true;
for (ParameterDefinition property : properties) {
if (property.getClass().getName().endsWith("ChoiceParameter") ||
property.getClass().getName().endsWith("CascadeChoiceParameter") ||
property.getClass().getName().endsWith("DynamicReferenceParameter") ) {
LOG.log(Level.FINEST, "unochoice " + property);
try {
Object scriptSource = property.getClass().getMethod("getScript",null).invoke(property);
if (scriptSource.getClass().getName().endsWith("GroovyScript")) {
Object script = scriptSource.getClass().getMethod("getScript", null).invoke(scriptSource);
if (script != null && script.getClass().getName().endsWith("SecureGroovyScript")) {
if (!isSandbox(script.getClass().getMethod("isSandbox", null).invoke(script))) {
status = false;
if (properties != null) {
for (ParameterDefinition property : properties) {
if (property.getClass().getName().endsWith("ChoiceParameter") ||
property.getClass().getName().endsWith("CascadeChoiceParameter") ||
property.getClass().getName().endsWith("DynamicReferenceParameter")) {
LOG.log(Level.FINEST, "unochoice " + property);
try {
Object scriptSource = property.getClass().getMethod("getScript", null).invoke(property);
if (scriptSource.getClass().getName().endsWith("GroovyScript")) {
Object script = scriptSource.getClass().getMethod("getScript", null).invoke(scriptSource);
if (script != null && script.getClass().getName().endsWith("SecureGroovyScript")) {
if (!isSandbox(script.getClass().getMethod("isSandbox", null).invoke(script))) {
status = false;
}
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
}
}
@@ -163,8 +167,8 @@ private boolean isSandboxParameters(List<ParameterDefinition> properties) {

private boolean isSandbox(Object command) {
boolean status = false;
if (command instanceof Boolean) {
status = ((Boolean) command).booleanValue();
if (command != null && command instanceof Boolean) {
status = (Boolean) command;
}
return status;
}
@@ -121,18 +121,20 @@ private boolean isSystemExit(List<Builder> builders) {

private boolean isSystemExitInPublisher (DescribableList<Publisher, Descriptor<Publisher>> publishersList) {
boolean status = false;
for (Publisher publisher : publishersList) {
if (publisher.getClass().getName().endsWith("GroovyPostbuildRecorder")) {
LOG.log(Level.FINEST, "GroovyPostbuildRecorder " + publisher);
try {
Object scriptSource = publisher.getClass().getMethod("getScript",null).invoke(publisher);
if (scriptSource.getClass().getName().endsWith("SecureGroovyScript")) {
if (containsSystemExit(scriptSource.getClass().getMethod("getScript",null).invoke(scriptSource))) {
status = true;
if (publishersList != null) {
for (Publisher publisher : publishersList) {
if (publisher.getClass().getName().endsWith("GroovyPostbuildRecorder")) {
LOG.log(Level.FINEST, "GroovyPostbuildRecorder " + publisher);
try {
Object scriptSource = publisher.getClass().getMethod("getScript", null).invoke(publisher);
if (scriptSource.getClass().getName().endsWith("SecureGroovyScript")) {
if (containsSystemExit(scriptSource.getClass().getMethod("getScript", null).invoke(scriptSource))) {
status = true;
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
}
}
@@ -141,23 +143,25 @@ private boolean isSystemExitInPublisher (DescribableList<Publisher, Descriptor<P

private boolean isSystemExitInParameters (List<hudson.model.ParameterDefinition> properties) {
boolean status = false;
for (ParameterDefinition property : properties) {
if (property.getClass().getName().endsWith("ChoiceParameter") ||
property.getClass().getName().endsWith("CascadeChoiceParameter") ||
property.getClass().getName().endsWith("DynamicReferenceParameter") ) {
LOG.log(Level.FINEST, "unochoice " + property);
try {
Object scriptSource = property.getClass().getMethod("getScript",null).invoke(property);
if (scriptSource.getClass().getName().endsWith("GroovyScript")) {
Object script = scriptSource.getClass().getMethod("getScript", null).invoke(scriptSource);
if (script != null && script.getClass().getName().endsWith("SecureGroovyScript")) {
if (containsSystemExit(script.getClass().getMethod("getScript", null).invoke(script))) {
status = true;
if (properties != null) {
for (ParameterDefinition property : properties) {
if (property.getClass().getName().endsWith("ChoiceParameter") ||
property.getClass().getName().endsWith("CascadeChoiceParameter") ||
property.getClass().getName().endsWith("DynamicReferenceParameter")) {
LOG.log(Level.FINEST, "unochoice " + property);
try {
Object scriptSource = property.getClass().getMethod("getScript", null).invoke(property);
if (scriptSource.getClass().getName().endsWith("GroovyScript")) {
Object script = scriptSource.getClass().getMethod("getScript", null).invoke(scriptSource);
if (script != null && script.getClass().getName().endsWith("SecureGroovyScript")) {
if (containsSystemExit(script.getClass().getMethod("getScript", null).invoke(script))) {
status = true;
}
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
}
}
}
@@ -166,7 +170,7 @@ private boolean isSystemExitInParameters (List<hudson.model.ParameterDefinition>

private boolean containsSystemExit (Object command) {
boolean status = false;
if (command instanceof String) {
if (command !=null && command instanceof String) {
// TODO: Parse to search for non comments, otherwise some false positives!
status = (command != null && ((String) command).toLowerCase().contains("system.exit"));
LOG.log(Level.FINE, "isSystemExit " + status);
@@ -4,6 +4,8 @@
import hudson.model.AbstractProject;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

import java.util.logging.Level;

/**
* @author Victor Martinez
*/
@@ -16,7 +18,12 @@ public JobAssignedLabelChecker(boolean enabled) {
}

public boolean executeCheck(Item item) {
return item instanceof AbstractProject && (((AbstractProject) item).getAssignedLabelString() == null ||
((AbstractProject) item).getAssignedLabelString().length() == 0);
try {
return item instanceof AbstractProject && (((AbstractProject) item).getAssignedLabelString() == null ||
((AbstractProject) item).getAssignedLabelString().length() == 0);
} catch (java.lang.ClassCastException cce) {
// Workaround https://issues.jenkins-ci.org/browse/JENKINS-46383
return false;
}
}
}

0 comments on commit 61abe7c

Please sign in to comment.