Skip to content

Commit

Permalink
Merge pull request #194 from trivago/2.2.0
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
Benjamin Bischoff authored Jul 17, 2019
2 parents 413f22c + 9309f8c commit d462de1
Show file tree
Hide file tree
Showing 27 changed files with 678 additions and 457 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [2.2.0] - UNRELEASED
## [2.2.0] - 2019-07-17

### Added

* Hide scenarios with matching status on the `Scenario Sequence` page when disabling a status in the diagram (#175)
* Clicking a pie chart slice toggles the according scenarios in `All Scenarios` and `Scenario Sequence` (#175)
* Logging can be configured via the `logLevel` property (#189)

### Changed

* Changed internal chart generation to simplify future chart features
* Scenario runtimes is now displayed in seconds in the `Scenario Detail` page graph (#193)
* Renamed y axis of `All Steps` page graph to `Number of Usages` (#193)

### Fixed

* Wrong wording in `All Tags` page
* Wrong y axis scale labels in stacked bar charts
* Missing `All Features` navigation link

## [2.1.0] - 2019-06-25

Expand Down Expand Up @@ -510,6 +520,7 @@ steps with status `pending` or `undefined` (default value is `false`) (#74)

Initial project version on GitHub and Maven Central.

[2.2.0]: https://github.com/trivago/cluecumber-report-plugin/tree/2.2.0
[2.1.1]: https://github.com/trivago/cluecumber-report-plugin/tree/2.1.1
[2.1.0]: https://github.com/trivago/cluecumber-report-plugin/tree/2.1.0
[2.0.1]: https://github.com/trivago/cluecumber-report-plugin/tree/2.0.1
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ This points to the root directory of the generated Cluecumber HTML report.

## Optional Configuration Parameters

### Plugin Logging

By default, Cluecumber logs all information including

* its own name and version
* all passed property values
* the generated report location

This can be configured by passing the `logLevel` property:

```
<logLevel>default|compact|minimal|off</logLevel>
```

* _default_ will log all the mentioned information
* _compact_ will only log the source and target directories, plugin name and version and the generated report location
* _minimal_ will only log the generated report location
* _off_ will prevent any logging


### Add Custom Information to the Report

#### Add Custom Information Using Properties
Expand Down
16 changes: 11 additions & 5 deletions 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>2.1.0</version>
<version>2.2.0</version>

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

<!-- Optional custom colors for passed, failed and skipped -->
<!--<customStatusColorPassed>#017FAF</customStatusColorPassed>-->
<!--<customStatusColorFailed>#C94A38</customStatusColorFailed>-->
<!--<customStatusColorSkipped>#F48F00</customStatusColorSkipped>-->
<customStatusColorPassed>#017FAF</customStatusColorPassed>
<customStatusColorFailed>#C94A38</customStatusColorFailed>
<customStatusColorSkipped>#F48F00</customStatusColorSkipped>

<!-- Optional report page title -->
<customPageTitle>My Report</customPageTitle>
Expand All @@ -66,7 +66,13 @@
<!--<expandStepHooks>true</expandStepHooks>-->
<!--<expandDocStrings>true</expandDocStrings>-->

<!-- Optional skip property for the whole report generation -->
<!-- optional: Cluecumber log level -->
<!--<logLevel>default</logLevel>-->
<!--<logLevel>compact</logLevel>-->
<logLevel>minimal</logLevel>
<!--<logLevel>off</logLevel>-->

<!-- Optionally skip the whole report generation -->
<!--<skip>true</skip>-->
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion plugin-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>
<url>https://github.com/trivago/cluecumber-report-plugin</url>

<name>Cluecumber Maven Plugin for Cucumber Reports</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.nio.file.Path;
import java.util.List;

import static com.trivago.cluecumber.logging.CluecumberLogger.CluecumberLogLevel.COMPACT;
import static com.trivago.cluecumber.logging.CluecumberLogger.CluecumberLogLevel.DEFAULT;

/**
* The main plugin class.
*/
Expand Down Expand Up @@ -81,16 +84,18 @@ public CluecumberReportPlugin(
*/
public void execute() throws CluecumberPluginException {
// Initialize logger to be available outside the AbstractMojo class
logger.setMojoLogger(getLog());
logger.initialize(getLog(), logLevel);

if (skip) {
logger.info("Cluecumber report generation was skipped using the <skip> property.");
logger.info("Cluecumber report generation was skipped using the <skip> property.",
DEFAULT);
return;
}

logger.logSeparator();
logger.info(String.format(" Cluecumber Report Maven Plugin, version %s", getClass().getPackage().getImplementationVersion()));
logger.logSeparator();
logger.logInfoSeparator(DEFAULT);
logger.info(String.format(" Cluecumber Report Maven Plugin, version %s", getClass().getPackage()
.getImplementationVersion()), DEFAULT);
logger.logInfoSeparator(DEFAULT, COMPACT);

super.execute();

Expand All @@ -105,14 +110,18 @@ public void execute() throws CluecumberPluginException {
Report[] reports = jsonPojoConverter.convertJsonToReportPojos(jsonString);
allScenariosPageCollection.addReports(reports);
} catch (CluecumberPluginException e) {
logger.error("Could not parse JSON in file '" + jsonFilePath.toString() + "': " + e.getMessage());
logger.warn("Could not parse JSON in file '" + jsonFilePath.toString() + "': " + e.getMessage());
}
}
elementIndexPreProcessor.addScenarioIndices(allScenariosPageCollection.getReports());
reportGenerator.generateReport(allScenariosPageCollection);
logger.info(
"=> Cluecumber Report: " + propertyManager.getGeneratedHtmlReportDirectory() + "/" +
PluginSettings.SCENARIO_SUMMARY_PAGE_PATH + PluginSettings.HTML_FILE_EXTENSION);
PluginSettings.SCENARIO_SUMMARY_PAGE_PATH + PluginSettings.HTML_FILE_EXTENSION,
DEFAULT,
COMPACT,
CluecumberLogger.CluecumberLogLevel.MINIMAL
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public class PropertyCollector extends AbstractMojo {
@Parameter(property = "reporting.customPageTitle")
private String customPageTitle;

/**
* Optional log level to control what information is logged in the console.
* Allowed values: default, compact, minimal, off
*/
@Parameter(property = "parallel.logLevel", defaultValue = "default")
String logLevel;

@Inject
public PropertyCollector(final PropertyManager propertyManager) {
this.propertyManager = propertyManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trivago.cluecumber.constants;

import com.trivago.cluecumber.properties.PropertyManager;
Expand All @@ -21,6 +37,17 @@ public ChartConfiguration(final PropertyManager propertyManager) {
this.propertyManager = propertyManager;
}

public String getColorRgbaStringByStatus(final Status status) {
switch (status) {
case FAILED:
return getFailedColorRgbaString();
case SKIPPED:
return getSkippedColorRgbaString();
default:
return getPassedColorRgbaString();
}
}

public String getPassedColorRgbaString() {
if (passedColorRgbaString == null) {
passedColorRgbaString = getRgbaColorStringFromHex(propertyManager.getCustomStatusColorPassed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private String saveEmbeddingToFileAndGetFilename(final Embedding embedding) {
try {
fileIO.writeContentToFile(dataBytes, propertyManager.getGeneratedHtmlReportDirectory() + "/attachments/" + filename);
} catch (FileCreationException e) {
logger.error("Could not process image " + filename + " but will continue report generation...");
logger.warn("Could not process image " + filename + " but will continue report generation...");
}
embedding.encodeData(embedding.getData());
// Clear attachment data to reduce memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,93 @@
import org.apache.maven.plugin.logging.Log;

import javax.inject.Singleton;
import java.util.Arrays;

@Singleton
public class CluecumberLogger {

private Log mojoLogger;
private CluecumberLogLevel currentLogLevel;

public void setMojoLogger(final Log mojoLogger) {
/**
* Set the mojo logger so it can be used in any class that injects a CluecumberLogger.
*
* @param mojoLogger The current {@link Log}.
* @param currentLogLevel the log level that the logger should react to.
*/
public void initialize(final Log mojoLogger, final String currentLogLevel) {
this.mojoLogger = mojoLogger;
if (currentLogLevel == null) {
this.currentLogLevel = CluecumberLogLevel.DEFAULT;
return;
}

try {
this.currentLogLevel = CluecumberLogLevel.valueOf(currentLogLevel.toUpperCase());
} catch (IllegalArgumentException e) {
this.currentLogLevel = CluecumberLogLevel.DEFAULT;
warn("Log level " + currentLogLevel + " is unknown. Cluecumber will use 'default' logging.");
}
}

public void logInfoSeparator(final CluecumberLogLevel... cluecumberLogLevels) {
info("------------------------------------------------------------------------", cluecumberLogLevels);
}

/**
* Info logging based on the provided Cluecumber log levels.
*
* @param logString The {@link String} to be logged.
* @param cluecumberLogLevels The log levels ({@link CluecumberLogLevel} list) in which the message should be displayed.
*/
public void info(final CharSequence logString, CluecumberLogLevel... cluecumberLogLevels) {
log(LogLevel.INFO, logString, cluecumberLogLevels);
}

/**
* Warn logging. This is always displayed unless logging is off.
*
* @param logString The {@link String} to be logged.
*/
public void warn(final CharSequence logString) {
CluecumberLogLevel[] logLevels =
new CluecumberLogLevel[]{CluecumberLogLevel.DEFAULT, CluecumberLogLevel.COMPACT, CluecumberLogLevel.MINIMAL};
log(LogLevel.WARN, logString, logLevels);
}

public void info(final CharSequence charSequence) {
mojoLogger.info(charSequence);
/**
* Logs a message based on the provided log levels.
*
* @param logString The {@link String} to be logged.
* @param CluecumberLogLevels The log levels ({@link CluecumberLogger} list) in which the message should be displayed.
*/
private void log(final LogLevel logLevel, final CharSequence logString, CluecumberLogLevel... CluecumberLogLevels) {
if (currentLogLevel == CluecumberLogLevel.OFF) {
return;
}

if (currentLogLevel != null
&& CluecumberLogLevels != null
&& CluecumberLogLevels.length > 0
&& Arrays.stream(CluecumberLogLevels)
.noneMatch(CluecumberLogLevel -> CluecumberLogLevel == currentLogLevel)) {
return;
}
switch (logLevel) {
case INFO:
mojoLogger.info(logString);
break;
case WARN:
mojoLogger.warn(logString);
break;
}
}

public void error(final CharSequence charSequence) {
mojoLogger.error(charSequence);
private enum LogLevel {
INFO, WARN
}

public void logSeparator() {
info("------------------------------------------------------------------------");
public enum CluecumberLogLevel {
DEFAULT, COMPACT, MINIMAL, OFF
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trivago.cluecumber.properties;

import java.util.Enumeration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trivago.cluecumber.properties;

import com.trivago.cluecumber.exceptions.CluecumberPluginException;
Expand Down
Loading

0 comments on commit d462de1

Please sign in to comment.