Skip to content

Commit

Permalink
Implmeneted #25
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed May 2, 2018
1 parent 4b41f10 commit 6d2ee7b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/jenkins/plugins/sdelements/SDElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
}
}
} else {
run.addAction(new SDElementsRiskIndicatorBuildAction(riskIndicator, url));
run.addAction(new SDElementsRiskIndicatorBuildAction(riskIndicator, url, null));
throw new IllegalStateException("Improper connection selected. This is a required setting");
}
taskListener.getLogger().println("SD Elements compliance status: "+(riskIndicator == null ? "Undetermined" : riskIndicator));
run.addAction(new SDElementsRiskIndicatorBuildAction(riskIndicator, url));
run.addAction(new SDElementsRiskIndicatorBuildAction(riskIndicator, url, conn.getConnectionString()));
setBuildResult(markUnstable, riskIndicator, run);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Class<Job> type() {
public Collection<? extends Action> createFor(@Nonnull Job job) {
Run<?,?> r = job.getLastCompletedBuild();
SDElementsRiskIndicatorBuildAction sdba = r.getAction(SDElementsRiskIndicatorBuildAction.class);
SDElementsRiskIndicatorProjectAction sdpa = new SDElementsRiskIndicatorProjectAction(sdba.getRiskIndicator(), sdba.getProjectUrl());
SDElementsRiskIndicatorProjectAction sdpa = new SDElementsRiskIndicatorProjectAction(sdba.getRiskIndicator(), sdba.getProjectUrl(), sdba.getBaseUrl());
return Collections.singleton(sdpa);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ public class SDElementsRiskIndicatorBuildAction implements Action {

private RiskPolicyCompliance riskIndicator;
private String projectUrl;
private String baseUrl;

public SDElementsRiskIndicatorBuildAction(RiskPolicyCompliance riskIndicator, String projectUrl) {
public SDElementsRiskIndicatorBuildAction(RiskPolicyCompliance riskIndicator, String projectUrl, String baseUrl) {
this.riskIndicator = riskIndicator;
this.projectUrl = projectUrl;
this.baseUrl = baseUrl;
}

@Override
public String getIconFileName() {
if(riskIndicator == null || riskIndicator == RiskPolicyCompliance.UNDETERMINED) {
return "/plugin/sdelements/icons/none.png";
}
return riskIndicator == RiskPolicyCompliance.PASS ? "/plugin/sdelements/icons/pass.png" : "/plugin/sdelements/icons/fail.png";
return "/plugin/sdelements/icons/sdelements_icon.png";
}

@Override
Expand All @@ -31,7 +30,7 @@ public String getDisplayName() {

@Override
public String getUrlName() {
return projectUrl;
return baseUrl;
}

public RiskPolicyCompliance getRiskIndicator() {
Expand All @@ -49,4 +48,22 @@ public String getProjectUrl() {
public void setProjectUrl(String projectUrl) {
this.projectUrl = projectUrl;
}

public String getStatusIcon(RiskPolicyCompliance risk) {
if(risk == RiskPolicyCompliance.FAIL) {
return "/plugin/sdelements/icons/fail.png";
} else if(risk == RiskPolicyCompliance.PASS) {
return "/plugin/sdelements/icons/pass.png";
} else {
return "/plugin/sdelements/icons/none.png";
}
}

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package io.jenkins.plugins.sdelements;

import hudson.model.ProminentProjectAction;
import hudson.model.Action;
import io.jenkins.plugins.sdelements.api.RiskPolicyCompliance;

/**
* Created by mads on 4/12/18.
*/
public class SDElementsRiskIndicatorProjectAction implements ProminentProjectAction {
public class SDElementsRiskIndicatorProjectAction implements Action {

private RiskPolicyCompliance riskIndicator;
private String projectUrl;
private String baseUrl;

public SDElementsRiskIndicatorProjectAction(RiskPolicyCompliance riskIndicator, String projectUrl) {
public SDElementsRiskIndicatorProjectAction(RiskPolicyCompliance riskIndicator, String projectUrl, String baseUrl) {
this.riskIndicator = riskIndicator;
this.projectUrl = projectUrl;
this.baseUrl = baseUrl;
}

@Override
public String getIconFileName() {
if(riskIndicator == null || riskIndicator == RiskPolicyCompliance.UNDETERMINED) {
return "/plugin/sdelements/icons/none.png";
}
return riskIndicator == RiskPolicyCompliance.PASS ? "/plugin/sdelements/icons/pass.png" : "/plugin/sdelements/icons/fail.png";
return "/plugin/sdelements/icons/sdelements_icon.png";
}

@Override
public String getDisplayName() {
return "SD Elements: "+(riskIndicator == null ? "Undetermined" : riskIndicator);
return "SD Elements";
}

@Override
public String getUrlName() {
return projectUrl;
return baseUrl;
}

public RiskPolicyCompliance getRiskIndicator() {
Expand All @@ -49,4 +48,22 @@ public String getProjectUrl() {
public void setProjectUrl(String projectUrl) {
this.projectUrl = projectUrl;
}

public String getStatusIcon(RiskPolicyCompliance risk) {
if(risk == RiskPolicyCompliance.FAIL) {
return "/plugin/sdelements/icons/fail.png";
} else if(risk == RiskPolicyCompliance.PASS) {
return "/plugin/sdelements/icons/pass.png";
} else {
return "/plugin/sdelements/icons/none.png";
}
}

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:t="/lib/hudson">
<t:summary icon="/plugin/sdelements/icons/sdelements_icon.png">
<p><a href="${it.projectUrl}">Elements Risk Status</a></p>
<j:choose>
<j:when test="${it.riskIndicator != null}">
<p><img style="width:20px" src="${resURL}/${it.getStatusIcon(it.riskIndicator)}"/> Risk status: ${it.riskIndicator}</p>
</j:when>
<j:otherwise>
<p><img style="width:20px" src="${resURL}/${it.getStatusIcon(it.riskIndicator)}"/> Unable to determine risk compliance</p>
</j:otherwise>
</j:choose>
</t:summary>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:t="/lib/hudson">
<table style="margin-top: 1em; margin-left:1em;">
<t:summary icon="/plugin/sdelements/icons/sdelements_icon.png">
<div style="margin-left:-1em;">
<p><a href="${it.projectUrl}">Elements Risk Status</a></p>
<j:choose>
<j:when test="${it.riskIndicator != null}">
<p><img style="width:20px" src="${resURL}/${it.getStatusIcon(it.riskIndicator)}"/> Risk status: ${it.riskIndicator}</p>
</j:when>
<j:otherwise>
<p><img style="width:20px" src="${resURL}/${it.getStatusIcon(it.riskIndicator)}"/> Unable to determine risk compliance</p>
</j:otherwise>
</j:choose>
</div>
</t:summary>
</table>
</j:jelly>
Binary file modified src/main/webapp/icons/fail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/webapp/icons/none.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/webapp/icons/pass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/icons/sdelements_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private FreeStyleProject createProject(String connectionName, int id, boolean un
public void testActionCanBeSaved() throws Exception {
FreeStyleProject fp = jr.createFreeStyleProject();
Run r = jr.buildAndAssertSuccess(fp);
r.addAction(new SDElementsRiskIndicatorBuildAction(RiskPolicyCompliance.FAIL));
r.addAction(new SDElementsRiskIndicatorBuildAction(RiskPolicyCompliance.FAIL,"something", "something"));
r.save();
//This test is pass if no error is thrown.
}
Expand Down

0 comments on commit 6d2ee7b

Please sign in to comment.