This page explains how Java source files are automatically generated from external sources during the build of patternfly-java. Three distinct generation pipelines exist: CSS design token generation, icon spec generation, and version number generation. All three run before compilation, during Maven's generate-sources phase.
For how these pipelines integrate with the full Maven build lifecycle, see Build Pipeline. For how the resulting Token enum is used in component code, see Design Tokens System. For how the generated icon classes are used, see Icon System.
Pipeline diagram: Code generation inputs, scripts, and outputs
Sources: tokens/src/scripts/generate.mjs1-84 tokens/pom.xml42-103 icons/package.json1-17 core/version.java1-61
The patternfly-java-tokens module generates a single Java enum, Token, from the @patternfly/react-tokens npm package. The enum provides type-safe access to all PatternFly CSS custom property tokens.
Generation script detail: generate.mjs → Token.java
Sources: tokens/src/scripts/generate.mjs67-83
The generated Token.java is a Java enum annotated with @Generated("generate.mjs"). Each constant is produced by the generateConstant function tokens/src/scripts/generate.mjs60-61:
| Field | Type | Description |
|---|---|---|
name | String | CSS custom property name, e.g. --pf-t--color--blue--100 |
value | String | Default resolved value for the property |
var | String | Name wrapped in var(), e.g. var(--pf-t--color--blue--100) |
The enum constructor tokens/src/scripts/generate.mjs29-57 initializes all three fields for each constant.
Java keyword conflicts (e.g. clone, import, package, private) are resolved by appending an underscore, handled by failSafeName() tokens/src/scripts/generate.mjs63
The tokens/pom.xml wires the generation into the Maven lifecycle using frontend-maven-plugin. Three executions run in sequence during the generate-sources phase:
| Execution ID | Goal | Action |
|---|---|---|
install-node-and-yarn | install-node-and-npm | Installs Node.js at ${version.node} |
yarn-install | npm | Runs npm install |
generate-icon-specs | npm | Runs npm run generate |
The npm run generate command resolves to node src/scripts/generate.mjs as defined in tokens/package.json5-7
The maven-clean-plugin is also configured to delete Token.java on mvn clean, so the generated file is never accidentally committed as stale tokens/pom.xml43-57
Sources: tokens/pom.xml42-103 tokens/package.json1-13
The patternfly-java-icons module runs a similar Node.js-based pipeline. The script icons/src/scripts/generate.mjs reads icon definitions from three FontAwesome packages and from @patternfly/react-icons, then generates Java source files for the icon system.
Dependencies declared in icons/package.json:
| npm Package | Version | Icon Set |
|---|---|---|
@fortawesome/free-solid-svg-icons | ^5 | FontAwesome solid (fas) |
@fortawesome/free-regular-svg-icons | ^5 | FontAwesome regular (far) |
@fortawesome/free-brands-svg-icons | ^5 | FontAwesome brands (fab) |
@patternfly/react-icons | ^6.2.2 | PatternFly icons |
@patternfly/patternfly | ^6.2.3 | PatternFly CSS baseline |
camelcase | ^8.0.0 | Name conversion utility |
Sources: icons/package.json1-17
The generate script in icons/package.json5-7 is node src/scripts/generate.mjs, following the same invocation pattern as the token pipeline. The icons module's Maven pom.xml connects this to the generate-sources phase via frontend-maven-plugin in the same way as the tokens module.
core/version.java is a JBang script that generates a Java interface, Version, containing three string constants derived from Maven build properties.
The script accepts exactly three positional arguments core/version.java22-26:
| Argument | Description |
|---|---|
<basedir> | Maven project base directory (used to resolve output path) |
<patternfly.java.version> | The current version of patternfly-java (e.g. 0.5.1-SNAPSHOT) |
<patternfly-version> | The upstream PatternFly version (e.g. 6.2.3) |
The script writes to core/src/main/java/org/patternfly/core/Version.java core/version.java34-40 The generated interface Version contains:
| Constant | Example Value | Derivation |
|---|---|---|
PATTERN_FLY_JAVA_VERSION | "0.5.1-SNAPSHOT" | Passed as second argument |
PATTERN_FLY_VERSION | "6.2.3" | Passed as third argument |
PATTERN_FLY_MAJOR_VERSION | "v6" | Prefix v + major digit of third argument |
PATTERN_FLY_MAJOR_VERSION is computed by extracting the substring before the first . in the version string and prepending "v" core/version.java31-32
The generated file carries @Generated("version.java") and a "WARNING! This class is generated. Do not modify." comment core/version.java42-55
Flow diagram: version.java execution
Sources: core/version.java21-61
| Generated File | Source Script | Trigger | npm Source |
|---|---|---|---|
org/patternfly/token/Token.java | tokens/src/scripts/generate.mjs | mvn generate-sources (tokens module) | @patternfly/react-tokens |
| Icon Java classes | icons/src/scripts/generate.mjs | mvn generate-sources (icons module) | FontAwesome + @patternfly/react-icons |
org/patternfly/core/Version.java | core/version.java (JBang) | mvn generate-sources (core module) | Maven properties |
All generated files carry either an @Generated annotation or a prominent "WARNING: This class is generated. Do not modify." comment. The maven-clean-plugin is configured on relevant modules to delete generated files during mvn clean, ensuring a clean regeneration on the next build.