|
24 | 24 | import static org.junit.platform.launcher.TagFilter.includeTags;
|
25 | 25 | import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
|
26 | 26 |
|
| 27 | +import java.nio.file.Files; |
27 | 28 | import java.nio.file.Path;
|
| 29 | +import java.util.HashSet; |
28 | 30 | import java.util.LinkedHashSet;
|
29 | 31 | import java.util.List;
|
30 | 32 | import java.util.Objects;
|
31 | 33 | import java.util.Set;
|
32 | 34 | import java.util.regex.Pattern;
|
33 | 35 | import java.util.stream.Stream;
|
34 | 36 |
|
| 37 | +import org.junit.platform.commons.logging.Logger; |
| 38 | +import org.junit.platform.commons.logging.LoggerFactory; |
35 | 39 | import org.junit.platform.commons.util.ModuleUtils;
|
36 | 40 | import org.junit.platform.commons.util.Preconditions;
|
37 | 41 | import org.junit.platform.commons.util.ReflectionUtils;
|
|
49 | 53 | */
|
50 | 54 | class DiscoveryRequestCreator {
|
51 | 55 |
|
| 56 | + private static final Logger logger = LoggerFactory.getLogger(DiscoveryRequestCreator.class); |
| 57 | + |
52 | 58 | static LauncherDiscoveryRequestBuilder toDiscoveryRequestBuilder(TestDiscoveryOptions options) {
|
53 | 59 | LauncherDiscoveryRequestBuilder requestBuilder = request();
|
54 | 60 | List<? extends DiscoverySelector> selectors = createDiscoverySelectors(options);
|
@@ -87,9 +93,37 @@ private static Set<Path> determineClasspathRoots(TestDiscoveryOptions options) {
|
87 | 93 | if (selectedClasspathEntries.isEmpty()) {
|
88 | 94 | Set<Path> rootDirs = new LinkedHashSet<>(ReflectionUtils.getAllClasspathRootDirectories());
|
89 | 95 | rootDirs.addAll(options.getExistingAdditionalClasspathEntries());
|
90 |
| - return rootDirs; |
| 96 | + return validateAndLogInvalidRoots(rootDirs); |
| 97 | + } |
| 98 | + return validateAndLogInvalidRoots(new LinkedHashSet<>(selectedClasspathEntries)); |
| 99 | + } |
| 100 | + |
| 101 | + private static Set<Path> validateAndLogInvalidRoots(Set<Path> roots) { |
| 102 | + LinkedHashSet<Path> valid = new LinkedHashSet<>(); |
| 103 | + HashSet<Path> seen = new HashSet<>(); |
| 104 | + |
| 105 | + for (Path root : roots) { |
| 106 | + if (!seen.add(root)) |
| 107 | + continue; |
| 108 | + |
| 109 | + boolean exists = Files.exists(root); |
| 110 | + boolean readable = Files.isReadable(root); |
| 111 | + boolean dirOrJar = isDirOrJar(root); |
| 112 | + |
| 113 | + if (!exists || !readable || !dirOrJar) { |
| 114 | + logger.info( |
| 115 | + () -> "Ignoring invalid search path root: %s (exists=%s, readable=%s, dirOrJar=%s)".formatted(root, |
| 116 | + exists, readable, dirOrJar)); |
| 117 | + continue; |
| 118 | + } |
| 119 | + valid.add(root); |
91 | 120 | }
|
92 |
| - return new LinkedHashSet<>(selectedClasspathEntries); |
| 121 | + |
| 122 | + return valid; |
| 123 | + } |
| 124 | + |
| 125 | + private static boolean isDirOrJar(Path root) { |
| 126 | + return Files.isDirectory(root) || root.toString().endsWith(".jar"); |
93 | 127 | }
|
94 | 128 |
|
95 | 129 | private static void addFilters(LauncherDiscoveryRequestBuilder requestBuilder, TestDiscoveryOptions options,
|
|
0 commit comments