Skip to content

Commit 05d57f7

Browse files
committed
Remove deprecated usages and refactor library dependency folder deletion to use try-with-resources
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 979b298 commit 05d57f7

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/main/java/com/ibm/cldk/SystemDependencyGraph.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static List<Dependency> construct(
251251
options.setReflectionOptions(ReflectionOptions.NONE);
252252
IAnalysisCacheView cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory(),
253253
options.getSSAOptions());
254-
Language java = new JavaLanguage();
254+
255255
// Build call graph
256256
Log.info("Building call graph.");
257257

@@ -262,9 +262,9 @@ public static List<Dependency> construct(
262262
CallGraph callGraph;
263263
CallGraphBuilder<InstanceKey> builder;
264264
try {
265-
System.setOut(new PrintStream(new NullOutputStream()));
266-
System.setErr(new PrintStream(new NullOutputStream()));
267-
builder = Util.makeVanillaZeroOneCFABuilder(java, options, cache, cha);
265+
System.setOut(new PrintStream(NullOutputStream.INSTANCE));
266+
System.setErr(new PrintStream(NullOutputStream.INSTANCE));
267+
builder = Util.makeVanillaZeroOneCFABuilder(new JavaLanguage(), options, cache, cha);
268268
callGraph = builder.makeCallGraph(options, null);
269269
} finally {
270270
System.setOut(originalOut);

src/main/java/com/ibm/cldk/utils/BuildProject.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import java.nio.file.Path;
1111
import java.nio.file.Paths;
1212
import java.text.MessageFormat;
13-
import java.util.AbstractMap;
14-
import java.util.ArrayList;
15-
import java.util.Arrays;
16-
import java.util.List;
13+
import java.util.*;
14+
import java.util.stream.Stream;
1715

1816

1917
import static com.ibm.cldk.utils.ProjectDirectoryScanner.classFilesStream;
@@ -272,8 +270,14 @@ public static void cleanLibraryDependencies() {
272270
Log.info("Cleaning up library dependency directory: " + libDownloadPath);
273271
try {
274272
if (libDownloadPath.toFile().getAbsoluteFile().exists()) {
275-
Files.walk(libDownloadPath).filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete);
276-
Files.delete(libDownloadPath);
273+
try (Stream<Path> paths = Files.walk(libDownloadPath)) {
274+
paths.sorted(Comparator.reverseOrder()) // Delete files first, then directories
275+
.map(Path::toFile)
276+
.forEach(file -> {
277+
if (!file.delete())
278+
Log.warn("Failed to delete: " + file.getAbsolutePath());
279+
});
280+
}
277281
}
278282
} catch (IOException e) {
279283
Log.warn("Unable to fully delete library dependency directory: " + e.getMessage());

0 commit comments

Comments
 (0)