GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / src / commons / org / codehaus / groovy / grails / plugins / AbstractGrailsPlugin.java
blob14086b4fc163211bda8fe52dab627504947bb4f4
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.groovy.grails.plugins;
18 import groovy.lang.GroovyObjectSupport;
19 import groovy.util.slurpersupport.GPathResult;
20 import org.codehaus.groovy.grails.commons.AbstractGrailsClass;
21 import org.codehaus.groovy.grails.commons.GrailsApplication;
22 import org.codehaus.groovy.grails.commons.GrailsClassUtils;
23 import org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration;
24 import org.springframework.beans.BeansException;
25 import org.springframework.context.ApplicationContext;
27 import java.util.HashMap;
28 import java.util.Map;
30 /**
31 * Abstract implementation that provides some default behaviours
33 * @author Graeme Rocher
36 public abstract class AbstractGrailsPlugin extends GroovyObjectSupport implements GrailsPlugin {
38 /* (non-Javadoc)
39 * @see org.codehaus.groovy.grails.plugins.GrailsPlugin#refresh()
41 public void refresh() {
42 // do nothing
45 protected GrailsApplication application;
46 protected String version = "1.0";
47 protected Map dependencies = new HashMap();
48 protected String[] dependencyNames = new String[0];
49 protected Class pluginClass;
50 protected ApplicationContext applicationContext;
51 protected GrailsPluginManager manager;
52 protected String[] evictionList = new String[0];
54 /**
55 * Wrapper Grails class for plugins
57 * @author Graeme Rocher
60 class GrailsPluginClass extends AbstractGrailsClass {
61 public GrailsPluginClass(Class clazz) {
62 super(clazz, TRAILING_NAME);
66 public AbstractGrailsPlugin(Class pluginClass, GrailsApplication application) {
67 if(pluginClass == null) {
68 throw new IllegalArgumentException("Argument [pluginClass] cannot be null");
70 if(!pluginClass.getName().endsWith(TRAILING_NAME)) {
71 throw new IllegalArgumentException("Argument [pluginClass] with value ["+pluginClass+"] is not a Grails plugin (class name must end with 'GrailsPlugin')");
73 this.application = application;
74 this.pluginClass = pluginClass;
77 public abstract void doWithApplicationContext(ApplicationContext applicationContext);
80 public abstract void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig);
82 public abstract void doArtefactConfiguration();
84 public boolean checkForChanges() {
85 return false;
88 public void doWithWebDescriptor(GPathResult webXml) {
89 // do nothing
91 public String[] getDependencyNames() {
92 return this.dependencyNames;
95 public String getDependentVersion(String name) {
96 return null;
99 public String getName() {
100 return pluginClass.getName();
103 public String getVersion() {
104 return this.version;
107 public String getPluginPath() {
108 return PLUGINS_PATH + '/' + GrailsClassUtils.getScriptName(getName()) + '-' + getVersion();
111 public GrailsPluginManager getManager() {
112 return this.manager;
115 public String[] getLoadAfterNames() {
116 return new String[0];
118 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
119 this.applicationContext = applicationContext;
121 /* (non-Javadoc)
122 * @see org.codehaus.groovy.grails.plugins.GrailsPlugin#setManager(org.codehaus.groovy.grails.plugins.GrailsPluginManager)
124 public void setManager(GrailsPluginManager manager) {
125 this.manager = manager;
127 /* (non-Javadoc)
128 * @see org.codehaus.groovy.grails.plugins.GrailsPlugin#setApplication(org.codehaus.groovy.grails.commons.GrailsApplication)
130 public void setApplication(GrailsApplication application) {
131 this.application = application;
133 public String[] getEvictionNames() {
134 return this.evictionList;