Skip to content
Browse files

This ostensibly fixes a problem with the _GrailsWar script which was

using the wrong signature for one of the PluginBuildSettings methods.

I also took the opportunity to change as much code as possible to use
PluginBuildSettings directly, rather than GrailsPluginUtils. In two
cases (DevelopmentResourceLoader and GrailsCompiler) this wasn't easily
done, so they still call into GrailsPluginUtils. Because of that, the
_GrailsSettings script now creates the PluginBuildSettings instance and
uses it to initialise GrailsPluginUtils.
  • Loading branch information...
1 parent 7fa889a commit 881a417f44b0d879d314482e955e43619d083b05 @pledbrook pledbrook committed Sep 23, 2009
Showing with 280 additions and 170 deletions.
  1. +2 −2 scripts/Help_.groovy
  2. +1 −1 scripts/Init.groovy
  3. +0 −1 scripts/ReleasePlugin.groovy
  4. +1 −2 scripts/Upgrade.groovy
  5. +2 −2 scripts/_GrailsBootstrap.groovy
  6. +6 −5 scripts/_GrailsClasspath.groovy
  7. +2 −3 scripts/_GrailsCompile.groovy
  8. +1 −2 scripts/_GrailsCreateProject.groovy
  9. +0 −1 scripts/_GrailsEvents.groovy
  10. +1 −2 scripts/_GrailsPackage.groovy
  11. +1 −3 scripts/_GrailsRun.groovy
  12. +10 −3 scripts/_GrailsSettings.groovy
  13. +5 −6 scripts/_GrailsWar.groovy
  14. +3 −4 scripts/_PackagePlugins.groovy
  15. +30 −18 scripts/_PluginDependencies.groovy
  16. +4 −2 src/java/grails/test/GrailsAwareGroovyTestSuite.java
  17. +46 −45 src/java/grails/util/PluginBuildSettings.groovy
  18. +3 −2 src/java/org/codehaus/groovy/grails/cli/support/GrailsBuildEventListener.java
  19. +18 −5 src/java/org/codehaus/groovy/grails/plugins/DefaultPluginMetaManager.java
  20. +19 −15 src/java/org/codehaus/groovy/grails/plugins/GrailsPluginUtils.groovy
  21. +1 −2 src/java/org/codehaus/groovy/grails/plugins/publishing/DefaultPluginPublisher.groovy
  22. +22 −24 src/java/org/codehaus/groovy/grails/plugins/web/GroovyPagesGrailsPlugin.groovy
  23. +15 −6 src/java/org/codehaus/groovy/grails/web/pages/GroovyPageResourceLoader.java
  24. +82 −9 src/test/grails/util/PluginBuildSettingsTests.groovy
  25. +0 −2 src/test/org/codehaus/groovy/grails/cli/AbstractCliTests.groovy
  26. +1 −3 src/test/org/codehaus/groovy/grails/scaffolding/DefaultGrailsTemplateGeneratorTests.groovy
  27. +1 −0 ...projects/plugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/messages.properties
  28. +1 −0 ...lugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/org/example/custom.properties
  29. +1 −0 ...in-build-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/org/example/custom_fr.properties
  30. BIN ...jects/plugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/lib/hibernate-annotations-3.4.0.GA.jar
  31. BIN ...est-projects/plugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/lib/hibernate-core-3.3.1.GA.jar
  32. +1 −0 ...t-projects/plugin-build-settings/plugins/webflow-1.2-SNAPSHOT/grails-app/i18n/messages.properties
  33. BIN ...gin-build-settings/plugins/webflow-1.2-SNAPSHOT/lib/org.springframework.webflow-2.0.8.RELEASE.jar
View
4 scripts/Help_.groovy
@@ -63,7 +63,7 @@ boolean shouldGenerateHelp(File script) {
target ( 'default' : "Prints out the help for each script") {
ant.mkdir(dir:grailsTmp)
- def scripts = getAllScripts().collect { it.file }
+ def scripts = pluginSettings.availableScripts.collect { it.file }
def helpText = ""
@@ -155,4 +155,4 @@ target( showHelp: "Show help for a particular command") {
}
}
-
+
View
2 scripts/Init.groovy
@@ -137,7 +137,7 @@ target(createArtifact: "Creates a specific Grails artifact") {
templateFile = "${basedir}/src/templates/artifacts/${artifactName}.groovy"
if (!new File(templateFile).exists()) {
// now check for template provided by plugins
- Resource[] pluginDirs = getPluginDirectories()
+ Resource[] pluginDirs = pluginSettings.pluginDirectories
List pluginTemplateFiles = []
pluginDirs.each {
File template = new File(it.file, "src/templates/artifacts/${artifactName}.groovy")
View
1 scripts/ReleasePlugin.groovy
@@ -23,7 +23,6 @@ import org.tmatesoft.svn.core.*
import org.tmatesoft.svn.core.auth.*
import org.tmatesoft.svn.core.wc.*
import org.codehaus.groovy.grails.documentation.MetadataGeneratingMetaClassCreationHandle
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.publishing.DefaultPluginPublisher
import org.springframework.core.io.FileSystemResource
View
3 scripts/Upgrade.groovy
@@ -23,7 +23,6 @@
* @since 0.4
*/
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import grails.util.Metadata
includeTargets << grailsScript("_GrailsPlugins")
@@ -217,7 +216,7 @@ move it to the new location of '${basedir}/test/integration'. Please move the di
updateMetadata("app.name": "$grailsAppName", "app.grails.version": "$grailsVersion")
// proceed plugin-specific upgrade logic contained in 'scripts/_Upgrade.groovy' under plugin's root
- def plugins = GrailsPluginUtils.getPluginBaseDirectories(pluginsHome)
+ def plugins = pluginSettings.pluginBaseDirectories
if (plugins) {
for (pluginDir in plugins) {
def f = new File(pluginDir)
View
4 scripts/_GrailsBootstrap.groovy
@@ -20,7 +20,6 @@ import org.codehaus.groovy.grails.commons.ApplicationAttributes
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.codehaus.groovy.grails.plugins.DefaultPluginMetaManager
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.codehaus.groovy.grails.web.context.ServletContextHolder
import org.springframework.core.io.FileSystemResourceLoader
@@ -47,14 +46,15 @@ target(loadApp:"Loads the Grails application object") {
def builder = parentContext ? new WebBeanBuilder(parentContext) : new WebBeanBuilder()
beanDefinitions = builder.beans {
resourceHolder(org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder) {
- resources = GrailsPluginUtils.getArtefactResources(basedir, resolveResources)
+ resources = pluginSettings.getArtefactResources(basedir)
}
grailsResourceLoader(org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean) {
grailsResourceHolder = resourceHolder
}
grailsApplication(org.codehaus.groovy.grails.commons.DefaultGrailsApplication, ref("grailsResourceLoader"))
pluginMetaManager(DefaultPluginMetaManager) {
grailsApplication = ref('grailsApplication')
+ pluginSettings = pluginSettings
}
}
}
View
11 scripts/_GrailsClasspath.groovy
@@ -15,7 +15,6 @@
*/
import org.codehaus.groovy.control.CompilerConfiguration
import org.springframework.core.io.FileSystemResource
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
/**
* Gant script containing the Grails classpath setup.
@@ -41,23 +40,25 @@ target(classpath: "Sets the Grails classpath") {
/**
* Obtains all of the plug-in Lib directories
+ * @deprecated Use "pluginSettings.pluginLibDirectories"
*/
getPluginLibDirs = {
- GrailsPluginUtils.getPluginLibDirectories(pluginsHome, resolveResources)
+ pluginSettings.pluginLibDirectories
}
/**
* Obtains an array of all plug-in JAR files as Spring Resource objects
+ * @deprecated Use "pluginSettings.pluginJarFiles".
*/
getPluginJarFiles = {
- GrailsPluginUtils.getPluginJarFiles(pluginsHome, resolveResources)
+ pluginSettings.pluginJarFiles
}
getJarFiles = {->
def jarFiles = resolveResources("file:${basedir}/lib/*.jar").toList()
if(includePluginJarsOnClasspath) {
- def pluginJars = getPluginJarFiles()
+ def pluginJars = pluginSettings.pluginJarFiles
for (pluginJar in pluginJars) {
boolean matches = jarFiles.any {it.file.name == pluginJar.file.name}
@@ -115,7 +116,7 @@ commonClasspath = {
pathelement(location: "${d.file.absolutePath}")
}
- def pluginLibDirs = getPluginLibDirs().findAll { it.exists() }
+ def pluginLibDirs = pluginSettings.pluginLibDirectories.findAll { it.exists() }
for (pluginLib in pluginLibDirs) {
fileset(dir: pluginLib.file.absolutePath)
}
View
5 scripts/_GrailsCompile.groovy
@@ -15,7 +15,6 @@
*/
import org.codehaus.groovy.control.CompilationUnit
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.PluginInfo
import grails.util.GrailsNameUtils
@@ -92,7 +91,7 @@ target(compilePlugins: "Compiles source files of all referenced plugins.") {
// First compile the plugins so that we can exclude any
// classes that might conflict with the project's.
def classpathId = "grails.compile.classpath"
- def pluginResources = getPluginSourceFiles()
+ def pluginResources = pluginSettings.pluginSourceFiles
def excludedPaths = ["views", "i18n"] // conf gets special handling
pluginResources = pluginResources.findAll {
!excludedPaths.contains(it.file.name) && it.file.isDirectory()
@@ -174,7 +173,7 @@ target(compilegsp : "Compile GSP files") {
// compile views in plugins
loadPlugins()
- def pluginInfos = GrailsPluginUtils.getSupportedPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.supportedPluginInfos
if(pluginInfos) {
for(PluginInfo info in pluginInfos) {
File pluginViews = new File(info.pluginDir.file, "grails-app/views")
View
3 scripts/_GrailsCreateProject.groovy
@@ -16,7 +16,6 @@
import grails.util.GrailsNameUtils
import grails.util.Metadata
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
/**
* Gant script that handles the creation of Grails applications
@@ -58,7 +57,7 @@ def resetBaseDirectory(String basedir) {
metadata = Metadata.getInstance(metadataFile)
// Reset the plugin stuff.
- GrailsPluginUtils.clearCaches()
+ pluginSettings.clearCaches()
pluginsHome = grailsSettings.projectPluginsDir.path
}
View
1 scripts/_GrailsEvents.groovy
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.cli.support.GrailsBuildEventListener
/**
View
3 scripts/_GrailsPackage.groovy
@@ -19,7 +19,6 @@ import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper
import org.codehaus.groovy.grails.plugins.logging.Log4jConfig
import org.springframework.core.io.FileSystemResource
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.gparallelizer.Asynchronizer
import org.springframework.core.io.Resource
@@ -115,7 +114,7 @@ target( packageApp : "Implementation of package target") {
includes:"**/*.properties",
encoding:"UTF-8")
- def i18nPluginDirs = GrailsPluginUtils.getPluginI18nDirectories()
+ def i18nPluginDirs = pluginSettings.pluginI18nDirectories
if(i18nPluginDirs) {
Asynchronizer.withAsynchronizer(5) {
i18nPluginDirs.eachAsync { Resource srcDir ->
View
4 scripts/_GrailsRun.groovy
@@ -19,8 +19,6 @@ import grails.util.GrailsUtil
import grails.web.container.EmbeddableServerFactory
import grails.web.container.EmbeddableServer
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
-
/**
* Gant script that executes Grails using an embedded server
@@ -95,7 +93,7 @@ private EmbeddableServerFactory loadServerFactory() {
if(containerClass==defaultServer) {
println "WARNING: No default container found, installing Tomcat.."
doInstallPluginFromGrailsHomeOrRepository "tomcat", GrailsUtil.grailsVersion
- GrailsPluginUtils.clearCaches()
+ pluginSettings.clearCaches()
compilePlugins()
serverFactory = load(containerClass)
}
View
13 scripts/_GrailsSettings.groovy
@@ -14,17 +14,18 @@
* limitations under the License.
*/
+import grails.util.BuildScope
import grails.util.BuildSettings
+import grails.util.Environment
import grails.util.GrailsNameUtils
+import grails.util.Metadata
+import grails.util.PluginBuildSettings
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.FileSystemResource
import org.springframework.core.io.Resource
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
import org.springframework.util.FileCopyUtils
-import grails.util.Environment
-import grails.util.Metadata
-import grails.util.BuildScope
/**
* Gant script containing build variables.
@@ -73,7 +74,13 @@ buildProps = buildConfig.toProperties()
enableProfile = getPropertyValue("grails.script.profile", false).toBoolean()
pluginsHome = grailsSettings.projectPluginsDir.path
+// Used to find out about plugins used by this app. The plugin manager
+// is configured later when its created (see _PluginDependencies).
+pluginSettings = new PluginBuildSettings(grailsSettings)
+// While some code still relies on GrailsPluginUtils, make sure it
+// uses the same PluginBuildSettings instance as the scripts.
+GrailsPluginUtils.pluginBuildSettings = pluginSettings
// Load the application metadata (application.properties)
grailsAppName = null
View
11 scripts/_GrailsWar.groovy
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-import org.codehaus.groovy.grails.compiler.support.*
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import grails.util.BuildScope
-import grails.util.Metadata
import grails.util.Environment
+import grails.util.Metadata
+import org.codehaus.groovy.grails.compiler.support.*
import org.codehaus.groovy.grails.plugins.GrailsPluginManager
import org.codehaus.groovy.grails.plugins.PluginInfo
import org.codehaus.groovy.grails.plugins.GrailsPlugin
@@ -158,7 +157,7 @@ target (war: "The implementation target") {
if(includeJars) {
- def pluginInfos = GrailsPluginUtils.getSupportedPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.supportedPluginInfos
GrailsPluginManager pm = pluginManager
pluginInfos = pluginInfos.findAll { info -> pm.supportsCurrentBuildScope(info.name) }
@@ -229,7 +228,7 @@ target (war: "The implementation target") {
target(createDescriptor:"Creates the WEB-INF/grails.xml file used to load Grails classes in WAR mode") {
def resourceList = GrailsResourceLoaderHolder.resourceLoader.getResources()
- def pluginInfos = GrailsPluginUtils.getPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.getPluginInfos(pluginsHome)
new File("${stagingDir}/WEB-INF/grails.xml").withWriter { writer ->
def xml = new groovy.xml.MarkupBuilder(writer)
@@ -280,7 +279,7 @@ target(cleanUpAfterWar:"Cleans up after performing a WAR") {
target(warPlugins:"Includes the plugins in the WAR") {
ant.sequential {
- def pluginInfos = GrailsPluginUtils.getSupportedPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.supportedPluginInfos
if(pluginInfos) {
for(PluginInfo info in pluginInfos) {
def pluginBase = info.pluginDir.file
View
7 scripts/_PackagePlugins.groovy
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.PluginInfo
/**
@@ -68,7 +67,7 @@ packageFiles = { String from ->
target( packagePlugins : "Packages any Grails plugins that are installed for this project") {
depends( classpath )
- def pluginInfos = GrailsPluginUtils.getPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.getPluginInfos(pluginsHome)
for(PluginInfo info in pluginInfos) {
try {
def pluginBase = info.pluginDir.file
@@ -83,7 +82,7 @@ target( packagePlugins : "Packages any Grails plugins that are installed for thi
}
packagePluginsForWar = { targetDir ->
- def pluginInfos = GrailsPluginUtils.getPluginInfos(pluginsHome)
+ def pluginInfos = pluginSettings.getPluginInfos(pluginsHome)
for(PluginInfo info in pluginInfos) {
try {
@@ -105,4 +104,4 @@ packagePluginsForWar = { targetDir ->
}
}
-}
+}
View
48 scripts/_PluginDependencies.groovy
@@ -319,11 +319,11 @@ target(resolveDependencies:"Resolve plugin dependencies") {
// metadata. We only check on the plugins in the project's "plugins"
// directory and the global "plugins" dir. Plugins loaded via an
// explicit path should be left alone.
- def pluginDirs = GrailsPluginUtils.getImplicitPluginDirectories(pluginsHome)
+ def pluginDirs = pluginSettings.implicitPluginDirectories
def pluginsToUninstall = pluginDirs.findAll { Resource r -> !plugins.find { plugin -> r.filename == "$plugin.name-$plugin.version" }}
for(Resource pluginDir in pluginsToUninstall) {
- if(GrailsPluginUtils.isGlobalPluginLocation(pluginDir)) {
+ if(pluginSettings.isGlobalPluginLocation(pluginDir)) {
registerMetadataForPluginLocation(pluginDir)
}
else {
@@ -338,7 +338,7 @@ target(resolveDependencies:"Resolve plugin dependencies") {
}
private registerMetadataForPluginLocation(Resource pluginDir) {
- def plugin = GrailsPluginUtils.getMetadataForPlugin(pluginDir.filename)
+ def plugin = pluginSettings.getMetadataForPlugin(pluginDir.filename)
registerPluginWithMetadata(plugin.@name.text(), plugin.@version.text())
}
@@ -375,7 +375,7 @@ generatePluginXml = { File descriptor ->
// Write the content!
def props = ['author','authorEmail','title','description','documentation']
- def resourceList = GrailsPluginUtils.getArtefactResourcesForOne(descriptor.parentFile.absolutePath)
+ def resourceList = pluginSettings.getArtefactResourcesForOne(descriptor.parentFile.absolutePath)
def rcComparator = [ compare: {a, b -> a.URI.compareTo(b.URI) } ] as Comparator
Arrays.sort(resourceList, rcComparator)
@@ -446,7 +446,7 @@ target(loadPlugins:"Loads Grails' plugins") {
if(!PluginManagerHolder.pluginManager) { // plugin manager already loaded?
compConfig.setTargetDirectory(classesDir)
def unit = new CompilationUnit ( compConfig , null , new GroovyClassLoader(classLoader) )
- def pluginFiles = getPluginDescriptors()
+ def pluginFiles = pluginSettings.pluginDescriptors
for(plugin in pluginFiles) {
def pluginFile = plugin.file
@@ -492,12 +492,13 @@ target(loadPlugins:"Loads Grails' plugins") {
pluginManager = new DefaultGrailsPluginManager(pluginClasses as Class[], grailsApp)
PluginManagerHolder.setPluginManager(pluginManager)
+ pluginSettings.pluginManager = pluginManager
}
}
profile("loading plugins") {
event("PluginLoadStart", [pluginManager])
pluginManager.loadPlugins()
- def baseDescriptor = GrailsPluginUtils.getBasePluginDescriptor(grailsSettings.baseDir.absolutePath)
+ def baseDescriptor = pluginSettings.basePluginDescriptor()
if(baseDescriptor) {
def baseName = FilenameUtils.getBaseName(baseDescriptor.filename)
def plugin = pluginManager.getGrailsPluginForClassName(baseName)
@@ -574,7 +575,7 @@ target(updatePluginsList:"Updates the plugin list from the remote plugin-list.xm
def resetClasspathAndState() {
- GrailsPluginUtils.clearCaches()
+ pluginSettings.clearCaches()
classpathSet = false
classpath()
PluginManagerHolder.pluginManager = null
@@ -703,51 +704,62 @@ readPluginXmlMetadata = { String pluginName ->
* Reads all installed plugin descriptors returning a list
*/
readAllPluginXmlMetadata = {->
- getPluginXmlMetadata().collect { new XmlSlurper().parse(it.file) }
+ pluginSettings.pluginXmlMetadata.collect { new XmlSlurper().parse(it.file) }
}
+/**
+ * @deprecated Use "pluginSettings.pluginXmlMetadata" instead.
+ */
getPluginXmlMetadata = {
- GrailsPluginUtils.getPluginXmlMetadata(pluginsHome, resolveResources)
+ pluginSettings.pluginXmlMetadata
}
/**
* Obtains the directory for the given plugin name
*/
getPluginDirForName = { String pluginName ->
- GrailsPluginUtils.getPluginDirForName(pluginsHome, pluginName)
+ pluginSettings.getPluginDirForName(pluginName)
}
-/** Obtains all of the plugin directories */
+/**
+ * Obtains all of the plugin directories
+ * @deprecated Use "pluginSettings.pluginDirectories".
+ */
getPluginDirectories = {->
- GrailsPluginUtils.getPluginDirectories(pluginsHome)
+ pluginSettings.pluginDirectories
}
/**
* Obtains an array of all plugin source files as Spring Resource objects
+ * @deprecated Use "pluginSettings.pluginSourceFiles".
*/
getPluginSourceFiles = {
- GrailsPluginUtils.getPluginSourceFiles(pluginsHome, resolveResources)
+ pluginSettings.pluginSourceFiles
}
/**
* Obtains an array of all the plugin provides Gant scripts
+ * @deprecated Use "pluginSettings.pluginScripts".
*/
getPluginScripts = {
- GrailsPluginUtils.getPluginScripts(pluginsHome,resolveResources)
+ pluginSettings.pluginScripts
}
/**
* Gets a list of all scripts known to the application (excluding private scripts starting with _)
+ * @deprecated Use "pluginSettings.availableScripts".
*/
getAllScripts = {
- GrailsPluginUtils.getAvailableScripts(grailsHome,pluginsHome, basedir, resolveResources)
+ pluginSettings.availableScripts
}
/**
* Obtains a list of all Grails plugin descriptor classes
+ * @deprecated Use "pluginSettings.pluginDescriptors".
*/
getPluginDescriptors = {
- GrailsPluginUtils.getPluginDescriptors(basedir,pluginsHome,resolveResources)
+ pluginSettings.pluginDescriptors
}
/**
* Gets the base plugin descriptor
+ * @deprecated Use "pluginSettings.basePluginDescriptor".
*/
getBasePluginDescriptor = {
- GrailsPluginUtils.getBasePluginDescriptor(basedir)
+ pluginSettings.basePluginDescriptor
}
/**
* Runs a script contained within a plugin
@@ -919,7 +931,7 @@ installPluginForName = { String fullPluginName ->
event("InstallPluginStart", [fullPluginName])
def pluginInstallPath = "${globalInstall ? globalPluginsDirPath : pluginsHome}/${fullPluginName}"
- Resource currentInstall = GrailsPluginUtils.getPluginDirForName(currentPluginName)
+ Resource currentInstall = getPluginDirForName(currentPluginName)
if(currentInstall?.exists()) {
if(!isInteractive || confirmInput("You currently already have a version of the plugin installed [$currentInstall.filename]. Do you want to upgrade this version?", "upgrade.${fullPluginName}.plugin")) {
View
6 src/java/grails/test/GrailsAwareGroovyTestSuite.java
@@ -17,6 +17,7 @@
import grails.util.BuildSettings;
import grails.util.BuildSettingsHolder;
import groovy.util.GroovyTestSuite;
+import grails.util.PluginBuildSettings;
import java.io.File;
import java.util.ArrayList;
@@ -30,7 +31,6 @@
import org.codehaus.groovy.grails.compiler.injection.DefaultGrailsDomainClassInjector;
import org.codehaus.groovy.grails.compiler.injection.GrailsAwareClassLoader;
import org.codehaus.groovy.grails.compiler.support.GrailsResourceLoader;
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.springframework.core.io.Resource;
/**
@@ -54,6 +54,7 @@
public class GrailsAwareGroovyTestSuite extends GroovyTestSuite {
private GrailsAwareClassLoader gcl;
private BuildSettings grailsSettings;
+ private PluginBuildSettings pluginSettings;
protected boolean registerContextClassLoader = true;
public GrailsAwareGroovyTestSuite() {
@@ -91,7 +92,7 @@ protected void customizeClassInjectors(List<ClassInjector> classInjectors) {
}
private Resource[] resolveGrailsResources() {
- Resource[] baseResources = GrailsPluginUtils.getArtefactResources(grailsSettings.getBaseDir().getPath());
+ Resource[] baseResources = pluginSettings.getArtefactResources();
List<Resource> grailsResources = new ArrayList<Resource>(Arrays.asList(baseResources));
customizeGrailsResources(grailsResources);
return grailsResources.toArray(new Resource[grailsResources.size()]);
@@ -106,6 +107,7 @@ private void initBuildSettings() {
final File grailsHome = findGrailsHome();
System.setProperty(BuildSettings.APP_BASE_DIR, basedir.getPath());
grailsSettings = new BuildSettings(grailsHome, basedir);
+ pluginSettings = new PluginBuildSettings(grailsSettings);
customizeBuildSettings(grailsSettings);
BuildSettingsHolder.setSettings(grailsSettings);
}
View
91 src/java/grails/util/PluginBuildSettings.groovy
@@ -57,7 +57,7 @@ class PluginBuildSettings {
BuildSettings buildSettings
GrailsPluginManager pluginManager
private String pluginDirPath
- private java.util.concurrent.ConcurrentHashMap cache = new ConcurrentHashMap()
+ private Map cache = new ConcurrentHashMap()
private Map pluginToDirNameMap = new ConcurrentHashMap()
private Map pluginMetaDataMap = new ConcurrentHashMap()
private pluginLocations
@@ -89,7 +89,7 @@ class PluginBuildSettings {
*/
PluginInfo[] getPluginInfos(String pluginDirPath=this.pluginDirPath) {
def pluginInfos = []
- for(dir in getPluginDirectories(pluginDirPath)) {
+ for(dir in getPluginDirectories()) {
pluginInfos << new PluginInfo(dir, this)
}
return pluginInfos as PluginInfo[]
@@ -99,11 +99,11 @@ class PluginBuildSettings {
/**
* Obtains a Resource array of the Plugin metadata XML files used to describe the plugins provided resources
*/
- Resource[] getPluginXmlMetadata( String pluginsDirPath = pluginDirPath) {
+ Resource[] getPluginXmlMetadata() {
def allPluginXmlMetadata = cache['allPluginXmlMetadata']
if(!allPluginXmlMetadata) {
allPluginXmlMetadata = new Resource[0]
- allPluginXmlMetadata = resolvePluginResourcesAndAdd(allPluginXmlMetadata, pluginsDirPath) { pluginDir ->
+ allPluginXmlMetadata = resolvePluginResourcesAndAdd(allPluginXmlMetadata, pluginDirPath) { pluginDir ->
resourceResolver("file:${pluginDir}/plugin.xml")
}
cache['allPluginXmlMetadata'] = allPluginXmlMetadata
@@ -139,18 +139,18 @@ class PluginBuildSettings {
/**
* Obtains an array of all Gant scripts that are availabe for execution in a Grails application
*/
- Resource[] getAvailableScripts(String grailsHome = this.buildSettings.grailsHome.absolutePath,
- String pluginDirPath = this.pluginDirPath,
- String basedir = this.buildSettings.baseDir.absolutePath) {
+ Resource[] getAvailableScripts() {
def availableScripts = cache['availableScripts']
if(!availableScripts) {
def scripts = []
def userHome = System.getProperty("user.home")
+ def grailsHome = buildSettings.grailsHome.absolutePath
+ def basedir = buildSettings.baseDir.absolutePath
resourceResolver("file:${grailsHome}/scripts/**.groovy").each { if (!it.file.name.startsWith('_')) scripts << it }
resourceResolver("file:${basedir}/scripts/*.groovy").each { if (!it.file.name.startsWith('_')) scripts << it }
- getPluginScripts(pluginDirPath).each { if (!it.file.name.startsWith('_')) scripts << it }
+ pluginScripts.each { if (!it.file.name.startsWith('_')) scripts << it }
resourceResolver("file:${userHome}/.grails/scripts/*.groovy").each { if (!it.file.name.startsWith('_')) scripts << it }
availableScripts = scripts as Resource[]
cache['availableScripts'] = availableScripts
@@ -161,7 +161,7 @@ class PluginBuildSettings {
/**
* Obtains an array of plug-in provided Gant scripts available to a Grails application
*/
- Resource[] getPluginScripts(String pluginDirPath=this.pluginDirPath) {
+ Resource[] getPluginScripts() {
def pluginScripts = cache['pluginScripts']
if(!pluginScripts) {
pluginScripts = new Resource[0]
@@ -176,12 +176,12 @@ class PluginBuildSettings {
/**
* Obtains an array of all plugin provided resource bundles
*/
- Resource[] getPluginResourceBundles(String pluginDirPath=this.pluginDirPath) {
+ Resource[] getPluginResourceBundles() {
def pluginResourceBundles = cache['pluginResourceBundles']
if(!pluginResourceBundles) {
pluginResourceBundles = new Resource[0]
pluginResourceBundles = resolvePluginResourcesAndAdd(pluginResourceBundles,pluginDirPath) { pluginDir ->
- resourceResolver("file:${pluginDir}/grails-app/i18n/*.properties")
+ resourceResolver("file:${pluginDir}/grails-app/i18n/**/*.properties")
}
cache['pluginResourceBundles'] = pluginResourceBundles
@@ -193,11 +193,11 @@ class PluginBuildSettings {
* Obtains an array of all plug-in provided source files (Java and Groovy)
*/
- Resource[] getPluginSourceFiles(String pluginsDirPath=this.pluginDirPath) {
+ Resource[] getPluginSourceFiles() {
def sourceFiles = cache['sourceFiles']
if(!sourceFiles) {
sourceFiles = new Resource[0]
- sourceFiles = resolvePluginResourcesAndAdd(sourceFiles, pluginsDirPath) { pluginDir ->
+ sourceFiles = resolvePluginResourcesAndAdd(sourceFiles, pluginDirPath) { pluginDir ->
Resource[] pluginSourceFiles = resourceResolver("file:${pluginDir}/grails-app/*")
pluginSourceFiles = ArrayUtils.addAll(pluginSourceFiles,resourceResolver("file:${pluginDir}/src/java"))
pluginSourceFiles = ArrayUtils.addAll(pluginSourceFiles,resourceResolver("file:${pluginDir}/src/groovy"))
@@ -212,11 +212,11 @@ class PluginBuildSettings {
/**
* Obtains an array of all plug-in provided JAR files
*/
- Resource[] getPluginJarFiles(String pluginsDirPath=this.pluginDirPath) {
+ Resource[] getPluginJarFiles() {
def jarFiles = cache['jarFiles']
if(!jarFiles) {
jarFiles = new Resource[0]
- jarFiles = resolvePluginResourcesAndAdd(jarFiles, pluginsDirPath) { pluginDir ->
+ jarFiles = resolvePluginResourcesAndAdd(jarFiles, pluginDirPath) { pluginDir ->
resourceResolver("file:${pluginDir}/lib/*.jar")
}
cache['jarFiles'] = jarFiles
@@ -228,7 +228,7 @@ class PluginBuildSettings {
/**
* Obtains a list of plugin directories for the application
*/
- Resource[] getPluginDirectories(String pluginDirPath=pluginDirPath) {
+ Resource[] getPluginDirectories() {
def pluginDirectoryResources = cache['pluginDirectoryResources']
if(!pluginDirectoryResources) {
def dirList = getImplicitPluginDirectories()
@@ -252,10 +252,10 @@ class PluginBuildSettings {
* @see grails.util.Environment
* @see grails.util.BuildScope
*/
- PluginInfo[] getSupportedPluginInfos(String pluginDirPath = pluginDirPath) {
- if(pluginManager == null) return getPluginInfos(pluginDirPath)
+ PluginInfo[] getSupportedPluginInfos() {
+ if(pluginManager == null) return getPluginInfos()
else {
- def pluginInfos = getPluginInfos(pluginDirPath).findAll {PluginInfo info ->
+ def pluginInfos = getPluginInfos().findAll {PluginInfo info ->
GrailsPlugin plugin = pluginManager.getGrailsPlugin(info.getName())
return plugin?.supportsCurrentScopeAndEnvironment()
}
@@ -268,13 +268,13 @@ class PluginBuildSettings {
* Returns a list of all plugin directories in both the given path
* and the global "plugins" directory together.
*/
- List<Resource> getImplicitPluginDirectories(String pluginDirPath=pluginDirPath) {
+ List<Resource> getImplicitPluginDirectories() {
def dirList = []
def directoryNamePredicate = {
it.isDirectory() && (!it.name.startsWith(".") && it.name.indexOf('-')>-1)
}
- for(pluginBase in getPluginBaseDirectories(pluginDirPath)) {
+ for(pluginBase in getPluginBaseDirectories()) {
List pluginDirs = new File(pluginBase).listFiles().findAll(directoryNamePredicate).collect { new FileSystemResource(it) }
dirList.addAll( pluginDirs )
}
@@ -285,32 +285,33 @@ class PluginBuildSettings {
/**
* Gets a list of all the known plugin base directories (directories where plugins are installed to)
*/
- List<String> getPluginBaseDirectories(String pluginDirPath=pluginDirPath) {
+ List<String> getPluginBaseDirectories() {
[ pluginDirPath, buildSettings.globalPluginsDir.path ]
}
/**
* Returns true if the specified plugin directory is a global plugin
*/
boolean isGlobalPluginLocation(Resource pluginDir) {
- def globalPluginsDir = buildSettings?.globalPluginsDir
- def containingDir = pluginDir?.file?.parentFile
- if(globalPluginsDir && containingDir) {
- return globalPluginsDir.equals(containingDir)
+ def globalPluginsDir = buildSettings?.globalPluginsDir?.canonicalFile
+ def containingDir = pluginDir?.file?.parentFile?.canonicalFile
+ if(globalPluginsDir || containingDir) {
+ return globalPluginsDir == containingDir
}
return false
}
/**
* Obtains a reference to all artefact resources (all Groovy files contained within the grails-app directory of plugins or applications)
*/
- Resource[] getArtefactResources(String basedir = this.buildSettings.baseDir.absolutePath) {
+ Resource[] getArtefactResources() {
+ def basedir = this.buildSettings.baseDir.absolutePath
def allArtefactResources = cache['allArtefactResources']
if(!allArtefactResources) {
- def resources = getArtefactResourcesForOne(new File(basedir).canonicalFile.absolutePath, resourceResolver)
+ def resources = getArtefactResourcesForOne(new File(basedir).canonicalFile.absolutePath)
resources = resolvePluginResourcesAndAdd(resources) { String pluginDir ->
- getArtefactResourcesForOne(pluginDir, resourceResolver)
+ getArtefactResourcesForOne(pluginDir)
}
allArtefactResources = resources
@@ -323,19 +324,18 @@ class PluginBuildSettings {
* Returns an array of all artefacts in the given application or
* plugin directory as Spring resources.
*/
- Resource[] getArtefactResourcesForOne(String projectDir, Closure resourceResolver = resourceResolver) {
+ Resource[] getArtefactResourcesForOne(String projectDir) {
return resourceResolver("file:${projectDir}/grails-app/**/*.groovy")
}
/**
* Obtains an array of all plug-in descriptors (the root classes that end with *GrailsPlugin.groovy)
*/
- Resource[] getPluginDescriptors(String basedir = this.buildSettings.baseDir.absolutePath,
- String pluginsDirPath = this.pluginDirPath) {
+ Resource[] getPluginDescriptors() {
def pluginDescriptors = cache['pluginDescriptors']
if(!pluginDescriptors) {
- def pluginDirs = getPluginDirectories(pluginsDirPath) as List
- pluginDirs << new FileSystemResource(basedir)
+ def pluginDirs = getPluginDirectories() as List
+ pluginDirs << new FileSystemResource(this.buildSettings.baseDir)
def descriptors = []
pluginDirs.each {
@@ -350,11 +350,11 @@ class PluginBuildSettings {
/**
* Obtains an array of all plug-in lib directories
*/
- Resource[] getPluginLibDirectories(String pluginsDirPath=this.pluginDirPath) {
+ Resource[] getPluginLibDirectories() {
def pluginLibs = cache['pluginLibs']
if(!pluginLibs) {
pluginLibs = new Resource[0]
- pluginLibs = resolvePluginResourcesAndAdd(pluginLibs, pluginsDirPath) { pluginDir ->
+ pluginLibs = resolvePluginResourcesAndAdd(pluginLibs, pluginDirPath) { pluginDir ->
resourceResolver("file:${pluginDir}/lib")
}
cache['pluginLibs'] = pluginLibs
@@ -365,11 +365,11 @@ class PluginBuildSettings {
/**
* Obtains an array of all plugin i18n directories
*/
- Resource[] getPluginI18nDirectories(String pluginsDirPath = this.pluginDirPath) {
+ Resource[] getPluginI18nDirectories() {
def plugin18nDirectories = cache['plugin18nDirectories']
if(!plugin18nDirectories) {
plugin18nDirectories = new Resource[0]
- plugin18nDirectories = resolvePluginResourcesAndAdd(plugin18nDirectories, pluginsDirPath) { pluginDir ->
+ plugin18nDirectories = resolvePluginResourcesAndAdd(plugin18nDirectories, pluginDirPath) { pluginDir ->
resourceResolver("file:${pluginDir}/grails-app/i18n")
}
cache['plugin18nDirectories'] = plugin18nDirectories
@@ -385,7 +385,7 @@ class PluginBuildSettings {
/**
* Obtains a plugin directory for the given name
*/
- Resource getPluginDirForName(String pluginName, String pluginsDirPath = this.pluginDirPath) {
+ Resource getPluginDirForName(String pluginName) {
Resource pluginResource = pluginToDirNameMap[pluginName]
if(!pluginResource) {
@@ -394,7 +394,7 @@ class PluginBuildSettings {
it.isDirectory() && (it.name == pluginName || it.name.startsWith("$pluginName-"))
}
- List<String> pluginDirs = getPluginBaseDirectories(pluginsDirPath)
+ List<String> pluginDirs = getPluginBaseDirectories()
File pluginFile
for(pluginDir in pluginDirs) {
pluginFile = new File("${pluginDir}").listFiles().find(directoryNamePredicate)
@@ -428,10 +428,11 @@ class PluginBuildSettings {
/**
* Obtains the 'base' plugin descriptor, which is the plugin descriptor of the current plugin project
*/
- Resource getBasePluginDescriptor(String basedir=this.buildSettings.baseDir.absolutePath) {
+ Resource getBasePluginDescriptor() {
def basePluginDescriptor = cache['basePluginDescriptor']
if(!basePluginDescriptor) {
- basePluginDescriptor = getDescriptorForPlugin(new FileSystemResource(basedir))
+ basePluginDescriptor = getDescriptorForPlugin(
+ new FileSystemResource(this.buildSettings.baseDir.absolutePath))
if(basePluginDescriptor) {
cache['basePluginDescriptor'] = basePluginDescriptor
}
@@ -445,7 +446,7 @@ class PluginBuildSettings {
*/
Resource getDescriptorForPlugin(Resource pluginDir) {
FileSystemResource descriptor = null
- File baseFile = pluginDir.getFile().getCanonicalFile()
+ File baseFile = pluginDir.file.canonicalFile
File basePluginFile = baseFile.listFiles().find { it.name.endsWith("GrailsPlugin.groovy")}
if (basePluginFile?.exists()) {
@@ -462,7 +463,7 @@ class PluginBuildSettings {
* in the closure
*/
private resolvePluginResourcesAndAdd(Resource[] originalResources, String pluginsDirPath = this.pluginDirPath, Closure resolver) {
- Resource[] pluginDirs = getPluginDirectories(pluginsDirPath)
+ Resource[] pluginDirs = getPluginDirectories()
for (dir in pluginDirs) {
def newResources = dir ? resolver(dir.file.absolutePath) : null
if (newResources) {
@@ -471,4 +472,4 @@ class PluginBuildSettings {
}
return originalResources
}
-}
+}
View
5 src/java/org/codehaus/groovy/grails/cli/support/GrailsBuildEventListener.java
@@ -17,10 +17,10 @@
import grails.util.BuildSettings;
import grails.util.GrailsNameUtils;
import grails.util.GrailsUtil;
+import grails.util.PluginBuildSettings;
import groovy.lang.*;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildListener;
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.springframework.core.io.Resource;
import java.io.File;
@@ -67,7 +67,8 @@ protected void loadEventHooks(BuildSettings buildSettings) {
loadEventsScript( findEventsScript(new File(buildSettings.getUserHome(),".grails/scripts")) );
loadEventsScript( findEventsScript(new File(buildSettings.getBaseDir(), "scripts")) );
- for (Resource pluginBase : GrailsPluginUtils.getPluginDirectories()) {
+ PluginBuildSettings pluginSettings = (PluginBuildSettings) binding.getVariable("pluginSettings");
+ for (Resource pluginBase : pluginSettings.getPluginDirectories()) {
try {
loadEventsScript( findEventsScript(new File(pluginBase.getFile(), "scripts")) );
}
View
23 src/java/org/codehaus/groovy/grails/plugins/DefaultPluginMetaManager.java
@@ -16,6 +16,7 @@
import grails.util.BuildSettings;
import grails.util.BuildSettingsHolder;
+import grails.util.PluginBuildSettings;
import groovy.util.XmlSlurper;
import groovy.util.slurpersupport.GPathResult;
import org.apache.commons.lang.StringUtils;
@@ -55,14 +56,23 @@
public class DefaultPluginMetaManager implements PluginMetaManager, GrailsApplicationAware, InitializingBean, ResourceLoaderAware {
private static final Log LOG = LogFactory.getLog(DefaultPluginMetaManager.class);
+ private static final String PLUGINS_PATH = "/plugins/";
+
private Map pluginInfo = new HashMap();
private Map resourceToPluginMap = new HashMap();
private GrailsPluginManager pluginManager;
- private static final String PLUGINS_PATH = "/plugins/";
private GrailsApplication grailsApplication;
private String resourcePattern;
private ResourceLoader resourceLoader;
+ /**
+ * The plugin settings for this application, which allows us to
+ * get access to the descriptors of the plugins used by the app.
+ * This is only used when the application is run from the command
+ * line, not when it's deployed as a WAR.
+ */
+ private PluginBuildSettings pluginSettings;
+
public DefaultPluginMetaManager() {
super();
}
@@ -81,6 +91,10 @@ public void setGrailsApplication(GrailsApplication grailsApplication) {
this.grailsApplication = grailsApplication;
}
+ public void setPluginBuildSettings(PluginBuildSettings settings) {
+ this.pluginSettings = settings;
+ }
+
public void afterPropertiesSet() throws Exception {
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(resourceLoader);
@@ -90,11 +104,10 @@ public void afterPropertiesSet() throws Exception {
pluginDescriptors = patternResolver.getResources(resourcePattern);
}
else {
- BuildSettings settings = BuildSettingsHolder.getSettings();
- File pluginDir = settings != null ? settings.getProjectPluginsDir() : null;
- if(pluginDir != null) {
- pluginDescriptors = GrailsPluginUtils.getPluginXmlMetadata(pluginDir.getPath());
+ if (pluginSettings == null) {
+ throw new RuntimeException("Plugin meta manager has not been configured with the plugin settings");
}
+ pluginDescriptors = pluginSettings.getPluginXmlMetadata();
}
} catch (Throwable e) {
LOG.debug("Error resolving plug-in descriptors: " + e.getMessage());
View
34 src/java/org/codehaus/groovy/grails/plugins/GrailsPluginUtils.groovy
@@ -149,6 +149,10 @@ public class GrailsPluginUtils {
return INSTANCE
}
+ static synchronized setPluginBuildSettings(PluginBuildSettings settings) {
+ INSTANCE = settings
+ }
+
/**
* Returns an array of PluginInfo objects
*/
@@ -167,15 +171,15 @@ public class GrailsPluginUtils {
if(!settings.pluginManager) {
settings.pluginManager = PluginManagerHolder.currentPluginManager()
}
- return settings.getSupportedPluginInfos(pluginDirPath)
+ return settings.getSupportedPluginInfos()
}
/**
* Gets a list of all the known plugin base directories (directories where plugins are installed to)
*/
static List<String> getPluginBaseDirectories(String pluginDirPath) {
- getPluginBuildSettings().getPluginBaseDirectories(pluginDirPath)
+ getPluginBuildSettings().getPluginBaseDirectories()
}
/**
@@ -190,15 +194,15 @@ public class GrailsPluginUtils {
}
static Resource[] getPluginDirectories(String pluginDirPath) {
- getPluginBuildSettings().getPluginDirectories(pluginDirPath)
+ getPluginBuildSettings().getPluginDirectories()
}
/**
* Returns a list of all plugin directories in both the given path
* and the global "plugins" directory together.
*/
static List<Resource> getImplicitPluginDirectories(String pluginDirPath = BuildSettingsHolder.settings?.projectPluginsDir?.path) {
- getPluginBuildSettings().getImplicitPluginDirectories(pluginDirPath)
+ getPluginBuildSettings().getImplicitPluginDirectories()
}
static boolean isGlobalPluginLocation(Resource pluginDir) {
@@ -209,7 +213,7 @@ public class GrailsPluginUtils {
* Obtains a reference to all artefact resources (all Groovy files contained within the grails-app directory of plugins or applications)
*/
static Resource[] getArtefactResources(String basedir, Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getArtefactResources(basedir)
+ getPluginBuildSettings().getArtefactResources()
}
/**
@@ -225,7 +229,7 @@ public class GrailsPluginUtils {
*/
static Resource[] getPluginXmlMetadata( String pluginsDirPath,
Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginXmlMetadata(pluginsDirPath)
+ getPluginBuildSettings().getPluginXmlMetadata()
}
@@ -236,35 +240,35 @@ public class GrailsPluginUtils {
String pluginDirPath,
String basedir,
Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getAvailableScripts(grailsHome, pluginDirPath,basedir)
+ getPluginBuildSettings().getAvailableScripts()
}
/**
* Obtains an array of plug-in provided Gant scripts available to a Grails application
*/
static Resource[] getPluginScripts(String pluginDirPath,Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginScripts(pluginDirPath)
+ getPluginBuildSettings().getPluginScripts()
}
/**
* Obtains an array of all plugin provided resource bundles
*/
static Resource[] getPluginResourceBundles(String pluginDirPath,Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginResourceBundles(pluginDirPath)
+ getPluginBuildSettings().getPluginResourceBundles()
}
/**
* Obtains an array of all plug-in provided source files (Java and Groovy)
*/
static Resource[] getPluginSourceFiles(String pluginsDirPath,Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginSourceFiles(pluginsDirPath)
+ getPluginBuildSettings().getPluginSourceFiles()
}
/**
* Obtains an array of all plug-in provided JAR files
*/
static Resource[] getPluginJarFiles(String pluginsDirPath,Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginJarFiles(pluginsDirPath)
+ getPluginBuildSettings().getPluginJarFiles()
}
/**
@@ -273,7 +277,7 @@ public class GrailsPluginUtils {
static Resource[] getPluginDescriptors(String basedir,
String pluginsDirPath,
Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginDescriptors(basedir, pluginsDirPath)
+ getPluginBuildSettings().getPluginDescriptors()
}
static Resource getBasePluginDescriptor(String basedir) {
@@ -294,7 +298,7 @@ public class GrailsPluginUtils {
*/
static Resource[] getPluginLibDirectories(String pluginsDirPath,
Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginLibDirectories(pluginsDirPath)
+ getPluginBuildSettings().getPluginLibDirectories()
}
@@ -304,7 +308,7 @@ public class GrailsPluginUtils {
*/
static Resource[] getPluginI18nDirectories(String pluginsDirPath = BuildSettingsHolder.settings?.projectPluginsDir?.path,
Closure resourceResolver = DEFAULT_RESOURCE_RESOLVER) {
- getPluginBuildSettings().getPluginI18nDirectories(pluginsDirPath)
+ getPluginBuildSettings().getPluginI18nDirectories()
}
/**
@@ -341,7 +345,7 @@ public class GrailsPluginUtils {
* Obtains a plugin directory for the given name
*/
static Resource getPluginDirForName(String pluginsDirPath, String pluginName) {
- getPluginBuildSettings().getPluginDirForName(pluginName, pluginsDirPath)
+ getPluginBuildSettings().getPluginDirForName(pluginName)
}
/**
View
3 src/java/org/codehaus/groovy/grails/plugins/publishing/DefaultPluginPublisher.groovy
@@ -16,7 +16,6 @@
package org.codehaus.groovy.grails.plugins.publishing
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import groovy.util.slurpersupport.GPathResult
import groovy.xml.MarkupBuilder
import org.springframework.core.io.Resource
@@ -156,4 +155,4 @@ public class DefaultPluginPublisher {
def basedir = BuildSettingsHolder.settings?.baseDir ?: new File(".")
return new XmlSlurper().parse(new File("${basedir.absolutePath}/plugin.xml"))
}
-}
+}
View
46 src/java/org/codehaus/groovy/grails/plugins/web/GroovyPagesGrailsPlugin.groovy
@@ -16,37 +16,28 @@
package org.codehaus.groovy.grails.plugins.web
+import grails.util.BuildSettingsHolder
+import grails.util.Environment
+import grails.util.PluginBuildSettings
-import groovy.lang.MetaClass;
-
-import org.codehaus.groovy.grails.web.pages.TagLibraryLookup;
-import org.springframework.context.ApplicationContext;
-import org.springframework.web.context.request.RequestContextHolder as RCH
-import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
+import groovy.lang.MetaClass
+import java.lang.reflect.Modifier
-import org.codehaus.groovy.grails.plugins.web.taglib.*
-import org.springframework.context.ApplicationContext
-import org.codehaus.groovy.grails.web.pages.GroovyPageBinding;
-import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
-import org.codehaus.groovy.grails.web.pages.ext.jsp.TagLibraryResolver
-import org.codehaus.groovy.grails.web.pages.TagLibraryLookup
-import org.springframework.core.io.FileSystemResource
-import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
-import grails.util.Environment
+import org.codehaus.groovy.grails.commons.GrailsClass
+import org.codehaus.groovy.grails.commons.GrailsClassUtils
import org.codehaus.groovy.grails.commons.GrailsTagLibClass
+import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
import org.codehaus.groovy.grails.plugins.PluginMetaManager
-import org.codehaus.groovy.grails.web.pages.GroovyPage
+import org.codehaus.groovy.grails.web.pages.ext.jsp.TagLibraryResolver
import org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils
-import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
-import org.codehaus.groovy.grails.commons.GrailsClass
-import org.codehaus.groovy.grails.web.taglib.NamespacedTagDispatcher
+import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
import org.codehaus.groovy.grails.web.servlet.view.GrailsViewResolver
-import org.codehaus.groovy.grails.commons.GrailsClassUtils
-import org.springframework.web.context.request.RequestContextHolder
-import org.codehaus.groovy.grails.commons.GrailsApplication
-import java.lang.reflect.Modifier
import org.springframework.beans.factory.config.PropertiesFactoryBean
-import org.codehaus.groovy.grails.web.pages.GroovyPageOutputStack
+import org.springframework.context.ApplicationContext
+import org.springframework.core.io.FileSystemResource
+import org.springframework.web.context.request.RequestContextHolder
+import org.codehaus.groovy.grails.plugins.web.taglib.*
+import org.codehaus.groovy.grails.web.pages.*
/**
* A Plugin that sets up and configures the GSP and GSP tag library support in Grails
@@ -112,12 +103,14 @@ public class GroovyPagesGrailsPlugin {
log.info "Configuring GSP views directory as '${viewsDir}'"
groovyPageResourceLoader(org.codehaus.groovy.grails.web.pages.GroovyPageResourceLoader) {
baseResource = "file:${viewsDir}"
+ pluginSettings = createPluginSettings()
}
}
else {
if (developmentMode) {
groovyPageResourceLoader(org.codehaus.groovy.grails.web.pages.GroovyPageResourceLoader) {
baseResource = new FileSystemResource(".")
+ pluginSettings = createPluginSettings()
}
}
else {
@@ -131,6 +124,7 @@ public class GroovyPagesGrailsPlugin {
else {
baseResource = "/WEB-INF"
}
+ pluginSettings = createPluginSettings()
}
}
}
@@ -363,4 +357,8 @@ public class GroovyPagesGrailsPlugin {
event.manager?.getGrailsPlugin("groovyPages")?.doWithDynamicMethods(event.ctx)
}
+
+ private PluginBuildSettings createPluginSettings() {
+ return new PluginBuildSettings(BuildSettingsHolder.settings);
+ }
}
View
21 src/java/org/codehaus/groovy/grails/web/pages/GroovyPageResourceLoader.java
@@ -14,6 +14,9 @@
*/
package org.codehaus.groovy.grails.web.pages;
+import grails.util.PluginBuildSettings;
+import java.io.IOException;
+
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -23,8 +26,6 @@
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
-import java.io.IOException;
-
/**
* A StaticResourceLoader that loads GSPs from a local grails-app folder instead of from WEB-INF in
* development mode
@@ -39,18 +40,25 @@
* Time: 4:25:08 PM
*/
public class GroovyPageResourceLoader extends StaticResourceLoader {
- private static final Log LOG = LogFactory.getLog(GroovyPageResourceLoader.class);
/**
* The id of the instance of this bean to be used in the Spring context
*/
public static final String BEAN_ID = "groovyPageResourceLoader";
- private Resource localBaseResource;
+
+ private static final Log LOG = LogFactory.getLog(GroovyPageResourceLoader.class);
private static final String PLUGINS_PATH = "plugins/";
+ private Resource localBaseResource;
+ private PluginBuildSettings pluginSettings;
+
public void setBaseResource(Resource baseResource) {
this.localBaseResource = baseResource;
super.setBaseResource(baseResource);
}
+
+ public void setPluginSettings(PluginBuildSettings settings) {
+ this.pluginSettings = settings;
+ }
public Resource getResource(String location) {
if(StringUtils.isBlank(location)) throw new IllegalArgumentException("Argument [location] cannot be null or blank");
@@ -66,7 +74,8 @@ public Resource getResource(String location) {
Resource resource = super.getResource(location);
if(!resource.exists() && location.startsWith(PLUGINS_PATH)) {
if(location.equals(PLUGINS_PATH)) {
- return new FileSystemResource(GrailsPluginUtils.getPluginBaseDirectories().get(0));
+ if (pluginSettings == null) throw new RuntimeException("'pluginsettings' has not been initialised.");
+ return new FileSystemResource(pluginSettings.getPluginBaseDirectories().get(0));
}
else {
final Resource pluginResource = lookupResourceForPluginPath(location);
@@ -87,7 +96,7 @@ protected Resource lookupResourceForPluginPath(String location) {
if(firstSlash > -1) {
String pluginName = pluginPath.substring(0, firstSlash);
String viewPath = pluginPath.substring(firstSlash+1, pluginPath.length());
- Resource pluginBase = GrailsPluginUtils.getPluginDirForName(pluginName);
+ Resource pluginBase = pluginSettings.getPluginDirForName(pluginName);
if(pluginBase != null) {
try {
Resource tmp = new FileSystemResource(pluginBase.getFile().getAbsolutePath() + '/' +viewPath);
View
91 src/test/grails/util/PluginBuildSettingsTests.groovy
@@ -1,10 +1,21 @@
package grails.util
+
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.GrailsPluginManager
+import org.springframework.core.io.Resource
+
/**
* @author Graeme Rocher
* @since 1.1
*/
-
public class PluginBuildSettingsTests extends GroovyTestCase{
+ private static final File TEST_PROJ_DIR = new File("test/test-projects/plugin-build-settings")
+
+ PluginBuildSettings createPluginBuildSettings() {
+ def settings = new BuildSettings(new File("."), TEST_PROJ_DIR)
+ settings.loadConfig()
+ return new PluginBuildSettings(settings)
+ }
void testGetPluginSourceFiles() {
PluginBuildSettings pluginSettings = createPluginBuildSettings()
@@ -86,11 +97,34 @@ public class PluginBuildSettingsTests extends GroovyTestCase{
assertNotNull "should contain webflow", pluginInfos.find { it.name == 'webflow' }
}
- PluginBuildSettings createPluginBuildSettings() {
- def settings = new BuildSettings(new File("."), new File("./test/test-projects/plugin-build-settings"))
- settings.loadConfig()
- def pluginSettings = new PluginBuildSettings(settings)
- return pluginSettings
+ void testGetPluginResourceBundles() {
+ def bundles = createPluginBuildSettings().pluginResourceBundles
+
+ // Check the bundles that there are 3 bundles (2 from Hibernate,
+ // 1 from WebFlow).
+ assertEquals 4, bundles.size()
+
+ // Check that the caching doesn't break anything.
+ assertEquals 4, bundles.size()
+ }
+
+ void testGetImplicitPluginDirectories() {
+ def pluginDirs = createPluginBuildSettings().getImplicitPluginDirectories()
+
+ assertEquals 2, pluginDirs.size()
+ assertNotNull "hibernate plugin should be there",pluginDirs.find { it.filename.contains('hibernate') }
+ assertNotNull "webflow plugin should be there",pluginDirs.find { it.filename.contains('webflow') }
+ }
+
+ void testGetPluginBaseDirectories() {
+ def pluginSettings = createPluginBuildSettings()
+ def baseDirs = pluginSettings.pluginBaseDirectories
+ def pluginDir = new File(TEST_PROJ_DIR, "plugins").canonicalFile
+ def globalPluginDir = pluginSettings.buildSettings.globalPluginsDir.canonicalFile
+
+ assertEquals 2, baseDirs.size()
+ assertTrue baseDirs.any { path -> new File(path).canonicalFile == pluginDir }
+ assertTrue baseDirs.any { path -> new File(path).canonicalFile == globalPluginDir }
}
void testGetPluginDirectories() {
@@ -99,12 +133,51 @@ public class PluginBuildSettingsTests extends GroovyTestCase{
def pluginDirs = pluginSettings.getPluginDirectories()
- println pluginDirs
-
assertEquals 2, pluginDirs.size()
assertNotNull "hibernate plugin should be there",pluginDirs.find { it.filename.contains('hibernate') }
assertNotNull "webflow plugin should be there",pluginDirs.find { it.filename.contains('webflow') }
}
-}
+ void testGetPluginJarFiles() {
+ def jars = createPluginBuildSettings().pluginJarFiles
+
+ // Make sure that all the JARs provided by the plugins are
+ // included in the list.
+ assertEquals 3, jars.size()
+
+ // Check that the caching doesn't break anything.
+ assertEquals 3, jars.size()
+ }
+
+ void testGetSupportPluginInfos() {
+ def pluginInfos = createPluginBuildSettings().supportedPluginInfos
+
+ assertEquals 2, pluginInfos.size()
+ }
+
+ void testGetSupportPluginInfosWithPluginManager() {
+ def pluginSettings = createPluginBuildSettings()
+ pluginSettings.pluginManager = [
+ getGrailsPlugin: { String pluginName ->
+ return [ supportsCurrentScopeAndEnvironment: {-> pluginName == "hibernate" } ] as GrailsPlugin
+ }
+ ] as GrailsPluginManager
+
+ def pluginInfos = pluginSettings.supportedPluginInfos
+
+ assertEquals 1, pluginInfos.size()
+ }
+
+ void testIsGlobalPluginLocation() {
+ def pluginSettings = createPluginBuildSettings()
+ assertFalse pluginSettings.isGlobalPluginLocation([ getFile: {-> new File(".").absoluteFile} ] as Resource)
+ assertFalse pluginSettings.isGlobalPluginLocation([ getFile: {-> new File(TEST_PROJ_DIR, "test")} ] as Resource)
+ assertTrue pluginSettings.isGlobalPluginLocation([
+ getFile: {-> new File(pluginSettings.buildSettings.globalPluginsDir, "test")}
+ ] as Resource)
+ assertTrue pluginSettings.isGlobalPluginLocation([
+ getFile: {-> new File(pluginSettings.buildSettings.globalPluginsDir, "test/../gwt")}
+ ] as Resource)
+ }
+}
View
2 src/test/org/codehaus/groovy/grails/cli/AbstractCliTests.groovy
@@ -6,7 +6,6 @@ import grails.util.BuildSettingsHolder
import org.codehaus.gant.GantBinding
import org.codehaus.groovy.grails.cli.support.GrailsRootLoader
import org.codehaus.groovy.grails.commons.ConfigurationHolder
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
abstract class AbstractCliTests extends GroovyTestCase {
@@ -87,7 +86,6 @@ abstract class AbstractCliTests extends GroovyTestCase {
protected void gantRun(String scriptName) {
def workDir = "${appBase}/work"
def projectDir = "${System.getProperty("base.dir")}/work"
- GrailsPluginUtils.clearCaches()
System.setProperty("grails.script.profile","true")
// Configure the build settings directly rather than using
View
4 src/test/org/codehaus/groovy/grails/scaffolding/DefaultGrailsTemplateGeneratorTests.groovy
@@ -4,8 +4,6 @@ import org.codehaus.groovy.grails.validation.metaclass.ConstraintsEvaluatingDyna
import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
import grails.util.BuildSettings
import grails.util.BuildSettingsHolder
-import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
-
/**
* @author Graeme Rocher
@@ -83,4 +81,4 @@ class ScaffoldingTest {
assertTrue "Should have rendered a select box for the number editor",sw.toString().contains('g:select id="status" name="status" from="${scaffoldingTest.constraints.status.inList}" value="${scaffoldingTest.status}" ></g:select>')
}
-}
+}
View
1 .../plugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/messages.properties
@@ -0,0 +1 @@
+invalid = Invalid entry
View
1 ...ild-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/org/example/custom.properties
@@ -0,0 +1 @@
+hello = Hello
View
1 ...-settings/plugins/hibernate-1.2-SNAPSHOT/grails-app/i18n/org/example/custom_fr.properties
@@ -0,0 +1 @@
+hello = Bonjour
View
BIN ...ugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/lib/hibernate-annotations-3.4.0.GA.jar
Binary file not shown.
View
BIN ...ects/plugin-build-settings/plugins/hibernate-1.2-SNAPSHOT/lib/hibernate-core-3.3.1.GA.jar
Binary file not shown.
View
1 ...ts/plugin-build-settings/plugins/webflow-1.2-SNAPSHOT/grails-app/i18n/messages.properties
@@ -0,0 +1 @@
+invalid = Invalid entry
View
BIN ...d-settings/plugins/webflow-1.2-SNAPSHOT/lib/org.springframework.webflow-2.0.8.RELEASE.jar
Binary file not shown.

0 comments on commit 881a417

Please sign in to comment.
Something went wrong with that request. Please try again.