Skip to content

Commit

Permalink
GRAILS-6853 - fix for nested inline plugins not being resolved relati…
Browse files Browse the repository at this point in the history
…ve to the plugin that included it.
  • Loading branch information
ldaley committed Oct 20, 2010
1 parent f83e098 commit 6a0f411
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 7 deletions.
23 changes: 20 additions & 3 deletions src/java/grails/util/AbstractBuildSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @since 1.3.4
*/
public class AbstractBuildSettings {
abstract public class AbstractBuildSettings {

private static final String KEY_PLUGIN_DIRECTORY_RESOURCES = "pluginDirectoryResources";
private static final String KEY_INLINE_PLUGIN_LOCATIONS = "inlinePluginLocations";
Expand All @@ -46,6 +46,8 @@ public class AbstractBuildSettings {
@SuppressWarnings("rawtypes")
protected Map flatConfig = Collections.emptyMap();

abstract File getBaseDir();

/**
* Clears any locally cached values
*/
Expand Down Expand Up @@ -115,8 +117,23 @@ public Collection<File> getPluginDirectories() {
return pluginDirectoryResources;
}

@SuppressWarnings({ "rawtypes", "hiding" })
/**
* Extracts the inline plugin dirs relative to the base dir of this project.
*
* @see getInlinePluginsFromConfiguration(Map, File)
*/
@SuppressWarnings({ "rawtypes" })
protected Collection<File> getInlinePluginsFromConfiguration(Map config) {
return getInlinePluginsFromConfiguration(config, getBaseDir());
}

/**
* Extracts the inline plugin dirs from the given config, relative to the given baseDir.
*
* @todo consider trowing an error here if an plugin does not exists at the location.
*/
@SuppressWarnings({ "rawtypes", "hiding" })
protected Collection<File> getInlinePluginsFromConfiguration(Map config, File baseDir) {
Collection<File> inlinePlugins = new ConcurrentLinkedQueue<File>();
if (config != null) {
Map pluginLocations = lookupPluginLocationConfig(config);
Expand All @@ -125,7 +142,7 @@ protected Collection<File> getInlinePluginsFromConfiguration(Map config) {
if (value != null) {
File resource;
try {
resource = new File(value.toString()).getCanonicalFile();
resource = new File(baseDir, value.toString()).getCanonicalFile();
inlinePlugins.add(resource);
}
catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/grails/util/BuildSettings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class BuildSettings extends AbstractBuildSettings {
dependencyManager.parseDependencies(pluginName, pluginDependencyConfig)
}

def inlinePlugins = getInlinePluginsFromConfiguration(pluginConfig)
def inlinePlugins = getInlinePluginsFromConfiguration(pluginConfig, dir)
if(inlinePlugins) {

for(File inlinePlugin in inlinePlugins) {
Expand Down
33 changes: 30 additions & 3 deletions src/test/grails/util/PluginBuildSettingsTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import org.springframework.core.io.Resource
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)
private static final File NESTED_INLINE_PLUGIN_TEST_PROJ_DIR = new File("test/test-projects/nested-inline-plugins/app")

PluginBuildSettings createPluginBuildSettings(File projectDir = TEST_PROJ_DIR) {
def settings = new BuildSettings(new File("."), projectDir)
settings.loadConfig()
return new PluginBuildSettings(settings)
}
Expand Down Expand Up @@ -182,4 +183,30 @@ class PluginBuildSettingsTests extends GroovyTestCase {
-> new File(pluginSettings.buildSettings.globalPluginsDir, "test/../gwt")
}] as Resource)
}

void testNestedInlinePlugins() {
def pluginSettings = createPluginBuildSettings(NESTED_INLINE_PLUGIN_TEST_PROJ_DIR)
def inlinePluginDirs = pluginSettings.inlinePluginDirectories*.file

assertEquals("inline plugins found", 2, inlinePluginDirs.size())

def pluginOneDir = inlinePluginDirs.find { it.name.endsWith("plugin-one") }
assertNotNull("plugin one dir", pluginOneDir)
assertTrue("plugin one dir exists", pluginOneDir.exists())

def pluginTwoDir = inlinePluginDirs.find { it.name.endsWith("plugin-two") }
assertNotNull("plugin two dir", pluginTwoDir)

// This is the most important test.
//
// plugin two is a dependency of plugin one, and is defined relative to it
// which means the path it is defined with does not point to it if resolved
// relative to the "root" app that included plugin one. This would produce
// a false positive if test/test-projects/nested-inline-plugins/plugin-two existed.
assertTrue("plugin two dir exists", pluginTwoDir.exists())

// Make sure no one has done the wrong thing and put a dir at test/test-projects/nested-inline-plugins/plugin-two
def pluginTwoInSameDirAsRootApp = new File(NESTED_INLINE_PLUGIN_TEST_PROJ_DIR.parentFile, "plugin-two")
assertTrue("should not be a plugin-two dir in same dir as root app", !pluginTwoInSameDirAsRootApp.exists())
}
}
3 changes: 3 additions & 0 deletions test/test-projects/nested-inline-plugins/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Used by PluginBuildSettingsTests.

It verifies that inline plugins of inline plugins are "found" relative to the plugin that included them and not the "root" app.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grails.plugin.location.'plugin-one'="../plugins/plugin-one"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PluginOneGrailsPlugin {



}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grails.plugin.location.'plugin-two'="../plugin-two"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PluginTwoGrailsPlugin {



}

0 comments on commit 6a0f411

Please sign in to comment.