|
8 | 8 | import java.nio.file.Path;
|
9 | 9 | import java.util.ArrayList;
|
10 | 10 | import java.util.Collection;
|
| 11 | +import java.util.Collections; |
11 | 12 | import java.util.List;
|
12 | 13 | import java.util.Optional;
|
13 | 14 | import java.util.function.Consumer;
|
14 | 15 | import java.util.function.Function;
|
15 | 16 | import java.util.function.Predicate;
|
16 | 17 | import java.util.function.Supplier;
|
17 | 18 |
|
| 19 | +import static io.cucumber.core.resource.ClasspathSupport.classPathScanningExplanation; |
18 | 20 | import static io.cucumber.core.resource.ClasspathSupport.determineFullyQualifiedClassName;
|
19 | 21 | import static io.cucumber.core.resource.ClasspathSupport.getUrisForPackage;
|
20 | 22 | import static io.cucumber.core.resource.ClasspathSupport.requireValidPackageName;
|
@@ -69,12 +71,18 @@ private List<Class<?>> findClassesForUris(List<URI> baseUris, String packageName
|
69 | 71 | }
|
70 | 72 |
|
71 | 73 | private List<Class<?>> findClassesForUri(URI baseUri, String packageName, Predicate<Class<?>> classFilter) {
|
72 |
| - List<Class<?>> classes = new ArrayList<>(); |
73 |
| - pathScanner.findResourcesForUri( |
74 |
| - baseUri, |
75 |
| - path -> isNotModuleInfo(path) && isNotPackageInfo(path) && isClassFile(path), |
76 |
| - processClassFiles(packageName, classFilter, classes::add)); |
77 |
| - return classes; |
| 74 | + try { |
| 75 | + List<Class<?>> classes = new ArrayList<>(); |
| 76 | + pathScanner.findResourcesForUri( |
| 77 | + baseUri, |
| 78 | + path -> isNotModuleInfo(path) && isNotPackageInfo(path) && isClassFile(path), |
| 79 | + processClassFiles(packageName, classFilter, classes::add)); |
| 80 | + return classes; |
| 81 | + |
| 82 | + } catch (Exception e) { |
| 83 | + log.warn(e, () -> "Failed to find classes in '" + baseUri + "'.\n" + classPathScanningExplanation()); |
| 84 | + } |
| 85 | + return Collections.emptyList(); |
78 | 86 | }
|
79 | 87 |
|
80 | 88 | private static boolean isNotModuleInfo(Path path) {
|
@@ -105,17 +113,9 @@ private Function<Path, Consumer<Path>> processClassFiles(
|
105 | 113 | private Optional<Class<?>> safelyLoadClass(String fqn) {
|
106 | 114 | try {
|
107 | 115 | return Optional.ofNullable(getClassLoader().loadClass(fqn));
|
108 |
| - } catch (Throwable e) { |
109 |
| - UnrecoverableExceptions.rethrowIfUnrecoverable(e); |
110 |
| - log.warn(e, () -> "" + |
111 |
| - "Failed to class '" + fqn + "'.\n" + |
112 |
| - "By default Cucumber scans the classpath for step definitions.\n" + |
113 |
| - "You can restrict this by configuring the glue path.\n" + |
114 |
| - "\n" + |
115 |
| - "Examples:\n" + |
116 |
| - " - @CucumberOptions(glue = \"com.example.application\")\n" + |
117 |
| - " - src/test/resources/junit-platform.properties cucumber.glue=com.example.application\n" + |
118 |
| - " - src/test/resources/cucumber.properties cucumber.glue=com.example.application\n"); |
| 116 | + } catch (Throwable t) { |
| 117 | + UnrecoverableExceptions.rethrowIfUnrecoverable(t); |
| 118 | + log.warn(t, () -> "Failed to class '" + fqn + "'.\n" + classPathScanningExplanation()); |
119 | 119 | }
|
120 | 120 | return Optional.empty();
|
121 | 121 | }
|
|
0 commit comments