You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/docs/src/docs/asciidoc/optional-quarkus-extension/quarkus-extension.adoc
+19-16
Original file line number
Diff line number
Diff line change
@@ -135,44 +135,47 @@ For this, what do we need:
135
135
The _runtime_ part of an extension contains only the classes and resources required at runtime.
136
136
For the version extension, it would be a single class that prints the version.
137
137
138
+
First, let's create the configuration class that will allow users to dynamically configure whether the version should be printed:
138
139
[example, role="cta"]
139
140
--
140
141
141
-
In the runtime module, create the `src/main/java` directory, and, in this directory, the `io.quarkus.workshop.superheroes.version.runtime.VersionRecorder` class with the following content:
142
+
Under the `runtime` module, create the `src/main/java` directory, and, in this directory, create a new interface named `io.quarkus.workshop.superheroes.version.runtime.VersionConfig` with the following content:
The `@ConfigMapping` annotation declares `VersionConfig` as a configuration interface which configuration properties are prefixed with `quarkus.version` prefix. It is also used in CDI aware environments to scan and register Config Mappings.
148
150
149
-
Simple right?
150
-
But how does it work?
151
-
Look at the `@Recorder` annotation.
152
-
It indicates that this class is a _recorder_ used to record actions executed later at runtime.
153
-
Indeed, these actions are replayed at runtime.
154
-
We will see how this recorder is used from the _deployment_ module.
151
+
The `@ConfigRoot` annotation declares that the configuration is available during runtime.
155
152
156
-
== The deployment module
153
+
The `@WithDefault("true")` is used to declare the default value returned when `enabled()` is called.
157
154
158
-
This module contains _build steps_, i.e., methods called during the augmentation phase and computing just enough bytecode to serve the services the application requires.
159
-
The version extension consists of a single build step that extracts the version and uses the `VersionRecorder`.
155
+
By default, the name of the property is derived from what's declared in the `prefix` attribute inside `@ConfigMapping` plus the name of the method. In our case, the user-configured property will be `quarkus.version.enabled`.
160
156
161
157
[example, role="cta"]
162
158
--
163
-
First, let's create the configuration class that will allow users to dynamically configure whether the version should be printed:
164
159
165
-
Under the `deployment` module, create new class `io.quarkus.workshop.superheroes.version.deployment.VersionConfig` with the following content:
160
+
Still in the `runtime` module, create the `io.quarkus.workshop.superheroes.version.runtime.VersionRecorder` class with the following content:
The `@ConfigRoot` annotation declares `VersionConfig` as a configuration class which configuration properties are prefixed with `quarkus.` prefix.
168
+
Simple right?
169
+
But how does it work?
170
+
Look at the `@Recorder` annotation.
171
+
It indicates that this class is a _recorder_ used to record actions executed later at runtime.
172
+
Indeed, these actions are replayed at runtime.
173
+
We will see how this recorder is used from the _deployment_ module.
174
+
175
+
== The deployment module
174
176
175
-
The `@ConfigItem` is used to declare individual configuration properties. By default, the name of the property is derived from the name of the field. In our case, the user-configured property will be `quarkus.version.enabled`.
177
+
This module contains _build steps_, i.e., methods called during the augmentation phase and computing just enough bytecode to serve the services the application requires.
178
+
The version extension consists of a single build step that extracts the version and uses the `VersionRecorder`.
176
179
177
180
Next, open the `ExtensionVersionProcessor` class, and update the content to be:
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/deployment/src/main/java/io/quarkus/workshop/superheroes/version/deployment/ExtensionVersionProcessor.java
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/deployment/src/main/java/io/quarkus/workshop/superheroes/version/deployment/VersionConfig.java
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/runtime/src/main/java/io/quarkus/workshop/superheroes/version/runtime/VersionRecorder.java
0 commit comments