Skip to content

Commit

Permalink
Merge pull request #170 from trivago/custom-parameters-file
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
Benjamin Bischoff authored Jun 14, 2019
2 parents c3a9cfa + 6d616e4 commit 7815ad5
Show file tree
Hide file tree
Showing 21 changed files with 424 additions and 108 deletions.
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
language: java
sudo: false # faster builds
language:
java

before_install:
- pip install --user codecov

script:
before_script:
- cd plugin-code
- mvn cobertura:cobertura
- pip install --user codecov

after_success:
- bash <(curl -s https://codecov.io/bash)
- codecov

- codecov
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [2.0.0] - UNRELEASED
## [2.0.0] - 2019-06-14

### Added
* Ability to set custom parameters via a properties file through the `customParametersFile` property (#167, contributed by gazler22)

### Fixed
* Custom parameters are now displayed in the order of definition (#157)
* Better logging and error handling

### Changed
* Major internal architecture change to ease extension
* Major internal architecture change to ease future extension

## [1.11.0] - 2019-05-21

Expand Down
47 changes: 36 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,6 @@ This points to the root directory of the generated Cluecumber HTML report.

## Optional Configuration Parameters

### skip

The `skip` property is used to skip the report generation. The default value is `false`

```xml
<configuration>
<skip>true</skip>
...
</configuration>
```

### customParameters

The `customParameters` block can be used to define custom information that should be displayed on the report start page.
Expand All @@ -178,6 +167,42 @@ The property definitions above are shown in the report like this:

![custom parameters](documentation/img/custom_params.png)

### customParametersFile

You can also set custom parameters by specifying the path to a `.properties` file in the `customParametersFile` property like this:

```xml
<configuration>
<customParametersFile>path/to/your/customParameters.properties</customParametersFile>
...
</configuration>
```

This file needs to have a format like this:

```properties
Custom_Parameter=This is a test
Custom_URL=http://www.google.com
```

__Note:__ These custom parameters behave exactly like the ones defined by the `customParameters` property and will be added on top of already defined properties.
If a property has the same name as an existing one, its value will be overwritten!

The property definitions above are shown in the report like this:

![custom parameters](documentation/img/custom_params.png)

### skip

The `skip` property is used to skip the report generation. The default value is `false`

```xml
<configuration>
<skip>true</skip>
...
</configuration>
```

### failScenariosOnPendingOrUndefinedSteps

This optional property can be set to `true` if you scenarios should be marked as `failed` when they contain `pending` or `skipped` steps.
Expand Down
Empty file.
5 changes: 4 additions & 1 deletion example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.benjamin-bischoff</groupId>
<artifactId>cluecumber-test-project</artifactId>
<version>1.11.0</version>
<version>2.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -42,6 +42,9 @@
<Empty_Parameter/>
</customParameters>

<!-- Optional custom parameters file -->
<customParametersFile>custom/custom.properties</customParametersFile>

<!-- Optional: mark scenarios as failed that contain pending or undefined steps (default: false) -->
<!--<failScenariosOnPendingOrUndefinedSteps>true</failScenariosOnPendingOrUndefinedSteps>-->

Expand Down
31 changes: 20 additions & 11 deletions plugin-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,28 @@
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.maven.plugin}</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -156,6 +164,7 @@
<configuration>
<goalPrefix>cluecumber-report</goalPrefix>
<skipErrorNoDescriptorsFound>false</skipErrorNoDescriptorsFound>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public final class CluecumberReportPlugin extends AbstractMojo {
@Parameter(property = "reporting.customParameters")
private LinkedHashMap<String, String> customParameters = new LinkedHashMap<>();

/**
* Path to a properties file. The included properties are converted to custom parameters.
* <pre>
*
* </pre>
*/
@Parameter(property = "reporting.customParametersFile")
private String customParametersFile = "";

/**
* Mark scenarios as failed if they contain pending or undefined steps (default: false).
*/
Expand Down Expand Up @@ -141,12 +150,12 @@ public void execute() throws CluecumberPluginException {
propertyManager.setSourceJsonReportDirectory(sourceJsonReportDirectory);
propertyManager.setGeneratedHtmlReportDirectory(generatedHtmlReportDirectory);
propertyManager.setCustomParameters(customParameters);
propertyManager.setCustomParametersFile(customParametersFile);
propertyManager.setFailScenariosOnPendingOrUndefinedSteps(failScenariosOnPendingOrUndefinedSteps);
propertyManager.setExpandBeforeAfterHooks(expandBeforeAfterHooks);
propertyManager.setExpandStepHooks(expandStepHooks);
propertyManager.setExpandDocStrings(expandDocStrings);
propertyManager.setCustomCss(customCss);
propertyManager.validateSettings();
propertyManager.setCustomCssFile(customCss);

logger.logSeparator();
logger.info(String.format(" Cluecumber Report Maven Plugin, version %s", getClass().getPackage().getImplementationVersion()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.trivago.cluecumber.exceptions.filesystem.MissingFileException;

import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -79,4 +80,15 @@ public String readContentFromFile(final String filePath) throws MissingFileExcep
throw new MissingFileException(filePath);
}
}

/**
* Check if a file exists.
*
* @param filePath the complete path to the file.
* @return true if the file exists.
*/
public boolean isExistingFile(final String filePath) {
File file = new File(filePath);
return file.exists() && file.isFile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.trivago.cluecumber.properties;

import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class LinkedProperties extends Properties {

private static final long serialVersionUID = 1L;

private Map<Object, Object> linkMap = new LinkedHashMap<>();

@Override
public synchronized Object put(Object key, Object value) {
return linkMap.put(key, value);
}

@Override
public synchronized boolean contains(Object value) {
return linkMap.containsValue(value);
}

@Override
public boolean containsValue(Object value) {
return linkMap.containsValue(value);
}

@Override
public synchronized Enumeration<Object> elements() {
throw new UnsupportedOperationException(
"Please use keySet() or entrySet() instead of Enumeration.");
}

@Override
public Set<Map.Entry<Object, Object>> entrySet() {
return linkMap.entrySet();
}

@Override
public synchronized void clear() {
linkMap.clear();
}

@Override
public synchronized boolean containsKey(Object key) {
return linkMap.containsKey(key);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.trivago.cluecumber.properties;

import com.trivago.cluecumber.exceptions.CluecumberPluginException;
import com.trivago.cluecumber.filesystem.FileIO;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.StringReader;
import java.util.LinkedHashMap;
import java.util.Map;

@Singleton
public class PropertiesFileLoader {

private FileIO fileIO;

@Inject
public PropertiesFileLoader(final FileIO fileIO) {
this.fileIO = fileIO;
}

LinkedHashMap<String, String> loadPropertiesMap(final String propertiesFilePath) throws CluecumberPluginException {
LinkedHashMap<String, String> propertiesMap = new LinkedHashMap<>();
String content = fileIO.readContentFromFile(propertiesFilePath);
LinkedProperties properties = new LinkedProperties();
try {
properties.load(new StringReader(content));
} catch (IOException e) {
throw new CluecumberPluginException("Could not parse properties file '" + "': " + e.getMessage());
}
for (Map.Entry<Object, Object> propertyEntry : properties.entrySet()) {
propertiesMap.put((String) propertyEntry.getKey(), (String) propertyEntry.getValue());
}
return propertiesMap;
}
}
Loading

0 comments on commit 7815ad5

Please sign in to comment.