Skip to content
Merged
26 changes: 15 additions & 11 deletions inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import jakarta.inject.Provider;
import org.jspecify.annotations.Nullable;

import io.avaje.applog.AppLog;
import io.avaje.config.Configuration;
import io.avaje.inject.spi.AvajeModule;
import io.avaje.inject.spi.Builder;
import io.avaje.inject.spi.ClosePair;
import io.avaje.inject.spi.ConfigPropertyPlugin;
import io.avaje.inject.spi.EnrichBean;
import io.avaje.inject.spi.ModuleOrdering;
import io.avaje.inject.spi.SuppliedBean;
import jakarta.inject.Provider;

/** Build a bean scope with options for shutdown hook and supplying test doubles. */
final class DBeanScopeBuilder implements BeanScopeBuilder.ForTesting {
Expand Down Expand Up @@ -220,16 +221,19 @@ private ConfigPropertyPlugin defaultPropertyPlugin() {
return detectAvajeConfig() ? new DConfigProps() : new DSystemProps();
}

private boolean detectAvajeConfig() {
if (ModuleLayer.boot().findModule("io.avaje.config").isPresent()) {
return true;
}
try {
Class.forName("io.avaje.config.Configuration", false, classLoader);
return true;
} catch (final ClassNotFoundException e) {
return false;
}
@SuppressWarnings("ConstantValue")
private static boolean detectAvajeConfig() {
var modules = ModuleLayer.boot();
return modules
.findModule("io.avaje.inject")
.map(m -> modules.findModule("io.avaje.config").isPresent())
.orElseGet(() -> {
try {
return Configuration.class != null;
} catch (NoClassDefFoundError e) {
return false;
}
});
}

private void initProfiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* Plugin interface which contains the application properties used for wiring. Used with
* {@link io.avaje.inject.RequiresProperty} and {@link io.avaje.inject.Profile}.
*
* <p>The plugin is loaded via ServiceLoader and defaults to an implementation that uses
* {@link System#getProperty(String)} and {@link System#getenv(String)}.
* @see InjectExtension
*/
@NullMarked
public interface ConfigPropertyPlugin extends InjectExtension {
Expand Down