-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6639f58
commit da6d28e
Showing
7 changed files
with
102 additions
and
77 deletions.
There are no files selected for viewing
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
54 changes: 0 additions & 54 deletions
54
...java/jakarta/enterprise/inject/build/compatible/spi/AnnotationBuilderFactoryResolver.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServices.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,19 @@ | ||
package jakarta.enterprise.inject.build.compatible.spi; | ||
|
||
import jakarta.enterprise.inject.spi.Prioritized; | ||
|
||
/** | ||
* Service facade for various services needed by {@link BuildCompatibleExtension} implementations. | ||
*/ | ||
public interface BuildServices extends Prioritized { | ||
/** | ||
* @return The {@link AnnotationBuilderFactory} instance, never {@code null} | ||
*/ | ||
AnnotationBuilderFactory annotationBuilderFactory(); | ||
|
||
/** | ||
* | ||
* @return The {@link ClassInfoFactory} instance, never {@code null} | ||
*/ | ||
ClassInfoFactory classInfoFactory(); | ||
} |
54 changes: 54 additions & 0 deletions
54
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServicesResolver.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,54 @@ | ||
package jakarta.enterprise.inject.build.compatible.spi; | ||
|
||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.ServiceConfigurationError; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
final class BuildServicesResolver { | ||
private static final Object lock = new Object(); | ||
private static volatile Set<BuildServices> discoveredBuildServices; | ||
private static volatile BuildServices configuredBuildServices; | ||
|
||
static BuildServices get() { | ||
if (configuredBuildServices != null) { | ||
return configuredBuildServices; | ||
} | ||
|
||
if (discoveredBuildServices == null) { | ||
synchronized (lock) { | ||
if (discoveredBuildServices == null) { | ||
discoverFactories(); | ||
} | ||
} | ||
} | ||
|
||
configuredBuildServices = discoveredBuildServices.iterator().next(); | ||
|
||
return configuredBuildServices; | ||
} | ||
|
||
private static void discoverFactories() { | ||
Set<BuildServices> factories = new TreeSet<>( | ||
Comparator.comparingInt(BuildServices::getPriority).reversed()); | ||
|
||
ServiceLoader<BuildServices> loader = SecurityActions.loadService( | ||
BuildServices.class, BuildServicesResolver.class.getClassLoader()); | ||
|
||
if (!loader.iterator().hasNext()) { | ||
throw new IllegalStateException("Unable to locate AnnotationBuilderFactory implementation"); | ||
} | ||
|
||
try { | ||
for (BuildServices buildServicies : loader) { | ||
factories.add(buildServicies); | ||
} | ||
} catch (ServiceConfigurationError e) { | ||
throw new IllegalStateException(e); | ||
} | ||
|
||
BuildServicesResolver.discoveredBuildServices = Collections.unmodifiableSet(factories); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/ClassInfoFactory.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,16 @@ | ||
package jakarta.enterprise.inject.build.compatible.spi; | ||
|
||
import jakarta.enterprise.lang.model.declarations.ClassInfo; | ||
|
||
/** | ||
* A factory for resolving instances of {@link jakarta.enterprise.lang.model.declarations.ClassInfo}. | ||
*/ | ||
public interface ClassInfoFactory { | ||
/** | ||
* Allows resolving instances of {@link ClassInfo} from the application class path using the {@link Class#getName() binary name} of the class. | ||
* | ||
* @param name The binary name of the class, must not be {@code null} | ||
* @return A {@link ClassInfo} instance or {@code null} if it does not exist | ||
*/ | ||
ClassInfo resolve(String name); | ||
} |
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