Skip to content

Conversation

maeveho25
Copy link
Collaborator

@maeveho25 maeveho25 commented Aug 7, 2025

This PR adds a new feature that automatically generates Java POJO classes from Tekton Custom Resource Definitions (CRDs) during Maven build time.

What's Added

Core Components

  • CrdJavaGenerator Main entry point for Maven exec plugin integration.

  • EnhancedCrdProcessor Core logic for processing CRD YAML files and generating Java classes using jsonschema2pojo.

  • Maven Profile Integration A new Maven profile download-binaries is added for:

    • CRD generation
    • JX Pipeline binary downloads

Generated Output

  • 1000+ Java Classes generated from Tekton CRD schemas
  • Support for Multiple API Versions: v1, v1beta1, v1alpha1
  • Jenkins Integration: All generated classes extend BaseStep and include @DataBoundConstructor for pipeline compatibility

Next Steps

  • CRD to POJO generation logic
  • UI Integration
    • Auto-generate Jelly files for Jenkins UI rendering
  • Unit Tests
    • Validate POJO generation from mock CRD YAML
    • Test CRD processor with various CRD formats and edge cases
  • Generated POJO Tests
    • Test core methods such as createCustomTaskRun, pipeline, etc.
    • Verify all generated steps extend BaseStep
  • End-to-End Testing
    • CRD → POJO → Jenkins Step → Kubernetes API

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Architecture Diagram

CRD YAML Files
       ↓
CrdJavaGenerator
       ↓
EnhancedCrdProcessor
       ↓
jsonschema2pojo
       ↓
Generated POJOs

@maeveho25 maeveho25 added In progress Work on this is in progress feature Addition to list of existing features labels Aug 7, 2025
@maeveho25 maeveho25 changed the title Feature/crd generator integration [WIP] Feature: CRD Generation to POJO Classes at Maven Build Time Aug 7, 2025
@maeveho25 maeveho25 force-pushed the feature/crd-generator-integration branch from 42965e9 to 1ea861b Compare August 11, 2025 02:16
@waveywaves waveywaves requested a review from Copilot August 15, 2025 14:35
Copilot

This comment was marked as outdated.

@waveywaves waveywaves self-assigned this Aug 15, 2025
@maeveho25 maeveho25 force-pushed the feature/crd-generator-integration branch from 9a31b26 to a68e870 Compare August 26, 2025 19:10
maeveho25 and others added 6 commits August 26, 2025 15:17
- Resolves JUnit version incompatibility issue
- Fixes 'TestEngine with ID junit-jupiter failed to discover tests' error
- Aligns JUnit Jupiter Engine with other JUnit components
- All 27 tests now pass successfully
- Move exec-maven-plugin from download-binaries profile to main build
- Change execution phase from process-classes to generate-sources
- Move build-helper-maven-plugin to main build for consistency
- Enable CRD generation with simple 'mvn generate-sources' command
- Generate 800+ Tekton POJO classes from CRD definitions
- Support all Tekton resources: Tasks, Pipelines, TaskRuns, PipelineRuns, CustomRuns, StepActions
- Generated classes extend Jenkins BaseStep for pipeline integration
- Includes multi-version support: v1, v1beta1, v1alpha1

This improves developer experience by simplifying the code generation workflow.
@maeveho25
Copy link
Collaborator Author

Fix: Disable equals/hashCode generation to avoid SpotBugs issues

Root cause: jsonschema2pojo library generates equals() methods with problematic string comparison (== instead of .equals()), causing SpotBugs violations.

Solution: Disable equals/hashCode generation entirely by setting isIncludeHashcodeAndEquals() = false.

Explanation on this approach:

  • Generated POJOs are used as DTOs for JSON serialization/Jenkins binding only
  • They don't need object comparison in business logic
  • Cleaner than post-processing or forking the library to fix the template

@maeveho25 maeveho25 requested a review from Copilot August 26, 2025 20:49
Copilot

This comment was marked as outdated.

@maeveho25 maeveho25 requested a review from Copilot August 26, 2025 21:00
Copilot

This comment was marked as outdated.

maeveho25 and others added 2 commits August 26, 2025 17:03
@maeveho25 maeveho25 requested a review from Copilot August 26, 2025 21:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive CRD (Custom Resource Definition) to POJO generation feature for the Tekton Jenkins plugin, automatically generating over 1000 Java classes from Tekton CRD schemas during Maven build time. The feature enables automatic creation of typed Java classes that extend BaseStep for Jenkins pipeline integration.

Key changes include:

  • Core CRD processing engine using jsonschema2pojo with enhanced inheritance capabilities
  • Maven integration for automatic POJO generation during build time
  • Addition of multiple Tekton CRD YAML files (pipeline, task, stepaction, etc.)

Reviewed Changes

Copilot reviewed 13 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/org/waveywaves/jenkins/plugins/tekton/generator/EnhancedCrdProcessor.java Core CRD processing logic that converts YAML schemas to Java POJOs with Jenkins BaseStep inheritance
src/main/java/org/waveywaves/jenkins/plugins/tekton/generator/CrdJavaGenerator.java Maven exec plugin entry point for CRD generation with Jenkins-specific configuration
src/main/resources/crds/*.yaml Multiple Tekton CRD definition files for pipeline, task, stepaction, and other resources
pom.xml Maven configuration updates including new dependencies, exec plugin setup, and build process changes
src/test/java/org/waveywaves/jenkins/plugins/tekton/client/build/delete/DeleteRawTest.java Test import addition for DeleteAllBlock inner class

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@maeveho25 maeveho25 requested a review from waveywaves August 26, 2025 21:26
@krisstern krisstern self-requested a review August 27, 2025 13:12
- Rename CrdJavaGenerator.java -> TektonPojoGenerator.java
- Rename EnhancedCrdProcessor.java -> TektonCrdToJavaProcessor.java
- Update all class names and references in code
- Update pom.xml mainClass references
- More descriptive and comprehensive naming convention
- Replace all System.exit() calls with appropriate exception throwing
- Use IllegalArgumentException for invalid arguments
- Use RuntimeException for runtime failures
- Addresses Jenkins security scan warning about unsafe method calls
- Prevents plugin from terminating entire Jenkins process
@maeveho25
Copy link
Collaborator Author

hi @krisstern I have fixed the security warning

@maeveho25
Copy link
Collaborator Author

Fix: Disable equals/hashCode generation to avoid SpotBugs issues

Root cause: jsonschema2pojo library generates equals() methods with problematic string comparison (== instead of .equals()), causing SpotBugs violations.

Solution: Disable equals/hashCode generation entirely by setting isIncludeHashcodeAndEquals() = false.

Explanation on this approach:

  • Generated POJOs are used as DTOs for JSON serialization/Jenkins binding only
  • They don't need object comparison in business logic
  • Cleaner than post-processing or forking the library to fix the template

@waveywaves this is the issue i was talking about

@jonesbusy
Copy link

Just an open question here (Maybe this discussion already happend).

Any reason to not use https://github.com/fabric8io/kubernetes-client/blob/main/doc/java-generation-from-CRD.md to generate the Java Object from CRDs?

This can be used with java-generator-maven-plugin maven plugin and specifying the location of the CRDs

Since we already have the https://plugins.jenkins.io/kubernetes-client-api/ it should not be an issue to have such POJO implement interface like (HasMetadata)

I used the mentionned approach not so long ago to generate Java classes from Flux CD CRDs (like HelmRelease) and this works like a charm (fabric8io/kubernetes-client#7130)

Looking at the config and dependencies added this look fragile to me, but maybe I miss the reason

@maeveho25
Copy link
Collaborator Author

Just an open question here (Maybe this discussion already happend).

Any reason to not use https://github.com/fabric8io/kubernetes-client/blob/main/doc/java-generation-from-CRD.md to generate the Java Object from CRDs?

This can be used with java-generator-maven-plugin maven plugin and specifying the location of the CRDs

Since we already have the https://plugins.jenkins.io/kubernetes-client-api/ it should not be an issue to have such POJO implement interface like (HasMetadata)

I used the mentionned approach not so long ago to generate Java classes from Flux CD CRDs (like HelmRelease) and this works like a charm (fabric8io/kubernetes-client#7130)

Looking at the config and dependencies added this look fragile to me, but maybe I miss the reason

Thank you for pointing that out! Your approach definitely looks more efficient. I’m looking into it now and will work on applying it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Addition to list of existing features In progress Work on this is in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants