Skip to content

Commit 8c0bc63

Browse files
tomas-langerdanielkectrentjeffDavid Kral
authored
4.x: Inject update - collateral (helidon-io#8281)
* Introduction of codegen modules * Refactoring of modules to use new builder codegen (remove use of config metadata for builders) * Deprecated old processor modules (such as builder processor) Co-authored-by: Daniel Kec <daniel.kec@oracle.com> Co-authored-by: Jeff Trent <jeff.trent@oracle.com> Co-authored-by: David Kral <david.kral@oracle.com> Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
1 parent b9f3fe1 commit 8c0bc63

294 files changed

Lines changed: 22724 additions & 902 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

all/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,30 @@
385385
<groupId>io.helidon.common</groupId>
386386
<artifactId>helidon-common-tls</artifactId>
387387
</dependency>
388+
<dependency>
389+
<groupId>io.helidon.codegen</groupId>
390+
<artifactId>helidon-codegen</artifactId>
391+
</dependency>
392+
<dependency>
393+
<groupId>io.helidon.codegen</groupId>
394+
<artifactId>helidon-codegen-apt</artifactId>
395+
</dependency>
396+
<dependency>
397+
<groupId>io.helidon.codegen</groupId>
398+
<artifactId>helidon-codegen-scan</artifactId>
399+
</dependency>
400+
<dependency>
401+
<groupId>io.helidon.codegen</groupId>
402+
<artifactId>helidon-codegen-compiler</artifactId>
403+
</dependency>
404+
<dependency>
405+
<groupId>io.helidon.codegen</groupId>
406+
<artifactId>helidon-codegen-class-model</artifactId>
407+
</dependency>
408+
<dependency>
409+
<groupId>io.helidon.codegen</groupId>
410+
<artifactId>helidon-codegen-helidon-copyright</artifactId>
411+
</dependency>
388412
<dependency>
389413
<groupId>io.helidon.common.processor</groupId>
390414
<artifactId>helidon-common-processor</artifactId>
@@ -986,6 +1010,10 @@
9861010
<groupId>io.helidon.builder</groupId>
9871011
<artifactId>helidon-builder-processor</artifactId>
9881012
</dependency>
1013+
<dependency>
1014+
<groupId>io.helidon.builder</groupId>
1015+
<artifactId>helidon-builder-codegen</artifactId>
1016+
</dependency>
9891017
<dependency>
9901018
<groupId>io.helidon.inject</groupId>
9911019
<artifactId>helidon-inject-api</artifactId>

bom/pom.xml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,6 @@
237237
<artifactId>helidon-security-integration-common</artifactId>
238238
<version>${helidon.version}</version>
239239
</dependency>
240-
<dependency>
241-
<groupId>io.helidon.security.integration</groupId>
242-
<artifactId>helidon-security-integration-webserver</artifactId>
243-
<version>${helidon.version}</version>
244-
</dependency>
245240
<dependency>
246241
<groupId>io.helidon.security</groupId>
247242
<artifactId>helidon-security-annotations</artifactId>
@@ -507,16 +502,49 @@
507502
<version>${helidon.version}</version>
508503
</dependency>
509504
<dependency>
505+
<groupId>io.helidon.codegen</groupId>
506+
<artifactId>helidon-codegen</artifactId>
507+
<version>${helidon.version}</version>
508+
</dependency>
509+
<dependency>
510+
<groupId>io.helidon.codegen</groupId>
511+
<artifactId>helidon-codegen-apt</artifactId>
512+
<version>${helidon.version}</version>
513+
</dependency>
514+
<dependency>
515+
<groupId>io.helidon.codegen</groupId>
516+
<artifactId>helidon-codegen-scan</artifactId>
517+
<version>${helidon.version}</version>
518+
</dependency>
519+
<dependency>
520+
<groupId>io.helidon.codegen</groupId>
521+
<artifactId>helidon-codegen-compiler</artifactId>
522+
<version>${helidon.version}</version>
523+
</dependency>
524+
<dependency>
525+
<groupId>io.helidon.codegen</groupId>
526+
<artifactId>helidon-codegen-class-model</artifactId>
527+
<version>${helidon.version}</version>
528+
</dependency>
529+
<dependency>
530+
<groupId>io.helidon.codegen</groupId>
531+
<artifactId>helidon-codegen-helidon-copyright</artifactId>
532+
<version>${helidon.version}</version>
533+
</dependency>
534+
<dependency>
535+
<!-- deprecated module -->
510536
<groupId>io.helidon.common.processor</groupId>
511537
<artifactId>helidon-common-processor</artifactId>
512538
<version>${helidon.version}</version>
513539
</dependency>
514540
<dependency>
541+
<!-- deprecated module -->
515542
<groupId>io.helidon.common.processor</groupId>
516543
<artifactId>helidon-common-processor-helidon-copyright</artifactId>
517544
<version>${helidon.version}</version>
518545
</dependency>
519546
<dependency>
547+
<!-- deprecated module -->
520548
<groupId>io.helidon.common.processor</groupId>
521549
<artifactId>helidon-common-processor-class-model</artifactId>
522550
<version>${helidon.version}</version>
@@ -1296,6 +1324,11 @@
12961324
<artifactId>helidon-builder-processor</artifactId>
12971325
<version>${helidon.version}</version>
12981326
</dependency>
1327+
<dependency>
1328+
<groupId>io.helidon.builder</groupId>
1329+
<artifactId>helidon-builder-codegen</artifactId>
1330+
<version>${helidon.version}</version>
1331+
</dependency>
12991332

13001333
<!-- Injection Core -->
13011334
<dependency>

builder/api/src/main/java/io/helidon/builder/api/Option.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -426,4 +426,23 @@ private Option() {
426426
*/
427427
String value();
428428
}
429+
430+
/**
431+
* Define an option decorator.
432+
* This is useful for example when setting a compound option, where we need to set additional options on this builder.
433+
* <p>
434+
* Decorator on collection based options will be ignored.
435+
* Decorator on optional values must accept an option (as it would be called both from the setter and unset methods).
436+
*/
437+
@Target(ElementType.METHOD)
438+
// note: class retention needed for cases when derived builders are inherited across modules
439+
@Retention(RetentionPolicy.CLASS)
440+
public @interface Decorator {
441+
/**
442+
* Type declaration including generic types (must match the declared generic type on the blueprint).
443+
*
444+
* @return type name with generic declaration
445+
*/
446+
Class<? extends Prototype.OptionDecorator<?, ?>> value();
447+
}
429448
}

builder/api/src/main/java/io/helidon/builder/api/Prototype.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -209,7 +209,7 @@ public interface Factory<T> {
209209
public @interface Blueprint {
210210
/**
211211
* The generated interface is public by default. We can switch it to package local
212-
* by setting this property to {@code false}-
212+
* by setting this property to {@code false}.
213213
*
214214
* @return whether the generated interface should be public
215215
*/
@@ -231,9 +231,10 @@ public interface Factory<T> {
231231
boolean createFromConfigPublic() default true;
232232

233233
/**
234-
* Method create() is public by default.
234+
* Method create() is created whenever there are no fields required (or all have default values).
235+
* This property can disable generation of the method.
235236
*
236-
* @return whether factory method create() should be public on prototype
237+
* @return whether factory method create() should be created on prototype
237238
*/
238239
boolean createEmptyPublic() default true;
239240

@@ -309,7 +310,7 @@ public interface Factory<T> {
309310
* The builder provides accessors to all types, using {@link java.util.Optional} for any field that is optional,
310311
* or any other field unless it has a default value. Primitive types are an exception (unless declared as required).
311312
*
312-
* @param <T> the type of the bean builder to intercept
313+
* @param <T> the type of the builder to decorate
313314
* @see io.helidon.builder.api.Prototype.Blueprint#decorator()
314315
*/
315316
@FunctionalInterface
@@ -322,6 +323,28 @@ public interface BuilderDecorator<T> {
322323
void decorate(T target);
323324
}
324325

326+
/**
327+
* Provides a way to decorate a single option when it is applied to the builder.
328+
* The decorator must have an accessible no argument constructor (at least package local).
329+
*
330+
* @param <B> the type of the builder to decorate
331+
* @param <T> the type of the option to decorate
332+
* @see io.helidon.builder.api.Prototype.Blueprint#decorator()
333+
*/
334+
@FunctionalInterface
335+
public interface OptionDecorator<B, T> {
336+
/**
337+
* Provides the ability to decorate option as it is being set on the target builder.
338+
* This method is invoked from within the setter of the value before the value is set on the builder (i.e. the
339+
* builder still contains previous value).
340+
* Do not call the same setter again from within this method, as it would end in a stack overflow.
341+
*
342+
* @param builder the target builder being decorated
343+
* @param optionValue option value set by the caller of the setter method
344+
*/
345+
void decorate(B builder, T optionValue);
346+
}
347+
325348
/**
326349
* Adding this annotation in conjunction with the {@link Prototype.Blueprint} on a target interface
327350
* type or method causes the {@link #value()} be added to the generated implementation class and methods respectfully.
@@ -407,6 +430,15 @@ public interface BuilderDecorator<T> {
407430
public @interface PrototypeMethod {
408431
}
409432

433+
/**
434+
* Annotated constant of a custom methods type to be added to prototype interface.
435+
* The constant will be generated as a reference to the annotated constant (so it must be package local).
436+
*/
437+
@Target(ElementType.FIELD)
438+
@Retention(RetentionPolicy.CLASS)
439+
public @interface Constant {
440+
}
441+
410442
/**
411443
* Add additional interfaces to implement by the prototype. Provide correct types (fully qualified) for generics.
412444
*/
@@ -418,6 +450,5 @@ public interface BuilderDecorator<T> {
418450
*/
419451
String[] value();
420452
}
421-
422453
}
423454

builder/codegen/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2022, 2024 Oracle and/or its affiliates.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<parent>
24+
<groupId>io.helidon.builder</groupId>
25+
<artifactId>helidon-builder-project</artifactId>
26+
<version>4.0.0-SNAPSHOT</version>
27+
<relativePath>../pom.xml</relativePath>
28+
</parent>
29+
<modelVersion>4.0.0</modelVersion>
30+
31+
<artifactId>helidon-builder-codegen</artifactId>
32+
<name>Helidon Builder Code Generator</name>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>io.helidon.common</groupId>
37+
<artifactId>helidon-common-types</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.helidon.codegen</groupId>
41+
<artifactId>helidon-codegen</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.helidon.codegen</groupId>
45+
<artifactId>helidon-codegen-class-model</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-api</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.hamcrest</groupId>
54+
<artifactId>hamcrest-all</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
</dependencies>
58+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.builder.codegen;
18+
19+
import java.util.List;
20+
import java.util.Set;
21+
22+
import io.helidon.common.types.TypeName;
23+
24+
record AnnotationDataBlueprint(
25+
boolean prototypePublic,
26+
boolean builderPublic,
27+
boolean createFromConfigPublic,
28+
boolean createEmptyPublic,
29+
boolean isFactory,
30+
Set<TypeName> extendsList,
31+
String javadoc,
32+
List<TypeName> typeArguments) {
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.builder.codegen;
18+
19+
import io.helidon.common.types.Annotation;
20+
import io.helidon.common.types.TypeInfo;
21+
22+
record AnnotationDataConfigured(boolean configured, String rootPrefix, boolean isRoot) {
23+
static AnnotationDataConfigured create(TypeInfo typeInfo) {
24+
boolean configured = false;
25+
boolean isRoot = false;
26+
String prefix = null;
27+
28+
if (typeInfo.hasAnnotation(Types.PROTOTYPE_CONFIGURED)) {
29+
configured = true;
30+
31+
Annotation annotation = typeInfo.annotation(Types.PROTOTYPE_CONFIGURED);
32+
// if the annotation is present, the value has to be defined (may be empty string)
33+
prefix = annotation.stringValue().orElse(null);
34+
if (prefix != null) {
35+
isRoot = annotation.booleanValue("root").orElse(true);
36+
}
37+
}
38+
39+
return new AnnotationDataConfigured(configured, prefix, isRoot);
40+
}
41+
}

0 commit comments

Comments
 (0)