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 Icon Path Parameter #277

Open
wants to merge 3 commits 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
46 changes: 37 additions & 9 deletions src/main/java/htmlpublisher/HtmlPublisherTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
*/
private final boolean allowMissing;


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

/**
* Do not use, but keep to maintain compatibility with older releases. See JENKINS-31366.
*/
Expand All @@ -95,11 +101,11 @@
private Boolean useWrapperFileDirectly;

/**
* @deprecated Use {@link #HtmlPublisherTarget(java.lang.String, java.lang.String, java.lang.String, boolean, boolean, boolean)}.
* @deprecated Use {@link #HtmlPublisherTarget(java.lang.String, java.lang.String, java.lang.String, boolean, boolean, boolean, java.lang.String)}.
*/
@Deprecated
public HtmlPublisherTarget(String reportName, String reportDir, String reportFiles, boolean keepAll, boolean allowMissing) {
this(reportName, reportDir, reportFiles, keepAll, false, allowMissing);
public HtmlPublisherTarget(String reportName, String reportDir, String reportFiles, boolean keepAll, boolean allowMissing, String iconPath) {
this(reportName, reportDir, reportFiles, keepAll, false, allowMissing, iconPath);

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

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 108 is not covered by tests
}

public String getReportTitles() {
Expand All @@ -115,16 +121,18 @@
* @param alwaysLinkToLastBuild If true, the job action will refer the latest build.
* Otherwise, the latest successful one will be referenced
* @param allowMissing If true, blocks the build failure if the report is missing
* @param iconPath The path of an icon to use for the HTML report in the sidebar (relative to reportDir)
* @since 1.4
*/
@DataBoundConstructor
public HtmlPublisherTarget(String reportName, String reportDir, String reportFiles, boolean keepAll, boolean alwaysLinkToLastBuild, boolean allowMissing) {
public HtmlPublisherTarget(String reportName, String reportDir, String reportFiles, boolean keepAll, boolean alwaysLinkToLastBuild, boolean allowMissing, String iconPath) {
this.reportName = StringUtils.trim(reportName);
this.reportDir = StringUtils.trim(reportDir);
this.reportFiles = StringUtils.trim(reportFiles);
this.keepAll = keepAll;
this.alwaysLinkToLastBuild = alwaysLinkToLastBuild;
this.allowMissing = allowMissing;
this.iconPath = StringUtils.trim(iconPath);
}

public String getReportName() {
Expand Down Expand Up @@ -152,6 +160,10 @@
return this.allowMissing;
}

public String getIconPath() {
return this.iconPath;
}

public boolean getEscapeUnderscores() {
if (this.escapeUnderscores == null) {
return true;
Expand Down Expand Up @@ -253,11 +265,6 @@
String action = actualHtmlPublisherTarget.reportName;
return dir().exists() ? action : null;
}

public String getIconFileName() {
return dir().exists() ? "symbol-document-text" : null;
}

public String getBackToName() {
return Encode.forHtml(project.getDisplayName());
}
Expand Down Expand Up @@ -328,6 +335,16 @@
}
}

public String getIconFileName() {
String icon;
if (StringUtils.isNotBlank(super.actualHtmlPublisherTarget.iconPath)) {
icon = project.getUrl() + dir().getName() + "/" + super.actualHtmlPublisherTarget.iconPath;
} else {
icon = "symbol-document-text";
}
return dir().exists() ? icon : null;

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

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

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

@Override
protected String getTitle() {
return this.project.getDisplayName() + " html2";
Expand Down Expand Up @@ -423,6 +440,17 @@
return buildArchiveDir;
}

public String getIconFileName() {
String icon;
if (StringUtils.isNotBlank(super.actualHtmlPublisherTarget.iconPath)) {
icon = build.getUrl() + dir().getName() + "/" + super.actualHtmlPublisherTarget.iconPath;
} else {
icon = "symbol-document-text";
}
return dir().exists() ? icon : null;

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

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 445-450 are not covered by tests
}


/**
* Gets {@link HtmlPublisherTarget}, for which the action has been created.
* @return HTML Report description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
<f:entry field="useWrapperFileDirectly" title="${%useWrapperFileDirectly.title}">
<f:checkbox default="true"/>
</f:entry>
<f:entry field="iconPath" title="${%iconPath.title}">
<f:textbox />
</f:entry>
</f:advanced>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ keepAll.title=Keep past HTML reports
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
useWrapperFileDirectly.title=Use the legacy wrapper file
iconPath.title=Sidebar Icon Path
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
The path of an icon to use for the HTML report in the sidebar (relative to reportDir)
</div>
4 changes: 2 additions & 2 deletions src/test/java/htmlpublisher/HtmlFileNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void fileNameWithSpecialCharactersAndSingleSlash() throws Exception {

job.getBuildersList().add(new CreateFileBuilder("subdir/#$+,;= @.html", content));
job.getPublishersList().add(new HtmlPublisher(Arrays.asList(
new HtmlPublisherTarget("report-name", "", "subdir/*.html", true, true, false))));
new HtmlPublisherTarget("report-name", "", "subdir/*.html", true, true, false, ""))));
job.save();

j.buildAndAssertSuccess(job);
Expand All @@ -52,7 +52,7 @@ public void fileNameWithSpecialCharactersAndMultipleSlashes() throws Exception {

job.getBuildersList().add(new CreateFileBuilder("subdir/subdir2/#$+,;= @.html", content));
job.getPublishersList().add(new HtmlPublisher(Arrays.asList(
new HtmlPublisherTarget("report-name", "", "subdir/subdir2/*.html", true, true, false))));
new HtmlPublisherTarget("report-name", "", "subdir/subdir2/*.html", true, true, false, ""))));
job.save();

j.buildAndAssertSuccess(job);
Expand Down
34 changes: 17 additions & 17 deletions src/test/java/htmlpublisher/HtmlPublisherIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void dispose() throws IOException, InterruptedException {
public void testConfigRoundtrip() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
HtmlPublisherTarget[] l = {
new HtmlPublisherTarget("a", "b", "c", true, true, false),
new HtmlPublisherTarget("", "", "", false, false, false)
new HtmlPublisherTarget("a", "b", "c", true, true, false, "d"),
new HtmlPublisherTarget("", "", "", false, false, false, "")
};

p.getPublishersList().add(new HtmlPublisher(Arrays.asList(l)));
Expand All @@ -81,8 +81,8 @@ public void testConfigRoundtrip() throws Exception {
HtmlPublisher r = p.getPublishersList().get(HtmlPublisher.class);
assertEquals(2, r.getReportTargets().size());

j.assertEqualBeans(l[0], r.getReportTargets().get(0), "reportName,reportDir,reportFiles,keepAll,alwaysLinkToLastBuild,allowMissing");
j.assertEqualBeans(l[1], r.getReportTargets().get(1), "reportName,reportDir,reportFiles,keepAll,alwaysLinkToLastBuild,allowMissing");
j.assertEqualBeans(l[0], r.getReportTargets().get(0), "reportName,reportDir,reportFiles,keepAll,alwaysLinkToLastBuild,allowMissing,iconPath");
j.assertEqualBeans(l[1], r.getReportTargets().get(1), "reportName,reportDir,reportFiles,keepAll,alwaysLinkToLastBuild,allowMissing,iconPath");
}

@Test
Expand All @@ -99,10 +99,10 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", reportDir, "tab1.html", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", reportDir, "tab1.html", true, true, false, "");
//default behavior is include all
target1.setIncludes(HtmlPublisherTarget.INCLUDE_ALL_PATTERN);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("tab2", reportDir, "tab2.html", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("tab2", reportDir, "tab2.html", true, true, false, "");
String includes = "tab2.html";
target2.setIncludes(includes);
assertEquals(includes, target2.getIncludes());
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", "", "tab1/test.txt,tab1/test2.txt,**/test3.txt", true, false, true);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", "", "tab1/test.txt,tab1/test2.txt,**/test3.txt", true, false, true, "");
p.getPublishersList().add(new HtmlPublisher(Arrays.asList(target1)));
p.setAssignedLabel(Label.get("agent"));
FreeStyleBuild build = j.buildAndAssertSuccess(p);
Expand Down Expand Up @@ -168,7 +168,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
return true;
}
});
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "${MYREPORTFILES}", true, true, false );
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "${MYREPORTFILES}", true, true, false, "" );
target2.setReportTitles("${MYREPORTTITLE}");
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target2);
Expand All @@ -193,7 +193,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "**/aReportDir/*/afile.html, **/otherDir/afile.html", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "**/aReportDir/*/afile.html, **/otherDir/afile.html", true, true, false, "");
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
Expand All @@ -216,8 +216,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, true);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, true, "");
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false, "");

List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
Expand All @@ -238,8 +238,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, false, "");
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false, "");

List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
Expand All @@ -266,11 +266,11 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
});


HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", reportDir, "tab1.html", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", reportDir, "tab1.html", true, true, false, "");
//default behavior is to not use wrapper file directly
target1.setUseWrapperFileDirectly(false);
assertFalse(target1.getUseWrapperFileDirectly());
HtmlPublisherTarget target2 = new HtmlPublisherTarget("tab2", reportDir, "tab2.html", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("tab2", reportDir, "tab2.html", true, true, false, "");
target2.setUseWrapperFileDirectly(true);
assertTrue(target2.getUseWrapperFileDirectly());

Expand All @@ -296,8 +296,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, false, "");
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false, "");

List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/htmlpublisher/HtmlPublisherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class HtmlPublisherTest {
@Test
public void testDefaultIncludes() {
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", "target", "tab1.html", true, true, false);
HtmlPublisherTarget target1 = new HtmlPublisherTarget("tab1", "target", "tab1.html", true, true, false, "");
assertEquals(HtmlPublisherTarget.INCLUDE_ALL_PATTERN, target1.getIncludes());
target1.setIncludes(null);
assertEquals(HtmlPublisherTarget.INCLUDE_ALL_PATTERN, target1.getIncludes());
Expand All @@ -19,10 +19,11 @@ public void testDefaultIncludes() {

@Test
public void testSpacesTrimmed() {
HtmlPublisherTarget target = new HtmlPublisherTarget("tab1 ", "target ", "tab1.html ", true, true, false);
HtmlPublisherTarget target = new HtmlPublisherTarget("tab1 ", "target ", "tab1.html ", true, true, false, " icon.png ");
assertEquals(target.getReportName(), "tab1");
assertEquals(target.getReportDir(), "target");
assertEquals(target.getReportFiles(), "tab1.html");
assertEquals(target.getIconPath(), "icon.png");
}

@Test
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/htmlpublisher/Security3302Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public void security3302sanitizeJobNameTest() throws Exception {
"index.html",
true,
false,
false
false,
""
);

target.setUseWrapperFileDirectly(true);
target.setEscapeUnderscores(true);
target.setReportTitles("");
target.setIncludes("**/*");

List<HtmlPublisherTarget> reportTargets = new ArrayList<>();
reportTargets.add(target);

Expand Down Expand Up @@ -125,7 +126,8 @@ public void security3302sanitizeOptionalNameTest() throws Exception {
"test.txt",
true,
false,
false
false,
""
);

target.setUseWrapperFileDirectly(true);
Expand Down Expand Up @@ -174,7 +176,8 @@ public void security3302sanitizeExistingReportTitleTest() throws Exception {
"",
true,
false,
false
false,
""
);

target.setUseWrapperFileDirectly(true);
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/htmlpublisher/workflow/PublishHTMLStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void configRoundTrip() throws Exception {
public void testDeprecationWarningDisplayedWhenTryingToResolveParameters() throws Exception {
writeTestHTML("index.html");
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", TEST_REPORT_DIR, "${TEST}", false, false, false);
("testReport", TEST_REPORT_DIR, "${TEST}", false, false, false, "");
setupAndRunProject(target);

// Ensure that the report has been attached properly
Expand All @@ -103,7 +103,7 @@ public void testDeprecationWarningDisplayedWhenTryingToResolveParameters() throw
public void testDeprecationWarningNotDisplayedWhenNotTryingToResolveParameters() throws Exception {
writeTestHTML("index.html");
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", TEST_REPORT_DIR, "test", false, false, false);
("testReport", TEST_REPORT_DIR, "test", false, false, false, "");
setupAndRunProject(target);

// Ensure that the report has been attached properly
Expand All @@ -119,7 +119,7 @@ public void publishReportOnProjectLevel() throws Exception {

// Run the project
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", TEST_REPORT_DIR, "index.html", false, false, false);
("testReport", TEST_REPORT_DIR, "index.html", false, false, false, "");
setupAndRunProject(target);

// Ensure that the report has been attached properly
Expand All @@ -139,7 +139,7 @@ public void publishReportOnBuildLevel() throws Exception {

// Run the project
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", TEST_REPORT_DIR, "index.html", true, false, false);
("testReport", TEST_REPORT_DIR, "index.html", true, false, false, "");
target.setReportTitles("index");
setupAndRunProject(target);

Expand All @@ -157,7 +157,7 @@ public void publishReportOnBuildLevel() throws Exception {
public void publishMissingReportFolder() throws Exception {
final String missingReportDir = "testReportDirNonExistent";
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", missingReportDir, "index.html", false, false, false);
("testReport", missingReportDir, "index.html", false, false, false, "");
target.setReportTitles("index");
setupAndRunProject(target);
File missingReportDirFile = new File(testWorkspace, "workspace/" + TEST_PROJECT_NAME + "/" + missingReportDir);
Expand All @@ -172,7 +172,7 @@ public void publishMissingReportFolder() throws Exception {
@Test
public void publishMissingReport_allowMissing() throws Exception {
final HtmlPublisherTarget target = new HtmlPublisherTarget
("testReport", "testReportDirNonExistent", "index.html", false, false, true);
("testReport", "testReportDirNonExistent", "index.html", false, false, true, "");
target.setReportTitles("index");
setupAndRunProject(target);

Expand Down Expand Up @@ -214,15 +214,15 @@ private void setupAndRunProject(@NonNull HtmlPublisherTarget target) throws Exce

private void configRoundTrip(String reportName, String reportDir, String reportFiles) throws Exception {
final HtmlPublisherTarget target = new HtmlPublisherTarget
(reportName, reportDir, reportFiles, false, false, false);
(reportName, reportDir, reportFiles, false, false, false, "");
target.setReportTitles("index");
configRoundTrip(target);
}

private void configRoundTrip(String reportName, String reportDir, String reportFiles,
boolean keepAll, boolean alwaysLinkToLastBuild, boolean allowMissing) throws Exception {
final HtmlPublisherTarget target = new HtmlPublisherTarget
(reportName, reportDir, reportFiles, false, false, false);
(reportName, reportDir, reportFiles, false, false, false, "");
target.setReportTitles("index");
configRoundTrip(target);
}
Expand Down