You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The Aider Autofix plugin leverages LLM tools to fix code violations in your Java projects running within automated CI/CD pipelines, based on a generated analysis report. Jtest identifies violations, uses LLM integration to propose fixes for those violations, and verifies each proposed fix to ensure that all issues are fully resolved and no new problems are introduced. Successful fixes result in automatically created commits in the working branch of your project source control repository, enabling manual review and approval before merging.

The Jtest Autofix Python script is located in <INSTALL_DIR>/integration/aider.

Note: Support for the Aider Autofix plugin is deprecated and will be removed in future releases.

Prerequisites

The following are required to use this functionality:

  • Python 3.10-3.12

  • A version control system
  • Your secret LLM provider API key

This feature depends on LLMs, which may produce inaccurate information

Jtest Autofix Configuration

Preparing a Virtual Environment

We strongly recommend running the JtestAutoFix.py script inside a Python virtual environment to isolate it from your system-wide Python installation and prevent dependency conflicts.

Follow these steps to set up your virtual environment:


Windows

  1. Create a virtual environment:
    python -m venv venv
  2. Enter the virtual environment:
    CALL venv\Scripts\activate.bat
  3. Install the required dependencies:
    python -m pip install --upgrade pip
    pip install -r requirements.txt

Linux/Unix

  1. Create a virtual environment:
    python -m venv venv
  2. Enter the virtual environment:
    source venv/bin/activate
  3. Install required dependencies:
    python -m pip install --upgrade pip
    pip install -r requirements.txt

Autofix Configuration Options

The JtestAutoFix.py script can be configured using environment variables or command-line arguments. Command-line arguments take precedence over environment variables when both are specified.

Below is the complete reference for all available configuration options:

OptionRequiredCLI ArgumentEnvironment VariableDefault ValueDescription
LLM API KeyYesN/A%PROVIDER%_API_KEY=<KEY>-Your secret LLM provider API key required by Aider. Replace %PROVIDER% with the provider of your choice. Learn more about providers and variables.
Data fileYes--data DATA_FILE_PATHN/A-Path to the Jtest .data.json file. It must match the project used for the baseline analysis report.
Baseline ReportYes--report XML_REPORT_PATHREPORT=<XML_REPORT_PATH>-Path to the Jtest XML report containing violations to be fixed.
Tool HomeNo--tool-home JTEST_HOMETOOL_HOME=<JTEST_HOME>Jtest directoryPath to the Jtest installation directory. By default, it is set to the "../.." directory where the script is located.
Fix LimitNo--fix-limit COUNTFIX_LIMIT=<COUNT>0 (no limit)Maximum number of violation fix attempts per run.
Max AttemptsNo--max-attempts MAX_ATTEMPTSN/A3Maximum retry attempts per violation before stopping.
Model NameNoN/AMODEL_NAME=MODELgpt-4o-miniAI model for fixing violations (e.g., gpt-4, gpt-4o, claude-3-sonnet). Use aider --list-models <fragment> to see the available models.
Weak Model NameNoN/AWEAK_MODEL_NAME=MODEL-Lightweight model for auxiliary tasks, such as commit message generation. When not specified, it defaults to the specified model name (MODEL_NAME).
Verification CommandNo--verification-command COMMANDN/A-Command to verify code integrity after each fix (e.g., "mvn compile" or "./gradlew assemble"). Success is determined by exit code (0 = success).
No Source ControlNo--allow-no-source-controlN/ADisabledBypass source control warnings. Use with caution - changes will be made without version control and cannot be reverted.
HelpNo-h or --helpN/AN/ADisplay help information for the JtestAutoFix.py script.

Configuring the Environment

You can use the provided .env.template file as a starting point to create your own .env file with the necessary environment variables.

Running Autofix

Before running the Autofix script, we recommend creating a dedicated branch for the automated fixes. This allows you to review and test all changes before merging them into your main branch.

Basic Usage for a Gradle project

Windows


  1. Set your API key:
    SET OPENAI_API_KEY=your_secret_open_ai_key
  2. Execute Autofix with the recommended settings:

python JtestAutoFix.py
 --report "<PROJECT_PATH>/build/jtest/report.xml"
 --max-attempts 3
 --data "<PROJECT_PATH>/build/jtest/jtest.data.json"
 --tool-home "C:\Program Files\Parasoft\Jtest\2025.2"

Linux/Unix

  1. Set your API key:
    export OPENAI_API_KEY=your_secret_open_ai_key
  2. Execute Autofix with the recommended settings:
    python3 JtestAutoFix.py
     --report "<PROJECT_PATH>/build/jtest/report.xml"
     --max-attempts 3
     --data "<PROJECT_PATH>/build/jtest/jtest.data.json"
     --tool-home "/opt/parasoft/jtest/2025.2"

Advanced Usage Examples

Windows with the Verification Command

  1. Set the environment variables:
    SET OPENAI_API_KEY=your_secret_open_ai_key
    SET MODEL_NAME=gpt-4.1
    SET WEAK_MODEL_NAME=gpt-4o-mini
  2. Execute Autofix with build verification:
    python JtestAutoFix.py
     --report "C:\projects\myapp\build\jtest\report.xml"
     --data "C:\projects\myapp\build\jtest\jtest.data.json"
     --tool-home "C:\Program Files\Parasoft\Jtest\2025.2"
     --verification-command "gradle build"
     --fix-limit 10
     --max-attempts 2

Linux/Unix with the Verification Command

  1. Set the environment variables:
    export OPENAI_API_KEY=your_secret_open_ai_key
    export MODEL_NAME=gpt-4.1
    export WEAK_MODEL_NAME=gpt-4o-mini
  2. Execute Autofix with build verification:
    python JtestAutoFix.py
     --report "/home/user/projects/myapp/build/jtest/report.xml"
     --data "/home/user/projects/myapp/build/jtest/jtest.data.json"
     --tool-home "/opt/parasoft/jtest/2025.2"
     --verification-command "./gradlew build"
     --fix-limit 10
     --max-attempts 2

To ensure accurate results and efficient use of the Autofix plugin, follow these best practices:

Generate a new baseline after each Autofix session: Code changes made during the autofix process can alter file line numbers and structure, making the violation locations in your original report.xml obsolete. Regenerate your baseline report to ensure it accurately reflects your updated codebase.

Fix history tracking: The script creates data files in the .cliAutoFix folder to track fix attempts and outcomes in *.history.yaml files.

Preserve history: To avoid re-attempting the same violations:

  • Preserve the .cliAutoFix folder and its *.history.yaml files between runs.
  • Alternatively, ensure all attempted violations are either fixed or suppressed before the next run.

Reviewing Results

After each successful fix, the Autofix script creates a commit in your repository. Since AI-generated code may contain errors or suboptimal solutions, it is crucial to review all changes carefully.

Follow these best practices when reviewing AI-generated fixes:

  • Read the commit messages - Understand what changes were made and why.
  • Test the changes - Ensure the fix resolves the violation without introducing new issues.
  • Check the code quality - Verify that the fix follows your team's coding standards.
  • Apply incremental fixes - For minor issues in otherwise good fixes, create separate commits with manual corrections.
  • Revert when necessary - If a fix is fundamentally wrong, revert the entire commit.
  • Use a branching strategy - Work on a feature branch and merge after review, or cherry-pick verified commits.

Troubleshooting

If you encounter any issues while running the script, ensure that:

  • All dependencies are correctly installed
  • Environment variables are properly configured
  • All required CLI parameters are properly passed

  • Linux/Unix only: Ensure that Python 3.10+ is installed and accessible via the python3 or python commands.
  • Linux/Unix only: Check the file permissions for the script and data files.

  • No labels