-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5912 from pkriens/feature/metainf-services
Parses META-INF/services files for annotations
- Loading branch information
Showing
11 changed files
with
559 additions
and
9 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
biz.aQute.bndlib.tests/test/test/annotationheaders/ServiceProviderFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package test.annotationheaders; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import aQute.bnd.header.Parameters; | ||
import aQute.bnd.osgi.Builder; | ||
import aQute.bnd.osgi.Domain; | ||
import aQute.lib.io.IO; | ||
|
||
public class ServiceProviderFileTest { | ||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void testServiceProviderOnPackage() throws Exception { | ||
try (Builder b = new Builder();) { | ||
b.addClasspath(IO.getFile("bin_test")); | ||
b.setProperty("-includeresource", """ | ||
META-INF/services/com.example.service.Type;\ | ||
literal='\ | ||
#import aQute.bnd.annotation.spi.ServiceProvider;\n\ | ||
#@ServiceProvider(attribute:List<String>="a=1,b=2", effective:=foobar)\n\ | ||
java.lang.String' | ||
"""); | ||
b.build(); | ||
assertTrue(b.check()); | ||
Domain manifest = Domain.domain(b.getJar() | ||
.getManifest()); | ||
Parameters provideCapability = manifest.getProvideCapability(); | ||
|
||
assertThat(provideCapability.get("osgi.service")).isNotNull(); | ||
assertThat(provideCapability.get("osgi.service")).containsEntry("objectClass", "com.example.service.Type") | ||
.containsEntry("a", "1") | ||
.containsEntry("b", "2") | ||
.containsEntry("effective:", "active"); | ||
|
||
assertThat(provideCapability.get("osgi.serviceloader")).isNotNull(); | ||
assertThat(provideCapability.get("osgi.serviceloader") | ||
.get("osgi.serviceloader")).isEqualTo("com.example.service.Type"); | ||
assertThat(provideCapability.get("osgi.serviceloader")) | ||
.containsEntry("osgi.serviceloader", "com.example.service.Type") | ||
.containsEntry("a", "1") | ||
.containsEntry("b", "2") | ||
.containsEntry("register:", "java.lang.String"); | ||
|
||
Parameters requireCapability = manifest.getRequireCapability(); | ||
|
||
System.out.println(provideCapability.toString() | ||
.replace(',', '\n')); | ||
System.out.println(requireCapability.toString() | ||
.replace(',', '\n')); | ||
} | ||
} | ||
|
||
@Test | ||
public void testBothMetaInfoAndAnnotations() throws Exception { | ||
try (Builder b = new Builder();) { | ||
b.addClasspath(IO.getFile("bin_test")); | ||
b.setPrivatePackage("test.annotationheaders.spi.providerF"); | ||
b.setProperty("-includeresource", """ | ||
META-INF/services/com.example.service.Type;\ | ||
literal='\ | ||
#import aQute.bnd.annotation.spi.ServiceProvider;\n\ | ||
#@ServiceProvider(attribute:List<String>="a=1,b=2")\n\ | ||
java.lang.String' | ||
"""); | ||
b.build(); | ||
assertTrue(b.check()); | ||
Domain manifest = Domain.domain(b.getJar() | ||
.getManifest()); | ||
Parameters provideCapability = manifest.getProvideCapability(); | ||
Parameters requireCapability = manifest.getRequireCapability(); | ||
assertThat(provideCapability.size()).isEqualTo(4); | ||
assertThat(requireCapability.size()).isEqualTo(2); | ||
} | ||
} | ||
|
||
@Test | ||
public void testBothMetaInfoAndAnnotationsNoParentheses() throws Exception { | ||
try (Builder b = new Builder();) { | ||
b.addClasspath(IO.getFile("bin_test")); | ||
b.setPrivatePackage("test.annotationheaders.spi.providerF"); | ||
b.setProperty("-includeresource", """ | ||
META-INF/services/com.example.service.Type;\ | ||
literal='\ | ||
#import aQute.bnd.annotation.spi.ServiceProvider;\n\ | ||
#@ServiceProvider\n\ | ||
java.lang.String' | ||
"""); | ||
b.build(); | ||
assertTrue(b.check()); | ||
Domain manifest = Domain.domain(b.getJar() | ||
.getManifest()); | ||
Parameters provideCapability = manifest.getProvideCapability(); | ||
Parameters requireCapability = manifest.getRequireCapability(); | ||
assertThat(provideCapability.size()).isEqualTo(4); | ||
assertThat(requireCapability.size()).isEqualTo(2); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@Version("2.6.0") | ||
@Version("2.7.0") | ||
package aQute.bnd.header; | ||
|
||
import org.osgi.annotation.versioning.Version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.