16
16
17
17
package io .helidon .pico .processor ;
18
18
19
+ import java .io .IOException ;
20
+ import java .nio .file .Path ;
19
21
import java .util .ArrayList ;
20
22
import java .util .Collection ;
21
23
import java .util .LinkedHashMap ;
40
42
import io .helidon .common .types .AnnotationAndValueDefault ;
41
43
import io .helidon .common .types .TypeInfo ;
42
44
import io .helidon .common .types .TypeName ;
45
+ import io .helidon .common .types .TypeNameDefault ;
43
46
import io .helidon .common .types .TypedElementInfo ;
44
47
import io .helidon .pico .api .Activator ;
45
48
import io .helidon .pico .api .Contract ;
51
54
import io .helidon .pico .api .ServiceInfoBasics ;
52
55
import io .helidon .pico .runtime .Dependencies ;
53
56
import io .helidon .pico .tools .ActivatorCreatorCodeGen ;
57
+ import io .helidon .pico .tools .ActivatorCreatorCodeGenDefault ;
54
58
import io .helidon .pico .tools .ActivatorCreatorConfigOptionsDefault ;
55
59
import io .helidon .pico .tools .ActivatorCreatorDefault ;
56
60
import io .helidon .pico .tools .ActivatorCreatorRequest ;
61
+ import io .helidon .pico .tools .ActivatorCreatorRequestDefault ;
57
62
import io .helidon .pico .tools .ActivatorCreatorResponse ;
58
63
import io .helidon .pico .tools .InterceptionPlan ;
59
64
import io .helidon .pico .tools .InterceptorCreatorProvider ;
68
73
import jakarta .annotation .PreDestroy ;
69
74
import jakarta .inject .Inject ;
70
75
76
+ import static io .helidon .builder .processor .tools .BeanUtils .isBuiltInJavaType ;
71
77
import static io .helidon .builder .processor .tools .BuilderTypeTools .createTypeNameFromElement ;
72
78
import static io .helidon .common .types .TypeNameDefault .createFromTypeName ;
73
79
import static io .helidon .pico .processor .ActiveProcessorUtils .MAYBE_ANNOTATIONS_CLAIMED_BY_THIS_PROCESSOR ;
81
87
import static io .helidon .pico .processor .GeneralProcessorUtils .toScopeNames ;
82
88
import static io .helidon .pico .processor .GeneralProcessorUtils .toServiceTypeHierarchy ;
83
89
import static io .helidon .pico .processor .GeneralProcessorUtils .toWeight ;
90
+ import static io .helidon .pico .processor .ProcessingTracker .DEFAULT_SCRATCH_FILE_NAME ;
91
+ import static io .helidon .pico .processor .ProcessingTracker .initializeFrom ;
92
+ import static io .helidon .pico .tools .CodeGenFiler .scratchClassOutputPath ;
93
+ import static io .helidon .pico .tools .CodeGenFiler .targetClassOutputPath ;
84
94
import static io .helidon .pico .tools .TypeTools .createTypedElementInfoFromElement ;
85
95
import static io .helidon .pico .tools .TypeTools .toAccess ;
86
96
import static java .util .Objects .requireNonNull ;
@@ -112,6 +122,7 @@ public class PicoAnnotationProcessor extends BaseAnnotationProcessor {
112
122
113
123
private final Set <TypedElementInfo > allElementsOfInterestInThisModule = new LinkedHashSet <>();
114
124
private final Map <TypeName , TypeInfo > typeInfoToCreateActivatorsForInThisModule = new LinkedHashMap <>();
125
+ private ProcessingTracker tracker ;
115
126
private CreatorHandler creator ;
116
127
private boolean autoAddInterfaces ;
117
128
@@ -149,10 +160,7 @@ public void init(ProcessingEnvironment processingEnv) {
149
160
super .init (processingEnv );
150
161
this .autoAddInterfaces = Options .isOptionEnabled (Options .TAG_AUTO_ADD_NON_CONTRACT_INTERFACES );
151
162
this .creator = new CreatorHandler (getClass ().getSimpleName (), processingEnv , utils ());
152
- // if (BaseAnnotationProcessor.ENABLED) {
153
- // // we are is simulation mode when the base one is operating...
154
- // this.creator.activateSimulationMode();
155
- // }
163
+ this .tracker = initializeFrom (trackerStatePath (), processingEnv );
156
164
}
157
165
158
166
@ Override
@@ -165,7 +173,6 @@ public boolean process(Set<? extends TypeElement> annotations,
165
173
}
166
174
167
175
ServicesToProcess .onBeginProcessing (utils (), getSupportedAnnotationTypes (), roundEnv );
168
- // ServicesToProcess.addOnDoneRunnable(CreatorHandler.reporting());
169
176
170
177
try {
171
178
// build the model
@@ -243,6 +250,7 @@ protected Set<String> supportedElementTargetAnnotations() {
243
250
* Code generate these {@link io.helidon.pico.api.Activator}'s ad {@link io.helidon.pico.api.ModuleComponent}'s.
244
251
*
245
252
* @param services the services to code generate
253
+ * @throws ToolsException if there is problem code generating sources or resources
246
254
*/
247
255
protected void doFiler (ServicesToProcess services ) {
248
256
ActivatorCreatorCodeGen codeGen = ActivatorCreatorDefault .createActivatorCreatorCodeGen (services ).orElse (null );
@@ -257,8 +265,28 @@ protected void doFiler(ServicesToProcess services) {
257
265
.build ();
258
266
ActivatorCreatorRequest req = ActivatorCreatorDefault
259
267
.createActivatorCreatorRequest (services , codeGen , configOptions , creator .filer (), false );
268
+ Set <TypeName > allActivatorTypeNames = tracker .remainingTypeNames ().stream ()
269
+ .map (TypeNameDefault ::createFromTypeName )
270
+ .collect (Collectors .toSet ());
271
+ if (!allActivatorTypeNames .isEmpty ()) {
272
+ req = ActivatorCreatorRequestDefault .toBuilder (req )
273
+ .codeGen (ActivatorCreatorCodeGenDefault .toBuilder (req .codeGen ())
274
+ .allModuleActivatorTypeNames (allActivatorTypeNames )
275
+ .build ())
276
+ .build ();
277
+ }
260
278
ActivatorCreatorResponse res = creator .createModuleActivators (req );
261
- if (!res .success ()) {
279
+ if (res .success ()) {
280
+ res .activatorTypeNamesPutInComponentModule ()
281
+ .forEach (it -> tracker .processing (it .name ()));
282
+ if (processingOver ) {
283
+ try {
284
+ tracker .close ();
285
+ } catch (IOException e ) {
286
+ throw new ToolsException (e .getMessage (), e );
287
+ }
288
+ }
289
+ } else {
262
290
ToolsException exc = new ToolsException ("Error during codegen" , res .error ().orElse (null ));
263
291
utils ().error (exc .getMessage (), exc );
264
292
// should not get here since the error above should halt further processing
@@ -504,14 +532,11 @@ private void gatherContracts(Set<TypeName> contracts,
504
532
if (fqProviderTypeName != null ) {
505
533
if (!genericTypeName .generic ()) {
506
534
providerForSet .add (genericTypeName );
507
-
508
- Optional <String > moduleName = filterModuleName (typeInfo .moduleNameOf (genericTypeName ));
509
- moduleName .ifPresent (externalModuleNamesRequired ::add );
510
- if (moduleName .isPresent ()) {
511
- externalContracts .add (genericTypeName );
512
- } else {
513
- contracts .add (genericTypeName );
514
- }
535
+ extractModuleAndContract (contracts ,
536
+ externalContracts ,
537
+ externalModuleNamesRequired ,
538
+ typeInfo ,
539
+ genericTypeName );
515
540
}
516
541
517
542
// if we are dealing with a Provider<> then we should add those too as module dependencies
@@ -529,13 +554,11 @@ private void gatherContracts(Set<TypeName> contracts,
529
554
|| !isTypeAnInterface
530
555
|| AnnotationAndValueDefault .findFirst (Contract .class , typeInfo .annotations ()).isPresent ();
531
556
if (isTypeAContract ) {
532
- Optional <String > moduleName = filterModuleName (typeInfo .moduleNameOf (genericTypeName ));
533
- moduleName .ifPresent (externalModuleNamesRequired ::add );
534
- if (moduleName .isPresent ()) {
535
- externalContracts .add (genericTypeName );
536
- } else {
537
- contracts .add (genericTypeName );
538
- }
557
+ extractModuleAndContract (contracts ,
558
+ externalContracts ,
559
+ externalModuleNamesRequired ,
560
+ typeInfo ,
561
+ genericTypeName );
539
562
}
540
563
}
541
564
}
@@ -574,6 +597,20 @@ private void gatherContracts(Set<TypeName> contracts,
574
597
true ));
575
598
}
576
599
600
+ private void extractModuleAndContract (Set <TypeName > contracts ,
601
+ Set <TypeName > externalContracts ,
602
+ Set <String > externalModuleNamesRequired ,
603
+ TypeInfo typeInfo ,
604
+ TypeName genericTypeName ) {
605
+ Optional <String > moduleName = filterModuleName (typeInfo .moduleNameOf (genericTypeName ));
606
+ moduleName .ifPresent (externalModuleNamesRequired ::add );
607
+ if (moduleName .isPresent () || isBuiltInJavaType (genericTypeName )) {
608
+ externalContracts .add (genericTypeName );
609
+ } else {
610
+ contracts .add (genericTypeName );
611
+ }
612
+ }
613
+
577
614
private Optional <String > filterModuleName (Optional <String > moduleName ) {
578
615
String name = moduleName .orElse (null );
579
616
if (name != null && (name .startsWith ("java." ) || name .startsWith ("jdk" ))) {
@@ -727,4 +764,8 @@ private void gatherTypeInfosToProcessInThisModule(Map<TypeName, TypeInfo> result
727
764
});
728
765
}
729
766
767
+ private Path trackerStatePath () {
768
+ return scratchClassOutputPath (targetClassOutputPath (processingEnv .getFiler ())).resolve (DEFAULT_SCRATCH_FILE_NAME );
769
+ }
770
+
730
771
}
0 commit comments