You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2026/05/09 16:30:14 UTC

(sling-whiteboard) 01/01: Look for @Component annotation anywhere prior to class declaration

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/make-generate-metatype-more-resilient
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 0ffd3b814bf314a1e3631b8c1730de499dd95483
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Sat May 9 18:29:02 2026 +0200

    Look for @Component annotation anywhere prior to class declaration
    
    Not just in the 20 lines before class declaration, as it can be further up in the file.
    Print warning and skip metatype generation if @Component annotation or class declaration cannot be found.
---
 skills/osgi-scr-migrator/scripts/migrate_annotations.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/skills/osgi-scr-migrator/scripts/migrate_annotations.py b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
index 70385722..148f2549 100755
--- a/skills/osgi-scr-migrator/scripts/migrate_annotations.py
+++ b/skills/osgi-scr-migrator/scripts/migrate_annotations.py
@@ -905,16 +905,19 @@ class AnnotationMigrator:
                 break
 
         if class_idx is None:
+            print(f"Warning: Could not find class declaration for {self.component_name}, skipping metatype generation")
             return
 
         # Find the @Component annotation
         component_idx = None
-        for i in range(class_idx - 1, max(0, class_idx - 20), -1):
+        # must be somewhere between start of file and class declaration, look backwards from class declaration
+        for i in range(class_idx - 1, 0, -1): 
             if '@Component' in self.lines[i]:
                 component_idx = i
                 break
 
         if component_idx is None:
+            print(f"Warning: Could not find @Component annotation for {self.component_name}, skipping metatype generation")
             return
 
         # Add @Designate annotation before @Component