@@ -127,6 +127,8 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
127127 // All java packages present in this bazel package.
128128 allPackageNames := sorted_set .NewSortedSetFn ([]types.PackageName {}, types .PackageNameLess )
129129
130+ annotationProcessorClasses := sorted_set .NewSortedSetFn (nil , types .ClassNameLess )
131+
130132 if isModule {
131133 for mRel , mJavaPkg := range l .javaPackageCache {
132134 if ! strings .HasPrefix (mRel , args .Rel ) {
@@ -152,6 +154,9 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
152154 accumulateJavaFile (cfg , testJavaFiles , testHelperJavaFiles , separateTestJavaFiles , file , mJavaPkg .PerClassMetadata , log )
153155 }
154156 }
157+ for _ , annotationClass := range mJavaPkg .AllAnnotations ().SortedSlice () {
158+ annotationProcessorClasses .AddAll (cfg .GetAnnotationProcessorPluginClasses (annotationClass ))
159+ }
155160 }
156161 } else {
157162 allPackageNames .Add (javaPkg .Name )
@@ -174,6 +179,9 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
174179 productionJavaFiles .Add (path )
175180 }
176181 }
182+ for _ , annotationClass := range javaPkg .AllAnnotations ().SortedSlice () {
183+ annotationProcessorClasses .AddAll (cfg .GetAnnotationProcessorPluginClasses (annotationClass ))
184+ }
177185 }
178186
179187 allPackageNamesSlice := allPackageNames .SortedSlice ()
@@ -192,7 +200,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
192200 }
193201
194202 if productionJavaFiles .Len () > 0 {
195- l .generateJavaLibrary (args .File , args .Rel , filepath .Base (args .Rel ), productionJavaFiles .SortedSlice (), allPackageNames , nonLocalProductionJavaImports , nonLocalJavaExports , false , javaLibraryKind , & res )
203+ l .generateJavaLibrary (args .File , args .Rel , filepath .Base (args .Rel ), productionJavaFiles .SortedSlice (), allPackageNames , nonLocalProductionJavaImports , nonLocalJavaExports , annotationProcessorClasses , false , javaLibraryKind , & res )
196204 }
197205
198206 var testHelperJavaClasses * sorted_set.SortedSet [types.ClassName ]
@@ -228,7 +236,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
228236 testJavaImportsWithHelpers .Add (tf .pkg )
229237 srcs = append (srcs , tf .pathRelativeToBazelWorkspaceRoot )
230238 }
231- l .generateJavaLibrary (args .File , args .Rel , filepath .Base (args .Rel ), srcs , packages , testJavaImports , nonLocalJavaExports , true , javaLibraryKind , & res )
239+ l .generateJavaLibrary (args .File , args .Rel , filepath .Base (args .Rel ), srcs , packages , testJavaImports , nonLocalJavaExports , annotationProcessorClasses , true , javaLibraryKind , & res )
232240 }
233241 }
234242
@@ -240,7 +248,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
240248 case "file" :
241249 for _ , tf := range testJavaFiles .SortedSlice () {
242250 separateJavaTestReasons := separateTestJavaFiles [tf ]
243- l .generateJavaTest (args .File , args .Rel , cfg .MavenRepositoryName (), tf , isModule , testJavaImportsWithHelpers , nil , separateJavaTestReasons .wrapper , separateJavaTestReasons .attributes , & res )
251+ l .generateJavaTest (args .File , args .Rel , cfg .MavenRepositoryName (), tf , isModule , testJavaImportsWithHelpers , annotationProcessorClasses , nil , separateJavaTestReasons .wrapper , separateJavaTestReasons .attributes , & res )
244252 }
245253
246254 case "suite" :
@@ -268,6 +276,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
268276 packageNames ,
269277 cfg .MavenRepositoryName (),
270278 testJavaImportsWithHelpers ,
279+ annotationProcessorClasses ,
271280 cfg .GetCustomJavaTestFileSuffixes (),
272281 testHelperJavaFiles .Len () > 0 ,
273282 & res ,
@@ -284,7 +293,7 @@ func (l javaLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
284293 testHelperDep = ptr (testHelperLibname (suiteName ))
285294 }
286295 separateJavaTestReasons := separateTestJavaFiles [src ]
287- l .generateJavaTest (args .File , args .Rel , cfg .MavenRepositoryName (), src , isModule , testJavaImportsWithHelpers , testHelperDep , separateJavaTestReasons .wrapper , separateJavaTestReasons .attributes , & res )
296+ l .generateJavaTest (args .File , args .Rel , cfg .MavenRepositoryName (), src , isModule , testJavaImportsWithHelpers , annotationProcessorClasses , testHelperDep , separateJavaTestReasons .wrapper , separateJavaTestReasons .attributes , & res )
288297 }
289298 }
290299 }
@@ -415,7 +424,7 @@ func addFilteringOutOwnPackage(to *sorted_set.SortedSet[types.PackageName], from
415424
416425func accumulateJavaFile (cfg * javaconfig.Config , testJavaFiles , testHelperJavaFiles * sorted_set.SortedSet [javaFile ], separateTestJavaFiles map [javaFile ]separateJavaTestReasons , file javaFile , perClassMetadata map [string ]java.PerClassMetadata , log zerolog.Logger ) {
417426 if cfg .IsJavaTestFile (filepath .Base (file .pathRelativeToBazelWorkspaceRoot )) {
418- annotationClassNames := sorted_set.NewSortedSet [ string ](nil )
427+ annotationClassNames := sorted_set .NewSortedSetFn [types. ClassName ](nil , types . ClassNameLess )
419428 metadataForClass := perClassMetadata [file .ClassName ().FullyQualifiedClassName ()]
420429 annotationClassNames .AddAll (metadataForClass .AnnotationClassNames )
421430 for _ , key := range metadataForClass .MethodAnnotationClassNames .Keys () {
@@ -425,15 +434,15 @@ func accumulateJavaFile(cfg *javaconfig.Config, testJavaFiles, testHelperJavaFil
425434 perFileAttrs := make (map [string ]bzl.Expr )
426435 wrapper := ""
427436 for _ , annotationClassName := range annotationClassNames .SortedSlice () {
428- if attrs , ok := cfg .AttributesForAnnotation (annotationClassName ); ok {
437+ if attrs , ok := cfg .AttributesForAnnotation (annotationClassName . FullyQualifiedClassName () ); ok {
429438 for k , v := range attrs {
430439 if old , ok := perFileAttrs [k ]; ok {
431440 log .Error ().Str ("file" , file .pathRelativeToBazelWorkspaceRoot ).Msgf ("Saw conflicting attr overrides from annotations for attribute %v: %v and %v. Picking one at random." , k , old , v )
432441 }
433442 perFileAttrs [k ] = v
434443 }
435444 }
436- newWrapper , ok := cfg .WrapperForAnnotation (annotationClassName )
445+ newWrapper , ok := cfg .WrapperForAnnotation (annotationClassName . FullyQualifiedClassName () )
437446 if ok {
438447 if wrapper != "" {
439448 log .Error ().Str ("file" , file .pathRelativeToBazelWorkspaceRoot ).Msgf ("Saw conflicting wrappers from annotations: %v and %v. Picking one at random." , wrapper , newWrapper )
@@ -453,7 +462,7 @@ func accumulateJavaFile(cfg *javaconfig.Config, testJavaFiles, testHelperJavaFil
453462 }
454463}
455464
456- func (l javaLang ) generateJavaLibrary (file * rule.File , pathToPackageRelativeToBazelWorkspace string , name string , srcsRelativeToBazelWorkspace []string , packages , imports * sorted_set.SortedSet [types.PackageName ], exports * sorted_set.SortedSet [types.PackageName ], testonly bool , javaLibraryRuleKind string , res * language.GenerateResult ) {
465+ func (l javaLang ) generateJavaLibrary (file * rule.File , pathToPackageRelativeToBazelWorkspace string , name string , srcsRelativeToBazelWorkspace []string , packages , imports * sorted_set.SortedSet [types.PackageName ], exports * sorted_set.SortedSet [types.PackageName ], annotationProcessorClasses * sorted_set. SortedSet [types. ClassName ], testonly bool , javaLibraryRuleKind string , res * language.GenerateResult ) {
457466 const ruleKind = "java_library"
458467 r := rule .NewRule (ruleKind , name )
459468
@@ -487,6 +496,7 @@ func (l javaLang) generateJavaLibrary(file *rule.File, pathToPackageRelativeToBa
487496 PackageNames : packages ,
488497 ImportedPackageNames : imports ,
489498 ExportedPackageNames : exports ,
499+ AnnotationProcessors : annotationProcessorClasses ,
490500 }
491501 res .Imports = append (res .Imports , resolveInput )
492502}
@@ -511,7 +521,7 @@ func (l javaLang) generateJavaBinary(file *rule.File, m types.ClassName, libName
511521 })
512522}
513523
514- func (l javaLang ) generateJavaTest (file * rule.File , pathToPackageRelativeToBazelWorkspace string , mavenRepositoryName string , f javaFile , includePackageInName bool , imports * sorted_set.SortedSet [types.PackageName ], depOnTestHelpers * string , wrapper string , extraAttributes map [string ]bzl.Expr , res * language.GenerateResult ) {
524+ func (l javaLang ) generateJavaTest (file * rule.File , pathToPackageRelativeToBazelWorkspace string , mavenRepositoryName string , f javaFile , includePackageInName bool , imports * sorted_set.SortedSet [types.PackageName ], annotationProcessorClasses * sorted_set. SortedSet [types. ClassName ], depOnTestHelpers * string , wrapper string , extraAttributes map [string ]bzl.Expr , res * language.GenerateResult ) {
515525 className := f .ClassName ()
516526 fullyQualifiedTestClass := className .FullyQualifiedClassName ()
517527 var testName string
@@ -571,6 +581,7 @@ func (l javaLang) generateJavaTest(file *rule.File, pathToPackageRelativeToBazel
571581 resolveInput := types.ResolveInput {
572582 PackageNames : sorted_set .NewSortedSetFn ([]types.PackageName {f .pkg }, types .PackageNameLess ),
573583 ImportedPackageNames : testImports ,
584+ AnnotationProcessors : annotationProcessorClasses ,
574585 }
575586 res .Imports = append (res .Imports , resolveInput )
576587}
@@ -598,7 +609,7 @@ var junit5RuntimeDeps = []string{
598609 "org.junit.platform:junit-platform-reporting" ,
599610}
600611
601- func (l javaLang ) generateJavaTestSuite (file * rule.File , name string , srcs []string , packageNames * sorted_set.SortedSet [types.PackageName ], mavenRepositoryName string , imports * sorted_set.SortedSet [types.PackageName ], customTestSuffixes * []string , hasHelpers bool , res * language.GenerateResult ) {
612+ func (l javaLang ) generateJavaTestSuite (file * rule.File , name string , srcs []string , packageNames * sorted_set.SortedSet [types.PackageName ], mavenRepositoryName string , imports * sorted_set.SortedSet [types.PackageName ], annotationProcessorClasses * sorted_set. SortedSet [types. ClassName ], customTestSuffixes * []string , hasHelpers bool , res * language.GenerateResult ) {
602613 const ruleKind = "java_test_suite"
603614 r := rule .NewRule (ruleKind , name )
604615 r .SetAttr ("srcs" , srcs )
@@ -636,6 +647,7 @@ func (l javaLang) generateJavaTestSuite(file *rule.File, name string, srcs []str
636647 resolveInput := types.ResolveInput {
637648 PackageNames : packageNames ,
638649 ImportedPackageNames : suiteImports ,
650+ AnnotationProcessors : annotationProcessorClasses ,
639651 }
640652 res .Imports = append (res .Imports , resolveInput )
641653}
0 commit comments