Skip to content
Permalink
Browse files

Add flat-styled images, make them default

You can get the old "plastic" style badges by adding ?style=plastic to
the badge URL.

The new images were generated with

  wget https://img.shields.io/badge/build-failing-red.svg?style=flat         -O build-failing-red-flat.svg
  wget https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat -O build-passing-brightgreen-flat.svg
  wget https://img.shields.io/badge/build-running-blue.svg?style=flat        -O build-running-blue-flat.svg
  wget https://img.shields.io/badge/build-unknown-lightgrey.svg?style=flat   -O build-unknown-lightgrey-flat.svg
  wget https://img.shields.io/badge/build-unstable-yellow.svg?style=flat     -O build-unstable-yellow-flat.svg

Fixes JENKINS-26705.
  • Loading branch information
mgedmin committed Jan 30, 2015
1 parent fe2441b commit f13eccb8551fd3c888f3f44856b539c344d0da62
@@ -8,6 +8,7 @@
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.QueryParameter;

import javax.servlet.ServletException;
import java.io.IOException;
@@ -43,7 +44,7 @@ public String getUrlName() {
/**
* Serves the badge image.
*/
public HttpResponse doIcon() {
return factory.getImage(project.getIconColor());
public HttpResponse doIcon(@QueryParameter String style) {
return factory.getImage(project.getIconColor(), style);
}
}
@@ -17,7 +17,7 @@
public class BadgeActionFactory extends TransientProjectActionFactory {

private final ImageResolver iconResolver;

public BadgeActionFactory() throws IOException {
iconResolver = new ImageResolver();
}
@@ -31,4 +31,8 @@ public StatusImage getImage(BallColor color) {
return iconResolver.getImage(color);
}

public StatusImage getImage(BallColor color, String style) {
return iconResolver.getImage(color, style);
}

}
@@ -26,22 +26,47 @@
import hudson.model.BallColor;

import java.io.IOException;
import java.util.HashMap;

public class ImageResolver {

private final StatusImage[] images;


private final HashMap<String, StatusImage[]> styles;
private final StatusImage[] defaultStyle;

public ImageResolver() throws IOException{
images = new StatusImage[] {
styles = new HashMap<String, StatusImage[]>();
// shields.io "plastic" style (aka the old default)
StatusImage[] plasticImages = new StatusImage[] {
new StatusImage("build-failing-red.svg"),
new StatusImage("build-unstable-yellow.svg"),
new StatusImage("build-passing-brightgreen.svg"),
new StatusImage("build-running-blue.svg"),
new StatusImage("build-unknown-lightgrey.svg")
};
styles.put("plastic", plasticImages);
// shields.io "flat" style (new default from Feb 1 2015)
StatusImage[] flatImages = new StatusImage[] {
new StatusImage("build-failing-red-flat.svg"),
new StatusImage("build-unstable-yellow-flat.svg"),
new StatusImage("build-passing-brightgreen-flat.svg"),
new StatusImage("build-running-blue-flat.svg"),
new StatusImage("build-unknown-lightgrey-flat.svg")
};
styles.put("flat", flatImages);
// Pick a default style
defaultStyle = flatImages;
styles.put("default", defaultStyle);
}

public StatusImage getImage(BallColor color) {
return getImage(color, "default");
}

public StatusImage getImage(BallColor color, String style) {
StatusImage[] images = styles.get(style);
if (images == null)
images = defaultStyle;

if (color.isAnimated())
return images[3];

@@ -58,5 +83,4 @@ public StatusImage getImage(BallColor color) {
}
}


}
@@ -90,13 +90,13 @@ public String getDisplayName() {
/**
* Serves the badge image.
*/
public HttpResponse doIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String build) {
public HttpResponse doIcon(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String build, @QueryParameter String style) {
if(build != null) {
Run run = getRun(job, build);
return iconResolver.getImage(run.getIconColor());
return iconResolver.getImage(run.getIconColor(), style);
} else {
AbstractProject<?, ?> project = getProject(job);
return iconResolver.getImage(project.getIconColor());
return iconResolver.getImage(project.getIconColor(), style);
}
}

@@ -5,6 +5,7 @@
import hudson.model.Run;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;

public class RunBadgeAction implements Action {
private final RunBadgeActionFactory factory;
@@ -32,7 +33,7 @@ public String getUrlName() {
/**
* Serves the badge image.
*/
public HttpResponse doIcon() {
return factory.getImage(run.getIconColor());
public HttpResponse doIcon(@QueryParameter String style) {
return factory.getImage(run.getIconColor(), style);
}
}
@@ -24,4 +24,8 @@ public RunBadgeActionFactory() throws IOException {
public StatusImage getImage(BallColor color) {
return iconResolver.getImage(color);
}

public StatusImage getImage(BallColor color, String style) {
return iconResolver.getImage(color, style);
}
}
@@ -38,6 +38,8 @@ l.layout {
h3 {
text(_("Image"))
img(id:"badge",src:badge)
text(_(" or "))
img(src:badge + "?style=plastic")
}
b {text(_("protected"))}
input(type:"text",value:badge,class:"select-all")
@@ -5,5 +5,10 @@ blurb=Jenkins exposes the current status of your build as an image in a fixed UR
<li><b>protected</b> exposes the badge to users having at least 'Read' permission on the job</li> \
<li><b>unprotected</b> exposes the badge to users having at least 'ViewStatus' permission on the job</li> \
</ul> \
If you want the status icons to be public readable/accessible, just grant the 'ViewStatus' permission globally to 'anonymous'.

If you want the status icons to be public readable/accessible, just grant the 'ViewStatus' permission globally to 'anonymous'. \
<br>There are two styles available: \
<ul> \
<li><b>flat</b> (default since version 1.7)\
<li><b>plastic</b> (the one used in version 1.5)\
</ul> \
You can choose the one you prefer by appending <tt>?style=plastic</tt> to the URL.
@@ -38,6 +38,8 @@ l.layout {
h3 {
text(_("Image"))
img(id:"badge",src:badge)
text(_(" or "))
img(src:badge + "?style=plastic")
}
b {text(_("protected"))}
input(type:"text",value:badge,class:"select-all")
@@ -5,5 +5,10 @@ blurb=Jenkins exposes the status of the specific build as an image in a fixed UR
<li><b>protected</b> exposes the badge to users having at least 'Read' permission on the job</li> \
<li><b>unprotected</b> exposes the badge to users having at least 'ViewStatus' permission on the job</li> \
</ul> \
If you want the status icons to be public readable/accessible, just grant the 'ViewStatus' permission globally to 'anonymous'.

If you want the status icons to be public readable/accessible, just grant the 'ViewStatus' permission globally to 'anonymous'. \
<br>There are two styles available: \
<ul> \
<li><b>flat</b> (default since version 1.7)\
<li><b>plastic</b> (the one used in version 1.5)\
</ul> \
You can choose the one you prefer by appending <tt>?style=plastic</tt> to the URL.
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="81" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="81" height="20" fill="#555"/><rect rx="3" x="37" width="44" height="20" fill="#e05d44"/><path fill="#e05d44" d="M37 0h4v20h-4z"/><rect rx="3" width="81" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="58" y="15" fill="#010101" fill-opacity=".3">failing</text><text x="58" y="14">failing</text></g></svg>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="90" height="20" fill="#555"/><rect rx="3" x="37" width="53" height="20" fill="#4c1"/><path fill="#4c1" d="M37 0h4v20h-4z"/><rect rx="3" width="90" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="62.5" y="15" fill="#010101" fill-opacity=".3">passing</text><text x="62.5" y="14">passing</text></g></svg>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="90" height="20" fill="#555"/><rect rx="3" x="37" width="53" height="20" fill="#007ec6"/><path fill="#007ec6" d="M37 0h4v20h-4z"/><rect rx="3" width="90" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="62.5" y="15" fill="#010101" fill-opacity=".3">running</text><text x="62.5" y="14">running</text></g></svg>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="98" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="98" height="20" fill="#555"/><rect rx="3" x="37" width="61" height="20" fill="#9f9f9f"/><path fill="#9f9f9f" d="M37 0h4v20h-4z"/><rect rx="3" width="98" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="66.5" y="15" fill="#010101" fill-opacity=".3">unknown</text><text x="66.5" y="14">unknown</text></g></svg>
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="95" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="95" height="20" fill="#555"/><rect rx="3" x="37" width="58" height="20" fill="#dfb317"/><path fill="#dfb317" d="M37 0h4v20h-4z"/><rect rx="3" width="95" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="65" y="15" fill="#010101" fill-opacity=".3">unstable</text><text x="65" y="14">unstable</text></g></svg>
@@ -63,6 +63,8 @@ public void authenticatedAccess() throws Exception {
wc.goTo("buildStatus/icon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
wc.goTo("buildStatus/icon?job=free&build=1", "image/svg+xml");
wc.goTo("buildStatus/icon?job=free&build=1&style=plastic", "image/svg+xml");
wc.goTo("buildStatus/icon?job=free&build=1&style=unknown", "image/svg+xml");
}

@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)

0 comments on commit f13eccb

Please sign in to comment.
You can’t perform that action at this time.