Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix630 2 #633

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,16 @@
!org.glassfish.hk2.osgiresourcelocator,
*
</Import-Package>
<Require-Capability><![CDATA[
osgi.extender;filter:="(&(osgi.extender=osgi.serviceloader.processor)
(version>=1.0.0)(!(version>=2.0.0)))",
osgi.serviceloader;
filter:="(osgi.serviceloader=jakarta.mail.util.StreamProvider)";
cardinality:=multiple,
osgi.serviceloader;
filter:="(osgi.serviceloader=jakarta.mail.Provider)";
cardinality:=multiple]]>
</Require-Capability>
</instructions>
</configuration>
<executions>
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/java/jakarta/mail/util/FactoryFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ static <T> T find(Class<T> factoryClass) throws RuntimeException {
}

// handling Glassfish/OSGi (platform specific default)
if (isOsgi()) {
T result = lookupUsingOSGiServiceLoader(factoryId);
if (isHk2Available()) {
T result = lookupUsingHk2ServiceLoader(factoryId);
if (result != null) {
return result;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ private static String fromSystemProperty(String factoryId) {

private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "org.glassfish.hk2.osgiresourcelocator.ServiceLoader";

private static boolean isOsgi() {
private static boolean isHk2Available() {
try {
Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
return true;
Expand All @@ -98,7 +98,7 @@ private static boolean isOsgi() {
}

@SuppressWarnings({"unchecked"})
private static <T> T lookupUsingOSGiServiceLoader(String factoryId) {
private static <T> T lookupUsingHk2ServiceLoader(String factoryId) {
try {
// Use reflection to avoid having any dependency on HK2 ServiceLoader class
Class<?> serviceClass = Class.forName(factoryId);
Expand Down