-
Notifications
You must be signed in to change notification settings - Fork 232
/
CucumberReportBaseAction.java
51 lines (36 loc) · 1.64 KB
/
CucumberReportBaseAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package net.masterthought.jenkins;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import hudson.FilePath;
import hudson.model.Action;
import hudson.model.DirectoryBrowserSupport;
import net.masterthought.cucumber.ReportBuilder;
public abstract class CucumberReportBaseAction implements Action {
protected static final String BASE_URL = "cucumber-html-reports";
private static final String DEFAULT_PAGE = ReportBuilder.HOME_PAGE;
public String getUrlName() {
return BASE_URL;
}
public String getDisplayName() {
return Messages.SidePanel_DisplayName();
}
public String getIconFileName() {
return "/plugin/cucumber-reports/cuke.png";
}
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
// since Jenkins blocks JavaScript as described at
// https://wiki.jenkins-ci.org/display/JENKINS/Configuring+Content+Security+Policy and fact that plugin uses JS
// to display charts, following must be applied
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP",
"sandbox; script-src 'self' 'unsafe-inline'; default-src 'self'; img-src 'self'; style-src 'self';");
DirectoryBrowserSupport dbs = new DirectoryBrowserSupport(this, new FilePath(dir()), getTitle(), getUrlName(),
false);
dbs.setIndexFileName(DEFAULT_PAGE);
dbs.generateResponse(req, rsp, this);
}
protected abstract String getTitle();
protected abstract File dir();
}