Skip to content

Commit

Permalink
Merge pull request #2 from jenkinsci/JENKINS-36472
Browse files Browse the repository at this point in the history
[JENKINS-36472] depend on Icon Shim Plugin
  • Loading branch information
cpoenisch committed Jan 6, 2017
2 parents 5e8f792 + 2a0a74d commit d8bdb34
Show file tree
Hide file tree
Showing 41 changed files with 142 additions and 119 deletions.
16 changes: 11 additions & 5 deletions pom.xml
Expand Up @@ -84,6 +84,7 @@

<!-- Jenkins plugins -->
<matrix-project.version>1.4</matrix-project.version>
<icon-shim.version>2.0.2</icon-shim.version>
<junit.version>1.3</junit.version>
<job-dsl.version>1.37</job-dsl.version>
<structs.version>1.5</structs.version>
Expand Down Expand Up @@ -159,6 +160,16 @@
<artifactId>matrix-project</artifactId>
<version>${matrix-project.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.icon-shim</groupId>
<artifactId>icon-shim</artifactId>
<version>${icon-shim.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>${structs.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -186,11 +197,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>${structs.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/de/tracetronic/jenkins/plugins/ecutest/ETPlugin.java
Expand Up @@ -37,6 +37,9 @@
import jenkins.model.Jenkins;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconType;

import de.tracetronic.jenkins.plugins.ecutest.report.atx.ATXPublisher.DescriptorImpl;

Expand Down Expand Up @@ -191,6 +194,50 @@ public static ToolVersion parse(final String version) throws IllegalArgumentExce
}
}

@Override
public void start() throws Exception {
super.start();

for (final String name : new String[] {
"atx-report",
"atx-trend",
"ecu-test",
"ecu-test-pkg",
"ecu-test-prj",
"report-generator",
"test-guide",
"trf-report",
}) {
// Register small (16x16) icons
IconSet.icons.addIcon(new Icon(
String.format("icon-ecutest-%s icon-sm", name),
String.format("ecutest/icons/16x16/%s.png", name),
Icon.ICON_SMALL_STYLE, IconType.PLUGIN)
);

// Register medium (24x24) icons
IconSet.icons.addIcon(new Icon(
String.format("icon-ecutest-%s icon-md", name),
String.format("ecutest/icons/24x24/%s.png", name),
Icon.ICON_MEDIUM_STYLE, IconType.PLUGIN)
);

// Register large (32x32) icons
IconSet.icons.addIcon(new Icon(
String.format("icon-ecutest-%s icon-lg", name),
String.format("ecutest/icons/32x32/%s.png", name),
Icon.ICON_LARGE_STYLE, IconType.PLUGIN)
);

// Register x-large (48x48) icons
IconSet.icons.addIcon(new Icon(
String.format("icon-ecutest-%s icon-xlg", name),
String.format("ecutest/icons/48x48/%s.png", name),
Icon.ICON_XLARGE_STYLE, IconType.PLUGIN)
);
}
}

@Override
public void postInitialize() throws Exception {
super.postInitialize();
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2017 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,24 +29,23 @@
*/
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 java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.annotation.CheckForNull;

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

import org.jenkins.ui.icon.Icon;
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 +54,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 +108,16 @@ protected VirtualFile getArchiveTargetDir(final File rootDir) {
@CheckForNull
protected abstract Run<?, ?> getLastReportBuild(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";
}
@Override
public String getIconFileName() {
final String iconClass = getIconClassName() + " icon-xlg";
try {
// FIXME: workaround signature changes in different versions of {@link IconSet} by reflection
final Method getIconByClassSpec = IconSet.class.getMethod("getIconByClassSpec", Object.class);
return ((Icon) getIconByClassSpec.invoke(IconSet.icons, iconClass)).getUrl();
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// ignore
}
return iconPath;
return IconSet.icons.getIconByClassSpec(iconClass).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";
}
}
@@ -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

0 comments on commit d8bdb34

Please sign in to comment.