Skip to content

Commit

Permalink
plugin resilience
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Apr 3, 2020
1 parent d1aa4e8 commit 9496212
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [1.7.2] - 2020-04-03

### Fixed

* Cucable does not fail on empty Cucumber feature list file.

## [1.7.1] - 2020-04-03

### Changed
Expand Down Expand Up @@ -298,6 +304,8 @@ Back to [Readme](README.md).

Initial project version on GitHub and Maven Central.

[1.7.2]: https://github.com/trivago/cucable-plugin/compare/1.7.1...1.7.2
[1.7.1]: https://github.com/trivago/cucable-plugin/compare/1.7.0...1.7.1
[1.7.0]: https://github.com/trivago/cucable-plugin/compare/1.6.0...1.7.0
[1.6.0]: https://github.com/trivago/cucable-plugin/compare/1.5.3...1.6.0
[1.5.3]: https://github.com/trivago/cucable-plugin/compare/1.5.2...1.5.3
Expand Down
4 changes: 2 additions & 2 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cucable-test-project</artifactId>
<version>1.7.1</version>
<version>1.7.2</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -70,7 +70,7 @@
<!--</sourceFeatures>-->

<!-- process a text file containing paths to features and line numbers (as it is written by the Cucumber rerun formatter) -->
<!-- <sourceFeatures>@src/test/resources/cucumber-feature-list.txt</sourceFeatures>-->
<sourceFeatures>@src/test/resources/cucumber-feature-list.txt</sourceFeatures>

<!-- process a specific feature file and specific line numbers in the given directory -->
<!--<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature:8:19</sourceFeatures>-->
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>cucable-plugin</artifactId>
<version>1.7.1</version>
<version>1.7.2</version>
<url>https://github.com/trivago/cucable-plugin</url>

<name>Cucable Maven Plugin</name>
Expand Down
20 changes: 14 additions & 6 deletions plugin-code/src/main/java/com/trivago/files/FileSystemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,23 @@ public List<Path> getPathsFromCucableFeature(final CucableFeature cucableFeature
replace("file://", "");

File sourceFeaturesFile = new File(sourceFeatures);

if (sourceFeatures.trim().isEmpty()) {
return Collections.emptyList();
}

// Check if the property value is a single file or a directory
if (sourceFeaturesFile.isFile() && sourceFeatures.endsWith(FEATURE_FILE_EXTENSION)) {
return Collections.singletonList(Paths.get(sourceFeatures));
} else if (sourceFeaturesFile.isDirectory()) {
}

if (sourceFeaturesFile.isDirectory()) {
return getFilesWithFeatureExtension(sourceFeatures);
} else {
throw new CucablePluginException(
sourceFeatures + " is not a feature file or a directory."
);
}

throw new CucablePluginException(
sourceFeatures + " is not a feature file or a directory."
);
}

/**
Expand All @@ -79,7 +86,8 @@ public List<Path> getPathsFromCucableFeature(final CucableFeature cucableFeature
* @return A list of feature files in the given directory.
* @throws CucablePluginException see {@link CucablePluginException}.
*/
private List<Path> getFilesWithFeatureExtension(final String sourceFeatureDirectory) throws CucablePluginException {
private List<Path> getFilesWithFeatureExtension(final String sourceFeatureDirectory) throws
CucablePluginException {
try {
return Files.walk(Paths.get(sourceFeatureDirectory))
.filter(Files::isRegularFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PropertyManager {
private int desiredNumberOfRunners;
private int desiredNumberOfFeaturesPerRunner;
private List<String> scenarioNames = new ArrayList<>();
private boolean isCucumberFeatureListFileSource;
private String cucumberFeatureListFile;

@Inject
public PropertyManager(final CucableLogger logger, final FileIO fileIO) {
Expand Down Expand Up @@ -87,8 +87,8 @@ public List<CucableFeature> getSourceFeatures() {
public void setSourceFeatures(final String sourceFeatures) throws MissingFileException {
String featuresToProcess;
if (sourceFeatures.startsWith("@")) {
isCucumberFeatureListFileSource = true;
featuresToProcess = fileIO.readContentFromFile(sourceFeatures.substring(1))
cucumberFeatureListFile = sourceFeatures.substring(1);
featuresToProcess = fileIO.readContentFromFile(cucumberFeatureListFile)
.replace(System.lineSeparator(), ",");
} else {
featuresToProcess = sourceFeatures;
Expand Down Expand Up @@ -256,7 +256,11 @@ public void checkForDisallowedPropertyCombinations() throws CucablePluginExcepti
public void logProperties() {
CucableLogLevel[] logLevels = new CucableLogLevel[]{DEFAULT, COMPACT};

logger.info("- sourceFeatures :", logLevels);
if (!isCucumberFeatureListFileSource()) {
logger.info("- sourceFeatures:", logLevels);
} else {
logger.info(String.format("- sourceFeatures from file %s:", cucumberFeatureListFile), logLevels);
}
if (sourceFeatures != null) {
for (CucableFeature sourceFeature : sourceFeatures) {
String logLine = " - " + sourceFeature.getName();
Expand Down Expand Up @@ -319,7 +323,7 @@ private void saveMissingProperty(
}

public boolean isCucumberFeatureListFileSource() {
return isCucumberFeatureListFileSource;
return cucumberFeatureListFile != null && !cucumberFeatureListFile.isEmpty();
}

public enum ParallelizationMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void logMandatoryPropertiesTest() throws CucablePluginException {
propertyManager.logProperties();
verify(logger, times(6)).info(logCaptor.capture(), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class));
List<String> capturedLogs = logCaptor.getAllValues();
assertThat(capturedLogs.get(0), is("- sourceFeatures :"));
assertThat(capturedLogs.get(0), is("- sourceFeatures:"));
assertThat(capturedLogs.get(1), is("- sourceRunnerTemplateFile : null"));
assertThat(capturedLogs.get(2), is("- generatedRunnerDirectory : null"));
assertThat(capturedLogs.get(3), is("- generatedFeatureDirectory : null"));
Expand All @@ -247,7 +247,7 @@ public void logExtendedPropertiesTest() throws CucablePluginException {

verify(logger, times(12)).info(logCaptor.capture(), any(CucableLogger.CucableLogLevel.class), any(CucableLogger.CucableLogLevel.class));
List<String> capturedLogs = logCaptor.getAllValues();
assertThat(capturedLogs.get(0), is("- sourceFeatures :"));
assertThat(capturedLogs.get(0), is("- sourceFeatures:"));
assertThat(capturedLogs.get(1), is(" - test.feature (line 3)"));
assertThat(capturedLogs.get(2), is("- sourceRunnerTemplateFile : null"));
assertThat(capturedLogs.get(3), is("- generatedRunnerDirectory : null"));
Expand Down

0 comments on commit 9496212

Please sign in to comment.