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
}
}
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
}
}
}
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);
}
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);
}
}
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()]);
}
Aggregations