Skip to content

Commit

Permalink
update docs to recent patch
Browse files Browse the repository at this point in the history
- 'auto' as the new default makes things much easier for library authors since no additional configuration is required

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Oct 8, 2024
1 parent 16b43b3 commit f31f44c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
7 changes: 1 addition & 6 deletions docs/_chapters/230-manifest-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ META-INF/services/com.example.ServiceType:
```
The processing is identical to the normal class based annotation processing. The `#class` macro will be set to the implementation class. The `#value` will be set in all cases to the service type unless overridden.

This behavior can be controlled with the [-metainf-services](/instructions/metainf-services.html) instruction. You can set `-metainf-services: auto` to also automatically create `Provide-Capability` headers for services without annotations.
This behavior can be controlled with the [-metainf-services](/instructions/metainf-services.html) instruction. Default is `auto` which automatically create `Provide-Capability` headers for services without textual annotations.

Clearly using the class annotation is far superior:

Expand All @@ -55,11 +55,6 @@ The analysis of these files happens after the analyzer plugins have been run. Th
Since the annotations & imports happen in the comments, it is not possible to diagnose any errors. If the comment does not match its regular expression, it will be silently ignored.


**Note:** Make sure `biz.aQute.bnd.annotation` is on the classpath / buildpath which contains the `aQute.bnd.annotation.spi.ServiceProvider` annotation. Otherwise the annotation won't be processed and you might see a warning in the log like this:

`Unable to determine whether the meta annotation aQute.bnd.annotation.spi.ServiceProvider applied to type xyz provides bundle annotations as it is not on the project build path. If this annotation does provide bundle annotations then it must be present on the build path in order to be processed`


### @Requirement & @Capability Annotations

Though Java class files contain enough information to find code dependencies, there are many dependencies that are indirect. OSGi _extenders_ for instance are often a requirement to make a bundle function correctly but often client bundles have no code dependency on the extender. For example, Declarative Services (DS) went out of its way to allow components to be Plain Old Java Objects (POJO). The result is that resolving a closure of bundles starting from a DS client bundle would not drag in the Service Component Runtime (SCR), resulting in a satisfied but rather idle closure.
Expand Down
16 changes: 5 additions & 11 deletions docs/_instructions/metainf-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ See the chapter about [META-INF/services Annotations](/chapters/230-manifest-ann

This instruction can have the following values:

- `annotation` (default if not set): Scan files and only process annotations.
- `auto`: process annotations and special treatment and auto-register services without annotations. That means that bnd auto-generates a `aQute.bnd.annotation.spi.ServiceProvider` annotation without attributes if an Implementation doesn't have one. This is useful if you just want to have bnd generate the `Provide-Capability` headers for `osgi.serviceloader`.
- `auto` (default if not set): auto-register services without textual annotations. That means that bnd auto-generates a `aQute.bnd.annotation.spi.ServiceProvider` annotation without attributes 'under the hood' if an Implementation doesn't have one. This is useful if you just want to have bnd generate the `Provide-Capability` headers for `osgi.serviceloader`. Additionally 'auto' behaves like 'annotation'.
- `annotation`: Scan files and only process textual annotations in comments of META-INF/services files.
- `none`: disable processing of files in `META-INF/services`

## Example
Expand All @@ -22,12 +22,10 @@ We will use `-includeresource: @lib/groovy-3.0.22.jar` to [unroll the jar](/inst

```
# bnd.bnd
-buildpath: biz.aQute.bnd.annotation;version='7.0'
-includeresource: @lib/groovy-3.0.22.jar
-metainf-services: auto
```

This creates a new jar with the following MANIFEST.MF headers from the `META-INF/services` folder:
This uses the default `-metainf-services: auto` and creates a new jar with the following MANIFEST.MF headers from the `META-INF/services` folder:

```
# MANIFEST.MF
Expand All @@ -37,11 +35,7 @@ Require-Capability osgi.ee;filter:="(&(osgi.ee=JavaSE)(vers
osgi.extender;filter:="(&(osgi.extender=osgi.serviceloader.registrar)(version>=1.0.0)(!(version>=2.0.0)))"
```

`-metainf-services: auto` causes bnd to process annotations and also auto-generate an annotation for services without annotations.
To prevent the latter (auto-generation) use the default `-metainf-services: annotation` or remove the instruction completely.

**Note:** Make sure `biz.aQute.bnd.annotation` is on the classpath / buildpath which contains `aQute.bnd.annotation.spi.ServiceProvider` annotation.


Because the default `-metainf-services: auto` is used, it instructs bnd to process textual annotations and also auto-generate a `@ServiceProvider` annotation annotation under the hood for services without annotations.
To prevent the latter (auto-generation) use the default `-metainf-services: annotation` or use `-metainf-services: none`.

[source](https://github.com/bndtools/bnd/blob/master/biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfServiceParser.java)

0 comments on commit f31f44c

Please sign in to comment.