Skip to content

Commit

Permalink
Enhance the lookup for jmods folder. We now use a recursive folder se…
Browse files Browse the repository at this point in the history
…arch seeded at the JAVA_HOME directory to look for a folder.

Signed-off-by: Rahul Krishna <[email protected]>
  • Loading branch information
rahlk committed Jan 24, 2025
1 parent 5355c2f commit 575f6a7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/ibm/cldk/utils/ScopeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.jar.JarFile;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;

Expand Down Expand Up @@ -70,7 +72,7 @@ public static AnalysisScope createScope(String projectPath, String applicationDe
throw new RuntimeException("JAVA_HOME is not set.");
}

String[] stdlibs = Files.walk(Paths.get(System.getenv("JAVA_HOME"), "jmods"))
String[] stdlibs = Files.walk(getJmodsPath())
.filter(path -> path.toString().endsWith(".jmod"))
.map(path -> path.toAbsolutePath().toString())
.toArray(String[]::new);
Expand Down Expand Up @@ -130,6 +132,19 @@ public static AnalysisScope createScope(String projectPath, String applicationDe
return scope;
}

private static Path getJmodsPath() {
try {
try (Stream<Path> paths = Files.walk(Path.of(System.getenv("JAVA_HOME")), Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS)) {
return paths
.filter(path -> path.getFileName().toString().equals("jmods"))
.findFirst()
.orElseThrow(() -> new RuntimeException("jmods directory not found in " + System.getenv("JAVA_HOME")));
}
} catch (IOException e) {
throw new RuntimeException("Error searching for jmods directory", e);
}
}

private static AnalysisScope addDefaultExclusions(AnalysisScope scope)
throws IOException {
Log.info("Add exclusions to scope.");
Expand Down
Empty file.

This file was deleted.

This file was deleted.

0 comments on commit 575f6a7

Please sign in to comment.