Search in sources :

Example 1 with MetaModule

use of io.crnk.meta.MetaModule in project crnk-framework by crnk-project.

the class TSGeneratorTest method setup.

@Before
public void setup() {
    Project project = Mockito.mock(Project.class);
    TSGeneratorExtension config = new TSGeneratorExtension(project, null);
    File outputDir = testProjectDir.getRoot();
    MetaModuleConfig metaConfig = new MetaModuleConfig();
    metaConfig.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(metaConfig);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new EmptyServiceDiscovery());
    boot.addModule(metaModule);
    boot.boot();
    generator = new TSGenerator(outputDir, metaModule.getLookup(), config);
}
Also used : Project(org.gradle.api.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) File(java.io.File) MetaModule(io.crnk.meta.MetaModule) TSGeneratorExtension(io.crnk.gen.typescript.TSGeneratorExtension) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) Before(org.junit.Before)

Example 2 with MetaModule

use of io.crnk.meta.MetaModule in project crnk-framework by crnk-project.

the class MetaModuleProducer method createMetaModule.

@Produces
@ApplicationScoped
public MetaModule createMetaModule() {
    MetaModuleConfig metaConfig = new MetaModuleConfig();
    metaConfig.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(metaConfig);
    return metaModule;
}
Also used : ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) MetaModule(io.crnk.meta.MetaModule) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 3 with MetaModule

use of io.crnk.meta.MetaModule in project crnk-framework by crnk-project.

the class AbstractMetaJerseyTest method createModule.

public MetaModule createModule() {
    MetaModule module = MetaModule.create();
    module.addMetaProvider(new ResourceMetaProvider());
    return module;
}
Also used : ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) MetaModule(io.crnk.meta.MetaModule)

Example 4 with MetaModule

use of io.crnk.meta.MetaModule in project crnk-framework by crnk-project.

the class CdiRunner method run.

public void run(GeneratorTrigger context) throws IOException {
    Weld weld = new Weld();
    try {
        weld.setClassLoader(context.getClassLoader());
        weld.initialize();
        CrnkBoot boot = new CrnkBoot();
        boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://<generator>"));
        boot.boot();
        ModuleRegistry moduleRegistry = boot.getModuleRegistry();
        Optional<MetaModule> optionalModule = moduleRegistry.getModule(MetaModule.class);
        if (!optionalModule.isPresent()) {
            throw new IllegalStateException("add MetaModule to CDI setup, got: " + moduleRegistry.getModules() + " with " + boot.getServiceDiscovery());
        }
        MetaModule metaModule = optionalModule.get();
        MetaLookup lookup = metaModule.getLookup();
        context.generate(lookup);
    } finally {
        weld.shutdown();
    }
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) MetaLookup(io.crnk.meta.MetaLookup) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) MetaModule(io.crnk.meta.MetaModule) Weld(org.jboss.weld.environment.se.Weld)

Example 5 with MetaModule

use of io.crnk.meta.MetaModule in project crnk-framework by crnk-project.

the class SpringRunner method run.

public void run(GeneratorTrigger context) {
    SpringRuntimeConfig springConfig = context.getConfig().getRuntime().getSpring();
    if (springConfig.getConfiguration() == null) {
        throw new IllegalStateException("typescriptGen.runtime.spring.configuration not specified");
    }
    if (springConfig.getProfile() == null) {
        throw new IllegalStateException("typescriptGen.runtime.spring.profile not specified");
    }
    ConfigurableApplicationContext applicationContext = null;
    try {
        Class configurationClass = getClass().getClassLoader().loadClass(springConfig.getConfiguration());
        String initializerMethodName = springConfig.getInitializerMethod();
        if (initializerMethodName != null) {
            Method initializerMethod = configurationClass.getMethod(initializerMethodName);
            initializerMethod.invoke(configurationClass);
        }
        SpringApplication application = new SpringApplication(configurationClass);
        application.setWebEnvironment(false);
        application.setAdditionalProfiles(springConfig.getProfile());
        application.setDefaultProperties(springConfig.getDefaultProperties());
        applicationContext = application.run();
        MetaModule metaModule = applicationContext.getBean(MetaModule.class);
        MetaLookup lookup = metaModule.getLookup();
        context.generate(lookup);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    } catch (NoSuchMethodException e) {
        throw new IllegalStateException(e);
    } catch (InvocationTargetException e) {
        throw new IllegalStateException(e);
    } finally {
        if (applicationContext != null) {
            applicationContext.close();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MetaLookup(io.crnk.meta.MetaLookup) SpringApplication(org.springframework.boot.SpringApplication) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MetaModule(io.crnk.meta.MetaModule)

Aggregations

MetaModule (io.crnk.meta.MetaModule)10 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)8 CrnkBoot (io.crnk.core.boot.CrnkBoot)5 Before (org.junit.Before)5 MetaModuleConfig (io.crnk.meta.MetaModuleConfig)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)3 CrnkClient (io.crnk.client.CrnkClient)2 EmptyServiceDiscovery (io.crnk.core.module.discovery.EmptyServiceDiscovery)2 MetaLookup (io.crnk.meta.MetaLookup)2 TestModule (io.crnk.test.mock.TestModule)2 IOException (java.io.IOException)2 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 TSGeneratorConfig (io.crnk.gen.typescript.TSGeneratorConfig)1 TSGeneratorExtension (io.crnk.gen.typescript.TSGeneratorExtension)1 TSGenerator (io.crnk.gen.typescript.internal.TSGenerator)1 JpaModule (io.crnk.jpa.JpaModule)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1