Add module-info support via multi-version jar (#2381)

This commit is contained in:
Rob Bygrave
2021-09-21 14:37:51 +12:00
committed by GitHub
parent b450227b13
commit 0bf8c9eb64
43 changed files with 390 additions and 222 deletions
@@ -5,7 +5,9 @@ import io.avaje.classpath.scanner.ClassPathScannerFactory;
import io.ebean.config.DatabaseConfig;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
/**
* Utility to finds and return the list of ClassPathScanner services.
@@ -17,7 +19,7 @@ public class ClassPathScanners {
*/
public static List<ClassPathScanner> find(DatabaseConfig config) {
List<ClassPathScanner> scanners = new ArrayList<>();
for (ClassPathScannerFactory factory : config.serviceLoad(ClassPathScannerFactory.class)) {
for (ClassPathScannerFactory factory : ServiceLoader.load(ClassPathScannerFactory.class)) {
scanners.add(factory.createScanner(config.getClassLoadConfig().getClassLoader()));
}
return scanners;
@@ -380,7 +380,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
*/
public void start() {
if (config.isRunMigration() && TenantMode.DB != config.getTenantMode()) {
final AutoMigrationRunner migrationRunner = config.service(AutoMigrationRunner.class);
final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
if (migrationRunner == null) {
throw new IllegalStateException("No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
}
@@ -124,7 +124,7 @@ final class InitDataSource {
* Attach DataSourceAlert via service loader if present.
*/
private void attachAlert(DataSourceConfig dsConfig) {
DataSourceAlertFactory alertFactory = config.service(DataSourceAlertFactory.class);
DataSourceAlertFactory alertFactory = ServiceUtil.service(DataSourceAlertFactory.class);
if (alertFactory != null) {
dsConfig.setAlert(alertFactory.createAlert());
}
@@ -156,7 +156,7 @@ public final class InternalConfiguration {
this.clockService = new ClockService(config.getClock());
this.tableModState = new TableModState();
this.logManager = initLogManager();
this.docStoreFactory = initDocStoreFactory(config.service(DocStoreFactory.class));
this.docStoreFactory = initDocStoreFactory(service(DocStoreFactory.class));
this.jsonFactory = config.getJsonFactory();
this.clusterManager = clusterManager;
this.backgroundExecutor = backgroundExecutor;
@@ -191,8 +191,12 @@ public final class InternalConfiguration {
return new InternalConfigXmlMap(xmEbeans, config.getClassLoadConfig().getClassLoader());
}
private <S> S service(Class<S> cls) {
return ServiceUtil.service(cls);
}
private List<XmapEbean> readExternalMapping() {
final XmapService xmapService = config.service(XmapService.class);
final XmapService xmapService = service(XmapService.class);
if (xmapService == null) {
return Collections.emptyList();
}
@@ -201,7 +205,7 @@ public final class InternalConfiguration {
private SpiLogManager initLogManager() {
// allow plugin - i.e. capture executed SQL for testing/asserts
SpiLoggerFactory loggerFactory = config.service(SpiLoggerFactory.class);
SpiLoggerFactory loggerFactory = service(SpiLoggerFactory.class);
if (loggerFactory == null) {
loggerFactory = new DLoggerFactory();
}
@@ -336,7 +340,7 @@ public final class InternalConfiguration {
}
AutoTuneService createAutoTuneService(SpiEbeanServer server) {
final AutoTuneServiceProvider provider = config.service(AutoTuneServiceProvider.class);
final AutoTuneServiceProvider provider = service(AutoTuneServiceProvider.class);
return provider == null ? new NoAutoTuneService() : provider.create(server, config);
}
@@ -445,7 +449,7 @@ public final class InternalConfiguration {
if (!profilingConfig.isEnabled()) {
return new NoopProfileHandler();
}
SpiProfileHandler handler = config.service(SpiProfileHandler.class);
SpiProfileHandler handler = service(SpiProfileHandler.class);
if (handler == null) {
handler = new DefaultProfileHandler(profilingConfig);
}
@@ -533,7 +537,7 @@ public final class InternalConfiguration {
}
SlowQueryListener listener = config.getSlowQueryListener();
if (listener == null) {
listener = config.service(SlowQueryListener.class);
listener = service(SlowQueryListener.class);
if (listener == null) {
listener = new DefaultSlowQueryListener();
}
@@ -589,7 +593,7 @@ public final class InternalConfiguration {
}
ServerCacheFactory factory = serverCachePlugin.create(config, backgroundExecutor);
ServerCacheNotifyPlugin notifyPlugin = config.service(ServerCacheNotifyPlugin.class);
ServerCacheNotifyPlugin notifyPlugin = service(ServerCacheNotifyPlugin.class);
if (notifyPlugin != null) {
// plugin supplied so use that to send notifications
cacheNotify = notifyPlugin.create(config);
@@ -644,7 +648,7 @@ public final class InternalConfiguration {
* Return the DDL generator.
*/
public SpiDdlGenerator initDdlGenerator(SpiEbeanServer server) {
final SpiDdlGeneratorProvider service = config.service(SpiDdlGeneratorProvider.class);
final SpiDdlGeneratorProvider service = service(SpiDdlGeneratorProvider.class);
return service == null ? new NoopDdl() : service.generator(server);
}
@@ -0,0 +1,13 @@
package io.ebeaninternal.server.core;
import java.util.Iterator;
import java.util.ServiceLoader;
public final class ServiceUtil {
public static <S> S service(Class<S> cls) {
ServiceLoader<S> load = ServiceLoader.load(cls);
Iterator<S> serviceInstances = load.iterator();
return serviceInstances.hasNext() ? serviceInstances.next() : null;
}
}
@@ -17,6 +17,7 @@ import io.ebean.types.Inet;
import io.ebean.util.AnnotationUtil;
import io.ebeaninternal.api.DbOffline;
import io.ebeaninternal.api.GeoTypeProvider;
import io.ebeaninternal.server.core.ServiceUtil;
import io.ebeaninternal.server.core.bootup.BootupClasses;
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import org.joda.time.DateTime;
@@ -156,7 +157,7 @@ public final class DefaultTypeManager implements TypeManager {
}
private void loadGeoTypeBinder(DatabaseConfig config) {
final GeoTypeProvider provider = config.service(GeoTypeProvider.class);
final GeoTypeProvider provider = ServiceUtil.service(GeoTypeProvider.class);
if (provider != null) {
geoTypeBinder = provider.createBinder(config);
}