Skip to content
Permalink
Browse files
[JENKINS-41449] RestAPI feature based on hashes
RestAPI feature: creating a list of elements with some hierarchy

RestAPI feature: refreshing data when quering through the api otherwise it will keep the previous run which means null when it hasn't been requested through the UI

RestAPI feature: fixing bug when creating a list of elements with some hierarchy

Deprecated public api and created an alternative one based on Hashes
  • Loading branch information
v1v committed Jan 26, 2017
1 parent 2d83215 commit 99aae03674d0144657b0baaa8e0113c31df89b9e
Showing 9 changed files with 100 additions and 10 deletions.
@@ -30,13 +30,18 @@
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.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import hudson.model.Api;

@ExportedBean
@Extension
public final class JenkinsLintAction implements RootAction {

@@ -46,6 +51,15 @@ public final class JenkinsLintAction implements RootAction {
private Hashtable<String, Slave> slaveSet = new Hashtable<String, Slave>();
private ArrayList<InterfaceSlaveCheck> slaveCheckList = new ArrayList<InterfaceSlaveCheck>();

public Api getApi() {
try {
this.getData();
} catch (IOException ioe) {
LOG.log(Level.INFO, "Failing when getting the JenkinsLint data through the API");
}
return new Api(this);
}

public void getData() throws IOException {
LOG.log(Level.FINE, "getData()");
jobSet.clear();
@@ -114,19 +128,43 @@ public String getUrlName() {
return Messages.UrlName();
}

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

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<InterfaceCheck> getCheckList() {
return checkList;
}

@Exported
public Hashtable<String, InterfaceCheck> getCheckSet() {
Hashtable<String, InterfaceCheck> temp = new Hashtable<String, InterfaceCheck>();
for (InterfaceCheck check : checkList) {
temp.put(check.getName(), check);
}
return temp;
}

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

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<InterfaceSlaveCheck> getSlaveCheckList() {
return slaveCheckList;
}

@Exported
public Hashtable<String, InterfaceSlaveCheck> getSlaveCheckSet() {
Hashtable<String, InterfaceSlaveCheck> temp = new Hashtable<String, InterfaceSlaveCheck>();
for (InterfaceSlaveCheck check : slaveCheckList) {
temp.put(check.getName(), check);
}
return temp;
}
}
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import java.util.logging.Logger;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* AbstractCheck class.
* @author Victor Martinez
*/
@ExportedBean
public abstract class AbstractCheck implements Comparable<AbstractCheck>, InterfaceCheck {
private String name;
private String description;
@@ -18,6 +21,7 @@ public AbstractCheck() {
this.setName(this.getClass().getSimpleName());
}

@Exported
public String getName() {
return name;
}
@@ -30,6 +34,7 @@ public String getId() {
return id;
}

@Exported
public String getDescription() {
return description;
}
@@ -38,6 +43,7 @@ public void setDescription(final String description) {
this.description = description;
}

@Exported
public String getSeverity() {
return severity;
}
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import java.util.logging.Logger;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* AbstractCheck class.
* @author Victor Martinez
*/
@ExportedBean
public abstract class AbstractSlaveCheck implements Comparable<AbstractSlaveCheck>, InterfaceSlaveCheck {
private String name;
private String description;
@@ -18,6 +21,7 @@ public AbstractSlaveCheck() {
this.setName(this.getClass().getSimpleName());
}

@Exported
public String getName() {
return name;
}
@@ -30,6 +34,7 @@ public String getId() {
return id;
}

@Exported
public String getDescription() {
return description;
}
@@ -38,6 +43,7 @@ public void setDescription(final String description) {
this.description = description;
}

@Exported
public String getSeverity() {
return severity;
}
@@ -7,7 +7,7 @@
* @author Victor Martinez
*/
public interface InterfaceCheck {

public String getName();
boolean executeCheck(Item item);
boolean isIgnored(String jobDescription);
}
@@ -7,7 +7,7 @@
* @author Victor Martinez
*/
public interface InterfaceSlaveCheck {

public String getName();
boolean executeCheck(Node item);
boolean isIgnored(String jobDescription);
}
@@ -3,11 +3,14 @@
import hudson.model.HealthReport;
import org.jenkins.ci.plugins.jenkinslint.Messages;
import java.util.ArrayList;

import java.util.Hashtable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
/**
* Job class.
* @author Victor Martinez
*/
@ExportedBean
public final class Job implements Comparable<Job> {
private String name;
private String url;
@@ -19,6 +22,7 @@ public Job(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
@@ -35,10 +39,21 @@ public void setUrl(final String url) {
this.url = url;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<Lint> getLintList() {
return lintList;
}

@Exported
public Hashtable<String, Lint> getLintSet() {
Hashtable<String, Lint> temp = new Hashtable<String, Lint>();
for (Lint lint : lintList) {
temp.put(lint.getName(), lint);
}
return temp;
}

public void addLint(Lint lint) {
lintList.add(lint);
}
@@ -75,6 +90,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

@Exported
public HealthReport getLintHealthReport() {
if (lintList != null && lintList.size() > 0) {
int ok = 0;
@@ -1,9 +1,13 @@
package org.jenkins.ci.plugins.jenkinslint.model;

import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* Check class.
* @author Victor Martinez
*/
@ExportedBean
public final class Lint implements Comparable<Lint> {
private String name;
private boolean found = false;
@@ -16,6 +20,7 @@ public Lint(final String name, final boolean found, final boolean ignored) {
this.setIgnored(ignored);
}

@Exported
public String getName() {
return name;
}
@@ -31,6 +36,7 @@ public int compareTo(final Lint other) {
return getName().compareTo(other.getName());
}

@Exported
public boolean isFound() {
return found;
}
@@ -39,6 +45,7 @@ public void setFound(boolean found) {
this.found = found;
}

@Exported
public boolean isIgnored() {
return ignored;
}
@@ -4,11 +4,15 @@
import org.jenkins.ci.plugins.jenkinslint.Messages;

import java.util.ArrayList;
import java.util.Hashtable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;

/**
* Slave class.
* @author Victor Martinez
*/
@ExportedBean
public final class Slave implements Comparable<Slave> {
private String name;
private String url;
@@ -20,6 +24,7 @@ public Slave(final String name, final String url) {
this.url = url;
}

@Exported
public String getName() {
return name;
}
@@ -36,10 +41,21 @@ public void setUrl(final String url) {
this.url = url;
}

/** @deprecated this is the only we can keep backward compatibility temporarily in case someone is using this public method */
@Deprecated
public ArrayList<Lint> getLintList() {
return lintList;
}

@Exported
public Hashtable<String, Lint> getLintSet() {
Hashtable<String, Lint> temp = new Hashtable<String, Lint>();
for (Lint lint : lintList) {
temp.put(lint.getName(), lint);
}
return temp;
}

public void addLint(Lint lint) {
lintList.add(lint);
}
@@ -76,6 +92,7 @@ public String toString() {
append(", ").append(lintList).toString();
}

@Exported
public HealthReport getLintHealthReport() {
if (lintList != null && lintList.size() > 0) {
int ok = 0;
@@ -32,7 +32,7 @@
<thead>
<tr>
<th class="pane-header">Job Name</th>
<j:forEach var="checker" items="${it.checkList}">
<j:forEach var="checker" items="${it.checkSet.elements()}">
<j:set var="index" value="${index+1}"/>
<th tooltip="${checker.getName()}" class="pane-header">${checker.getId()}${index}</th>
</j:forEach>
@@ -43,7 +43,7 @@
<j:forEach var="job" items="${it.jobSet.elements()}">
<tr>
<td><a href="${app.rootUrl}${job.url}" target="_blank">${job.name}</a></td>
<j:forEach var="lint" items="${job.lintList}">
<j:forEach var="lint" items="${job.lintSet.elements()}">
<j:if test="${lint.ignored}">
<td tooltip="ignored" style="background-color: #f0f0f0;"/>
</j:if>
@@ -65,7 +65,7 @@
</j:if>
<j:if test="${(filter != null) and (filter == 'description')}">
<j:set var="index" value="0"/>
<j:forEach var="checker" items="${it.checkList}">
<j:forEach var="checker" items="${it.checkSet.elements()}">
<j:set var="index" value="${index+1}"/>
<table class="pane bigtable" id="jenkinsLintDescriptionTable">
<thead>
@@ -87,7 +87,7 @@
</table>
<br/>
</j:forEach>
<j:forEach var="check" items="${it.slaveCheckList}">
<j:forEach var="check" items="${it.slaveCheckSet.elements()}">
<j:set var="index" value="${index+1}"/>
<table class="pane bigtable" id="jenkinsLintDescriptionTable">
<thead>
@@ -117,12 +117,12 @@
${%Jenkins.Lint.Description.2}
<br/>
</j:if>
<j:set var="index" value="${it.checkList.size()}"/>
<j:set var="index" value="${it.checkSet.elements().size()}"/>
<table class="sortable pane bigtable" id="jenkinsSlaveTable">
<thead>
<tr>
<th class="pane-header">Slave Name</th>
<j:forEach var="check" items="${it.slaveCheckList}">
<j:forEach var="check" items="${it.slaveCheckSet}">
<j:set var="index" value="${index+1}"/>
<th tooltip="${check.getName()}" class="pane-header">${check.getId()}${index}</th>
</j:forEach>
@@ -133,7 +133,7 @@
<j:forEach var="slave" items="${it.slaveSet.elements()}">
<tr>
<td><a href="${app.rootUrl}${slave.url}" target="_blank">${slave.name}</a></td>
<j:forEach var="lint" items="${slave.lintList}">
<j:forEach var="lint" items="${slave.lintSet.elements()}">
<j:if test="${lint.ignored}">
<td tooltip="ignored" style="background-color: #f0f0f0;"/>
</j:if>

0 comments on commit 99aae03

Please sign in to comment.