Search in sources :

Example 1 with PluginException

use of grails.plugins.exceptions.PluginException in project grails-core by grails.

the class DefaultGrailsPluginTests method testDefaultGrailsPlugin.

public void testDefaultGrailsPlugin() {
    @SuppressWarnings("unused") GrailsPlugin versionPlugin = new DefaultGrailsPlugin(versioned, ga);
    try {
        @SuppressWarnings("unused") GrailsPlugin notVersionPlugin = new DefaultGrailsPlugin(notVersion, ga);
        fail("Should have thrown IllegalArgumentException for unversioned plugin");
    } catch (PluginException e) {
    // expected
    }
    try {
        @SuppressWarnings("unused") GrailsPlugin notPlugin = new DefaultGrailsPlugin(notPluginClass, ga);
        fail("Should have thrown an exception for invalid plugin");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : GrailsPlugin(grails.plugins.GrailsPlugin) DefaultGrailsPlugin(org.grails.plugins.DefaultGrailsPlugin) PluginException(grails.plugins.exceptions.PluginException) DefaultGrailsPlugin(org.grails.plugins.DefaultGrailsPlugin)

Example 2 with PluginException

use of grails.plugins.exceptions.PluginException in project grails-core by grails.

the class BinaryGrailsPlugin method initializeViewMap.

protected void initializeViewMap(BinaryGrailsPluginDescriptor descriptor) {
    final Resource descriptorResource = descriptor.getResource();
    Resource viewsPropertiesResource = null;
    try {
        viewsPropertiesResource = descriptorResource.createRelative(VIEWS_PROPERTIES);
    } catch (IOException e) {
    // ignore
    }
    if (viewsPropertiesResource == null || !viewsPropertiesResource.exists()) {
        try {
            String urlString = descriptorResource.getURL().toString();
            if (urlString.endsWith(PLUGIN_DESCRIPTOR_PATH)) {
                urlString = urlString.substring(0, urlString.length() - PLUGIN_DESCRIPTOR_PATH.length());
                URL newUrl = new URL(urlString + RELATIVE_VIEWS_PROPERTIES);
                viewsPropertiesResource = new UrlResource(newUrl);
            }
        } catch (IOException e) {
        // ignore
        }
    }
    if (viewsPropertiesResource == null || !viewsPropertiesResource.exists()) {
        return;
    }
    Properties viewsProperties = new Properties();
    InputStream input = null;
    try {
        input = viewsPropertiesResource.getInputStream();
        viewsProperties.load(input);
        for (Object view : viewsProperties.keySet()) {
            String viewName = view.toString();
            final String viewClassName = viewsProperties.getProperty(viewName);
            try {
                final Class<?> viewClass = grailsApplication.getClassLoader().loadClass(viewClassName);
                precompiledViewMap.put(viewName, viewClass);
            } catch (Throwable e) {
                throw new PluginException("Failed to initialize view [" + viewName + "] from plugin [" + getName() + "] : " + e.getMessage(), e);
            }
        }
    } catch (IOException e) {
        LOG.error("Error loading views for binary plugin [" + this + "]: " + e.getMessage(), e);
    } finally {
        try {
            if (input != null)
                input.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) PluginException(grails.plugins.exceptions.PluginException) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with PluginException

use of grails.plugins.exceptions.PluginException in project grails-core by grails.

the class AbstractGrailsPluginManager method doRuntimeConfiguration.

/**
 * Base implementation that will perform runtime configuration for the specified plugin name.
 */
public void doRuntimeConfiguration(String pluginName, RuntimeSpringConfiguration springConfig) {
    checkInitialised();
    GrailsPlugin plugin = getGrailsPlugin(pluginName);
    if (plugin == null) {
        throw new PluginException("Plugin [" + pluginName + "] not found");
    }
    if (!plugin.supportsCurrentScopeAndEnvironment()) {
        return;
    }
    if (!plugin.isEnabled(applicationContext.getEnvironment().getActiveProfiles()))
        return;
    String[] dependencyNames = plugin.getDependencyNames();
    doRuntimeConfigurationForDependencies(dependencyNames, springConfig);
    String[] loadAfters = plugin.getLoadAfterNames();
    for (String name : loadAfters) {
        GrailsPlugin current = getGrailsPlugin(name);
        if (current != null) {
            current.doWithRuntimeConfiguration(springConfig);
        }
    }
    plugin.doWithRuntimeConfiguration(springConfig);
}
Also used : GrailsPlugin(grails.plugins.GrailsPlugin) PluginException(grails.plugins.exceptions.PluginException)

Example 4 with PluginException

use of grails.plugins.exceptions.PluginException in project grails-core by grails.

the class AbstractGrailsPluginManager method doRuntimeConfigurationForDependencies.

private void doRuntimeConfigurationForDependencies(String[] dependencyNames, RuntimeSpringConfiguration springConfig) {
    for (String dn : dependencyNames) {
        GrailsPlugin current = getGrailsPlugin(dn);
        if (current == null) {
            throw new PluginException("Cannot load Plugin. Dependency [" + current + "] not found");
        }
        String[] pluginDependencies = current.getDependencyNames();
        if (pluginDependencies.length > 0) {
            doRuntimeConfigurationForDependencies(pluginDependencies, springConfig);
        }
        if (isPluginDisabledForProfile(current))
            continue;
        current.doWithRuntimeConfiguration(springConfig);
    }
}
Also used : GrailsPlugin(grails.plugins.GrailsPlugin) PluginException(grails.plugins.exceptions.PluginException)

Example 5 with PluginException

use of grails.plugins.exceptions.PluginException in project grails-core by grails.

the class BinaryGrailsPlugin method initializeProvidedArtefacts.

protected void initializeProvidedArtefacts(List<String> classNames) {
    List<Class> artefacts = new ArrayList<Class>();
    if (!classNames.isEmpty()) {
        final ClassLoader classLoader = grailsApplication.getClassLoader();
        for (String className : classNames) {
            try {
                artefacts.add(classLoader.loadClass(className));
            } catch (Throwable e) {
                throw new PluginException("Failed to initialize class [" + className + "] from plugin [" + getName() + "] : " + e.getMessage(), e);
            }
        }
    }
    artefacts.addAll(Arrays.asList(super.getProvidedArtefacts()));
    providedArtefacts = artefacts.toArray(new Class[artefacts.size()]);
}
Also used : PluginException(grails.plugins.exceptions.PluginException)

Aggregations

PluginException (grails.plugins.exceptions.PluginException)5 GrailsPlugin (grails.plugins.GrailsPlugin)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 DefaultGrailsPlugin (org.grails.plugins.DefaultGrailsPlugin)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1