Revision of CallGraphUtils incl. addition of tests
@@ -23,10 +23,7 @@ import eu.fasten.core.data.ExtendedRevisionJavaCallGraph;
import eu.fasten.core.data.JSONUtils;
import eu.fasten.core.data.JavaNode;
import it.unimi.dsi.fastutil.ints.IntIntPair;
-
-import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
@@ -37,6 +34,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
@@ -60,7 +58,8 @@ public class CallGraphUtils {
*/
public static void diffInFile(final String resultPath, final int graphNumber,
final ExtendedRevisionJavaCallGraph firstGraph,
- final ExtendedRevisionJavaCallGraph secondGraph) throws IOException {
+ final ExtendedRevisionJavaCallGraph secondGraph)
+ throws IOException {
final String graphPath =
resultPath + graphNumber + "_" + firstGraph.product + "." + firstGraph.version;
@@ -77,19 +76,30 @@ public class CallGraphUtils {
* Writes Strings to files, can be used to output the graphs.
*
* @param path the path to write
- * @param graph the String representation of graph or any other String to be written to a file
+ * @param content the String representation of graph or any other String to be written to a file
* @param suffix the suffix to put at the end of the path, most of the time file name
* @throws IOException throws if IO problems occur during writing in a file
*/
- public static void writeToFile(final String path, final String graph, final String suffix)
+ public static void writeToFile(final String path, final String content, final String suffix)
throws IOException {
- if (!graph.isEmpty()) {
+ if (content.isEmpty()) {
+ logger.info("Trying to write empty graph");
+ }
logger.info("Writing graph to {}", path + suffix);
+ final var f = new File(path + suffix);
+ FileUtils.write(f, content, StandardCharsets.UTF_8);
}
- final BufferedWriter writer;
- writer = new BufferedWriter(new FileWriter(path + suffix));
- writer.write(graph);
- writer.close();
+
+ /**
+ * Writes Strings to files, can be used to output the graphs.
+ *
+ * @param path the path to write
+ * @param content the String representation of graph or any other String to be written to a file
+ * @throws IOException throws if IO problems occur during writing in a file
+ */
+ public static void writeToFile(final String path, final String content)
+ throws IOException {
+ writeToFile(path, content, "");
}
/**
@@ -145,7 +155,8 @@ public class CallGraphUtils {
for (final var exCall : calls.entrySet()) {
result.add(MutablePair.of(decode(types.get(exCall.getKey().firstInt())) + "." +
decode(methods.get(exCall.getKey().firstInt()).getSignature()),
- decode(types.get(exCall.getKey().secondInt())) + "." + decode(methods.get(exCall.getKey().secondInt()).getSignature())));
+ decode(types.get(exCall.getKey().secondInt())) + "." +
+ decode(methods.get(exCall.getKey().secondInt()).getSignature())));
}
return result;
}
