Search in sources :

Example 1 with GrailsConfigurationException

use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.

the class DefaultGrailsPlugin method evaluatePluginScopes.

private void evaluatePluginScopes() {
    // Damn I wish Java had closures
    pluginScopes = evaluateIncludeExcludeProperty(SCOPES, new Closure(this) {

        private static final long serialVersionUID = 1;

        @Override
        public Object call(Object arguments) {
            final String scopeName = ((String) arguments).toUpperCase();
            try {
                return BuildScope.valueOf(scopeName);
            } catch (IllegalArgumentException e) {
                throw new GrailsConfigurationException("Plugin " + this + " specifies invalid scope [" + scopeName + "]");
            }
        }
    });
    pluginEnvs = evaluateIncludeExcludeProperty(ENVIRONMENTS, new Closure(this) {

        private static final long serialVersionUID = 1;

        @Override
        public Object call(Object arguments) {
            String envName = (String) arguments;
            Environment env = Environment.getEnvironment(envName);
            if (env != null)
                return env.getName();
            return arguments;
        }
    });
}
Also used : GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) Environment(grails.util.Environment)

Example 2 with GrailsConfigurationException

use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.

the class ProfilingGrailsPluginManager method doDynamicMethods.

@Override
public void doDynamicMethods() {
    long time = System.currentTimeMillis();
    System.out.println("doWithDynamicMethods started");
    checkInitialised();
    // remove common meta classes just to be sure
    MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
    for (Class<?> COMMON_CLASS : COMMON_CLASSES) {
        registry.removeMetaClass(COMMON_CLASS);
    }
    for (GrailsPlugin plugin : pluginList) {
        if (plugin.supportsCurrentScopeAndEnvironment()) {
            try {
                long pluginTime = System.currentTimeMillis();
                System.out.println("doWithDynamicMethods for plugin [" + plugin.getName() + "] started");
                plugin.doWithDynamicMethods(applicationContext);
                System.out.println("doWithDynamicMethods for plugin [" + plugin.getName() + "] took " + (System.currentTimeMillis() - pluginTime));
            } catch (Throwable t) {
                throw new GrailsConfigurationException("Error configuring dynamic methods for plugin " + plugin + ": " + t.getMessage(), t);
            }
        }
    }
    System.out.println("doWithDynamicMethods took " + (System.currentTimeMillis() - time));
}
Also used : MetaClassRegistry(groovy.lang.MetaClassRegistry) GrailsPlugin(grails.plugins.GrailsPlugin) GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException)

Example 3 with GrailsConfigurationException

use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.

the class CorePluginFinder method loadCorePluginsFromResources.

@SuppressWarnings("rawtypes")
private void loadCorePluginsFromResources(Resource[] resources) throws IOException {
    LOG.debug("Attempting to load [" + resources.length + "] core plugins");
    try {
        SAXParser saxParser = SpringIOUtils.newSAXParser();
        for (Resource resource : resources) {
            InputStream input = null;
            try {
                input = resource.getInputStream();
                PluginHandler ph = new PluginHandler();
                saxParser.parse(input, ph);
                for (String pluginType : ph.pluginTypes) {
                    Class<?> pluginClass = attemptCorePluginClassLoad(pluginType);
                    if (pluginClass != null) {
                        addPlugin(pluginClass);
                        binaryDescriptors.put(pluginClass, new BinaryGrailsPluginDescriptor(resource, ph.pluginClasses));
                    }
                }
            } finally {
                if (input != null) {
                    input.close();
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    } catch (SAXException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    }
}
Also used : GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 4 with GrailsConfigurationException

use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.

the class DefaultGrailsPluginManager method doDynamicMethods.

@Override
public void doDynamicMethods() {
    checkInitialised();
    // remove common meta classes just to be sure
    MetaClassRegistry registry = GroovySystem.getMetaClassRegistry();
    for (Class<?> COMMON_CLASS : COMMON_CLASSES) {
        registry.removeMetaClass(COMMON_CLASS);
    }
    for (GrailsPlugin plugin : pluginList) {
        if (plugin.supportsCurrentScopeAndEnvironment()) {
            try {
                plugin.doWithDynamicMethods(applicationContext);
            } catch (Throwable t) {
                throw new GrailsConfigurationException("Error configuring dynamic methods for plugin " + plugin + ": " + t.getMessage(), t);
            }
        }
    }
}
Also used : MetaClassRegistry(groovy.lang.MetaClassRegistry) GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException)

Example 5 with GrailsConfigurationException

use of org.grails.core.exceptions.GrailsConfigurationException in project grails-core by grails.

the class DefaultGrailsApplication method addArtefact.

/**
     * Adds an artefact of the given type for the given GrailsClass.
     *
     * @param artefactType        The type of the artefact as defined by a ArtefactHandler instance
     * @param artefactGrailsClass A GrailsClass instance that matches the type defined by the ArtefactHandler
     * @return The GrailsClass if successful or null if it couldn't be added
     * @throws GrailsConfigurationException If the specified GrailsClass is not the same as the type defined by the ArtefactHandler
     * @see grails.core.ArtefactHandler
     */
public GrailsClass addArtefact(String artefactType, GrailsClass artefactGrailsClass) {
    ArtefactHandler handler = artefactHandlersByName.get(artefactType);
    if (handler.isArtefactGrailsClass(artefactGrailsClass)) {
        // Store the GrailsClass in cache
        DefaultArtefactInfo info = getArtefactInfo(artefactType, true);
        info.addGrailsClass(artefactGrailsClass);
        info.updateComplete();
        initializeArtefacts(artefactType);
        return artefactGrailsClass;
    }
    throw new GrailsConfigurationException("Cannot add " + artefactType + " class [" + artefactGrailsClass + "]. It is not a " + artefactType + "!");
}
Also used : GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler)

Aggregations

GrailsConfigurationException (org.grails.core.exceptions.GrailsConfigurationException)6 MetaClassRegistry (groovy.lang.MetaClassRegistry)2 DomainClassArtefactHandler (org.grails.core.artefact.DomainClassArtefactHandler)2 ArtefactAdditionEvent (grails.core.events.ArtefactAdditionEvent)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 Environment (grails.util.Environment)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1 SAXException (org.xml.sax.SAXException)1