Skip to content

Commit a26e03c

Browse files
authored
[Core] Ignore class load error while class scanning (#1844)
In practice the class path may be rather dirty and not all available classes can be loaded. Because Cucumber will by default scan in the root package it guaranteed to run into class loading errors. By logging these at debug level rather then throwing an exception Cucumber will most probably continue to work as expected. To debug occurrences of missing glue you can enable debug logging via: ``` -Djava.util.logging.config.file=path/to/logging.properties ``` ```properties handlers=java.util.logging.ConsoleHandler .level=FINE java.util.logging.ConsoleHandler.level=FINE java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter ``` Fixes: #1843
1 parent b500580 commit a26e03c

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

core/README.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,40 @@ Cucumber Core
33

44
Provides components needed to discover, parse and execute feature files. The
55
core is designed with a few extension systems and plugin points. You
6-
typically don't depend on `cucumber-core` but rather use the different
6+
typically don't depend directly on `cucumber-core` but rather use the different
77
sub modules together e.g. `cucumber-junit` and `cucumber-java`.
88

99
## Backend ##
1010

1111
Backends consists of two components, a `Backend` and `ObjectFactory`. They are
1212
respectively responsible for discovering glue classes, registering step definitions
13-
and creating instances of said glue classes.
13+
and creating instances of said glue classes. Backend and object factory
14+
implementations are discovered via SPI
1415

1516
## Plugin ##
1617

1718
By implementing the Plugin interface classes can listen to execution events
18-
inside Cucumber JVM.
19+
inside Cucumber JVM. Consider using a Plugin when creating test execution reports.
1920

2021
## FileSystem ##
2122

2223
Cucumber uses `java.nio.fileFileSystems` to scan for features and will be able
23-
to scan features on any file system registered with the JVM.
24+
to scan features on any file system registered with the JVM.
25+
26+
## Logging ##
27+
Cucumber uses the Java Logging APIs from `java.util.logging`. See the
28+
[LogManager](https://docs.oracle.com/javase/8/docs/api/java/util/logging/LogManager.html)
29+
for configuration options or use the [JUL to SLF4J Bridge](https://www.slf4j.org/legacy.html#jul-to-slf4j).
30+
31+
For quick debugging run with:
32+
33+
```
34+
-Djava.util.logging.config.file=path/to/logging.properties
35+
```
36+
37+
```properties
38+
handlers=java.util.logging.ConsoleHandler
39+
.level=FINE
40+
java.util.logging.ConsoleHandler.level=FINE
41+
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
42+
```

core/src/main/java/io/cucumber/core/resource/ClasspathScanner.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.cucumber.core.resource;
22

3+
import io.cucumber.core.logging.Logger;
4+
import io.cucumber.core.logging.LoggerFactory;
5+
36
import java.net.URI;
47
import java.nio.file.Path;
58
import java.util.ArrayList;
@@ -19,6 +22,8 @@
1922

2023
public final class ClasspathScanner {
2124

25+
private static final Logger log = LoggerFactory.getLogger(ClasspathScanner.class);
26+
2227
private static final String CLASS_FILE_SUFFIX = ".class";
2328
private static final String PACKAGE_INFO_FILE_NAME = "package-info" + CLASS_FILE_SUFFIX;
2429
private static final String MODULE_INFO_FILE_NAME = "module-info" + CLASS_FILE_SUFFIX;
@@ -95,7 +100,7 @@ private Function<Path, Consumer<Path>> processClassFiles(String basePackageName,
95100
.filter(classFilter)
96101
.ifPresent(classConsumer);
97102
} catch (ClassNotFoundException | NoClassDefFoundError e) {
98-
throw new IllegalArgumentException("Unable to load " + fqn, e);
103+
log.debug(e, () -> "Failed to load class " + fqn);
99104
}
100105
};
101106
}

0 commit comments

Comments
 (0)