Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for icon on sidebar report action #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Clicking _Publishing options..._ will present you with some additional options:
* Allow missing report - if `false`, build will be marked as failed if the report directory does not exist.
* Include files - Optional Ant pattern that specifies what files in the report directory to archive. Defaults to archiving all files in the given report directory.
* Escape underscores in Report Title - if `true`, underscores in report titles will be escaped to `_5F` along with other non-alphanumeric characters. If `false` they will be left as is.
* Icon - Optional icon to use for the report. If not provided, a default icon will be used. The icon can be an existing `symbol` or an icon from the reportDir

#### Using with Pipeline Jobs

Expand Down
27 changes: 26 additions & 1 deletion src/main/java/htmlpublisher/HtmlPublisherTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
*/
private final boolean allowMissing;

/**
* The path or symbol of an icon to use for the HTML report in the sidebar (relative to reportDir)
*/
private String icon;

/**
* Do not use, but keep to maintain compatibility with older releases. See JENKINS-31366.
*/
Expand Down Expand Up @@ -162,6 +167,15 @@
}
}

public String getIcon() {
return icon;
}

@DataBoundSetter
public void setIcon(String icon) {
this.icon = StringUtils.trim(icon);
}

@DataBoundSetter
public void setEscapeUnderscores(boolean escapeUnderscores) {
this.escapeUnderscores = escapeUnderscores;
Expand Down Expand Up @@ -266,7 +280,18 @@
}

public String getIconFileName() {
return dir().exists() ? "symbol-document-text" : null;
String icon;
if (StringUtils.isNotBlank(actualHtmlPublisherTarget.icon)) {

Check warning on line 284 in src/main/java/htmlpublisher/HtmlPublisherTarget.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 284 is only partially covered, one branch is missing
if (actualHtmlPublisherTarget.icon.startsWith("symbol-")) {
icon = actualHtmlPublisherTarget.icon;
}
else {
icon = project.getUrl() + dir().getName() + "/" + actualHtmlPublisherTarget.icon;

Check warning on line 289 in src/main/java/htmlpublisher/HtmlPublisherTarget.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 285-289 are not covered by tests
}
} else {
icon = "symbol-document-text";
}
return dir().exists() ? icon : null;

Check warning on line 294 in src/main/java/htmlpublisher/HtmlPublisherTarget.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 294 is only partially covered, one branch is missing
}

public String getBackToName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
<f:entry field="numberOfWorkers" title="${%numberOfWorkers.title}">
<f:number/>
</f:entry>
<f:entry field="icon" title="${%icon.title}">
<f:textbox />
</f:entry>
</f:advanced>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ alwaysLinkToLastBuild.title=Always link to last build
allowMissing.title=Allow missing report
escapeUnderscores.title=Escape underscores in Report Title
useWrapperFileDirectly.title=Use the legacy wrapper file
numberOfWorkers.title=Number of workers
numberOfWorkers.title=Number of workers
icon.title=Icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
The path of an icon or symbol to use for the HTML report (relative to reportDir)
</div>
27 changes: 27 additions & 0 deletions src/test/java/htmlpublisher/HtmlPublisherIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,33 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
assertFalse("reportnameB/htmlpublisher-wrapper.html must not exist", new File(build.getRootDir(), "htmlreports/reportnameB/htmlpublisher-wrapper.html").exists());
}

@Test
public void testIcon() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace();
ws.child("dirA").child("file1.html").write("hello", "UTF-8");
ws.child("dirA").child("file2.html").write("hello", "UTF-8");
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, true);
target1.setIcon("symbol-cube");
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
target2.setIcon("symbol-build");

List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
AbstractBuild build = j.buildAndAssertSuccess(p);
assertTrue("reportnameA/htmlpublisher-wrapper.html must exist", new File(build.getRootDir(), "htmlreports/reportnameA/htmlpublisher-wrapper.html").exists());
assertTrue("reportnameA/file1.html must exist", new File(build.getRootDir(), "htmlreports/reportnameA/file1.html").exists());
assertTrue("reportnameA/file2.html must exist", new File(build.getRootDir(), "htmlreports/reportnameA/file2.html").exists());
assertFalse("reportnameB/htmlpublisher-wrapper.html must not exist", new File(build.getRootDir(), "htmlreports/reportnameB/htmlpublisher-wrapper.html").exists());
}

@Test
public void testPublishesTwoReportsOneJob() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
Expand Down