stg-tud / MUDetect

Mozilla Public License 2.0
24 stars 8 forks source link

Running MuDetect directly (standalone) #22

Closed oneturkmen closed 4 years ago

oneturkmen commented 4 years ago

Hello,

I create a MuDetect package (via mvn package -Dskiptests) and tried to run MuDetect on one of its (.java) test files to see if the project runs or not, with the following command:

$ java -cp mubench/target/classes/ de.tu_darmstadt.stg.mubench.MuDetectRunner ...

However, it says that:

Error: Unable to initialize main class de.tu_darmstadt.stg.mubench.MuDetectRunner
Caused by: java.lang.NoClassDefFoundError: de/tu_darmstadt/stg/mubench/cli/DetectionStrategy

I also tried running this:

$ java mubench.src.main.java.de.tu_darmstadt.stg.mubench.MuDetectRunner detector_mode "0"
          target_src_path "src2egroum2aug/src/test/resources/input/" target_classpath ""
          dep_classpath "target:dependency:classpath"
          target "findings-output.yml" run_info "run-info-output.yml"

From which I get a similar response:

Error: Could not find or load main class mubench.src.main.java.de.tu_darmstadt.stg.mubench.MuDetectRunner
Caused by: java.lang.ClassNotFoundException: mubench.src.main.java.de.tu_darmstadt.stg.mubench.MuDetectRunner

I feel like I am missing a step or two. How could I resolve this? (if you have an example command somewhere, that'd be great!)

oneturkmen commented 4 years ago

This has been resolved. Attaching an example here for potential references to the same issue:

  1. Build the project:

mvn package -DskipTests

  1. Run MuDetect (mode 0) on some project of your choice.

java -cp MUDetect/mubench/target/MuDetect.jar de.tu_darmstadt.stg.mubench.MuDetectRunner detector_mode 0 target_src_path ./foo/src/main target_classpath ./foo/target/classes target findings-foo.yml run_info run-info-foo.yml

Note: I am not sure whether you have to provide target_classpath or not. For the mining part, MuDetect seems to provide the same results with and without target_classpath.

Update: Consider including dependency classpath for better type resolution. Check more info in the comment below.

salsolatragus commented 4 years ago

Thanks for coming back to this.

MUDetect, in it's current implementation, does not use target_classpath. The parameters are those defined by MUBench and the classpath is used by detectors that analyze Java Bytecode (while MUDetect analyzes source code).

You might want to consider providing dep_classpath though. This is the classpath containing the analyzed source code's dependencies. MUDetect uses this for type resolution when parsing the code, which improves accuracy w.r.t type names (e.g., it can then resolve method declarations, such as List.isEmpty(), instead of taking the concrete type in the source, e.g., MyFancyList.isEmpty()). The Java Standard Library is always, implicitly, on the dependency path. All other dependencies need to be explicitly specified.