Search in sources :

Example 16 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class DefaultGrailsPluginManagerTests method loadPlugins.

DefaultGrailsPluginManager loadPlugins(String firstClassString, String secondClassString, String thirdClassString, String fourthClassString) {
    GroovyClassLoader gcl = new GroovyClassLoader();
    first = gcl.parseClass(firstClassString);
    second = gcl.parseClass(secondClassString);
    third = gcl.parseClass(thirdClassString);
    fourth = gcl.parseClass(fourthClassString);
    GrailsApplication app = new DefaultGrailsApplication(new Class[] {}, gcl);
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.getDefaultListableBeanFactory().registerSingleton(GrailsApplication.APPLICATION_ID, app);
    DefaultGrailsPluginManager manager = new DefaultGrailsPluginManager(new Class[] { first, second, third, fourth }, app);
    manager.setParentApplicationContext(parent);
    manager.setPluginFilter(new IncludingPluginFilter(new String[] { "first", "second", "third", "fourth" }));
    manager.loadPlugins();
    return manager;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IncludingPluginFilter(org.grails.plugins.IncludingPluginFilter) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication)

Example 17 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class DefaultGrailsPluginManagerTests method testLoadPlugins.

@SuppressWarnings("rawtypes")
public void testLoadPlugins() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    first = gcl.parseClass("class FirstGrailsPlugin {\n" + "def version = 1.0\n" + "}");
    second = gcl.parseClass("class SecondGrailsPlugin {\n" + "def version = 1.0\n" + "def dependsOn = [first:version]\n" + "}");
    third = gcl.parseClass("import grails.util.GrailsUtil\n" + "class ThirdGrailsPlugin {\n" + "def version = GrailsUtil.getGrailsVersion()\n" + "def dependsOn = [i18n:version]\n" + "}");
    fourth = gcl.parseClass("class FourthGrailsPlugin {\n" + "def version = 1.0\n" + "def dependsOn = [second:version, third:version]\n" + "}");
    GrailsApplication app = new DefaultGrailsApplication(new Class[] {}, gcl);
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.getDefaultListableBeanFactory().registerSingleton(GrailsApplication.APPLICATION_ID, app);
    DefaultGrailsPluginManager manager = new DefaultGrailsPluginManager(new Class[] { first, second, third, fourth }, app);
    manager.setParentApplicationContext(parent);
    manager.setPluginFilter(new IncludingPluginFilter(new String[] { "dataSource", "first", "third" }));
    manager.loadPlugins();
    List pluginList = manager.getPluginList();
    assertNotNull(manager.getGrailsPlugin("dataSource"));
    assertNotNull(manager.getGrailsPlugin("first"));
    assertNotNull(manager.getGrailsPlugin("third"));
    //dataSource depends on core
    assertNotNull(manager.getGrailsPlugin("core"));
    //third depends on i18n
    assertNotNull(manager.getGrailsPlugin("third"));
    assertEquals("Expected plugins not loaded. Expected " + 5 + " but got " + pluginList, 5, pluginList.size());
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IncludingPluginFilter(org.grails.plugins.IncludingPluginFilter) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) List(java.util.List) ArrayList(java.util.ArrayList) DefaultGrailsApplication(grails.core.DefaultGrailsApplication)

Example 18 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class Holders method getGrailsApplication.

public static GrailsApplication getGrailsApplication() {
    GrailsApplication grailsApplication = findApplication();
    Assert.notNull(grailsApplication, "GrailsApplication not found");
    return grailsApplication;
}
Also used : GrailsApplication(grails.core.GrailsApplication)

Aggregations

GrailsApplication (grails.core.GrailsApplication)18 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)9 GrailsDomainClass (grails.core.GrailsDomainClass)8 GroovyClassLoader (groovy.lang.GroovyClassLoader)8 Map (java.util.Map)4 CollectionDataBindingSource (grails.databinding.CollectionDataBindingSource)3 IncludingPluginFilter (org.grails.plugins.IncludingPluginFilter)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 DataBindingSource (grails.databinding.DataBindingSource)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 GrailsClass (grails.core.GrailsClass)1 GrailsControllerClass (grails.core.GrailsControllerClass)1 DataBinder (grails.databinding.DataBinder)1 grails.gorm.validation (grails.gorm.validation)1 Constrained (grails.gorm.validation.Constrained)1 ValidationErrors (grails.validation.ValidationErrors)1 GrailsWebDataBinder (grails.web.databinding.GrailsWebDataBinder)1