Development tooling for Java projects, including Checkstyle linting, Java method and REST API inventories, test-coverage analysis, and Maven dependency inventory.
- Requirements
- Setup
- Changed-Line Java Linter
- Using
pre-commit - Java Method Inventory
- REST API Inventory
- Test Coverage Analysis
- Maven Dependency Inventory
- Command Reference
- Checkstyle
- Development & Contribution
- Packaging
- Python 3
- Git
- JDK (
java,javac, andjar) - Maven (
mvn)
Initialize the project dependencies and build the inventory components:
python java_inventory.py setupRun setup before using the analysis and linting commands.
The lint command runs Checkstyle against Java code changed in Git.
For modified files, only violations on changed lines are reported. Newly added files are checked as a whole.
Check unstaged working-tree changes:
python java_inventory.py lint .Check staged changes:
python java_inventory.py lint . --cachedInclude untracked Java files:
python java_inventory.py lint . --include-untrackedShow the changed Java files and lines without running Checkstyle:
python java_inventory.py lint . --no-checkstyleEnable debug logging:
python java_inventory.py --debug lint .| Change | Lint behavior |
|---|---|
| Modified Java file | Check only violations on changed lines |
| Added Java file | Check the entire file |
Untracked Java file with --include-untracked |
Check the entire file |
| Non-Java file | Ignored |
For example:
warning: src/main/java/example/Foo.java:15:5: Missing a Javadoc comment. [MissingJavadocMethod]
warning: src/main/java/example/Foo.java:17:5: 'isValid' has incorrect indentation level 4, expected level should be 12. [Indentation]
error: src/main/java/example/Bar.java:8:48: java.lang.IllegalStateException: mismatched input '{' expecting ')'
info: checkstyle summary: 1 error(s), 2 warning(s).
| Option | Description |
|---|---|
--cached |
Analyze staged changes instead of unstaged working-tree changes |
--include-untracked |
Include untracked Java files and check them as whole files |
--no-checkstyle |
Print changed Java files and lines without running Checkstyle |
--debug |
Show internal commands and debug logging |
--debug is a global option and must appear before the subcommand:
python java_inventory.py --debug lint .For a normal Git hook, lint the staged snapshot.
Create .git/hooks/pre-commit:
#!/bin/sh
python java_inventory.py lint . --cachedMake it executable:
chmod +x .git/hooks/pre-commitThe --cached flag is important because a commit contains the staged version of the files, not arbitrary unstaged working-tree changes.
To bypass the hook for a commit:
git commit --no-verifyThe same lint command can be integrated with the Python pre-commit framework.
Install pre-commit:
python -m pip install pre-commitAdd the following to .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: java-inventory-lint
name: Java Inventory Checkstyle
entry: python java_inventory.py lint . --cached
language: unsupported
pass_filenames: false
always_run: trueInstall the Git hook:
pre-commit installOr install the hook and its environments:
pre-commit install --install-hooksRun the lint hook manually:
pre-commit run java-inventory-lintRun it against all files known to pre-commit:
pre-commit run java-inventory-lint --all-filesThe hook uses pass_filenames: false because java_inventory.py determines the changed files itself from Git.
Generate an inventory of Java methods:
python java_inventory.py inventory-method dev-test/src/mainWrite the inventory to a specific file:
python java_inventory.py inventory-method dev-test/src/main \
--output build/methods.csvGenerate a CSV inventory of REST APIs:
python java_inventory.py inventory-rest-api dev-test/src/mainBy default, the report is written to:
rest_apis.csv
Specify a different output file:
python java_inventory.py inventory-rest-api dev-test/src/main \
--output build/rest_apis.csvGenerate the test-coverage report:
python java_inventory.py test-coverage \
dev-test/src/main \
dev-test/src/testBy default, the report is written to:
test_coverage_report.html
Specify a different output file:
python java_inventory.py test-coverage \
dev-test/src/main \
dev-test/src/test \
--output build/test_coverage_report.htmlGenerate an inventory of Maven dependencies:
python java_inventory.py inventory path/to/projectThe inventory includes:
- Module
- Group ID
- Artifact ID
- Declared version
- Resolved version
- Scope
- Direct/transitive dependency
- Optional dependency
By default, dependency information is printed to the terminal.
Write a CSV report:
python java_inventory.py inventory path/to/project \
--output build/dependencies.csvWrite a JSON report:
python java_inventory.py inventory path/to/project \
--output build/dependencies.json \
--format jsonMaven projects are currently supported. Gradle projects are detected but are not supported yet.
The Maven dependency graph is resolved by the Java Maven resolver. Python handles the CLI integration and report formatting.
python java_inventory.py [--debug] <command>
| Command | Purpose |
|---|---|
setup |
Initialize dependencies and build inventory components |
lint |
Run Checkstyle on changed Java code |
inventory-method |
Generate a Java method inventory |
inventory-rest-api |
Generate a REST API inventory CSV |
test-coverage |
Generate the test-coverage report |
inventory |
Generate a Maven dependency inventory |
Show command help:
python java_inventory.py --helpShow help for a specific command:
python java_inventory.py lint --helppython java_inventory.py inventory-method --helppython java_inventory.py inventory-rest-api --helppython java_inventory.py test-coverage --helppython java_inventory.py inventory --helpThe linter uses the project's Checkstyle configuration and custom Checkstyle checks:
resources/style_guide.xml
resources/checkstyle-12.3.0-all.jar
checkstyle/target/checkstyle-inventory-0.1.0-SNAPSHOT.jar
Run setup first if the Checkstyle or Maven inventory components have not been built.
See CONTRIBUTING.md for development workflow and contribution guidelines.
See PACKAGING.md for standalone builds, platform packaging, and release details