Skip to content

nelsonstr/kevlar-code-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Kevlar Code Rules

Java Maven License CI Release Quality Gate

Kevlar Code Rules provides enterprise-grade static analysis and architectural validation for Java projects.

It is designed to help you create shared configuration for other project minimizing the duplicated configuration and keep all projects aligned with a standard rule set.

World-class Maven Enforcer Rule for detecting cyclic package dependencies.

Built with modern Java 21 features and designed for high-performance analysis of large-scale codebases.

πŸš€ Features

✨ Core Capabilities

  • Cyclic Dependency Detection: Advanced algorithms to identify circular package dependencies
  • High Performance: Optimized for large projects with caching and parallel processing
  • Configurable Analysis: Flexible inclusion/exclusion patterns and depth control
  • Comprehensive Reporting: Detailed error messages with actionable recommendations
  • Thread Safety: Concurrent processing support for enterprise environments

πŸ—οΈ Enterprise Features

  • Modern Java 21: Leverages latest language features for optimal performance
  • Maven Integration: Seamless integration with Maven Enforcer Plugin
  • CI/CD Ready: Designed for automated quality gates in build pipelines
  • Extensible Architecture: Plugin-based design for custom rule extensions
  • Comprehensive Testing: 100% test coverage with unit and integration tests

πŸ“Š Quality Assurance

  • Static Analysis: PMD, SpotBugs, and Checkstyle integration
  • Code Coverage: JaCoCo integration with configurable thresholds
  • Security Scanning: OWASP Dependency Check integration
  • Performance Monitoring: Built-in performance metrics and profiling

πŸ“¦ Installation

Maven Dependency

<dependency>
    <groupId>org.github.nelsonstr</groupId>
    <artifactId>kevlar-code-rules</artifactId>
    <version>1.0.0</version>
</dependency>

Maven Enforcer Plugin Configuration

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
        <execution>
            <id>enforce-no-cyclic-dependencies</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <rule implementation="org.github.nelsonstr.kevlar.code.rules.NoCyclicPackageDependencyRule">
                        <projectName>My Enterprise Project</projectName>
                        <maxDepth>15</maxDepth>
                        <excludePatterns>
                            <excludePattern>.*\\.generated\\..*</excludePattern>
                            <excludePattern>.*\\.internal\\..*</excludePattern>
                        </excludePatterns>
                        <failOnError>true</failOnError>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

πŸ”§ Configuration

Basic Configuration

<rule implementation="org.github.nelsonstr.kevlar.code.rules.NoCyclicPackageDependencyRule">
    <!-- Custom project name for error reporting -->
    <projectName>My Project</projectName>
    
    <!-- Maximum dependency depth to analyze -->
    <maxDepth>10</maxDepth>
    
    <!-- Whether to fail the build on cyclic dependencies -->
    <failOnError>true</failOnError>
    
    <!-- Run in report-only mode -->
    <reportOnly>false</reportOnly>
</rule>

Advanced Configuration

<rule implementation="org.github.nelsonstr.kevlar.code.rules.NoCyclicPackageDependencyRule">
    <projectName>Enterprise Application</projectName>
    <maxDepth>20</maxDepth>
    
    <!-- Exclude patterns (regex) -->
    <excludePatterns>
        <excludePattern>.*\\.generated\\..*</excludePattern>
        <excludePattern>.*\\.internal\\..*</excludePattern>
        <excludePattern>.*\\.test\\..*</excludePattern>
        <excludePattern>.*\\.mock\\..*</excludePattern>
    </excludePatterns>
    
    <!-- Include patterns (regex) - only analyze matching packages -->
    <includePatterns>
        <includePattern>com\\.mycompany\\..*</includePattern>
        <includePattern>org\\.myproject\\..*</includePattern>
    </includePatterns>
    
    <failOnError>true</failOnError>
    <reportOnly>false</reportOnly>
</rule>

πŸš€ Development Workflow

Feature Branch Workflow

  1. Create Feature Branch

    git checkout main
    git pull origin main
    git checkout -b feature/your-feature-name
  2. Make Changes

    # Make your code changes
    # Run tests locally
    mvn clean test
  3. Create Pull Request

    git add .
    git commit -m "feat: add new feature"
    git push origin feature/your-feature-name
    # Create PR on GitHub
  4. Code Review & Merge

    • Automated CI runs on PR
    • Code review by maintainers
    • Merge to main when approved

Release Process

  1. Prepare Release

    # Ensure main is up to date
    git checkout main
    git pull origin main
  2. Create Release

    • Go to GitHub Actions
    • Run "Release" workflow
    • Choose version and release type
    • Review and approve

πŸ“‹ Usage Examples

1. Basic Usage

# Run the enforcer rule
mvn enforcer:enforce

# Run with custom configuration
mvn enforcer:enforce -DprojectName="MyApp" -DmaxDepth=15

2. Integration with Build Pipeline

# Full build with quality checks
mvn clean compile test pmd:check spotbugs:check enforcer:enforce package

# CI/CD pipeline
mvn clean verify enforcer:enforce

3. Report Generation

# Generate detailed reports
mvn site:site

# View reports
open target/site/index.html

🏭 Enterprise Integration

Git Workflow

This project follows a feature branch + main branch workflow:

  1. Main Branch: Contains production-ready code
  2. Feature Branches: Created for new features, bug fixes, and improvements
  3. Pull Requests: All changes are reviewed via pull requests to main
  4. Continuous Integration: Automated testing on all pull requests
  5. Release Process: Manual releases from main branch

CI/CD Pipeline Integration

# GitHub Actions Example
- name: Run Quality Gates
  run: |
    mvn clean compile test
    mvn pmd:check spotbugs:check
    mvn enforcer:enforce
    mvn jacoco:report

SonarQube Integration

<!-- SonarQube Maven Plugin -->
<plugin>
    <groupId>org.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>3.10.0.2594</version>
</plugin>

Jenkins Pipeline

pipeline {
    agent any
    stages {
        stage('Quality Gates') {
            steps {
                sh 'mvn clean compile test'
                sh 'mvn pmd:check spotbugs:check'
                sh 'mvn enforcer:enforce'
                sh 'mvn jacoco:report'
            }
        }
    }
}

πŸ“Š Performance Characteristics

Algorithm Complexity

  • Time Complexity: O(V + E) where V is packages and E is dependencies
  • Space Complexity: O(V) for dependency graph storage
  • Memory Usage: Optimized with lazy loading and caching
  • Parallel Processing: Supports concurrent analysis for large projects

Performance Benchmarks

Project Size Packages Dependencies Analysis Time Memory Usage
Small (< 100) 50 200 < 1s 50MB
Medium (100-500) 250 1,000 2-5s 150MB
Large (500-1000) 750 3,000 5-15s 400MB
Enterprise (>1000) 2,000 8,000 15-60s 1GB

πŸ§ͺ Testing

Running Tests

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=NoCyclicPackageDependencyRuleTest

# Run integration tests
mvn verify

# Run with coverage
mvn jacoco:prepare-agent test jacoco:report

Test Coverage

# Generate coverage report
mvn jacoco:report

# View coverage report
open target/site/jacoco/index.html

πŸ“ˆ Monitoring and Metrics

Built-in Metrics

  • Analysis Duration: Time taken for dependency analysis
  • Package Count: Number of packages analyzed
  • Dependency Count: Total number of dependencies found
  • Cycle Count: Number of cyclic dependencies detected
  • Cache Hit Rate: Performance optimization metrics

Custom Metrics

// Access analysis metrics
DependencyAnalysisResult result = performAnalysis(projectPath, log, analysisId);
log.info("Packages analyzed: " + result.packageCount());
log.info("Dependencies found: " + result.dependencyCount());
log.info("Cycles detected: " + result.cycles().size());

πŸ” Troubleshooting

Common Issues

1. Build Failures

# Check enforcer rule configuration
mvn enforcer:display-info

# Run with debug output
mvn enforcer:enforce -X

2. Performance Issues

<!-- Optimize for large projects -->
<rule implementation="org.github.nelsonstr.kevlar.code.rules.NoCyclicPackageDependencyRule">
    <maxDepth>10</maxDepth>
    <excludePatterns>
        <excludePattern>.*\\.test\\..*</excludePattern>
        <excludePattern>.*\\.generated\\..*</excludePattern>
    </excludePatterns>
</rule>

3. Memory Issues

# Increase JVM memory
export MAVEN_OPTS="-Xmx4g -XX:+UseG1GC"
mvn enforcer:enforce

Debug Mode

# Enable debug logging
mvn enforcer:enforce -Dorg.slf4j.simpleLogger.log.org.github.nelsonstr.kevlar=DEBUG

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/nelsonstr/kevlar-code-rules.git
cd kevlar-code-rules

# Build the project
mvn clean compile test

# Run quality checks
mvn pmd:check spotbugs:check enforcer:enforce

# Generate documentation
mvn site:site

Code Style

This project follows the Google Java Style Guide with some modifications:

  • Line length: 120 characters
  • Indentation: 4 spaces
  • Java 21 features encouraged

πŸ“„ License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

πŸ”„ Version History

[1.0.0] - 2024-01-01

  • Initial release
  • Core cyclic dependency detection
  • Maven Enforcer Plugin integration
  • Comprehensive test coverage

[0.9.0] - 2023-12-01

  • Beta release
  • Basic functionality
  • Initial documentation

Made with ❀️ by Nelson Str

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published