Skip to content

Commit a5cb412

Browse files
committed
GRAILS-6719 applied patch for similarly-named inline plugin name confusion
1 parent be1fafb commit a5cb412

File tree

8 files changed

+43
-10
lines changed

8 files changed

+43
-10
lines changed

src/java/grails/util/PluginBuildSettings.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class PluginBuildSettings {
193193
}
194194

195195
for (Resource pluginDir in pluginDirs) {
196-
def pluginPath = pluginDir.file.canonicalPath
196+
def pluginPath = pluginDir.file.canonicalPath + File.separator
197197
def sourcePath = new File(sourceFile).canonicalPath
198198
if (sourcePath.startsWith(pluginPath)) {
199199
// Check the path of the source file relative to the

src/test/grails/util/PluginBuildSettingsTests.groovy

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class PluginBuildSettingsTests extends GroovyTestCase {
1212

1313
private static final File TEST_PROJ_DIR = new File("test/test-projects/plugin-build-settings")
1414
private static final File NESTED_INLINE_PLUGIN_TEST_PROJ_DIR = new File("test/test-projects/nested-inline-plugins/app")
15-
15+
private static final File INLINE_PLUGINS_TEST_PROJ_DIR = new File("test/test-projects/inline-plugins/app")
16+
1617
PluginBuildSettings createPluginBuildSettings(File projectDir = TEST_PROJ_DIR) {
1718
def settings = new BuildSettings(new File("."), projectDir)
1819
settings.loadConfig()
@@ -183,30 +184,50 @@ class PluginBuildSettingsTests extends GroovyTestCase {
183184
-> new File(pluginSettings.buildSettings.globalPluginsDir, "test/../gwt")
184185
}] as Resource)
185186
}
186-
187+
187188
void testNestedInlinePlugins() {
188189
def pluginSettings = createPluginBuildSettings(NESTED_INLINE_PLUGIN_TEST_PROJ_DIR)
189190
def inlinePluginDirs = pluginSettings.inlinePluginDirectories*.file
190-
191+
191192
assertEquals("inline plugins found", 2, inlinePluginDirs.size())
192-
193+
193194
def pluginOneDir = inlinePluginDirs.find { it.name.endsWith("plugin-one") }
194195
assertNotNull("plugin one dir", pluginOneDir)
195196
assertTrue("plugin one dir exists", pluginOneDir.exists())
196-
197+
197198
def pluginTwoDir = inlinePluginDirs.find { it.name.endsWith("plugin-two") }
198199
assertNotNull("plugin two dir", pluginTwoDir)
199-
200+
200201
// This is the most important test.
201-
//
202+
//
202203
// plugin two is a dependency of plugin one, and is defined relative to it
203204
// which means the path it is defined with does not point to it if resolved
204-
// relative to the "root" app that included plugin one. This would produce
205+
// relative to the "root" app that included plugin one. This would produce
205206
// a false positive if test/test-projects/nested-inline-plugins/plugin-two existed.
206207
assertTrue("plugin two dir exists", pluginTwoDir.exists())
207-
208+
208209
// Make sure no one has done the wrong thing and put a dir at test/test-projects/nested-inline-plugins/plugin-two
209210
def pluginTwoInSameDirAsRootApp = new File(NESTED_INLINE_PLUGIN_TEST_PROJ_DIR.parentFile, "plugin-two")
210211
assertTrue("should not be a plugin-two dir in same dir as root app", !pluginTwoInSameDirAsRootApp.exists())
211212
}
213+
214+
void testInlinePluginsWithCommonPrefix() {
215+
def pluginSettings = createPluginBuildSettings(INLINE_PLUGINS_TEST_PROJ_DIR)
216+
def pluginInfos = pluginSettings.getPluginInfos()
217+
218+
assertEquals "plugins found", 2, pluginInfos.size()
219+
220+
assertNotNull "should contain foo", pluginInfos.find { it.name == 'foo' }
221+
assertNotNull "should contain foobar", pluginInfos.find { it.name == 'foobar' }
222+
223+
def pluginsDir = new File(INLINE_PLUGINS_TEST_PROJ_DIR.parentFile, "plugins")
224+
def fooSource = new File(pluginsDir, "foo/grails-app/controllers/foo/FooController.groovy")
225+
def foobarSource = new File(pluginsDir, "foobar/grails-app/controllers/foobar/FoobarController.groovy")
226+
227+
assertEquals "FooController in foo plugin", "foo", pluginSettings.getPluginInfoForSource(fooSource.path).name
228+
assertEquals "FoobarController in foobar plugin", "foobar", pluginSettings.getPluginInfoForSource(foobarSource.path).name
229+
230+
def testSource = new File(pluginsDir, "foo/test/unit/foo/FooControllerTests.groovy")
231+
assertNull "test source should not return a plugin info", pluginSettings.getPluginInfoForSource(testSource.path)
232+
}
212233
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Used by PluginBuildSettingsTests to test GRAILS-6719
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
grails.plugin.location.foo="../plugins/foo"
2+
grails.plugin.location.foobar="../plugins/foobar"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class FooGrailsPlugin {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package foo
2+
3+
class FooController {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class FoobarGrailsPlugin {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package foobar
2+
3+
class FoobarController {}
4+

0 commit comments

Comments
 (0)