|
23 | 23 | package com.synopsys.method.analyzer.core.report; |
24 | 24 |
|
25 | 25 | import java.io.BufferedWriter; |
| 26 | +import java.io.File; |
26 | 27 | import java.io.FileInputStream; |
27 | 28 | import java.io.FileOutputStream; |
28 | 29 | import java.io.IOException; |
29 | 30 | import java.nio.file.Files; |
30 | 31 | import java.nio.file.Path; |
31 | 32 | import java.nio.file.Paths; |
32 | 33 | import java.util.Collection; |
| 34 | +import java.util.Comparator; |
33 | 35 | import java.util.HashMap; |
34 | 36 | import java.util.LinkedList; |
35 | 37 | import java.util.List; |
36 | 38 | import java.util.Map; |
37 | 39 | import java.util.Map.Entry; |
38 | 40 | import java.util.Objects; |
| 41 | +import java.util.stream.Stream; |
39 | 42 | import java.util.zip.ZipEntry; |
40 | 43 | import java.util.zip.ZipOutputStream; |
41 | 44 |
|
42 | 45 | import javax.annotation.Nullable; |
43 | 46 |
|
| 47 | +import org.slf4j.Logger; |
| 48 | +import org.slf4j.LoggerFactory; |
| 49 | + |
44 | 50 | import com.google.common.collect.Lists; |
45 | 51 | import com.google.common.collect.Multimap; |
46 | 52 | import com.google.gson.Gson; |
@@ -69,6 +75,9 @@ public class ReportGenerator { |
69 | 75 |
|
70 | 76 | private static final Gson GSON = new Gson(); |
71 | 77 |
|
| 78 | + /** Logger reference to output information to the application log files */ |
| 79 | + private final Logger logger = LoggerFactory.getLogger(getClass()); |
| 80 | + |
72 | 81 | private final MetaDataReportJson metaDataReport; |
73 | 82 |
|
74 | 83 | /** |
@@ -178,6 +187,17 @@ private Path writeReport(Path destinationFile, List<MethodIdJson> uniqueMethodKe |
178 | 187 |
|
179 | 188 | writeZipFile(destinationFile, outputFileMapping); |
180 | 189 |
|
| 190 | + // GH-22: Explicitly clean up temporary files once use of them is complete |
| 191 | + try { |
| 192 | + try (Stream<Path> walk = Files.walk(workingDirectory)) { |
| 193 | + walk.sorted(Comparator.reverseOrder()) |
| 194 | + .map(Path::toFile) |
| 195 | + .forEach(File::delete); |
| 196 | + } |
| 197 | + } catch (IOException e) { |
| 198 | + logger.warn("Error cleaning up temporary report files", e); |
| 199 | + } |
| 200 | + |
181 | 201 | return destinationFile; |
182 | 202 | } |
183 | 203 |
|
|
0 commit comments