Skip to content

Commit

Permalink
JBEHAVE-1358 Added JBehave version to view templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
maurotalevi committed May 22, 2019
1 parent 1b16022 commit cbd9307
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
32 changes: 32 additions & 0 deletions jbehave-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>jbehave.version</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>jbehave.version</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,30 @@ public Properties defaultViewProperties() {
properties.setProperty("encoding", charset.displayName());
properties.setProperty("decorateNonHtml", "true");
properties.setProperty("defaultFormats", "stats");
properties.setProperty("reportsViewType", Reports.ViewType.LIST.name());
properties.setProperty("version", jbehaveVersion());
properties.setProperty("reportsViewType", Reports.ViewType.LIST.name());
properties.setProperty("viewDirectory", "view");
return properties;
}

private String jbehaveVersion() {
try {
return IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("jbehave.version"), true);
} catch (IOException e) {
throw new RuntimeException("Failed to read JBehave version", e);
}
}

private Properties mergeWithDefault(Properties properties) {
Properties merged = defaultViewProperties();
merged.putAll(properties);
return merged;
}

private void addDateAndEncoding(Map<String, Object> dataModel) {
private void addViewProperties(Map<String, Object> dataModel) {
dataModel.put("date", new Date());
dataModel.put("encoding", this.viewProperties.getProperty("encoding"));
dataModel.put("version", this.viewProperties.getProperty("version"));
}

@Override
Expand All @@ -108,7 +118,7 @@ public void generateMapsView(File outputDirectory, StoryMaps storyMaps, Properti
String outputName = templateResource("viewDirectory") + "/maps.html";
String mapsTemplate = templateResource("maps");
Map<String, Object> dataModel = newDataModel();
addDateAndEncoding(dataModel);
addViewProperties(dataModel);
dataModel.put("storyLanes", new StoryLanes(storyMaps, nameResolver));
write(outputDirectory, outputName, mapsTemplate, dataModel);
generateViewsIndex(outputDirectory);
Expand All @@ -123,7 +133,7 @@ public void generateReportsView(File outputDirectory, List<String> formats, Prop
reports = createReports(readReportFiles(outputDirectory, outputName, mergedFormats));
reports.viewAs(ViewType.valueOf(viewProperties.getProperty("reportsViewType", Reports.ViewType.LIST.name())));
Map<String, Object> dataModel = newDataModel();
addDateAndEncoding(dataModel);
addViewProperties(dataModel);
dataModel.put("timeFormatter", new TimeFormatter());
dataModel.put("reports", reports);
dataModel.put("storyDurations", storyDurations(outputDirectory));
Expand Down Expand Up @@ -157,7 +167,7 @@ private void generateViewsIndex(File outputDirectory) {
String outputName = templateResource("viewDirectory") + "/index.html";
String viewsTemplate = templateResource("views");
Map<String, Object> dataModel = newDataModel();
addDateAndEncoding(dataModel);
addViewProperties(dataModel);
write(outputDirectory, outputName, viewsTemplate, dataModel);
}

Expand Down
2 changes: 1 addition & 1 deletion jbehave-core/src/main/resources/ftl/jbehave-maps.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ${inLane?string("x", "")}
<div class="clear"></div>
<div id="footer">
<div class="left">Generated on ${date?string("dd/MM/yyyy HH:mm:ss")}</div>
<div class="right">JBehave &#169; 2003-2015</div>
<div class="right">JBehave <#if version??>${version}</#if> &#169; 2003-${date?string("yyyy")}</div>
<div class="clear"></div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion jbehave-core/src/main/resources/ftl/jbehave-reports.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ${threads}-Thread Average
<div class="clear"></div>
<div id="footer">
<div class="left">Generated on ${date?string("dd/MM/yyyy HH:mm:ss")}</div>
<div class="right">JBehave &#169; 2003-2015</div>
<div class="right">JBehave <#if version??>${version}</#if> &#169; 2003-${date?string("yyyy")}</div>
<div class="clear"></div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion jbehave-core/src/main/resources/ftl/jbehave-views.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="clear"></div>
<div id="footer">
<div class="left">Generated on ${date?string("dd/MM/yyyy HH:mm:ss")}</div>
<div class="right">JBehave &#169; 2003-2015</div>
<div class="right">JBehave <#if version??>${version}</#if> &#169; 2003-${date?string("yyyy")}</div>
<div class="clear"></div>
</div>

Expand Down
1 change: 1 addition & 0 deletions jbehave-core/src/main/resources/jbehave.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${project.version}

0 comments on commit cbd9307

Please sign in to comment.