36
36
import org .jboss .jandex .MethodInfo ;
37
37
import org .jboss .jandex .ParameterizedType ;
38
38
import org .jboss .jandex .Type ;
39
- import org .slf4j .Logger ;
40
- import org .slf4j .LoggerFactory ;
39
+ import org .jboss .logging .Logger ;
41
40
42
41
import io .quarkus .arc .deployment .AdditionalBeanBuildItem ;
43
42
import io .quarkus .arc .deployment .BeanArchiveIndexBuildItem ;
87
86
88
87
public class QuteProcessor {
89
88
90
- private static final Logger LOGGER = LoggerFactory .getLogger (QuteProcessor .class );
89
+ private static final Logger LOGGER = Logger .getLogger (QuteProcessor .class );
91
90
92
91
public static final DotName RESOURCE_PATH = DotName .createSimple (ResourcePath .class .getName ());
93
92
public static final DotName TEMPLATE = DotName .createSimple (Template .class .getName ());
@@ -147,7 +146,9 @@ TemplatesAnalysisBuildItem analyzeTemplates(List<TemplatePathBuildItem> template
147
146
long start = System .currentTimeMillis ();
148
147
List <TemplateAnalysis > analysis = new ArrayList <>();
149
148
149
+ // A dummy engine instance is used to parse and validate all templates during the build. The real engine instance is created at startup.
150
150
Engine dummyEngine = Engine .builder ().addDefaultSectionHelpers ().computeSectionHelper (name -> {
151
+ // Create a dummy section helper factory for an uknown section that could be potentially registered at runtime
151
152
return new SectionHelperFactory <SectionHelper >() {
152
153
@ Override
153
154
public SectionHelper initialize (SectionInitContext context ) {
@@ -169,7 +170,7 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
169
170
LOGGER .warn ("Unable to analyze the template from path: " + path .getFullPath (), e );
170
171
}
171
172
}
172
- LOGGER .debug ("Finished analysis of {} templates in {} ms" ,
173
+ LOGGER .debugf ("Finished analysis of %s templates in %s ms" ,
173
174
analysis .size (), System .currentTimeMillis () - start );
174
175
return new TemplatesAnalysisBuildItem (analysis );
175
176
}
@@ -216,7 +217,7 @@ void validateExpressions(TemplatesAnalysisBuildItem templatesAnalysis, BeanArchi
216
217
member = findTemplateExtensionMethod (name , match .clazz , templateExtensionMethods );
217
218
}
218
219
if (member == null && excludes .stream ().anyMatch (e -> e .getPredicate ().test (name , match .clazz ))) {
219
- LOGGER .debug ("No property found for {} in [{} ] but it is intentionally ignored" , name ,
220
+ LOGGER .debugf ("No property found for %s in [%s ] but it is intentionally ignored" , name ,
220
221
expression .toOriginalString (), match .clazz );
221
222
break ;
222
223
}
@@ -324,7 +325,7 @@ void validateInjectedBeans(ApplicationArchivesBuildItem applicationArchivesBuild
324
325
}
325
326
if (member == null
326
327
&& excludes .stream ().anyMatch (e -> e .getPredicate ().test (name , match .clazz ))) {
327
- LOGGER .debug ("No property found for {} in [{} ] but it is intentionally ignored" , name ,
328
+ LOGGER .debugf ("No property found for %s in [%s ] but it is intentionally ignored" , name ,
328
329
expression .toOriginalString (), match .clazz );
329
330
break ;
330
331
}
@@ -409,7 +410,7 @@ public void write(String name, byte[] data) {
409
410
}
410
411
String className = name .substring (0 , idx ).replace ("/" , "." );
411
412
boolean appClass = appClassPredicate .test (className );
412
- LOGGER .debug ("Writing {} [appClass={} ]" , name , appClass );
413
+ LOGGER .debugf ("Writing %s [appClass=%s ]" , name , appClass );
413
414
generatedClass .produce (new GeneratedClassBuildItem (appClass , name , data ));
414
415
}
415
416
};
@@ -443,18 +444,18 @@ public void write(String name, byte[] data) {
443
444
generator .generate (data );
444
445
}
445
446
446
- Set <String > generateTypes = new HashSet <>();
447
- generateTypes .addAll (generator .getGeneratedTypes ());
447
+ Set <String > generatedTypes = new HashSet <>();
448
+ generatedTypes .addAll (generator .getGeneratedTypes ());
448
449
449
450
ExtensionMethodGenerator extensionMethodGenerator = new ExtensionMethodGenerator (classOutput );
450
451
for (TemplateExtensionMethodBuildItem templateExtension : templateExtensionMethods ) {
451
452
extensionMethodGenerator .generate (templateExtension .getMethod ());
452
453
}
453
- generateTypes .addAll (extensionMethodGenerator .getGeneratedTypes ());
454
+ generatedTypes .addAll (extensionMethodGenerator .getGeneratedTypes ());
454
455
455
- LOGGER .debug ("Generated types: {} " , generateTypes );
456
+ LOGGER .debugf ("Generated types: %s " , generatedTypes );
456
457
457
- for (String generateType : generateTypes ) {
458
+ for (String generateType : generatedTypes ) {
458
459
generatedResolvers .produce (new GeneratedValueResolverBuildItem (generateType ));
459
460
reflectiveClass .produce (new ReflectiveClassBuildItem (false , false , generateType ));
460
461
}
@@ -477,15 +478,18 @@ void collectTemplates(QuteConfig config, ApplicationArchivesBuildItem applicatio
477
478
String tagBasePath = basePath + "tags/" ;
478
479
Path tagsPath = applicationArchive .getChildPath (tagBasePath );
479
480
if (tagsPath != null ) {
480
- Iterator <Path > tagFiles = Files .list (tagsPath )
481
- .filter (Files ::isRegularFile )
482
- .iterator ();
483
- while (tagFiles .hasNext ()) {
484
- Path path = tagFiles .next ();
485
- String tagPath = path .getFileName ().toString ();
486
- LOGGER .debug ("Found tag: {}" , path );
487
- produceTemplateBuildItems (templatePaths , watchedPaths , nativeImageResources , tagBasePath , tagPath , path , true );
481
+ try (Stream <Path > tagFiles = Files .list (tagsPath )) {
482
+ Iterator <Path > iter = tagFiles .filter (Files ::isRegularFile )
483
+ .iterator ();
484
+ while (iter .hasNext ()) {
485
+ Path path = iter .next ();
486
+ String tagPath = path .getFileName ().toString ();
487
+ LOGGER .debugf ("Found tag: %s" , path );
488
+ produceTemplateBuildItems (templatePaths , watchedPaths , nativeImageResources , tagBasePath , tagPath , path ,
489
+ true );
490
+ }
488
491
}
492
+
489
493
}
490
494
}
491
495
@@ -563,7 +567,7 @@ void processInjectionPoints(QuteConfig config, ApplicationArchivesBuildItem appl
563
567
Map <String , List <String >> variants = new HashMap <>();
564
568
scanVariants (basePath , templatesPath , templatesPath , variantBases , variants );
565
569
templateVariants .produce (new TemplateVariantsBuildItem (variants ));
566
- LOGGER .debug ("Variant templates found: {} " , variants );
570
+ LOGGER .debugf ("Variant templates found: %s " , variants );
567
571
}
568
572
}
569
573
@@ -749,7 +753,7 @@ private void processsTemplateData(IndexView index, AnnotationInstance templateDa
749
753
new AnnotationValue [] { ignoreValue , propertiesValue });
750
754
});
751
755
} else {
752
- LOGGER .warn ("@TemplateData#target() not available: {} " , annotationTarget .asClass ().name ());
756
+ LOGGER .warnf ("@TemplateData#target() not available: %s " , annotationTarget .asClass ().name ());
753
757
}
754
758
}
755
759
}
@@ -804,37 +808,40 @@ private void scan(Path root, Path directory, String basePath, BuildProducer<HotD
804
808
BuildProducer <TemplatePathBuildItem > templatePaths ,
805
809
BuildProducer <NativeImageResourceBuildItem > nativeImageResources )
806
810
throws IOException {
807
- Iterator <Path > files = Files .list (directory ).iterator ();
808
- while (files .hasNext ()) {
809
- Path path = files .next ();
810
- if (Files .isRegularFile (path )) {
811
- LOGGER .debug ("Found template: {}" , path );
812
- String templatePath = root .relativize (path ).toString ();
813
- produceTemplateBuildItems (templatePaths , watchedPaths , nativeImageResources , basePath , templatePath , path ,
814
- false );
815
- } else if (Files .isDirectory (path ) && !path .getFileName ().toString ().equals ("tags" )) {
816
- LOGGER .debug ("Scan directory: {}" , path );
817
- scan (root , path , basePath , watchedPaths , templatePaths , nativeImageResources );
811
+ try (Stream <Path > files = Files .list (directory )) {
812
+ Iterator <Path > iter = files .iterator ();
813
+ while (iter .hasNext ()) {
814
+ Path path = iter .next ();
815
+ if (Files .isRegularFile (path )) {
816
+ LOGGER .debugf ("Found template: %s" , path );
817
+ String templatePath = root .relativize (path ).toString ();
818
+ produceTemplateBuildItems (templatePaths , watchedPaths , nativeImageResources , basePath , templatePath , path ,
819
+ false );
820
+ } else if (Files .isDirectory (path ) && !path .getFileName ().toString ().equals ("tags" )) {
821
+ LOGGER .debugf ("Scan directory: %s" , path );
822
+ scan (root , path , basePath , watchedPaths , templatePaths , nativeImageResources );
823
+ }
818
824
}
819
825
}
820
826
}
821
827
822
828
void scanVariants (String basePath , Path root , Path directory , Set <String > variantBases , Map <String , List <String >> variants )
823
829
throws IOException {
824
- Iterator <Path > files = Files .list (directory )
825
- .iterator ();
826
- while (files .hasNext ()) {
827
- Path path = files .next ();
828
- if (Files .isRegularFile (path )) {
829
- for (String base : variantBases ) {
830
- if (path .toAbsolutePath ().toString ().contains (base )) {
831
- // Variants are relative paths to base, e.g. "detail/item2"
832
- variants .computeIfAbsent (base , i -> new ArrayList <>())
833
- .add (root .relativize (path ).toString ());
830
+ try (Stream <Path > files = Files .list (directory )) {
831
+ Iterator <Path > iter = files .iterator ();
832
+ while (iter .hasNext ()) {
833
+ Path path = iter .next ();
834
+ if (Files .isRegularFile (path )) {
835
+ for (String base : variantBases ) {
836
+ if (path .toAbsolutePath ().toString ().contains (base )) {
837
+ // Variants are relative paths to base, e.g. "detail/item2"
838
+ variants .computeIfAbsent (base , i -> new ArrayList <>())
839
+ .add (root .relativize (path ).toString ());
840
+ }
834
841
}
842
+ } else if (Files .isDirectory (path )) {
843
+ scanVariants (basePath , root , path , variantBases , variants );
835
844
}
836
- } else if (Files .isDirectory (path )) {
837
- scanVariants (basePath , root , path , variantBases , variants );
838
845
}
839
846
}
840
847
}
0 commit comments