Skip to content

CAMEL-22894: Extract sys/env, date, properties, ref, type, messageAs, pretty/toJson Simple functions into dedicated factories#23544

Merged
davsclaus merged 3 commits into
apache:mainfrom
ammachado:CAMEL-22894
May 27, 2026
Merged

CAMEL-22894: Extract sys/env, date, properties, ref, type, messageAs, pretty/toJson Simple functions into dedicated factories#23544
davsclaus merged 3 commits into
apache:mainfrom
ammachado:CAMEL-22894

Conversation

@ammachado
Copy link
Copy Markdown
Contributor

@ammachado ammachado commented May 27, 2026

Description

Continues the CAMEL-22894 series, which extracts inline Simple language function dispatch from the monolithic SimpleFunctionExpression into dedicated SimpleLanguageFunctionFactory implementations.

This PR covers six new factory classes:

Factory Functions handled
SystemFunctionFactory ${sys.name}, ${sysenv.name}, ${sysenv:name}, ${env.name}, ${env:name}
PropertiesFunctionFactory ${propertiesExist:key}, ${properties:key}, ${properties:key:default}, ${ref:name}
TypeFunctionFactory ${type:fqn}, ${type:fqn.FIELD}
DateFunctionFactory ${date:command}, ${date:command:pattern}, ${date-with-timezone:command:timezone:pattern} (including date:millis code-gen special case)
MessageFunctionFactory ${messageAs(type)}, ${messageAs(type).OGNL}
OutputFunctionFactory ${pretty(exp)}, ${toJson(exp)}, ${toPrettyJson(exp)}

All factories follow the established pattern: createFunction() for runtime evaluation, createCode() (deprecated, csimple only) for code generation where applicable. MessageFunctionFactory and OutputFunctionFactory omit createCode() since csimple never supported those functions.

Also removes the two @Deprecated(forRemoval = true) methods tryCreate() and tryCreateCode() from SimpleFunctionDispatcher, which were confirmed unused.

SimpleFunctionExpression shrinks by ~160 lines after this PR.

Test changes

Tests for the six factories are moved out of the monolithic SimpleTest into dedicated per-factory test classes under o.a.c.language.simple.functions. Notable refinements:

  • SystemFunctionFactoryTest uses JUnit Pioneer's @SetSystemProperty (added junit-pioneer dependency to camel-core) to safely scope the property to the test method.
  • MessageFunctionFactoryTest documents a subtle semantic: messageAs(T) returns null at the expression layer when the type conversion fails; the Simple predicate engine then coerces null to false. The original SimpleTest only tested the predicate layer, masking this.
  • OutputFunctionFactoryTest documents the XmlPrettyPrinter behavior where text content directly inside the root element is silently dropped (only emitted when indent > 1).

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

Claude Code on behalf of Adriano Machado

ammachado added 3 commits May 26, 2026 22:15
… pretty/toJson Simple functions into dedicated factories

Continues the extraction of inline function logic from SimpleFunctionExpression
into SimpleLanguageFunctionFactory implementations:

- SystemFunctionFactory: sys., sysenv., env. prefixes
- PropertiesFunctionFactory: propertiesExist:, properties:, ref:
- TypeFunctionFactory: type:
- DateFunctionFactory: date:, date-with-timezone: (including date:millis code-gen)
- MessageFunctionFactory: messageAs(
- OutputFunctionFactory: pretty(, toJson(, toPrettyJson(

Also removes the two deprecated(forRemoval) tryCreate/tryCreateCode methods
from SimpleFunctionDispatcher, which were confirmed unused.

SimpleFunctionExpression shrinks by ~160 lines.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
…ple function factories

Move sys/env, date, properties/ref, type, messageAs, and pretty/toJson tests
from SimpleTest into their own *FunctionFactoryTest classes, following the
pattern established by previous PRs in this series.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
…st, use JUnit Pioneer, add behavioral comments

- Move date, date-with-timezone, sys, sysenv/env, ref, propertiesExist,
  properties, type, messageAs, pretty, toJson/toPrettyJson tests from
  SimpleTest into their dedicated factory test classes
- Add junit-pioneer dependency to camel-core for @SetSystemProperty,
  replacing a bare System.setProperty call that leaked the property
- Document the XmlPrettyPrinter root-element text-content quirk in
  OutputFunctionFactoryTest
- Document the null-vs-false coercion subtlety in MessageFunctionFactoryTest
  (expression layer returns null; predicate layer coerced it to false)
- Follow the established testCreateCodeUnknown() pattern for all factories
  that override createCode

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
@ammachado ammachado marked this pull request as ready for review May 27, 2026 03:30
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions github-actions Bot added the core label May 27, 2026
Copy link
Copy Markdown
Contributor

@davsclaus davsclaus left a comment

Choose a reason for hiding this comment

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

Clean extraction of six more Simple function families into dedicated factories, continuing the CAMEL-22894 series. All factories faithfully reproduce the original dispatch logic from SimpleFunctionExpression.

Verified:

  • tryCreate() / tryCreateCode() removals are safe — confirmed no external callers
  • Dead parts.length > 2 validation in propertiesExist: correctly dropped (split with limit 2 can never exceed 2 elements)
  • TypeFunctionFactory preserves the init() + cacheExpression() wrapping
  • OutputFunctionFactory prefix ordering is correct
  • Test coverage is thorough — MessageFunctionFactoryTest documents the subtle null-vs-false semantic, SystemFunctionFactoryTest uses JUnit Pioneer @SetSystemProperty properly

Minor observation (non-blocking): PropertiesFunctionFactory.createCode() still has the same dead parts.length > 2 check (line ~42 in the factory). Not a regression, just a cleanup opportunity.

LGTM.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions
Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • core/camel-core
  • core/camel-core-languages
  • core/camel-core

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.

POM dependency changes: targeted tests included

Modules affected by dependency changes (2)
  • :camel-core
  • :camel-core-languages

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • core/camel-core: 2 test(s) disabled on GitHub Actions
  • core/camel-core: 2 test(s) disabled on GitHub Actions
Build reactor — dependencies compiled but only changed modules were tested (2 modules)
  • Camel :: Core
  • Camel :: Core Languages

⚙️ View full build and test results

@davsclaus davsclaus merged commit bd45499 into apache:main May 27, 2026
6 checks passed
@ammachado ammachado deleted the CAMEL-22894 branch May 27, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants