Closed joerghoh closed 5 years ago
thanks @joerghoh , happy to help to implement this
Have you run into the scenario where OSGi property names have hypens in them? IIRC you can't do that w/ the new approach?
Good one! I thought this could be done via the name-attribute... @AttributeDefinition(name = "Multiple-Values", description = "Multi Configuration values")
But this is not the case.
No, the id is determined according to some rules, which described in chapter 105.15.2 (The \@AtributeDefinition in the metatype spec of R6). In R7 it's basically still the same.
The ID is deduced from the name of the method in the ObjectClassDefinition interface.
@joerghoh correct - so can we move ErrorPageHandler to use the new annotations when there is this existing OSGi Property: error-page.system-path
? If so, what does that ObjectClassDefinition method name look like? (I dont know how to do that)
Just checked with carsten, conclusion: don't use hyphens for property names
R7 allows to use "$_$" which is replaced by a single hyphen (105.15.2). Not supported on R6 though.
Nevertheless, we need to find a way how we can deal with these properties on already existing components. I created issue #1567 to specifically deal with this case
first batch of change: https://github.com/Adobe-Consulting-Services/acs-aem-commons/pull/1580
When moving to R6 I see the following change in behaviour: In both cases no config was saved, but with the felix-annotations the defaults get written into the DS-properties
New code: https://github.com/Adobe-Consulting-Services/acs-aem-commons/pull/1580/files#diff-20b6e15068c1d1500bdfc90f156d2071 Old code: https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/email/impl/EmailServiceImpl.java
@heervischer: I guess that this is a feature of the SCR plugin, which mixes up DS and Metatype in many ways. Just checked the R6 spec, but I have not found a way to add metatype data also to the DS properties (just the other way around). From my point of view it's also not a show stopper.
WDYT?
No issue indeed, using this is making it fail-safe: this.profileName = StringUtils.defaultIfEmpty(config.profile(), DEFAULT_PROFILE);
also how can this replaced in r6? @References({ @Reference( name = "namedImageTransformers", referenceInterface = NamedImageTransformer.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE ),
@heervisscher you should be able to do something like this:
thanks @davidjgonzalez
How much of this do we have remaining?
around 40 classes I think
factories can be done with : @Designate(ocd=StaticReferenceRewriteTransformerFactory.Config.class,factory=true)
when specifying Integer and Boolean values in @Component, you need to do this with :Boolean=false or :Integer=100
@joerghoh Is there any reason why with this switch you not also switched to bnd-maven-plugin (instead of maven-bundle-plugin). The latter is much better supported right now and Sling is also slowly moving away from maven-bundle-plugin.
Also it seems to me that with the current master Felix SCR annotations are no longer in use, but still the maven-scr-plugin is defined in the root pom.xml and also the maven-bundle-plugin is still leveraging the org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin
. The latter causes issue for some people (#1675) and also makes the build slower than necessary. Can we get rid of those legacy plugins now? Also there is still the usage of aQute.bnd.annotation.ProviderType
. This should be replaced by the official OSGi annotation as well. I will try to come up with a PR fixing those remaining leftovers.
Although the SCR annotations are still supported, we should switch over to OSGI annotations.
Carsten Ziegeler's blog:
Specific for AEM:
Registering Sling Servlets (new annotations): https://sling.apache.org/documentation/the-sling-engine/servlets.html#registering-a-servlet-using-java-annotations
References:
1567 how to deal with configuration ids containing a hyphen ("-")
Learnings regarding Labels and Descriptions
@Component
allows you to have a description, but I haven't found where it's reflected. Anyhow, just the full qualified classname in the /system/console/components isn't a bad thing either, isn't it?ObjectClassDefinition
annotation to provide metadata for the Configuration.Things I learned when dealing with Configurations and properties:
@Property
and@Properties
as you like (write on top of the class or annotate constant strings with it), OSGI annotations give some clear recommendations:propertyPrivate=true
), add it to the@Component
annotation. And propertyPrivate is not needed anymore.@ObjectClassDefinition
interface (tpyically calledConfig
).metatype=true|false
properties in the@Component
annotation anymore. If you have a@Designate(ocd=...class)
annotation on your service, it will generate metatype information automatically for it.Regarding Java package versions:
@Version
annotation to annotate package names with a version. Just change the import statement in the package-info.java files toimport org.osgi.annotation.versioning.Version;
In general: