Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly deal with dirs in loading the test classes #27

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading