Skip to content

Implement workflow compiler plugin with code analysis and modification features#8

Merged
hasithaa merged 11 commits intoballerina-platform:v2from
hasithaa:v2_task1
Feb 3, 2026
Merged

Implement workflow compiler plugin with code analysis and modification features#8
hasithaa merged 11 commits intoballerina-platform:v2from
hasithaa:v2_task1

Conversation

@hasithaa
Copy link
Copy Markdown
Contributor

Fixes #ballerina-platform/ballerina-library#8449

This pull request introduces the initial setup for the Ballerina Workflow module, including core workflow APIs, annotations, configuration, and CI/CD automation. The changes establish the foundation for workflow orchestration, registration, and activity execution, along with supporting infrastructure for building, testing, and publishing the module.

Module Implementation and APIs:

  • Added core workflow APIs and annotations:
    • Introduced callActivity, startProcess, sendEvent, registerProcess, getRegisteredWorkflows, and clearRegistry functions in functions.bal for workflow orchestration and management.
    • Defined @Process and @Activity annotations in annotations.bal to mark workflow process and activity functions.
  • Added initial documentation in README.md describing the purpose of the workflow library.

Configuration and Build System:

  • Added Ballerina.toml and CompilerPlugin.toml for package metadata and compiler plugin configuration. [1] [2]
  • Introduced a Gradle build script build.gradle to automate building, testing, and publishing the module, including updating TOML files and handling dependencies.

Testing:

  • Added comprehensive tests in tests/test.bal to verify process and activity registration, registry introspection, and clearing functionality.

CI/CD and Repository Management:

  • Added multiple GitHub Actions workflows for building, PR validation, GraalVM checks, Trivy vulnerability scanning, and publishing to Ballerina Central. [1] [2] [3] [4] [5] [6]
  • Added .gitattributes to enforce LF line endings for Java files.
  • Added .github/CODEOWNERS to specify repository owners.

…ntation

- Created build.gradle for the Ballerina workflow module, including tasks for updating TOML files and committing changes.
- Implemented placeholder function `getInfo` in functions.bal for the workflow module.
- Added unit tests for the `getInfo` function in test.bal.
- Introduced Checkstyle configuration in build-config/checkstyle/build.gradle for code quality checks.
- Created Ballerina.toml and CompilerPlugin.toml files for package metadata and compiler plugin configuration.
- Established a multi-project Gradle setup with separate modules for workflow-native, workflow-compiler-plugin, and their tests.
- Developed the WorkflowCompilerPlugin class with initialization logic for the compiler plugin.
- Implemented a native Java class WorkflowNative with a placeholder method for native functionality.
- Added Gradle wrapper files for consistent build environment setup.
- Configured dependencies and publishing settings for the workflow module and its components.
- Included SpotBugs and Checkstyle configurations to maintain code quality across the project.
- Created an exclusion file for SpotBugs to ignore specific patterns and test files.
…n features

- Add WorkflowCodeAnalyzer for validating @process and @activity function signatures.
- Introduce WorkflowCodeModifier to transform workflow process functions and register them.
- Create WorkflowCompilerPlugin to integrate the analyzer and modifier into the compilation process.
- Define WorkflowConstants for shared constants used across the plugin.
- Implement WorkflowModifierContext to hold information about process modifications.
- Develop WorkflowSourceModifier to handle AST transformations for process functions.
- Add WorkflowValidatorTask for validating function signatures based on workflow semantics.
- Create ModuleUtils for managing workflow module information.
- Enhance ProcessRegistry to track activities associated with processes.
- Implement native functions in WorkflowNative for registering processes and retrieving registered workflows.
- Add functionality to clear the registry for testing purposes.
@hasithaa hasithaa requested review from Copilot and rdulmina January 29, 2026 18:16
@hasithaa hasithaa changed the base branch from main to v2 January 29, 2026 18:16
@hasithaa hasithaa changed the title Add basic support for compiler plugins Implement workflow compiler plugin with code analysis and modification features Jan 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 54.40000% with 285 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v2@202e079). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ib/workflow/runtime/nativeimpl/WorkflowNative.java 37.50% 60 Missing ⚠️
.../io/ballerina/stdlib/workflow/utils/TypesUtil.java 0.00% 59 Missing ⚠️
...tdlib/workflow/compiler/WorkflowValidatorTask.java 67.16% 17 Missing and 27 partials ⚠️
...dlib/workflow/compiler/WorkflowSourceModifier.java 65.83% 27 Missing and 14 partials ⚠️
...workflow/compiler/ProcessFunctionAnalysisTask.java 64.04% 14 Missing and 18 partials ⚠️
...erina/stdlib/workflow/runtime/WorkflowRuntime.java 0.00% 28 Missing ⚠️
...rina/stdlib/workflow/registry/ProcessRegistry.java 73.33% 7 Missing and 1 partial ⚠️
...ina/stdlib/workflow/registry/ActivityRegistry.java 65.00% 6 Missing and 1 partial ⚠️
ballerina/functions.bal 66.66% 6 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##             v2       #8   +/-   ##
=====================================
  Coverage      ?   54.40%           
  Complexity    ?       85           
=====================================
  Files         ?       15           
  Lines         ?      625           
  Branches      ?      109           
=====================================
  Hits          ?      340           
  Misses        ?      224           
  Partials      ?       61           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

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

Introduces initial “workflow” module scaffolding including a Ballerina compiler plugin, native runtime stubs, Gradle build infrastructure, and CI workflows to enable basic workflow/process/activity registration and validation.

Changes:

  • Added Java-native runtime + registries and Ballerina APIs/annotations for workflow orchestration and registry introspection.
  • Added compiler plugin analyzer/modifier to validate @Process/@Activity signatures and rewrite activity calls / inject process registration.
  • Added Gradle multi-module build setup, wrapper, and CI workflows (PR build, release publish, Trivy, GraalVM checks).

Reviewed changes

Copilot reviewed 60 out of 63 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
spotbugs-exclude.xml SpotBugs suppressions for the new modules.
settings.gradle Defines multi-project Gradle structure and plugin management.
native/src/main/java/io/ballerina/stdlib/workflow/utils/TypesUtil.java Ballerina↔Java type conversion helpers.
native/src/main/java/io/ballerina/stdlib/workflow/runtime/nativeimpl/WorkflowNative.java Native entrypoints backing Ballerina workflow functions.
native/src/main/java/io/ballerina/stdlib/workflow/runtime/WorkflowRuntime.java Placeholder workflow runtime/executor and API stubs.
native/src/main/java/io/ballerina/stdlib/workflow/registry/ProcessRegistry.java In-memory process registry + process metadata.
native/src/main/java/io/ballerina/stdlib/workflow/registry/ActivityRegistry.java In-memory activity registry.
native/src/main/java/io/ballerina/stdlib/workflow/ModuleUtils.java Captures module reference for native record creation.
native/build.gradle Native module build configuration and deps (incl. Temporal).
gradlew.bat Gradle wrapper script (Windows).
gradlew Gradle wrapper script (POSIX).
gradle/wrapper/gradle-wrapper.properties Gradle wrapper distribution configuration.
gradle/wrapper/gradle-wrapper.jar Gradle wrapper binary.
gradle.properties Centralized version + plugin property definitions.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowValidatorTask.java Compiler-plugin validation of @Process/@Activity signatures.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowSourceModifier.java AST rewrite for activity calls + inject process registration.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowModifierContext.java Tracks process/activity info per document.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowConstants.java Shared constants and diagnostic messages/codes.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowCompilerPlugin.java Compiler plugin entrypoint wiring analyzer + modifier.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowCodeModifier.java Registers analysis/modification tasks for transformations.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/WorkflowCodeAnalyzer.java Registers validation task.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/ProcessFunctionInfo.java Stores per-process activity call metadata.
compiler-plugin/src/main/java/io/ballerina/stdlib/workflow/compiler/ProcessFunctionAnalysisTask.java Collects @Process and referenced @Activity calls.
compiler-plugin/spotbugs-exclude.xml SpotBugs suppressions specific to compiler plugin.
compiler-plugin/build.gradle Compiler plugin build configuration.
compiler-plugin-tests/src/test/resources/testng.xml TestNG suite configuration for plugin tests.
compiler-plugin-tests/src/test/resources/ballerina_sources/valid_process_with_context/main.bal Sample validating Context usage in @Process.
compiler-plugin-tests/src/test/resources/ballerina_sources/valid_process_with_context/Ballerina.toml Sample package metadata for Context test.
compiler-plugin-tests/src/test/resources/ballerina_sources/valid_process_with_activities/main.bal Sample with activities invoked from process.
compiler-plugin-tests/src/test/resources/ballerina_sources/valid_process_with_activities/Ballerina.toml Sample package metadata for activity test.
compiler-plugin-tests/src/test/resources/ballerina_sources/process_no_activities/main.bal Sample process without activities.
compiler-plugin-tests/src/test/resources/ballerina_sources/process_no_activities/Ballerina.toml Sample package metadata for no-activity test.
compiler-plugin-tests/src/test/resources/ballerina_sources/multiple_processes/main.bal Sample package with multiple processes + shared activities.
compiler-plugin-tests/src/test/resources/ballerina_sources/multiple_processes/Ballerina.toml Sample package metadata for multi-process test.
compiler-plugin-tests/src/test/resources/ballerina_sources/invalid_activity_return/main.bal Negative sample for invalid activity return type.
compiler-plugin-tests/src/test/resources/ballerina_sources/invalid_activity_return/Ballerina.toml Sample package metadata for invalid return test.
compiler-plugin-tests/src/test/resources/ballerina_sources/invalid_activity_param/main.bal Negative sample for invalid activity param type.
compiler-plugin-tests/src/test/resources/ballerina_sources/invalid_activity_param/Ballerina.toml Sample package metadata for invalid param test.
compiler-plugin-tests/src/test/java/io/ballerina/stdlib/workflow/compiler/WorkflowCompilerPluginTest.java Test harness for plugin validation and modification.
compiler-plugin-tests/build.gradle Test module build config incl. JaCoCo/TestNG.
codecov.yml Codecov reporting configuration.
changelog.md Initial changelog stub.
build.gradle Root Gradle configuration + build/release orchestration.
build-config/resources/CompilerPlugin.toml Template for generating module CompilerPlugin.toml.
build-config/resources/Ballerina.toml Template for generating module Ballerina.toml.
build-config/checkstyle/build.gradle Downloads shared WSO2 checkstyle rules.
ballerina/types.bal Public workflow types (Context, registry records).
ballerina/tests/test.bal Ballerina-level tests for registry functions.
ballerina/functions.bal Public workflow functions (native interop wrappers).
ballerina/build.gradle Ballerina package build/publish configuration + TOML generation.
ballerina/annotations.bal Defines @Process and @Activity annotations.
ballerina/README.md Minimal module README.
ballerina/CompilerPlugin.toml Module compiler plugin config (generated artifact path).
ballerina/Ballerina.toml Module package metadata + native dependency.
.gitignore Ignore rules updated for Gradle/IDE/Ballerina artifacts.
.github/workflows/trivy-scan.yml Scheduled/manual Trivy scanning workflow.
.github/workflows/pull-request.yml PR validation workflow configuration.
.github/workflows/publish-release.yml Release publish workflow wiring.
.github/workflows/central-publish.yml Central publish workflow wiring.
.github/workflows/build-with-bal-test-graalvm.yml GraalVM compatibility workflow wiring.
.github/workflows/build-timestamped-master.yml Main branch build workflow wiring.
.github/CODEOWNERS Repository ownership rules.
.gitattributes Enforces LF endings for Java sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/CODEOWNERS Outdated
Copy link
Copy Markdown

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

Copilot reviewed 66 out of 69 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread settings.gradle
Comment thread ballerina/annotations.bal Outdated
Comment thread ballerina/functions.bal
* Validates @Process function signature according to Agent.md semantics.
* <ul>
* <li>Optional first parameter: workflow:Context</li>
* <li>Required input parameter: subtype of anydata</li>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this is required?. It's a valid case that the workflow does not require any input, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can't derive the correlation without an input. In one of the discussions, we decided to drop the no-correlation concept.

@hasithaa
Copy link
Copy Markdown
Contributor Author

hasithaa commented Feb 1, 2026

@rdulmina I have fixed the review suggestion with #9 and 5d3dfc5. Please check.

@hasithaa hasithaa merged commit b8138b6 into ballerina-platform:v2 Feb 3, 2026
7 checks passed
@hasithaa hasithaa deleted the v2_task1 branch March 20, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants