Search in sources :

Example 1 with BeanManifest

use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.

the class BukkitCommandsI18nManifestTask method execute.

@Override
public void execute(OkaeriBukkitPlugin platform) {
    BeanManifest manifest = platform.getInjector().get("manifest", BeanManifest.class).orElseThrow(() -> new RuntimeException("Cannot hook i18n-platform-commands without manifest being present!"));
    ClassLoader classLoader = platform.getClass().getClassLoader();
    ComponentCreator creator = platform.getCreator();
    manifest.withDepend(BeanManifest.of(classLoader, I18nCommandsMessages.class, creator, false).name("i18n-platform-commands"));
}
Also used : ComponentCreator(eu.okaeri.platform.core.component.creator.ComponentCreator) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest)

Example 2 with BeanManifest

use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.

the class ListenerComponentResolver method make.

@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
    long start = System.currentTimeMillis();
    Class<?> manifestType = manifest.getType();
    Object instance = injector.createInstance(manifestType);
    Listener listener = (Listener) instance;
    this.plugin.getProxy().getPluginManager().registerListener(this.plugin, listener);
    long took = System.currentTimeMillis() - start;
    creator.log(ComponentHelper.buildComponentMessage().type("Added listener").name(listener.getClass().getSimpleName()).took(took).meta("methods", Arrays.stream(listener.getClass().getDeclaredMethods()).filter(method -> method.getAnnotation(EventHandler.class) != null).map(Method::getName).collect(Collectors.toList())).build());
    creator.increaseStatistics("listeners", 1);
    return listener;
}
Also used : Listener(net.md_5.bungee.api.plugin.Listener) Arrays(java.util.Arrays) Inject(eu.okaeri.injector.annotation.Inject) Component(eu.okaeri.platform.core.annotation.Component) NonNull(lombok.NonNull) Injector(eu.okaeri.injector.Injector) Collectors(java.util.stream.Collectors) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest) ComponentHelper(eu.okaeri.platform.core.component.ComponentHelper) ComponentCreator(eu.okaeri.platform.core.component.creator.ComponentCreator) ComponentResolver(eu.okaeri.platform.core.component.creator.ComponentResolver) Plugin(net.md_5.bungee.api.plugin.Plugin) EventHandler(net.md_5.bungee.event.EventHandler) Method(java.lang.reflect.Method) Listener(net.md_5.bungee.api.plugin.Listener) EventHandler(net.md_5.bungee.event.EventHandler) Method(java.lang.reflect.Method)

Example 3 with BeanManifest

use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.

the class RequestHandlerComponentResolver method make.

@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
    long start = System.currentTimeMillis();
    BeanManifest parent = manifest.getParent();
    Class<?> parentClass = parent.getType();
    Method method = manifest.getMethod();
    RequestHandlerMeta handlerMeta = RequestHandlerMeta.of(parentClass, method);
    int[] contextIndexes = handlerMeta.getContextIndexes();
    Map<Integer, Object[]> prefilledCallCache = new CacheMap<>(256);
    Handler handler = context -> {
        Object[] call = null;
        try {
            call = this.getCall(prefilledCallCache, handlerMeta, context, injector);
            method.invoke(parent.getObject(), call);
            this.flushCall(call, contextIndexes, handlerMeta);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
            this.logger.error("Handler (" + method + ") failure [" + Arrays.toString(call) + "]", exception);
        }
    };
    HandlerType handlerType = handlerMeta.getType();
    String handlerPath = handlerMeta.getPath();
    SimpleRouteRole[] handlerPermittedRoles = handlerMeta.getPermittedRoles();
    this.javalin.addHandler(handlerType, handlerPath, handler, handlerPermittedRoles);
    long took = System.currentTimeMillis() - start;
    creator.log(ComponentHelper.buildComponentMessage().type("Added handler").name(parentClass.getSimpleName() + "#" + method.getName()).took(took).meta("path", handlerPath).meta("type", handlerType).meta("permittedRoles", Arrays.stream(handlerPermittedRoles).map(SimpleRouteRole::getName).collect(Collectors.toList())).build());
    creator.increaseStatistics("handlers", 1);
    return handler;
}
Also used : Arrays(java.util.Arrays) Inject(eu.okaeri.injector.annotation.Inject) Logger(org.slf4j.Logger) NonNull(lombok.NonNull) RequestHandlerMeta(eu.okaeri.platform.web.meta.RequestHandlerMeta) Injector(eu.okaeri.injector.Injector) Javalin(io.javalin.Javalin) SimpleRouteRole(eu.okaeri.platform.web.meta.role.SimpleRouteRole) HandlerType(io.javalin.http.HandlerType) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Handler(io.javalin.http.Handler) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest) ComponentHelper(eu.okaeri.platform.core.component.ComponentHelper) RequestHandlerHelper(eu.okaeri.platform.web.meta.RequestHandlerHelper) ComponentCreator(eu.okaeri.platform.core.component.creator.ComponentCreator) Context(io.javalin.http.Context) Parameter(java.lang.reflect.Parameter) OkaeriInjector(eu.okaeri.injector.OkaeriInjector) Map(java.util.Map) ComponentResolver(eu.okaeri.platform.core.component.creator.ComponentResolver) CacheMap(eu.okaeri.commons.cache.CacheMap) PathParamMeta(eu.okaeri.platform.web.meta.PathParamMeta) Method(java.lang.reflect.Method) HandlerType(io.javalin.http.HandlerType) Handler(io.javalin.http.Handler) Method(java.lang.reflect.Method) SimpleRouteRole(eu.okaeri.platform.web.meta.role.SimpleRouteRole) RequestHandlerMeta(eu.okaeri.platform.web.meta.RequestHandlerMeta) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest) CacheMap(eu.okaeri.commons.cache.CacheMap)

Example 4 with BeanManifest

use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.

the class BeanManifestExecuteTask method execute.

@Override
public void execute(OkaeriPlatform platform) {
    // find manifest
    BeanManifest beanManifest = platform.getInjector().get("manifest", BeanManifest.class).orElseThrow(() -> new RuntimeException("Cannot execute manifest without manifest being present!"));
    // resolve resource provider
    ExternalResourceProvider resourceProvider = platform.getInjector().get("externalResourceProvider", ExternalResourceProvider.class).orElse(NULL_RESOURCE_PROVIDER);
    // execute component tree and register everything
    beanManifest.execute(platform.getCreator(), platform.getInjector(), resourceProvider);
    // sub-components do not require manual injecting because
    // these are filled at the initialization by the DI itself
    // plugin instance however is not, so here it goes
    ComponentHelper.injectComponentFields(platform, platform.getInjector());
    // call PostConstruct
    ComponentHelper.invokePostConstruct(platform, platform.getInjector());
}
Also used : ExternalResourceProvider(eu.okaeri.platform.core.component.ExternalResourceProvider) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest)

Example 5 with BeanManifest

use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.

the class ListenerComponentResolver method make.

@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
    long start = System.currentTimeMillis();
    Class<?> manifestType = manifest.getType();
    Object instance = injector.createInstance(manifestType);
    Listener listener = (Listener) instance;
    this.plugin.getServer().getPluginManager().registerEvents(listener, this.plugin);
    long took = System.currentTimeMillis() - start;
    creator.log(ComponentHelper.buildComponentMessage().type("Added listener").name(listener.getClass().getSimpleName()).took(took).meta("methods", Arrays.stream(listener.getClass().getDeclaredMethods()).filter(method -> method.getAnnotation(EventHandler.class) != null).map(Method::getName).collect(Collectors.toList())).build());
    creator.increaseStatistics("listeners", 1);
    return listener;
}
Also used : Arrays(java.util.Arrays) Inject(eu.okaeri.injector.annotation.Inject) Component(eu.okaeri.platform.core.annotation.Component) NonNull(lombok.NonNull) Injector(eu.okaeri.injector.Injector) Collectors(java.util.stream.Collectors) EventHandler(org.bukkit.event.EventHandler) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) BeanManifest(eu.okaeri.platform.core.component.manifest.BeanManifest) ComponentHelper(eu.okaeri.platform.core.component.ComponentHelper) ComponentCreator(eu.okaeri.platform.core.component.creator.ComponentCreator) ComponentResolver(eu.okaeri.platform.core.component.creator.ComponentResolver) Method(java.lang.reflect.Method) Listener(org.bukkit.event.Listener) Listener(org.bukkit.event.Listener) EventHandler(org.bukkit.event.EventHandler) Method(java.lang.reflect.Method)

Aggregations

BeanManifest (eu.okaeri.platform.core.component.manifest.BeanManifest)9 ComponentCreator (eu.okaeri.platform.core.component.creator.ComponentCreator)7 Injector (eu.okaeri.injector.Injector)6 Inject (eu.okaeri.injector.annotation.Inject)6 ComponentHelper (eu.okaeri.platform.core.component.ComponentHelper)6 ComponentResolver (eu.okaeri.platform.core.component.creator.ComponentResolver)6 Method (java.lang.reflect.Method)6 Collectors (java.util.stream.Collectors)6 NonNull (lombok.NonNull)6 ConfigManager (eu.okaeri.configs.ConfigManager)3 Configurer (eu.okaeri.configs.configurer.Configurer)3 OkaeriSerdesPack (eu.okaeri.configs.serdes.OkaeriSerdesPack)3 LocaleConfig (eu.okaeri.i18n.configs.LocaleConfig)3 LocaleConfigManager (eu.okaeri.i18n.configs.LocaleConfigManager)3 LocaleProvider (eu.okaeri.i18n.provider.LocaleProvider)3 ConfigurerProvider (eu.okaeri.persistence.document.ConfigurerProvider)3 Placeholders (eu.okaeri.placeholders.Placeholders)3 Messages (eu.okaeri.platform.core.annotation.Messages)3 PlaceholdersFactory (eu.okaeri.platform.core.placeholder.PlaceholdersFactory)3 java.io (java.io)3