Skip to content

Commit

Permalink
Merge pull request #3 from jenkinsci/from-workspace
Browse files Browse the repository at this point in the history
[FIXED JENKINS-30981] Custom files are now taken from workspace
  • Loading branch information
wolfs committed Nov 4, 2015
2 parents 62d623a + 901ec03 commit 414932c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
Expand Up @@ -30,7 +30,6 @@
import static hudson.init.InitMilestone.PLUGINS_STARTED;

public class JgivenReportGenerator extends Recorder implements SimpleBuildStep {

public static final String REPORTS_DIR = "jgiven-reports";
private List<ReportConfig> reportConfigs;

Expand Down Expand Up @@ -73,17 +72,17 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
listener.getLogger().println(Messages.JgivenReportGenerator_results_found(numFiles));
for (ReportConfig reportConfig : reportConfigs) {
listener.getLogger().println(Messages.JgivenReportGenerator_generating_report(reportConfig.getReportName()));
generateReport(reportRootDir, jgivenJsons, reportConfig);
generateReport(reportRootDir, jgivenJsons, reportConfig, workspace);
}
run.addAction(new JgivenReportAction(run, reportConfigs));
} else {
listener.getLogger().println(Messages._JgivenReportGenerator_no_reports());
}
}

private void generateReport(File reportRootDir, File JgivenJsons, ReportConfig reportConfig) throws IOException, InterruptedException {
private void generateReport(File reportRootDir, File JgivenJsons, ReportConfig reportConfig, FilePath workspace) throws IOException, InterruptedException {
try {
reportConfig.reportGenerator(JgivenJsons, reportRootDir).generate();
reportConfig.reportGenerator(JgivenJsons, reportRootDir, workspace).generate();
} catch (IOException e) {
throw e;
} catch (RuntimeException e) {
Expand Down Expand Up @@ -156,7 +155,7 @@ public String getReportUrl() {

abstract String getReportName();

public ReportGenerator reportGenerator(File sourceDir, File reportRootDir) {
public ReportGenerator reportGenerator(File sourceDir, File reportRootDir, FilePath workspace) throws IOException, InterruptedException {
ReportGenerator reportGenerator = new ReportGenerator();
reportGenerator.setSourceDirectory(sourceDir);
reportGenerator.setFormat(getFormat());
Expand Down Expand Up @@ -220,20 +219,26 @@ public void setTitle(String title) {
}

@Override
public ReportGenerator reportGenerator(File sourceDir, File reportRootDir) {
ReportGenerator reportGenerator = super.reportGenerator(sourceDir, reportRootDir);
public ReportGenerator reportGenerator(File sourceDir, File reportRootDir, FilePath workspace) throws IOException, InterruptedException {
ReportGenerator reportGenerator = super.reportGenerator(sourceDir, reportRootDir, workspace);
if (StringUtils.isNotBlank(customCssFile)) {
reportGenerator.getConfig().setCustomCssFile(new File(customCssFile));
reportGenerator.getConfig().setCustomCssFile(copyFileToMaster(workspace, customCssFile));
}
if (StringUtils.isNotBlank(customJsFile)) {
reportGenerator.getConfig().setCustomJsFile(new File(customJsFile));
reportGenerator.getConfig().setCustomJsFile(copyFileToMaster(workspace, customJsFile));
}
if (StringUtils.isNotBlank(title)) {
reportGenerator.getConfig().setTitle(title);
}
return reportGenerator;
}

private File copyFileToMaster(FilePath workspace, String file) throws IOException, InterruptedException {
File tmpFile = File.createTempFile("file", null);
workspace.child(file).copyTo(new FilePath(tmpFile));
return tmpFile;
}

@Extension
public static class DescriptorImpl extends Descriptor<ReportConfig> {
@Override
Expand Down
@@ -1,3 +1,4 @@
<div>
Custom Css File which will be referenced from the JGiven Reports. This file needs to be on the Jenkins master and will be copied to the report directory.
Custom Css File which will be referenced from the JGiven Reports. This path is relative to the workspace.
The file will be copied to the JGiven report directory.
</div>
@@ -1,4 +1,4 @@
<div>
Eigene CSS-Datei, die für die JGiven-Berichte benutzt wird. Diese Datei muss sich auf dem Jenkins Master befinden
und wird dann in das Berichtsverzeichnis kopiert.
Eigene CSS-Datei, die für die JGiven-Berichte benutzt wird. Der Pfad wird relativ zum Workspace-Verzeichnis ausgewertet.
Die Datei wird dann in das Berichtsverzeichnis kopiert.
</div>
@@ -1,3 +1,4 @@
<div>
Custom Js File which will be referenced from the JGiven Reports. This file needs to be on the Jenkins master and will be copied to the report directory.
Custom Js File which will be referenced from the JGiven Reports. This path is relative to the workspace.
The file will be copied to the JGiven report directory.
</div>
@@ -1,4 +1,4 @@
<div>
Eigene JS-Datei, die für die JGiven-Berichte benutzt wird. Diese Datei muss sich auf dem Jenkins Master befinden
und wird dann in das Berichtsverzeichnis kopiert.
Eigene JS-Datei, die für die JGiven-Berichte benutzt wird. Der Pfad wird relativ zum Workspace-Verzeichnis ausgewertet.
Die Datei wird dann in das Berichtsverzeichnis kopiert.
</div>

0 comments on commit 414932c

Please sign in to comment.