This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch bugfix/extract-property-name-also-from-non-private-constants in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 7bc771ae4c83ceec1e7778a64993fe53a2b6ce1d Author: Konrad Windszus <[email protected]> AuthorDate: Sat May 9 18:50:03 2026 +0200 fix(migrate_annotations): enhance property name extraction from non-private static final fields --- .../scripts/migrate_annotations.py | 5 +- .../scripts/tests/test_migrate_annotations.py | 60 ++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/skills/osgi-scr-migrator/scripts/migrate_annotations.py b/skills/osgi-scr-migrator/scripts/migrate_annotations.py index 70385722..2eeda572 100755 --- a/skills/osgi-scr-migrator/scripts/migrate_annotations.py +++ b/skills/osgi-scr-migrator/scripts/migrate_annotations.py @@ -357,13 +357,14 @@ class AnnotationMigrator: # Look for the field declaration on the next line(s) after the annotation for i in range(idx, min(idx + 3, len(self.lines))): field_line = self.lines[i] - # Match: private static final String FIELD_NAME = "property.name"; - field_match = re.search(r'private\s+static\s+final\s+String\s+\w+\s*=\s*"([^"]+)"', field_line) + # Match: [private|protected|public] static final String FIELD_NAME = "property.name"; + field_match = re.search(r'(?:(?:private|protected|public)\s+)?static\s+final\s+String\s+\w+\s*=\s*"([^"]+)"', field_line) if field_match: property_name = field_match.group(1) break if not property_name: + print(f"Warning: Could not extract property name from annotation in {self.file_path}: {annotation}") return None prop = Property(name=property_name) diff --git a/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py b/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py index f15eb00d..61127ee2 100644 --- a/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py +++ b/skills/osgi-scr-migrator/scripts/tests/test_migrate_annotations.py @@ -99,6 +99,66 @@ class TestPropertyParsing(unittest.TestCase): self.assertEqual(prop.description, "Request timeout in seconds") self.assertTrue(prop.is_configurable) + def test_property_name_derived_from_default_static_final_field(self): + """Test deriving property name from package-private static final field.""" + content = ''' +@Property(value = "Apache Software Foundation") +static final String SERVICE_VENDOR = "service.vendor"; +''' + stats = MigrationStats() + migrator = AnnotationMigrator(content, Path("test.java"), stats) + migrator._collect_properties() + + self.assertEqual(len(migrator.component_properties), 1) + prop = migrator.component_properties[0] + self.assertEqual(prop.name, "service.vendor") + self.assertEqual(prop.value, "Apache Software Foundation") + + def test_property_name_derived_from_private_static_final_field(self): + """Test deriving property name from private static final field.""" + content = ''' +@Property(value = "Apache Software Foundation") +private static final String SERVICE_VENDOR = "service.vendor"; +''' + stats = MigrationStats() + migrator = AnnotationMigrator(content, Path("test.java"), stats) + migrator._collect_properties() + + self.assertEqual(len(migrator.component_properties), 1) + prop = migrator.component_properties[0] + self.assertEqual(prop.name, "service.vendor") + self.assertEqual(prop.value, "Apache Software Foundation") + + def test_property_name_derived_from_protected_static_final_field(self): + """Test deriving property name from protected static final field.""" + content = ''' +@Property(value = "Apache Software Foundation") +protected static final String SERVICE_VENDOR = "service.vendor"; +''' + stats = MigrationStats() + migrator = AnnotationMigrator(content, Path("test.java"), stats) + migrator._collect_properties() + + self.assertEqual(len(migrator.component_properties), 1) + prop = migrator.component_properties[0] + self.assertEqual(prop.name, "service.vendor") + self.assertEqual(prop.value, "Apache Software Foundation") + + def test_property_name_derived_from_public_static_final_field(self): + """Test deriving property name from public static final field.""" + content = ''' +@Property(value = "Apache Software Foundation") +public static final String SERVICE_VENDOR = "service.vendor"; +''' + stats = MigrationStats() + migrator = AnnotationMigrator(content, Path("test.java"), stats) + migrator._collect_properties() + + self.assertEqual(len(migrator.component_properties), 1) + prop = migrator.component_properties[0] + self.assertEqual(prop.name, "service.vendor") + self.assertEqual(prop.value, "Apache Software Foundation") + class TestPropertyConversion(unittest.TestCase): """Test property conversion to OSGi R6/R7 format."""
