Created
August 22, 2023 05:03
-
-
Save Codegass/b9e9616c85daae7de842752e4b00a917 to your computer and use it in GitHub Desktop.
test file finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class YourPluginClass { | |
| // ... [Your other fields and methods] | |
| /** | |
| * Recursively searches for all .java files under "test" directories starting from the given root directory. | |
| * | |
| * @param rootDir The root directory to start the search. | |
| * @return A list of .java files under "test" directories. | |
| */ | |
| public List<File> findJavaFilesInTestDirectories(File rootDir) { | |
| List<File> javaFiles = new ArrayList<>(); | |
| searchForJavaFiles(rootDir, javaFiles); | |
| return javaFiles; | |
| } | |
| /** | |
| * Helper method to recursively search for .java files under "test" directories. | |
| * | |
| * @param currentDir The current directory being searched. | |
| * @param accumulator The list where found .java files are added. | |
| */ | |
| private void searchForJavaFiles(File currentDir, List<File> accumulator) { | |
| if (currentDir == null || !currentDir.exists() || !currentDir.isDirectory()) { | |
| return; | |
| } | |
| // Check if the current directory is named "test" | |
| if (currentDir.getName().equals("test")) { | |
| File[] javaFiles = currentDir.listFiles((dir, name) -> name.endsWith(".java")); | |
| if (javaFiles != null) { | |
| for (File javaFile : javaFiles) { | |
| accumulator.add(javaFile); | |
| } | |
| } | |
| // We've found a "test" directory, so no need to go deeper in this branch | |
| return; | |
| } | |
| // If the current directory is not "test", go deeper | |
| File[] subDirectories = currentDir.listFiles(File::isDirectory); | |
| if (subDirectories != null) { | |
| for (File subDir : subDirectories) { | |
| searchForJavaFiles(subDir, accumulator); | |
| } | |
| } | |
| } | |
| // ... [Your other methods] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment