This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 5b83a9a98 Remove the deprecated
ProviderParameters.getDirectoryScanner()
5b83a9a98 is described below
commit 5b83a9a9887a7767195184fc6c41f581fb3ad875
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Mon Nov 9 11:00:13 2026 +0000
Remove the deprecated ProviderParameters.getDirectoryScanner()
Providers get their tests through getScanResult(); nothing in Surefire
called the old method. DirectoryScanner and DefaultDirectoryScanner go
with it, and FileScanner moves back into the plugin, its only user.
DirectoryScannerParameters stays: it still carries includes and
excludes to the forked JVM.
Closes #3580.
---
.../plugin/surefire/util/DirectoryScanner.java | 1 -
.../maven/plugin/surefire/util}/FileScanner.java | 8 +-
.../plugin/surefire/util/SpecificFileFilter.java | 3 +-
maven-surefire-plugin/src/site/markdown/api.md | 2 +-
.../surefire/api/booter/BaseProviderFactory.java | 14 ---
.../api/filter/SpecificTestClassFilter.java | 3 +-
.../surefire/api/provider/ProviderParameters.java | 11 --
.../surefire/api/util/DefaultDirectoryScanner.java | 127 --------------------
.../maven/surefire/api/util/DirectoryScanner.java | 34 ------
.../api/util/DefaultDirectoryScannerTest.java | 132 ---------------------
10 files changed, 7 insertions(+), 328 deletions(-)
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java
index a6e182555..addb4fd92 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java
@@ -24,7 +24,6 @@
import org.apache.maven.surefire.api.testset.TestListResolver;
import org.apache.maven.surefire.api.util.DefaultScanResult;
-import org.apache.maven.surefire.api.util.internal.FileScanner;
/**
* Scans directories looking for tests.
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/internal/FileScanner.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/FileScanner.java
similarity index 94%
rename from
surefire-api/src/main/java/org/apache/maven/surefire/api/util/internal/FileScanner.java
rename to
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/FileScanner.java
index 2a7ba6a7b..3c8f25473 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/internal/FileScanner.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/FileScanner.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.surefire.api.util.internal;
+package org.apache.maven.plugin.surefire.util;
import java.io.File;
import java.util.Collection;
@@ -25,12 +25,12 @@
import static org.apache.maven.surefire.shared.lang3.StringUtils.isBlank;
-public final class FileScanner {
+final class FileScanner {
private final File basedir;
private final String ext;
- public FileScanner(File basedir, String ext) {
+ FileScanner(File basedir, String ext) {
this.basedir = basedir;
ext = ext.trim();
if (isBlank(ext)) {
@@ -39,7 +39,7 @@ public FileScanner(File basedir, String ext) {
this.ext = ext.startsWith(".") ? ext : "." + ext;
}
- public void scanTo(Collection<String> scannedJavaClassNames,
TestFilter<String, String> filter) {
+ void scanTo(Collection<String> scannedJavaClassNames, TestFilter<String,
String> filter) {
scan(scannedJavaClassNames, filter, basedir);
}
diff --git
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java
index 0167b23a3..b07ce6d18 100644
---
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java
+++
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java
@@ -48,8 +48,7 @@ public boolean accept(@Nullable String resourceName) {
// If the tests enumeration is empty, allow anything.
if (names != null && !names.isEmpty()) {
for (String pattern : names) {
- // This is the same utility used under the covers in the
plexus DirectoryScanner, and
- // therefore in the surefire DefaultDirectoryScanner
implementation.
+ // This is the same utility used under the covers in the
plexus DirectoryScanner.
if (SelectorUtils.matchPath(pattern, resourceName, true)) {
return true;
}
diff --git a/maven-surefire-plugin/src/site/markdown/api.md
b/maven-surefire-plugin/src/site/markdown/api.md
index fb7b2c9fd..48ca3b267 100644
--- a/maven-surefire-plugin/src/site/markdown/api.md
+++ b/maven-surefire-plugin/src/site/markdown/api.md
@@ -68,7 +68,7 @@ Prior to this version, the provider would do
final TestsToRun scanResult = directoryScanner.locateTestClasses(
testClassLoader, testChecker );
```
-In this version `ProviderParameters#getDirectoryScanner` has been deprecated,
and it \*will\* be removed for the next major version. Instead, use
+In this version `ProviderParameters#getDirectoryScanner` was deprecated, and
it has since been removed. Instead, use
```text
scanResult = booterParameters.getScanResult();
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/BaseProviderFactory.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/BaseProviderFactory.java
index 9658ee2b5..828c21966 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/BaseProviderFactory.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/booter/BaseProviderFactory.java
@@ -31,10 +31,8 @@
import org.apache.maven.surefire.api.testset.RunOrderParameters;
import org.apache.maven.surefire.api.testset.TestArtifactInfo;
import org.apache.maven.surefire.api.testset.TestRequest;
-import org.apache.maven.surefire.api.util.DefaultDirectoryScanner;
import org.apache.maven.surefire.api.util.DefaultRunOrderCalculator;
import org.apache.maven.surefire.api.util.DefaultScanResult;
-import org.apache.maven.surefire.api.util.DirectoryScanner;
import org.apache.maven.surefire.api.util.RunOrderCalculator;
import org.apache.maven.surefire.api.util.ScanResult;
@@ -83,18 +81,6 @@ public void setCommandReader(CommandChainReader
commandReader) {
this.commandReader = commandReader;
}
- @Override
- @Deprecated
- public DirectoryScanner getDirectoryScanner() {
- return directoryScannerParameters == null
- ? null
- : new DefaultDirectoryScanner(
- directoryScannerParameters.getTestClassesDirectory(),
- directoryScannerParameters.getIncludes(),
- directoryScannerParameters.getExcludes(),
- directoryScannerParameters.getSpecificTests());
- }
-
@Override
public ScanResult getScanResult() {
return DefaultScanResult.from(providerProperties);
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/filter/SpecificTestClassFilter.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/filter/SpecificTestClassFilter.java
index 532633f40..2db3cf868 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/filter/SpecificTestClassFilter.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/filter/SpecificTestClassFilter.java
@@ -57,8 +57,7 @@ public boolean accept(Class testClass) {
pattern = pattern.replace('/', FS);
}
- // This is the same utility used under the covers in the
plexus DirectoryScanner, and
- // therefore in the surefire DefaultDirectoryScanner
implementation.
+ // This is the same utility used under the covers in the
plexus DirectoryScanner.
if (SelectorUtils.matchPath(pattern, className, true)) {
found = true;
break;
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
index 55baf0b87..609d5824b 100644
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
+++
b/surefire-api/src/main/java/org/apache/maven/surefire/api/provider/ProviderParameters.java
@@ -27,7 +27,6 @@
import org.apache.maven.surefire.api.testset.DirectoryScannerParameters;
import org.apache.maven.surefire.api.testset.TestArtifactInfo;
import org.apache.maven.surefire.api.testset.TestRequest;
-import org.apache.maven.surefire.api.util.DirectoryScanner;
import org.apache.maven.surefire.api.util.RunOrderCalculator;
import org.apache.maven.surefire.api.util.ScanResult;
@@ -42,16 +41,6 @@
* @author Kristian Rosenvold
*/
public interface ProviderParameters {
- /**
- * Provides a directory scanner that enforces the includes/excludes
parameters that were passed to surefire.
- * See #getDirectoryScannerParameters for details.
- *
- * @return the directory scanner
- * @deprecated use scanresult instead, as of version 2.12.2. Will be
removed in next major version.
- */
- @Deprecated
- DirectoryScanner getDirectoryScanner();
-
/**
* Provides the result of the directory scan performed in the plugin.
*
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultDirectoryScanner.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultDirectoryScanner.java
deleted file mode 100644
index cfe043143..000000000
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DefaultDirectoryScanner.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.api.util;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.surefire.api.filter.SpecificTestClassFilter;
-import org.apache.maven.surefire.api.testset.TestListResolver;
-import org.apache.maven.surefire.api.util.internal.FileScanner;
-
-/**
- * Scans directories looking for tests.
- *
- * @author Karl M. Davis
- * @author Kristian Rosenvold
- */
-@Deprecated
-public class DefaultDirectoryScanner implements DirectoryScanner {
-
- private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
- private static final String JAVA_SOURCE_FILE_EXTENSION = ".java";
-
- private static final String JAVA_CLASS_FILE_EXTENSION = ".class";
-
- private final File basedir;
-
- private final List<String> includes;
-
- private final List<String> excludes;
-
- private final List<String> specificTests;
-
- public DefaultDirectoryScanner(
- File basedir, List<String> includes, List<String> excludes,
List<String> specificTests) {
- this.basedir = basedir;
- this.includes = includes;
- this.excludes = excludes;
- this.specificTests = specificTests;
- }
-
- @Override
- public TestsToRun locateTestClasses(ClassLoader classLoader, ScannerFilter
scannerFilter) {
- String[] testClassNames = collectTests();
- Set<Class<?>> result = new LinkedHashSet<>();
-
- String[] specific = specificTests == null ? new String[0] :
processIncludesExcludes(specificTests);
- SpecificTestClassFilter specificTestFilter = new
SpecificTestClassFilter(specific);
-
- for (String className : testClassNames) {
- Class<?> testClass = loadClass(classLoader, className);
-
- if (!specificTestFilter.accept(testClass)) {
- // FIXME: Log this somehow!
- continue;
- }
-
- if (scannerFilter == null || scannerFilter.accept(testClass)) {
- result.add(testClass);
- }
- }
-
- return new TestsToRun(result);
- }
-
- private static Class<?> loadClass(ClassLoader classLoader, String
className) {
- try {
- return classLoader.loadClass(className);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Unable to create test class '" +
className + "'", e);
- }
- }
-
- String[] collectTests() {
- if (!basedir.exists()) {
- return EMPTY_STRING_ARRAY;
- }
- List<String> tests = new ArrayList<>();
- new FileScanner(basedir, "class")
- .scanTo(
- tests,
- new TestListResolver(
- includes == null ?
Collections.<String>emptyList() : includes,
- excludes == null ?
Collections.<String>emptyList() : excludes));
- return tests.toArray(EMPTY_STRING_ARRAY);
- }
-
- private static String[] processIncludesExcludes(List<String> list) {
- List<String> newList = new ArrayList<>();
- for (String include : list) {
- String[] includes = include.split(",");
- Collections.addAll(newList, includes);
- }
-
- String[] incs = new String[newList.size()];
-
- for (int i = 0; i < incs.length; i++) {
- String inc = newList.get(i);
- if (inc.endsWith(JAVA_SOURCE_FILE_EXTENSION)) {
- inc = inc.substring(0,
inc.lastIndexOf(JAVA_SOURCE_FILE_EXTENSION)) + JAVA_CLASS_FILE_EXTENSION;
- }
- incs[i] = inc;
- }
- return incs;
- }
-}
diff --git
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DirectoryScanner.java
b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DirectoryScanner.java
deleted file mode 100644
index bd59c6063..000000000
---
a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/DirectoryScanner.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.api.util;
-
-/**
- * @author Kristian Rosenvold
- */
-@Deprecated
-public interface DirectoryScanner {
- /**
- * Locates tests based on scanning directories.
- *
- * @param classLoader the classloader to use when loading classes
- * @param scannerFilter the filter to include/exclude test classes
- * @return the found classes that match the filter
- */
- TestsToRun locateTestClasses(ClassLoader classLoader, ScannerFilter
scannerFilter);
-}
diff --git
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/DefaultDirectoryScannerTest.java
b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/DefaultDirectoryScannerTest.java
deleted file mode 100644
index e4869c555..000000000
---
a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/DefaultDirectoryScannerTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.api.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-/**
- * Test of the directory scanner.
- */
-public class DefaultDirectoryScannerTest {
- @Test
- public void testLocateTestClasses() throws IOException,
TestSetFailedException {
- // use target as people can configure ide to compile in an other place
than maven
- File baseDir = new File(new File("target").getCanonicalPath());
- List<String> include = new ArrayList<>();
- include.add("**/*ZT*A.java");
- List<String> exclude = new ArrayList<>();
-
- DefaultDirectoryScanner surefireDirectoryScanner =
- new DefaultDirectoryScanner(baseDir, include, exclude, new
ArrayList<String>());
-
- String[] classNames = surefireDirectoryScanner.collectTests();
- assertNotNull(classNames);
- System.out.println("classNames " + Arrays.asList(classNames));
- assertEquals(4, classNames.length);
- }
-
- @TempDir
- Path tmp;
-
- private File tree() throws IOException {
- for (String f : new String[] {
- "TopTest.class",
- "notes.txt",
- "folder1/sub/File5Test.class",
- "folder2/File6Test.class",
- "folder2/Helper.class",
- "folder2/Helper$1.class",
- "folder2/data.properties"
- }) {
- Path p = tmp.resolve(f);
- Files.createDirectories(p.getParent());
- Files.write(p, new byte[0]);
- }
- return tmp.toFile();
- }
-
- private String[] collect(List<String> includes, List<String> excludes)
throws IOException {
- return new DefaultDirectoryScanner(tree(), includes, excludes,
null).collectTests();
- }
-
- private static String p(String slashPath) {
- return slashPath.replace('/', File.separatorChar);
- }
-
- @Test
- void collectTestsWithJavaPatterns() throws IOException {
- assertThat(collect(Arrays.asList("**/*Test.java"), null))
- .containsExactlyInAnyOrder("TopTest", "folder1.sub.File5Test",
"folder2.File6Test");
- }
-
- @Test
- void collectTestsWithClassPatterns() throws IOException {
- assertThat(collect(Arrays.asList("**/*Test.class"), null))
- .containsExactlyInAnyOrder("TopTest", "folder1.sub.File5Test",
"folder2.File6Test");
- }
-
- @Test
- void collectTestsWithExcludes() throws IOException {
- assertThat(collect(Arrays.asList("**/*.java"), Arrays.asList("**/*$*",
"**/Helper.java")))
- .containsExactlyInAnyOrder("TopTest", "folder1.sub.File5Test",
"folder2.File6Test");
- }
-
- @Test
- void collectTestsWithCommaSeparatedIncludes() throws IOException {
- assertThat(collect(Arrays.asList("**/File5*.java, **/Helper.java"),
null))
- .containsExactlyInAnyOrder("folder1.sub.File5Test",
"folder2.Helper");
- }
-
- @Test
- void collectTestsWithDirectoryPatterns() throws IOException {
- assertThat(collect(Arrays.asList("folder2/*Test.java"),
null)).containsExactly("folder2.File6Test");
- assertThat(collect(Arrays.asList("folder1/**/*.java"),
null)).containsExactly("folder1.sub.File5Test");
- }
-
- @Test
- void collectTestsWithRegex() throws IOException {
- assertThat(collect(Arrays.asList("%regex[.*File[0-9]Test.*]"), null))
- .containsExactlyInAnyOrder("folder1.sub.File5Test",
"folder2.File6Test");
- }
-
- @Test
- void collectTestsIsCaseSensitive() throws IOException {
- assertThat(collect(Arrays.asList("**/*test.java"), null)).isEmpty();
- }
-
- @Test
- void collectTestsOfMissingDirectoryIsEmpty() {
- assertThat(new DefaultDirectoryScanner(new File(tmp.toFile(),
"missing"), null, null, null).collectTests())
- .isEmpty();
- }
-}