@@ -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}
0 commit comments