Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use command-line using jdk7? #1099

Closed
Albert-Gong opened this issue Oct 23, 2022 · 4 comments
Closed

How to use command-line using jdk7? #1099

Albert-Gong opened this issue Oct 23, 2022 · 4 comments

Comments

@Albert-Gong
Copy link

Hello,
I am trying to use PITest to mutate the code in Defects4J1.0, which requires jdk1.7.

Here is my java version

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

I have tried several versions of PITest and finally found that PITest before 1.3 is compatible with jdk1.7.

Here is my script:

java 
  -cp    jars/pitest-1.3.0.jar:
         jars/pitest-command-line-1.3.0.jar: 
         jars/pitest-entry-1.3.0.jar: 
         jars/junit-4.12.jar: 
         jars/hamcrest-all-1.3.jar: 
         checkouts/lang-1f/target/classes/: 
         checkouts/lang-1f/target/test-classes \
         org.pitest.mutationtest.commandline.MutationCoverageReport \
         --reportDir ./report \
         --targetClasses org.apache.commons.lang3.math.NumberUtils \
         --targetTests org.apache.commons.lang3.BooleanUtilsTest \
         --sourceDirs ./checkouts/lang-1f/src/main/java \
         --verbose True

But then I got this exception

Exception in thread "main" java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamWriter
	at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:106)
	at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:49)
	at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
	at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.io.HierarchicalStreamWriter
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

I ran the same script on another machine with jdk7 and got the same exception.

I wonder if it is possible to use the command line with jdk7, and if it is, which PITest version and jars should I use?

Thank you,
Albert

@rnveach
Copy link
Contributor

rnveach commented Oct 23, 2022

Not a maintainer but I have an old project with 1.3.2 CLI that runs on Java 8. So old is possibly.

You may want to verify that is just not a missing dependency since your not running in maven. It is listed as a dependency in the old POM.

<groupId>com.thoughtworks.xstream</groupId>

Just noting the following:
https://github.com/hcoles/pitest/releases/tag/pitest-parent-1.3.0

#196 - Raise minimum java version to 7

@Albert-Gong
Copy link
Author

Not a maintainer but I have an old project with 1.3.2 CLI that runs on Java 8. So old is possibly.

You may want to verify that is just not a missing dependency since your not running in maven. It is listed as a dependency in the old POM.

<groupId>com.thoughtworks.xstream</groupId>

Just noting the following: https://github.com/hcoles/pitest/releases/tag/pitest-parent-1.3.0

#196 - Raise minimum java version to 7

Thanks for your reply,

I downloaded the pitest1.3.0 source code and ran

mvn install

Then I got

[INFO] Reactor Summary for pitest-parent 1.3.0:
[INFO] 
[INFO] pitest-parent ...................................... SUCCESS [  0.254 s]
[INFO] Build Config ....................................... SUCCESS [  0.851 s]
[INFO] pitest ............................................. SUCCESS [ 22.346 s]
[INFO] pitest-entry ....................................... SUCCESS [ 54.354 s]
[INFO] pitest-html-report ................................. SUCCESS [  1.368 s]
[INFO] pitest-maven ....................................... SUCCESS [ 10.309 s]
[INFO] pitest-command-line ................................ SUCCESS [  1.465 s]
[INFO] pitest-ant ......................................... SUCCESS [  1.108 s]
[INFO] pitest-maven-verification .......................... FAILURE [02:02 min]
[INFO] pitest-groovy-verification ......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:34 min
[INFO] Finished at: 2022-10-23T13:18:56+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.17:verify (default) on project pitest-maven-verification: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/albert/Downloads/pitest-pitest-parent-1.3.0/pitest-maven-verification/target/failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :pitest-maven-verification

Still, I tried to use the pitest, pitest-entry and pitest-command-line jar and got the same exception as mentioned before, with both jdk7 and jdk8.

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)

@rnveach
Copy link
Contributor

rnveach commented Oct 23, 2022

Maven's install doesn't combine the dependencies into the jar unless it uses the maven-shade-plugin telling it to do so and usually JARs created by it are very large.

Have you tried downloading the jar and including it in your classpath along with pitest?
https://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.8/xstream-1.4.8.jar

@Albert-Gong
Copy link
Author

Thank you, @rnveach,
After many efforts, now I can mutate all five projects in defects4j1.0, with some extra jars downloaded.

Below is the command to mutate Lang-1-f. I would like to share the script in case someone has the same problem.

jar_path='xxx/defects4j-1.0.0/jars'
build_path='xxx/defects4j-1.0.0/checkouts/lang-1f/target/classes'
build_test_path='xxx/defects4j-1.0.0/checkouts/lang-1f/target/test-classes'
targetClasse='org.apache.commons.lang3.math.NumberUtils'
targetTests='org.apache.commons.lang3.math.NumberUtilsTest'
sourceDirs='xxx/defects4j-1.0.0/checkouts/lang-1f/src'


java -cp \
$jar_path/xstream-1.4.8.jar:$jar_path/xmlpull_1_0_5.jar:$jar_path/pitest-1.3.0.jar:$jar_path/pitest-command-line-1.3.0.jar:$jar_path/pitest-entry-1.3.0.jar:$jar_path/junit-4.12.jar:$jar_path/hamcrest-all-1.3.jar:\
$build_path:\
$build_test_path \
org.pitest.mutationtest.commandline.MutationCoverageReport \
--reportDir ./report \
--targetClasses $targetClasse \
--targetTests $targetTests \
--sourceDirs $sourceDirs

Thank you again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants