SpoonLabs / astor

Automatic program repair for Java with generate-and-validate techniques :v::v:: jGenProg (2014) - jMutRepair (2016) - jKali (2016) - DeepRepair (2017) - Cardumen (2018) - 3sfix (2018)
https://hal.archives-ouvertes.fr/hal-01321615/document
GNU General Public License v2.0
207 stars 106 forks source link

Running Gradle based project #306

Open zhiyufan opened 3 years ago

zhiyufan commented 3 years ago

Hi,

I'm wondering if Astor supports repairing gradle based projects. From the Getting Started document, I didn't see any description about Gradle. However, there is a project called Mockito_22 under the example/ folder. May I ask the command to repair Mockito_22 or other third-party Gradle-based projects? The command that I have tried on Mockito_22 is attached

  1. build Mockito_22 "gradle compileJava" and "gradle compileTestJava" " java -cp $(cat /tmp/astor-classpath.txt):target/classes fr.inria.main.evolution.AstorMain -mode jgenprog -srcjavafolder /src/java/ -srctestfolder /src/test/ -binjavafolder /build/classes/main -bintestfolder /build/classes/test -location /home/zhiyu/astor/examples/mockito_22/ -dependencies examples/mockito_22/lib " and this is the exception that I get. "15:54:10.804 [main] ERROR MutationSupporter - Error compiling: The import org.mockito.cglib cannot be resolved at /home/zhiyu/astor/examples/mockito_22/src/org/mockito/internal/creation/jmock/ClassImposterizer.java:7 15:54:10.848 [main] ERROR MutationSupporter - Astor continues when model build fails. Classes created: 306 Exception in thread "main" java.lang.NullPointerException"

I'm using java 8 as the environment

Thanks in advance!

martinezmatias commented 3 years ago

Hi @zhiyufan

From the Getting Started document, I didn't see any description about Gradle.

Astor is not capable of automatically determine the dependencies and structure (e.g., folders with the src/binaries) of a Gradle project. However, you can execute Astor on Gradle project by passing that info using via parameters (-dependencies, -srctestfolder, etc ) as you have done.

java -cp $(cat /tmp/astor-classpath.txt):target/classes fr.inria.main.evolution.AstorMain -mode jgenprog -srcjavafolder /src/java/ -srctestfolder /src/test/ -binjavafolder /build/classes/main -bintestfolder /build/classes/test -location /home/zhiyu/astor/examples/mockito_22/ -dependencies examples/mockito_22/lib "

I think the problem is in the dependencies parameter has a relative path, but it should be an absolute path

zhiyufan commented 3 years ago

Thanks for the quick reply.

I have changed to absolute path, but the error is still there. "java -cp $(cat /tmp/astor-classpath.txt):target/classes fr.inria.main.evolution.AstorMain -mode jgenprog -srcjavafolder /src/ -srctestfolder /test/ -binjavafolder /build/classes/main -bintestfolder /build/classes/test -location /home/zhiyu/astor/examples/mockito_22/ -dependencies /home/zhiyu/astor/examples/mockito_22/lib"

Also, I don't understand what does this error means "spoon.compiler.ModelBuildingException: The import org.mockito.cglib cannot be resolved at /home/zhiyu/astor/examples/mockito_22/src/org/mockito/internal/creation/jmock/ClassImposterizer.java:7 at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.report(JDTBasedSpoonCompiler.java:635) at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.reportProblems(JDTBasedSpoonCompiler.java:617) at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:116) at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:97) at fr.inria.astor.core.manipulation.MutationSupporter.buildModel(MutationSupporter.java:85) at fr.inria.astor.core.manipulation.MutationSupporter.buildSpoonModel(MutationSupporter.java:253) at fr.inria.astor.core.solutionsearch.AstorCoreEngine.initModel(AstorCoreEngine.java:776) at fr.inria.main.evolution.AstorMain.createEngine(AstorMain.java:113) at fr.inria.main.evolution.AstorMain.run(AstorMain.java:173) at fr.inria.main.evolution.AstorMain.execute(AstorMain.java:233) at fr.inria.main.evolution.AstorMain.main(AstorMain.java:204)"

It seems that spoon cannot parse the program correctly?

martinezmatias commented 3 years ago

It seems It cannot compile the code as it's missing one library: org.mockito.cglib.

Try to put the dependencies explicitly in the parameter, separated by File.pathSeparatior (e.g., :) -dependencies /home/x/x1.jar:/home/y/y1:jar

martinezmatias commented 3 years ago

Hello @zhiyufan

Is the issue solved? Can I close it?

Thanks Matias

byteSamurai commented 3 years ago

I am not sure if this is helpful, but I was able to run jgenprog with the Mockito 22 bug from defects4j. I did not use the example within the astor repository - maybe they are identical.

defects4j checkout -p Mockito -v 22b -w bugs/Mockito_22
java -cp astor.jar fr.inria.main.evolution.AstorMain \
 -out output \
 -mutationrate 1 \
 -maxtime 240 \
 -loglevel INFO \
 -location bugs/Mockito_22 \
 -mode jgenprog \
 -srcjavafolder /src/ \
 -srctestfolder /test/ \
 -binjavafolder /target/classes/ \
 -bintestfolder  /target/test-classes/ \
 -dependencies bugs/Mockito_22/lib/repackaged/cglib-and-asm-1.0.jar:bugs/Mockito_22/lib/compile/junit-4.10.jar:bugs/Mockito_22/lib/run/objenesis-2.1.jar

I get no error message though no patches are found.

JakkuSakura commented 3 years ago

I'm building a plugin for idea. It supports maven and gradle and is in active development these days. Now it can execute Astor with proper arguments and show diff of the best patch.

https://github.com/bc2021-program-repair/intellij-idea-astor-plugin/blob/fa5577978d6806c042d8f91466df2553e76cb9bf/src/main/kotlin/org/bytecamp/program_repair/astor_plugin/services/AstorProjectService.kt#L66-L102

martinezmatias commented 3 years ago

Hi @qiujiangkun

https://github.com/bc2021-program-repair/intellij-idea-astor-plugin/blob/fa5577978d6806c042d8f91466df2553e76cb9bf/src/main/kotlin/org/bytecamp/program_repair/astor_plugin/services/AstorProjectService.kt#L66-L102

That's really cool.

martinezmatias commented 3 years ago

@qiujiangkun PR are welcome. In case you want to integrate the plugin's code into the main project, please contact us.

JakkuSakura commented 3 years ago

It seems that it requires a new module to auto-configure these paths. Also the code shall be rewritten in Java to be used here. I'm glad to contribute if I had time.