Skip to content

Commit

Permalink
Properly deal with dirs in loading the test classes (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Stejskal <[email protected]>
  • Loading branch information
Frawless authored Feb 20, 2024
1 parent f4ad3ca commit 15f4f76
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dummy-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</execution>
</executions>
<configuration>
<testsPath>./dummy-module/src/test/java/io/</testsPath>
<testsPath>./dummy-module/src/test/java/io/skodjob/</testsPath>
<docsPath>./docs/</docsPath>
<generateFmf>true</generateFmf>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void execute() {
for (URL url : classRealm.getURLs()) {
getLog().debug(url.getFile());
}
getLog().info("testsPath: " + testsPath);

Map<String, String> classes = Utils.getTestClassesWithTheirPath(testsPath);

Expand Down Expand Up @@ -143,7 +142,7 @@ public void addJarFilesToClassPath(File directory, ClassRealm classRealm) throws
addJarFilesToClassPath(file, classRealm);
} else if (file.isFile() && file.getName().toLowerCase(Locale.ROOT).endsWith(".jar")) {
// Print the absolute path if it's a .jar file
getLog().info("Found .jar file: " + file.getAbsolutePath());
getLog().debug("Found .jar file: " + file.getAbsolutePath());
classRealm.addURL(file.toURI().toURL());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class Utils {

private static final Pattern REMOVE_BEFORE_PACKAGE = Pattern.compile(".*java\\/");
private static final Pattern REMOVE_BEFORE_PACKAGE = Pattern.compile(".*java/");

/**
* Updates Map ({@param classes}) with info about classes inside {@param packagePath}.
Expand All @@ -38,18 +38,16 @@ public class Utils {
* @return updated Map with test-classes info from the {@param packagePath}
*/
private static Map<String, String> getClassesForPackage(Map<String, String> classes, Path packagePath) {
try (Stream<Path> pathStream = Files.list(packagePath)) {
pathStream.forEach(path -> {
if (Files.isDirectory(path)) {
classes.putAll(getClassesForPackage(classes, path));
} else {
String classPackagePath = path.toAbsolutePath().toString().replaceAll(REMOVE_BEFORE_PACKAGE.toString(), "").replace(".java", "");
classes.put(classPackagePath, classPackagePath.replaceAll("/", "."));
}
});
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
if (Files.isDirectory(packagePath)) {
try (Stream<Path> pathStream = Files.list(packagePath)) {
pathStream.forEach(path -> classes.putAll(getClassesForPackage(classes, path)));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else {
String classPackagePath = packagePath.toAbsolutePath().toString().replaceAll(REMOVE_BEFORE_PACKAGE.toString(), "").replace(".java", "");
classes.put(classPackagePath, classPackagePath.replaceAll("/", "."));
}

return classes;
Expand Down

0 comments on commit 15f4f76

Please sign in to comment.