diff --git a/sdg-cli/pom.xml b/sdg-cli/pom.xml
index 4446f02..3f3e409 100644
--- a/sdg-cli/pom.xml
+++ b/sdg-cli/pom.xml
@@ -63,5 +63,10 @@
jgrapht-io
1.5.0
+
+ com.google.code.gson
+ gson
+ 2.10.1
+
diff --git a/sdg-cli/src/main/java/es/upv/mist/slicing/cli/Slicer.java b/sdg-cli/src/main/java/es/upv/mist/slicing/cli/Slicer.java
index 765baf0..c336037 100644
--- a/sdg-cli/src/main/java/es/upv/mist/slicing/cli/Slicer.java
+++ b/sdg-cli/src/main/java/es/upv/mist/slicing/cli/Slicer.java
@@ -3,10 +3,17 @@
import com.github.javaparser.Problem;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.CallableDeclaration;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.comments.BlockComment;
import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.stmt.Statement;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import es.upv.mist.slicing.graphs.augmented.ASDG;
import es.upv.mist.slicing.graphs.augmented.PSDG;
import es.upv.mist.slicing.graphs.exceptionsensitive.ESSDG;
@@ -21,7 +28,12 @@
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -90,6 +102,15 @@ public class Slicer {
.builder("h").longOpt("help")
.desc("Shows this text")
.build());
+ OPTIONS.addOption(Option
+ .builder("a").longOpt("all")
+ .desc("Slice all variables in the project and export to JSON")
+ .build());
+ OPTIONS.addOption(Option
+ .builder("p").longOpt("project")
+ .hasArg().argName("project-name")
+ .desc("The name of the project (used for EID generation in -a mode)")
+ .build());
}
private final Set dirIncludeSet = new HashSet<>();
@@ -103,22 +124,30 @@ public Slicer(String... cliArgs) throws ParseException {
cliOpts = new DefaultParser().parse(OPTIONS, cliArgs);
if (cliOpts.hasOption('h'))
printHelp();
- if (cliOpts.hasOption('c')) {
- Matcher matcher = SC_PATTERN.matcher(cliOpts.getOptionValue("criterion"));
- if (!matcher.matches())
- throw new ParseException("Invalid format for slicing criterion, see --help for more details");
- setScFile(matcher.group("file"));
- setScLine(Integer.parseInt(matcher.group("line")));
- String var = matcher.group("var");
- if (var != null)
- setScVar(var);
- } else if (cliOpts.hasOption('f') && cliOpts.hasOption('l')) {
- setScFile(cliOpts.getOptionValue('f'));
- setScLine(((Number) cliOpts.getParsedOptionValue("l")).intValue());
- if (cliOpts.hasOption('v'))
- setScVar(cliOpts.getOptionValue('v'));
+
+ if (cliOpts.hasOption('a')) {
+ // In 'all' mode, we don't need specific criterion arguments
+ if (cliOpts.hasOption('c') || (cliOpts.hasOption('f') && cliOpts.hasOption('l'))) {
+ System.out.println("Warning: Slicing criterion arguments ignored in 'all' mode.");
+ }
} else {
- throw new ParseException("Slicing criterion not specified: either use \"-c\" or \"-f\" and \"-l\".");
+ if (cliOpts.hasOption('c')) {
+ Matcher matcher = SC_PATTERN.matcher(cliOpts.getOptionValue("criterion"));
+ if (!matcher.matches())
+ throw new ParseException("Invalid format for slicing criterion, see --help for more details");
+ setScFile(matcher.group("file"));
+ setScLine(Integer.parseInt(matcher.group("line")));
+ String var = matcher.group("var");
+ if (var != null)
+ setScVar(var);
+ } else if (cliOpts.hasOption('f') && cliOpts.hasOption('l')) {
+ setScFile(cliOpts.getOptionValue('f'));
+ setScLine(((Number) cliOpts.getParsedOptionValue("l")).intValue());
+ if (cliOpts.hasOption('v'))
+ setScVar(cliOpts.getOptionValue('v'));
+ } else {
+ throw new ParseException("Slicing criterion not specified: either use \"-c\" or \"-f\" and \"-l\".");
+ }
}
if (cliOpts.hasOption('o'))
@@ -186,8 +215,11 @@ public void slice() throws ParseException {
boolean scFileFound = false;
for (File file : (Iterable) findAllJavaFiles(dirIncludeSet)::iterator)
scFileFound |= parse(file, units, problems);
- if (!scFileFound)
+
+ // In 'all' mode, we might not have scFile, but we need to parse all files in include dirs
+ if (!cliOpts.hasOption('a') && !scFileFound)
parse(scFile, units, problems);
+
if (!problems.isEmpty()) {
for (Problem p : problems)
System.out.println(" * " + p.getVerboseMessage());
@@ -207,6 +239,11 @@ public void slice() throws ParseException {
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, "Building the SDG");
sdg.build(new NodeList<>(units));
+ if (cliOpts.hasOption('a')) {
+ sliceAll(sdg, units);
+ return;
+ }
+
// Slice the SDG
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, "Searching for criterion and slicing");
SlicingCriterion sc = new FileLineSlicingCriterion(scFile, scLine, scVar);
@@ -231,13 +268,178 @@ public void slice() throws ParseException {
}
}
+ private void sliceAll(SDG sdg, Set units) {
+ Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.INFO, "Slicing all variables...");
+ List