Skip to content

[Core] CLI should search classpath root by default #1889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] (In Git)

### Added
* [Core] CLI should search classpath root by default ([#1889](https://github.com/cucumber/cucumber-jvm/pull/1889) M.P. Korstanje)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/cucumber/core/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static byte run(String[] argv, ClassLoader classLoader) {

RuntimeOptions runtimeOptions = new CommandlineOptionsParser()
.parse(argv)
.addDefaultGlueIfAbsent()
.addDefaultFeaturePathIfAbsent()
.addDefaultFormatterIfAbsent()
.addDefaultSummaryPrinterIfAbsent()
.build(systemOptions);
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/io/cucumber/core/options/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static io.cucumber.core.resource.ClasspathSupport.rootPackageUri;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;

Expand Down Expand Up @@ -64,6 +66,17 @@ void addDefaultSummaryPrinterIfAbsent(){
}
}

void addDefaultGlueIfAbsent() {
if (glue.isEmpty()) {
glue.add(rootPackageUri());
}
}

void addDefaultFeaturePathIfAbsent() {
if (featurePaths.isEmpty()) {
featurePaths.add(FeatureWithLines.create(rootPackageUri(), emptyList()));
}
}
public int getCount() {
return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public final class RuntimeOptionsBuilder {
private Class<? extends ObjectFactory> parsedObjectFactoryClass = null;
private boolean addDefaultSummaryPrinterIfAbsent;
private boolean addDefaultFormatterIfAbsent;
private boolean addDefaultGlueIfAbsent;
private boolean addDefaultFeaturePathIfAbsent;

public RuntimeOptionsBuilder addRerun(Collection<FeatureWithLines> featureWithLines) {
if (parsedRerunPaths == null) {
Expand Down Expand Up @@ -134,6 +136,14 @@ public RuntimeOptions build(RuntimeOptions runtimeOptions) {
runtimeOptions.addDefaultSummaryPrinterIfAbsent();
}

if (addDefaultGlueIfAbsent) {
runtimeOptions.addDefaultGlueIfAbsent();
}

if (addDefaultFeaturePathIfAbsent) {
runtimeOptions.addDefaultFeaturePathIfAbsent();
}

return runtimeOptions;
}

Expand Down Expand Up @@ -205,6 +215,17 @@ public RuntimeOptionsBuilder addDefaultFormatterIfAbsent() {
return this;
}

public RuntimeOptionsBuilder addDefaultGlueIfAbsent() {
this.addDefaultGlueIfAbsent = true;
return this;
}

public RuntimeOptionsBuilder addDefaultFeaturePathIfAbsent() {
this.addDefaultFeaturePathIfAbsent = true;
return this;
}


public void setObjectFactoryClass(Class<? extends ObjectFactory> objectFactoryClass) {
this.parsedObjectFactoryClass = objectFactoryClass;
}
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/resources/io/cucumber/core/options/USAGE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Options:
Defaults to 1.

-g, --glue PATH Package to load glue code (step
definitions, hooks and plugins) from.
E.g: com.example.app
definitions, hooks and plugins) from
e.g: com.example.app. When not
provided Cucumber will search the
classpath.

-p, --[add-]plugin PLUGIN[:PATH_OR_URL] Register a plugin.
Built-in formatter PLUGIN types:
Expand Down Expand Up @@ -69,6 +71,9 @@ Options:
META-INF/services/io.cucumber.core.backend.ObjectFactory

Feature path examples:
When no feature path is provided
cucumber will scan the classpath root
and its sub directories.

<path> Load the files with the extension
".feature" for the directory <path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static io.cucumber.core.options.Constants.FILTER_TAGS_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.OPTIONS_PROPERTY_NAME;
import static io.cucumber.core.resource.ClasspathSupport.rootPackageUri;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
Expand Down Expand Up @@ -734,6 +735,24 @@ void loads_no_features_when_rerun_file_specified_in_cucumber_options_property_is
assertThat(options.getFeaturePaths(), emptyCollectionOf(URI.class));
}

@Test
void scans_class_path_root_for_glue_by_default() {
RuntimeOptions options = new CommandlineOptionsParser()
.parse()
.addDefaultGlueIfAbsent()
.build();
assertThat(options.getGlue(), is(singletonList(rootPackageUri())));
}

@Test
void scans_class_path_root_for_features_by_default() {
RuntimeOptions options = new CommandlineOptionsParser()
.parse()
.addDefaultFeaturePathIfAbsent()
.build();
assertThat(options.getFeaturePaths(), is(singletonList(rootPackageUri())));
assertThat(options.getLineFilters(), is(emptyMap()));
}

public static final class AwareFormatter implements StrictAware, ColorAware, EventListener {

Expand Down
18 changes: 10 additions & 8 deletions picocontainer/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -66,13 +67,14 @@
</goals>
<configuration>
<target>
<echo message="Running CLI test for picocontainer" />
<java classname="io.cucumber.core.cli.Main" fork="true" failonerror="true" newenvironment="true" maxmemory="512m" classpathref="maven.test.classpath">
<arg value="--plugin" />
<arg value="progress" />
<arg value="--glue" />
<arg value="io.cucumber.picocontainer" />
<arg value="${basedir}/src/test/resources/io/cucumber/picocontainer" />
<echo message="Running CLI test for picocontainer"/>
<java classname="io.cucumber.core.cli.Main"
fork="true"
failonerror="true"
newenvironment="true"
maxmemory="512m"
classpathref="maven.test.classpath"
>
</java>
</target>
</configuration>
Expand Down