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

This commit is contained in:
Rob Bygrave authored and GitHub committed 2021-09-21 14:37:51 +12:00
1 parent b450227b13
commit 0bf8c9eb64
43 files changed
+390 -222

No files matched your search

@@ -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);
}
@@ -0,0 +1,63 @@
module io.ebean.core {
uses io.ebean.plugin.Plugin;
uses io.ebean.cache.ServerCachePlugin;
uses io.ebean.cache.ServerCacheNotifyPlugin;
uses io.ebean.config.DatabaseConfigProvider;
uses io.ebean.config.ServerConfigProvider;
uses io.ebean.config.ModuleInfoLoader;
uses io.ebean.datasource.DataSourceAlertFactory;
uses io.ebean.core.type.ExtraTypeFactory;
uses io.ebeanservice.docstore.api.DocStoreFactory;
uses io.ebean.migration.auto.AutoMigrationRunner;
uses io.avaje.classpath.scanner.ClassPathScannerFactory;
uses io.ebeaninternal.api.SpiLoggerFactory;
uses io.ebeaninternal.api.GeoTypeProvider;
uses io.ebeaninternal.api.SpiDdlGeneratorProvider;
uses io.ebeaninternal.xmapping.api.XmapService;
uses io.ebeaninternal.server.autotune.AutoTuneServiceProvider;
uses io.ebeaninternal.server.cluster.ClusterBroadcastFactory;
requires transitive io.ebean.api;
requires transitive io.ebean.migration.auto;
requires transitive io.ebean.xmapping.api;
requires transitive io.ebean.core.type;
requires transitive io.ebean.ddl.runner;
requires transitive org.antlr.antlr4.runtime;
requires io.avaje.classpath.scanner;
requires io.ebean.types;
requires org.slf4j;
requires static io.avaje.jsr305x;
requires static com.fasterxml.jackson.core;
requires static com.fasterxml.jackson.databind;
requires static jakarta.validation;
requires static java.transaction;
requires static java.naming;
requires static java.validation;
requires static org.postgresql.jdbc;
requires static joda.time;
exports io.ebeaninternal.api;
exports io.ebeaninternal.server.cache;
// export these for io.ebean.ddl.generator (but that becomes unnamed module in maven test scope)
exports io.ebeaninternal.server.deploy;
exports io.ebeaninternal.server.deploy.visitor;
// exports io.ebeaninternal.server.deploy to io.ebean.autotune, io.ebean.ddl.generator;
// exports io.ebeaninternal.server.deploy.visitor to io.ebean.ddl.generator;
exports io.ebeaninternal.server.el to io.ebean.autotune;
exports io.ebeaninternal.server.autotune to io.ebean.autotune;
exports io.ebeaninternal.server.querydefn to io.ebean.autotune, io.ebean.querybean;
exports io.ebeaninternal.server.type to io.ebean.postgis;
exports io.ebeaninternal.server.util to io.ebean.querybean;
exports io.ebeaninternal.server.expression to io.ebean.querybean;
provides io.ebean.metric.MetricFactory with io.ebeaninternal.server.profile.DMetricFactory;
provides io.ebean.service.SpiContainerFactory with io.ebeaninternal.server.DContainerFactory;
provides io.ebean.service.SpiFetchGroupService with io.ebeaninternal.server.query.DFetchGroupService;
provides io.ebean.service.SpiJsonService with io.ebeaninternal.json.DJsonService;
provides io.ebean.service.SpiProfileLocationFactory with io.ebeaninternal.server.profile.DProfileLocationFactory;
provides io.ebean.service.SpiRawSqlService with io.ebeaninternal.server.rawsql.DRawSqlService;
}
@@ -1,27 +0,0 @@
Manifest-Version: 1.0
Premain-Class: io.ebean.enhance.agent.Transformer
Automatic-Module-Name: io.ebean.core
Bundle-ManifestVersion: 2
Bundle-Name: Ebean-ORM
Bundle-SymbolicName: io.ebean
Bundle-Version: 4.2.0
Bundle-ClassPath: .
Bundle-Vendor: avaje
Export-Package: io.ebean,
io.ebean.annotation,
io.ebean.bean,
io.ebean.cache,
io.ebean.common,
io.ebean.config,
io.ebean.config.dbplatform,
io.ebean.event,
io.ebean.meta,
io.ebean.text,
io.ebean.text.csv,
io.ebean.text.json,
io.ebean.util
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.slf4j.api;bundle-version="1.7.2"
Import-Package: javax.persistence;version="2.0.0"