Skip to content

Commit

Permalink
[JENKINS-36472] utilize icon shim functionality
Browse files Browse the repository at this point in the history
- added icons for all sizes
- implemented IconSpec interface in all report actions
- replaced <img> markup with <lsi:icon> shim markup
  • Loading branch information
cpoenisch committed Jul 21, 2016
1 parent 7520274 commit d91c999
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 117 deletions.
Expand Up @@ -201,14 +201,14 @@ public void start() throws Exception {
super.start();

for (final String name : new String[] {
"atx",
"atx-report",
"atx-trend",
"ecu-test",
"ecu-test-pkg",
"ecu-test-prj",
"report-generator",
"test-guide",
"trf",
"trf-report",
}) {
// Register small (16x16) icons
IconSet.icons.addIcon(new Icon(
Expand Down
Expand Up @@ -29,24 +29,20 @@
*/
package de.tracetronic.jenkins.plugins.ecutest.report;

import hudson.PluginWrapper;
import hudson.model.Action;
import hudson.model.Job;
import hudson.model.Run;

import java.io.File;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;

import jenkins.model.Jenkins;
import jenkins.util.VirtualFile;

import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.StaplerRequest;

import de.tracetronic.jenkins.plugins.ecutest.ETPlugin;
import de.tracetronic.jenkins.plugins.ecutest.report.atx.AbstractATXAction;
import de.tracetronic.jenkins.plugins.ecutest.report.trf.AbstractTRFAction;

Expand All @@ -55,9 +51,7 @@
*
* @author Christian Pönisch <christian.poenisch@tracetronic.de>
*/
public abstract class AbstractReportAction extends AbstractRequestHandler implements Action {

private static final Logger LOGGER = Logger.getLogger(AbstractReportAction.class.getName());
public abstract class AbstractReportAction extends AbstractRequestHandler implements Action, IconSpec {

private final boolean projectLevel;

Expand Down Expand Up @@ -111,36 +105,8 @@ protected VirtualFile getArchiveTargetDir(final File rootDir) {
@CheckForNull
protected abstract Run<?, ?> getLastReportBuild(final Job<?, ?> project);

/**
* Gets the icon path inside of this plugin.
*
* @param icon
* the icon to search
* @return the full icon path or {@code null} if the icon does not exist
*/
@CheckForNull
protected String getIconPath(final String icon) {
String iconPath = null;
if (icon == null) {
return iconPath;
}
// Try plugin icons dir, fallback to Jenkins image
final Jenkins instance = Jenkins.getInstance();
if (instance != null) {
final PluginWrapper wrapper = instance.getPluginManager().getPlugin(ETPlugin.class);
boolean pluginIconExists = false;
try {
pluginIconExists = wrapper != null
&& new File(wrapper.baseResourceURL.toURI().getPath() + "/icons/" + icon).exists();
} catch (final URISyntaxException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
if (pluginIconExists) {
iconPath = "/plugin/" + wrapper.getShortName() + "/icons/" + icon;
} else {
iconPath = "/images/48x48/document.png";
}
}
return iconPath;
@Override
public String getIconFileName() {
return IconSet.icons.getIconByClassSpec(getIconClassName() + " icon-xlg").getUrl();
}
}
Expand Up @@ -66,21 +66,21 @@ public String getUrlName() {
}

@Override
public String getIconFileName() {
return getIconPath("48x48/test-guide.png");
public String getIconClassName() {
return "icon-ecutest-test-guide";
}

/**
* @return the report icon file name
* @return the report icon class name
*/
public String getReportIconFileName() {
return getIconPath("24x24/atx.png");
public String getReportIconClassName() {
return "icon-ecutest-atx-report";
}

/**
* @return the trend icon file name
* @return the trend icon class name
*/
public String getTrendIconFileName() {
return getIconPath("24x24/atx-trend.png");
public String getTrendIconClassName() {
return "icon-ecutest-atx-trend";
}
}
Expand Up @@ -66,16 +66,7 @@ public String getUrlName() {
}

@Override
public String getIconFileName() {
return getIconPath("48x48/report-generator.png");
}

/**
* Gets the small icon file name.
*
* @return the small icon file name
*/
public String getSmallIconFileName() {
return getIconPath("24x24/report-generator.png");
public String getIconClassName() {
return "icon-ecutest-report-generator";
}
}
Expand Up @@ -77,7 +77,7 @@ public String getUrlName() {
}

@Override
public String getIconFileName() {
return getIconPath("48x48/ecu-test.png");
public String getIconClassName() {
return "icon-ecutest-ecu-test";
}
}
Expand Up @@ -67,7 +67,7 @@ public String getUrlName() {
}

@Override
public String getIconFileName() {
return getIconPath("48x48/trf.png");
public String getIconClassName() {
return "icon-ecutest-trf-report";
}
}
Expand Up @@ -30,7 +30,6 @@

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:advanced title="${%publishing.title}">
<f:section title="${%publishing.title}">
<j:if test="${empty(showArchiving)}">
Expand Down
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2015 TraceTronic GmbH
Copyright (c) 2015-2016 TraceTronic GmbH
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -29,14 +29,14 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<j:set var="owner" value="${it.getOwner(request)}" />
<j:set var="build" value="${it.getBuild(request)}" />
<l:layout title="${it.displayName}" norefresh="true">
<st:include page="sidepanel.jelly" it="${owner}" />
<l:main-panel>
<h1>
<img src="${resURL}${it.iconFileName}" alt="ATX reports" height="48" width="48" />
<lsi:icon class="${it.iconClassName} icon-xlg" alt="ATX reports" />
${it.displayName}
</h1>
<j:if test="${owner != null}">
Expand All @@ -48,25 +48,27 @@
<table class="fileList">
<j:set var="indent" value="0" />
<j:set var="reports" value="${it.getATXReports()}" />
<j:forEach var="report" items="reports">
<st:include page="report.jelly" />
</j:forEach>
<j:choose>
<j:when test="${empty(reports)}">
${%reports.empty}
</j:when>
<j:when test="${it.hasArchivedReports()}">
<tr>
<td style="text-align:right;" colspan="2">
<div style="margin-top: 1em;">
<img src="${resURL}/images/16x16/package.png" /><st:nbsp />
<a href="${rootURL}/${build.url}${it.urlName}/zipDownload">
${%download.zip}
</a>
</div>
</td>
</tr>
</j:when>
<j:otherwhise>
<j:forEach var="report" items="${reports}">
<st:include page="report.jelly" />
</j:forEach>
<j:if test="${it.hasArchivedReports()}">
<tr>
<td style="text-align:right;" colspan="2">
<div style="margin-top: 1em;">
<l:icon class="icon-package icon-sm" /><st:nbsp />
<a href="${rootURL}/${build.url}${it.urlName}/zipDownload">
${%download.zip}
</a>
</div>
</td>
</tr>
</j:if>
</j:otherwhise>
</j:choose>
</table>
</j:if>
Expand Down
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2015 TraceTronic GmbH
Copyright (c) 2015-2016 TraceTronic GmbH
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -29,23 +29,23 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<tr>
<td>
<div style="text-indent: ${indent}px;">
<j:choose>
<j:when test="${report.hasTrendReport()}">
<lsi:icon class="${it.trendIconClassName} icon-sm" alt="ATX report" />
<st:nbsp />
<j:if test="${owner == build}">
<img src="${resURL}${it.trendIconFileName}" alt="ATX report" height="16" width="16" />
<st:nbsp /><a href="${report.url}" target="_blank">${%trend.view}</a>
<a href="${report.url}" target="_blank">${%trend.view}</a>
</j:if>
<j:if test="${owner != build}">
<img src="${resURL}${it.trendIconFileName}" alt="ATX trend report" height="16" width="16" />
<st:nbsp /><a href="${rootURL}/${build.url}${it.urlName}/${report.id}" target="_blank">${%trend.view}</a>
<a href="${rootURL}/${build.url}${it.urlName}/${report.id}" target="_blank">${%trend.view}</a>
</j:if>
</j:when>
<j:otherwise>
<img src="${resURL}${it.reportIconFileName}" alt="ATX report" height="16" width="16" />
<lsi:icon class="${it.reportIconClassName} icon-sm" alt="ATX report" />
<st:nbsp />
<j:if test="${owner == build}">
<a href="${report.url}" target="_blank">${report.title}</a>
Expand Down
Expand Up @@ -29,14 +29,14 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<j:set var="owner" value="${it.getOwner(request)}" />
<j:set var="build" value="${it.getBuild(request)}" />
<l:layout title="${it.displayName}" norefresh="true">
<st:include page="sidepanel.jelly" it="${owner}" />
<l:main-panel>
<h1>
<img src="${resURL}${it.iconFileName}" alt="Generated reports" height="48" width="48" />
<lsi:icon class="${it.iconClassName} icon-xlg" alt="Generated reports" />
${it.displayName}
</h1>
<j:if test="${owner != null}">
Expand All @@ -48,18 +48,18 @@
<table class="fileList">
<j:set var="indent" value="0" />
<j:set var="reports" value="${it.getGeneratorReports()}" />
<j:forEach var="report" items="reports">
<st:include page="report.jelly" />
</j:forEach>
<j:choose>
<j:when test="${empty(reports)}">
${%reports.empty}
</j:when>
<j:otherwise>
<j:forEach var="report" items="${reports}">
<st:include page="report.jelly" />
</j:forEach>
<tr>
<td style="text-align:right;" colspan="2">
<div style="margin-top: 1em;">
<img src="${resURL}/images/16x16/package.png" /><st:nbsp />
<l:icon class="icon-package icon-sm" /><st:nbsp />
<a href="${rootURL}/${build.url}${it.urlName}/zipDownload">
${%download.zip}
</a>
Expand Down
Expand Up @@ -29,11 +29,11 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<tr>
<td>
<div style="text-indent: ${indent}px;">
<img src="${resURL}${it.smallIconFileName}" alt="Generated report" height="16" width="16" />
<lsi:icon class="${it.iconClassName} icon-sm" alt="Generated report" />
<st:nbsp />
<j:if test="${owner == build}">
<a href="${report.url}/zipDownload">${report.title}</a>
Expand Down
Expand Up @@ -29,15 +29,15 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<j:set var="owner" value="${it.getOwner(request)}" />
<j:set var="build" value="${it.getBuild(request)}" />
<l:layout title="${it.displayName}" norefresh="true">
<link type="text/css" href="${resURL}/plugin/ecutest/css/style.css" rel="stylesheet" />
<st:include page="sidepanel.jelly" it="${owner}" />
<l:main-panel>
<h1>
<img src="${resURL}${it.iconFileName}" alt="ECU-TEST Logs" height="48" width="48" />
<lsi:icon class="${it.iconClassName} icon-xlg" alt="ECU-TEST Logs" />
${it.displayName}
</h1>
<j:if test="${owner != null}">
Expand All @@ -49,18 +49,18 @@
<table class="fileList" id="logs">
<j:set var="indent" value="0" />
<j:set var="reports" value="${it.getLogReports()}" />
<j:forEach var="report" items="reports">
<st:include page="report.jelly" />
</j:forEach>
<j:choose>
<j:when test="${empty(reports)}">
${%reports.empty}
</j:when>
<j:otherwise>
<j:forEach var="report" items="${reports}">
<st:include page="report.jelly" />
</j:forEach>
<tr>
<td style="text-align:right;" colspan="3">
<div style="margin-top: 1em;">
<img src="${resURL}/images/16x16/package.png" /><st:nbsp />
<l:icon class="icon-package icon-sm" /><st:nbsp />
<a href="${rootURL}/${build.url}${it.urlName}/zipDownload">
${%download.zip}
</a>
Expand Down
Expand Up @@ -29,11 +29,11 @@
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:lsi="/shim/layout/icon">
<tr>
<td>
<div style="text-indent: ${indent}px;">
<img src="${resURL}${it.iconFileName}" alt="ECU-TEST Log" height="16" width="16" />
<lsi:icon class="${it.iconClassName} icon-sm" alt="ECU-TEST Log" />
<st:nbsp />
<j:choose>
<j:when test="${!report.fileName.endsWith('.log')}">
Expand Down

0 comments on commit d91c999

Please sign in to comment.