Parse checkstyle comments

Automatically parse the output of a checkstyle test and display the comments on your students' code.

Checkstyle is a popular code quality tool for Java. Using the cg checkstyle command, you can easily install, run and parse the output to display the generated comments on your students' code.

The cg checkstyle command is automatically installed in AutoTest v2. You can also download the command for local testing via the following links:

Arguments

The cg checkstyle suite provides the following commands and command line arguments:

  • install This command downloads the JAR file for the specified version of checkstyle. The command uses $CG_INSTALL_DIR to determine where to install checkstyle. The command relies on "/installs" as a fallback if the above is not set. Use cg checkstyle install --help for more information about this command.

  • get-jar Returns the file path to the checkstyle runnable JAR if installed with the --install flag. Use cg checkstyle get-jar --help for more information about this command.

  • parse A parser for checkstyle that produces comments from XML reports. Use cg checkstyle parse --help for more information about this command.

  • run A reporter for checkstyle. Automatically runs and parses the XML output of a checkstyle test. Use cg checkstyle run --help for more information about this command.

  • --help or -h Help for the cg checkstyle command.

cg checkstyle install must be run before using any other cg checkstyle command and must be run with internet enabled.

Examples

Installing checkstyle

At the time of writing, the cg checkstyle command is not available in the setup portion of the AutoTest configuration. It is therefore important to use an Allow Internet block when running "cg checkstyle install" in your Tests configuration.

  1. Navigate to the Tests portion of your AutoTest.

  2. Create an Allow Internet block

  3. Create a Script block and nest it within the Allow internet block.

  4. Use the following command to install checkstyle version 10.12.3:

    cg checkstyle install 10.12.3

Running checkstyle with the default Sun style guide

  1. Navigate to the setup portion of your AutoTest and create an Upload Files block.

  2. Upload the default Sun style guide configuration file for checkstyle. You can find the latest version of that file, here. Read more about the Sun style guide for Java, here.

  3. Navigate back to the tests portion of your AutoTest and create a Custom Test block.

  4. Run checkstyle on MySubmission.java using the command:

    cg checkstyle run MySubmission.java --config $UPLOADED_FILES/sun_checks.xml

Running checkstyle with a custom configuration or custom checkstyle flags

  1. Navigate to the Setup portion of your AutoTest and create a Upload Files Block.

  2. Upload your prefered xml configuration file for checkstyle.

  3. Navigate back to the Tests portion of your AutoTest configuration and create a Script block.

  4. Run checkstyle on MySubmission.java with your own custom flag options using the following command:

    java -jar $(cg checkstyle get-jar) \
        -c $UPLOADED_FILES/sun_checks.xml \
        -f xml \
        -o report.xml \
        MySubmission.java
  5. Underneath, create a Custom Test block.

  6. Parse the XML output file generated by checkstyle and set the percentage of points deducted for comments with the "error" severity to 1% using the following command:

    cg checkstyle parse report.xml --deduction-error 1  

Last updated