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

Rename Pico Module #6682

Merged
merged 2 commits into from
Apr 25, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nima/webserver/webserver/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.helidon.common.features.api.Feature;
import io.helidon.common.features.api.HelidonFlavor;
import io.helidon.nima.webserver.http.spi.SinkProvider;
import io.helidon.pico.api.ModuleComponent;

/**
* Loom based WebServer.
Expand Down Expand Up @@ -72,5 +73,5 @@
uses SinkProvider;

provides io.helidon.nima.webserver.spi.ServerConnectionProvider with io.helidon.nima.webserver.http1.Http1ConnectionProvider;
provides io.helidon.pico.api.Module with io.helidon.nima.webserver.Pico$$Module;
provides ModuleComponent with io.helidon.nima.webserver.Pico$$Module;
}
2 changes: 1 addition & 1 deletion pico/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Request and Session scopes are simply not made available in Pico. We believe tha
* Dependency - An <i>injection point</i> represents what is considered to be a dependency, perhaps <i>qualified</i> or Optional, on another service or contract. This is just another what to describe an <i>injection point</i>.
* Activator (aka ServiceProvider) - This is what is code generated by Pico to lazily activate your <i>service</i> instance(s) in the Pico <i>services registry</i>, and it handles resolving all <i>dependencies</i> it has, along with <i>inject</i>ing the fields, methods, etc. that are required to be satisfied as part of that activation process.
* Services (aka services registry) - This is the collection of all services that are known to the JVM/runtime in Pico.
* Module - This is where your application will "bind" services into the <i>services registry</i> - typically code generated, and typically with one module per jar/module in your application.
* ModuleComponent - This is where your application will "bind" services into the <i>services registry</i> - typically code generated, and typically with one module per jar/module in your application.
* Application - The fully realized set of modules and services/service providers that constitute your application, and code-generated using <b>Helidon Pico Tooling</b>.

## Getting Started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* <p>
* Note: instances of this type are not eligible for injection.
*
* @see Module
* @see ModuleComponent
*/
@Contract
public interface Application extends OptionallyNamed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @see Application
*/
@Contract
public interface Module extends OptionallyNamed {
public interface ModuleComponent extends OptionallyNamed {

/**
* Called by the provider implementation at bootstrapping time to bind all services / service providers to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,25 @@ public boolean usesCompileTimeApplications() {


/**
* The key that controls whether any {@link io.helidon.pico.api.Module}'s
* The key that controls whether any {@link io.helidon.pico.api.ModuleComponent}'s
* (typically produced at compile-time by Pico tooling) can be discovered and is used during Pico startup processing. It is
* strongly suggested for developers to adopt a compile-time strategy for producing the dependency/injection model as it will
* lead to faster startup times as well as be deterministic and validated during compile-time instead of at runtime.
*/
public static final String KEY_USES_COMPILE_TIME_MODULES = "uses-compile-time-modules";
/**
* The default value for this is true, meaning that the Pico will attempt to find and use {@link io.helidon.pico.api.Module} code
* The default value for this is true, meaning that the Pico will attempt to find and use {@link io.helidon.pico.api.ModuleComponent} code
* generated during compile-time (see Pico's APT <i>processor</i> and <i>maven-plugin</i> modules for usage).
*/
public static final String DEFAULT_USES_COMPILE_TIME_MODULES = "true";

/**
* Flag indicating whether compile-time generated {@link io.helidon.pico.api.Module}'s should be used at Pico's startup
* Flag indicating whether compile-time generated {@link io.helidon.pico.api.ModuleComponent}'s should be used at Pico's startup
* initialization. Setting this value to false will have no affect if the underlying provider does not support compile-time
* generation via {@link #supportsCompileTime()}.
*
* @return the flag indicating whether the provider is permitted to use Application generated code from compile-time
* @see io.helidon.pico.api.Module
* @see ModuleComponent
* @see io.helidon.pico.api.Activator
*/
@ConfiguredOption(key = KEY_USES_COMPILE_TIME_MODULES, value = DEFAULT_USES_COMPILE_TIME_MODULES)
Expand All @@ -310,7 +310,7 @@ public boolean usesCompileTimeModules() {
* The key that represents whether the provider supports compile-time code generation of DI artifacts.
*
* @see io.helidon.pico.api.Application
* @see io.helidon.pico.api.Module
* @see io.helidon.pico.api.ModuleComponent
* @see io.helidon.pico.api.Activator
* @see #usesCompileTimeApplications()
* @see #usesCompileTimeModules()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public interface ServiceProvider<T> extends InjectionPointProvider<T>, Weighted
* The agent/instance to be used for binding this service provider to the pico application that was code generated.
*
* @return the service provider that should be used for binding, or empty if this provider does not support binding
* @see Module
* @see ModuleComponent
* @see ServiceBinder
* @see ServiceProviderBindable
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* and thereby works in conjunction with the {@link ServiceBinder} during pico service registry
* initialization.
* <p>
* The only guarantee the provider implementation has is ensuring that {@link Module} instances
* The only guarantee the provider implementation has is ensuring that {@link ModuleComponent} instances
* are bound to the pico services instances, as well as informed on the module name.
* <p>
* Generally this class should be called internally by the framework, and typically occurs only during initialization sequences.
Expand All @@ -36,7 +36,7 @@ public interface ServiceProviderBindable<T> extends ServiceProvider<T> {

/**
* Called to inform a service provider the module name it is bound to. Will only be called when there is a non-null
* module name associated for the given {@link Module}. A service provider can be associated with
* module name associated for the given {@link ModuleComponent}. A service provider can be associated with
* 0..1 modules.
*
* @param moduleName the non-null module name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import io.helidon.pico.api.CallingContextFactory;
import io.helidon.pico.api.DefaultCallingContext;
import io.helidon.pico.api.DefaultServiceInfoCriteria;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.PicoServices;
import io.helidon.pico.api.PicoServicesConfig;
import io.helidon.pico.api.ServiceProvider;
Expand Down Expand Up @@ -143,9 +143,9 @@ String getThisModuleName() {
return moduleName;
}

ServiceProvider<Module> lookupThisModule(String name,
Services services) {
return services.lookupFirst(Module.class, name, false).orElseThrow(() -> noModuleFoundError(name));
ServiceProvider<ModuleComponent> lookupThisModule(String name,
Services services) {
return services.lookupFirst(ModuleComponent.class, name, false).orElseThrow(() -> noModuleFoundError(name));
}

String getClassPrefixName() {
Expand Down Expand Up @@ -260,7 +260,9 @@ protected void innerExecute() {
ApplicationCreator creator = applicationCreator();

List<ServiceProvider<?>> allModules = services
.lookupAll(DefaultServiceInfoCriteria.builder().addContractImplemented(Module.class.getName()).build());
.lookupAll(DefaultServiceInfoCriteria.builder()
.addContractImplemented(ModuleComponent.class.getName())
.build());
getLog().info("processing modules: " + toDescriptions(allModules));
if (allModules.isEmpty()) {
warn("no modules to process");
Expand All @@ -284,7 +286,7 @@ protected void innerExecute() {
? moduleInfoPathRef.get().getPath()
: null;
String moduleInfoModuleName = getThisModuleName();
ServiceProvider<Module> moduleSp = lookupThisModule(moduleInfoModuleName, services);
ServiceProvider<ModuleComponent> moduleSp = lookupThisModule(moduleInfoModuleName, services);
String packageName = determinePackageName(Optional.ofNullable(moduleSp), serviceTypeNames, descriptor, true);

CodeGenPaths codeGenPaths = DefaultCodeGenPaths.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import io.helidon.common.types.DefaultTypeName;
import io.helidon.common.types.TypeName;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.PicoServicesConfig;
import io.helidon.pico.api.ServiceProvider;
import io.helidon.pico.tools.AbstractCreator;
Expand Down Expand Up @@ -264,7 +264,7 @@ public void execute() throws MojoExecutionException {
* @param persistIt pass true to write it to scratch, so that we can use it in the future for this module
* @return the package name (which also typically doubles as the application name)
*/
protected String determinePackageName(Optional<ServiceProvider<Module>> optModuleSp,
protected String determinePackageName(Optional<ServiceProvider<ModuleComponent>> optModuleSp,
Collection<TypeName> typeNames,
ModuleInfoDescriptor descriptor,
boolean persistIt) {
Expand All @@ -276,7 +276,7 @@ protected String determinePackageName(Optional<ServiceProvider<Module>> optModul
return packageName;
}

ServiceProvider<Module> moduleSp = optModuleSp.orElse(null);
ServiceProvider<ModuleComponent> moduleSp = optModuleSp.orElse(null);
if (moduleSp != null) {
packageName = DefaultTypeName.createFromTypeName(moduleSp.serviceInfo().serviceTypeName()).packageName();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import static io.helidon.pico.maven.plugin.MavenPluginUtils.externalModuleCreator;

/**
* Responsible for creating pico {@link io.helidon.pico.api.Activator}'s and a {@link io.helidon.pico.api.Module}
* Responsible for creating pico {@link io.helidon.pico.api.Activator}'s and a {@link io.helidon.pico.api.ModuleComponent}
* wrapping a set of packages from an external third-party jar.
*/
@Mojo(name = "external-module-create", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import io.helidon.pico.api.Injector;
import io.helidon.pico.api.InjectorOptions;
import io.helidon.pico.api.Metrics;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.Phase;
import io.helidon.pico.api.PicoException;
import io.helidon.pico.api.PicoServices;
Expand All @@ -75,7 +75,7 @@ class DefaultPicoServices implements PicoServices, Resettable {
private final AtomicBoolean initializingServicesFinished = new AtomicBoolean(false);
private final AtomicBoolean isBinding = new AtomicBoolean(false);
private final AtomicReference<DefaultServices> services = new AtomicReference<>();
private final AtomicReference<List<Module>> moduleList = new AtomicReference<>();
private final AtomicReference<List<ModuleComponent>> moduleList = new AtomicReference<>();
private final AtomicReference<List<Application>> applicationList = new AtomicReference<>();
private final Bootstrap bootstrap;
private final PicoServicesConfig cfg;
Expand Down Expand Up @@ -303,7 +303,7 @@ private void initializeServices() {

if (isGlobal) {
// iterate over all modules, binding to each one's set of services, but with NO activations
List<Module> modules = findModules(true);
List<ModuleComponent> modules = findModules(true);
try {
isBinding.set(true);
bindModules(thisServices, modules);
Expand Down Expand Up @@ -372,16 +372,16 @@ private List<Application> findApplications(boolean load) {
return result;
}

private List<Module> findModules(boolean load) {
List<Module> result = moduleList.get();
private List<ModuleComponent> findModules(boolean load) {
List<ModuleComponent> result = moduleList.get();
if (result != null) {
return result;
}

result = new ArrayList<>();
if (load) {
ServiceLoader<Module> serviceLoader = ServiceLoader.load(Module.class);
for (Module module : serviceLoader) {
ServiceLoader<ModuleComponent> serviceLoader = ServiceLoader.load(ModuleComponent.class);
for (ModuleComponent module : serviceLoader) {
result.add(module);
}

Expand Down Expand Up @@ -413,14 +413,14 @@ private void bindApplications(DefaultServices services,
}

private void bindModules(DefaultServices services,
Collection<Module> modules) {
Collection<ModuleComponent> modules) {
if (!cfg.usesCompileTimeModules()) {
LOGGER.log(System.Logger.Level.DEBUG, "module binding is disabled");
return;
}

if (modules.isEmpty()) {
LOGGER.log(System.Logger.Level.WARNING, "no " + Module.class.getName() + " was found.");
LOGGER.log(System.Logger.Level.WARNING, "no " + ModuleComponent.class.getName() + " was found.");
} else {
modules.forEach(module -> services.bind(this, module, isBinding.get()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import io.helidon.pico.api.InjectionException;
import io.helidon.pico.api.Intercepted;
import io.helidon.pico.api.Metrics;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.Phase;
import io.helidon.pico.api.PicoException;
import io.helidon.pico.api.PicoServices;
Expand Down Expand Up @@ -460,7 +460,7 @@ void bind(PicoServices picoServices,
}

void bind(PicoServices picoServices,
Module module,
ModuleComponent module,
boolean initializing) {
String moduleName = module.named().orElse(module.getClass().getName());
boolean isLoggable = DefaultPicoServices.LOGGER.isLoggable(System.Logger.Level.TRACE);
Expand All @@ -475,7 +475,7 @@ void bind(PicoServices picoServices,
}
}

private ServiceProvider<?> createServiceProvider(Module module,
private ServiceProvider<?> createServiceProvider(ModuleComponent module,
String moduleName,
PicoServices picoServices) {
return new PicoModuleServiceProvider(module, moduleName, picoServices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@

import io.helidon.pico.api.DefaultQualifierAndValue;
import io.helidon.pico.api.DefaultServiceInfo;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.PicoServices;
import io.helidon.pico.api.ServiceInfo;

/**
* Basic {@link io.helidon.pico.api.Module} implementation. A Pico module is-a service provider also.
* Basic {@link ModuleComponent} implementation. A Pico module is-a service provider also.
*/
class PicoModuleServiceProvider extends AbstractServiceProvider<Module> {
class PicoModuleServiceProvider extends AbstractServiceProvider<ModuleComponent> {

PicoModuleServiceProvider(Module module,
PicoModuleServiceProvider(ModuleComponent module,
String moduleName,
PicoServices picoServices) {
super(module, PicoServices.terminalActivationPhase(), createServiceInfo(module, moduleName), picoServices);
serviceRef(module);
}

static ServiceInfo createServiceInfo(Module module,
static ServiceInfo createServiceInfo(ModuleComponent module,
String moduleName) {
DefaultServiceInfo.Builder builder = DefaultServiceInfo.builder()
.serviceTypeName(module.getClass().getName())
.addContractsImplemented(Module.class.getName());
.addContractsImplemented(ModuleComponent.class.getName());
if (moduleName != null) {
builder.moduleName(moduleName)
.addQualifier(DefaultQualifierAndValue.createNamed(moduleName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.helidon.pico.api.Application;
import io.helidon.pico.api.DependenciesInfo;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.ServiceInfo;
import io.helidon.pico.api.ServiceProvider;

Expand All @@ -48,7 +48,7 @@ public static boolean isQualifiedInjectionTarget(ServiceProvider<?> sp) {
DependenciesInfo deps = sp.dependencies();
return (deps != AbstractServiceProvider.NO_DEPS)
|| (!contractsImplemented.isEmpty()
&& !contractsImplemented.contains(Module.class.getName())
&& !contractsImplemented.contains(ModuleComponent.class.getName())
&& !contractsImplemented.contains(Application.class.getName()));
}

Expand Down
2 changes: 1 addition & 1 deletion pico/runtime/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
provides io.helidon.pico.spi.PicoServicesProvider
with io.helidon.pico.runtime.DefaultPicoServicesProvider;

uses io.helidon.pico.api.Module;
uses io.helidon.pico.api.ModuleComponent;
uses io.helidon.pico.api.Application;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.helidon.pico.api.DefaultBootstrap;
import io.helidon.pico.api.DefaultInjectorOptions;
import io.helidon.pico.api.Injector;
import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.Phase;
import io.helidon.pico.api.PicoServices;
import io.helidon.pico.api.PicoServicesConfig;
Expand Down Expand Up @@ -91,7 +91,7 @@ void tearDown() {
void sanity() {
Services services = PicoServices.realizedServices();

List<ServiceProvider<Module>> moduleProviders = services.lookupAll(Module.class);
List<ServiceProvider<ModuleComponent>> moduleProviders = services.lookupAll(ModuleComponent.class);
assertThat(moduleProviders.size(),
equalTo(EXPECTED_MODULES));
List<String> descriptions = ServiceUtils.toDescriptions(moduleProviders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.helidon.pico.runtime.testsubjects;

import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.ServiceBinder;

import jakarta.inject.Singleton;
Expand All @@ -25,7 +25,7 @@
* For testing.
*/
@Singleton
public final class EmptyModule implements Module {
public final class EmptyModule implements ModuleComponent {

@Override
public void configure(ServiceBinder binder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Optional;

import io.helidon.pico.api.Module;
import io.helidon.pico.api.ModuleComponent;
import io.helidon.pico.api.ServiceBinder;

import jakarta.annotation.Generated;
Expand All @@ -28,7 +28,7 @@
@Generated(value = "example", comments = "API Version: n")
@Singleton
@Named(HelloPico$$Module.NAME)
public final class HelloPico$$Module implements Module {
public final class HelloPico$$Module implements ModuleComponent {

public static final String NAME = "example";

Expand Down
2 changes: 1 addition & 1 deletion pico/tests/resources-pico/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
exports io.helidon.pico.tests.pico.stacking;
exports io.helidon.pico.tests.pico.tbox;

provides io.helidon.pico.api.Module with io.helidon.pico.tests.pico.Pico$$Module;
provides io.helidon.pico.api.ModuleComponent with io.helidon.pico.tests.pico.Pico$$Module;
provides io.helidon.pico.api.Application with io.helidon.pico.tests.pico.Pico$$Application;
}
Loading