Skip to content

Commit eea8d3a

Browse files
rvowlesgraemerocher
authored andcommitted
GRAILS-3577 - PluginPackager shows a directory is accessible
1 parent 4413cfb commit eea8d3a

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/publishing/PluginDescriptorGenerator.groovy

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,6 @@ class PluginDescriptorGenerator {
8282
generatePluginXml(pluginProps, xml)
8383
}
8484

85-
/* the pluginExcludes are Ant matched from the base of the application, but since the
86-
pluginProps is not necessarily a class and we don't actually know where it is, we need
87-
to go through the resources figuring out what the common resource base is. We are going to assume
88-
a common Grails application layout to fudge this.
89-
*/
90-
private String resourceBaseMatchDirs = ['grails-app', 'web-app', 'scripts', 'test', 'src']
91-
private File findCommonResourceBase() {
92-
if (!resourceList) return null // no resources, won't loop
93-
94-
for (Resource r in resourceList) {
95-
File f = r.file
96-
97-
while (f != null && !resourceBaseMatchDirs.contains(f.name)) {
98-
f = f.parentFile
99-
}
100-
101-
if (f) {
102-
if (f.parentFile == null) { // wonderful, thanks Resource
103-
return new File(f.absolutePath.substring(0, f.absolutePath.lastIndexOf(File.separator)))
104-
} else {
105-
return f.parentFile
106-
}
107-
}
108-
}
109-
110-
GrailsUtil.warn("Unable to determine common resource base when generating plugin.xml")
111-
112-
return null
113-
}
114-
11585
private boolean matchesPluginExcludes(List<String> pluginExcludes, File commonResourceBase, Resource r) {
11686

11787
// if we have no excludes or no common resource base, we don't match
@@ -129,6 +99,17 @@ class PluginDescriptorGenerator {
12999
return false
130100
}
131101

102+
// this is needed to pass the test as the resources don't really exist
103+
private File filterPluginDir(File pluginDir) {
104+
if (!pluginDir) return null
105+
106+
if (pluginDir.absolutePath.endsWith(File.separator + ".")) {
107+
return new File(pluginDir.absolutePath.substring(0, pluginDir.absolutePath.lastIndexOf(File.separator)))
108+
} else {
109+
return pluginDir
110+
}
111+
}
112+
132113
protected void generatePluginXml(pluginProps, MarkupBuilder xml) {
133114
// Write the content!
134115
def props = ['author', 'authorEmail', 'title', 'description', 'documentation', 'type', 'packaging']
@@ -155,7 +136,7 @@ class PluginDescriptorGenerator {
155136
if (pluginProps[p]) "${p}"(pluginProps[p])
156137
}
157138
xml.resources {
158-
File commonResourceBase = findCommonResourceBase()
139+
File commonResourceBase = filterPluginDir(pluginProps['pluginDir']?.file)
159140

160141
for (r in resourceList) {
161142
def matcher = r.URL.toString() =~ ARTEFACT_PATTERN

grails-core/src/test/groovy/org/codehaus/groovy/grails/plugins/publishing/PluginDescriptorGeneratorSpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PluginDescriptorGeneratorSpec extends Specification {
3232
def generator = new PluginDescriptorGenerator(new BuildSettings(),"foo", [])
3333
when:
3434
def sw = new StringWriter()
35-
generator.generatePluginXml([version:1.0, dependsOn:[core:1.0], author:"Bob", pluginExcludes: ["**/test/**"]], sw)
35+
generator.generatePluginXml([version:1.0, dependsOn:[core:1.0], author:"Bob", pluginDir: new FileSystemResource(new File(".")), pluginExcludes: ["**/test/**"]], sw)
3636
def xml = new XmlSlurper().parseText(sw.toString())
3737
then:
3838
xml.@name == 'foo'
@@ -45,15 +45,15 @@ class PluginDescriptorGeneratorSpec extends Specification {
4545

4646
def "Test plugin/excludes is honoured for resources"() {
4747
given:
48-
def generator = new PluginDescriptorGenerator(new BuildSettings(),"foo", [
48+
def generator = new PluginDescriptorGenerator(new BuildSettings(),"foo", [
4949
new FileSystemResource(new File("grails-app/controllers/FooController.groovy")),
5050
new FileSystemResource(new File("grails-app/controllers/test/BarController.groovy")),
5151
new FileSystemResource(new File("grails-app/services/test/MyService.groovy")),
5252
new FileSystemResource(new File("grails-app/services/MyService2.groovy"))
5353
])
5454
when:
5555
def sw = new StringWriter()
56-
generator.generatePluginXml([version:1.0, dependsOn:[core:1.0], author:"Bob", pluginExcludes: ["**/test/**"]], sw)
56+
generator.generatePluginXml([version:1.0, dependsOn:[core:1.0], author:"Bob", pluginDir: new FileSystemResource(new File(".")), pluginExcludes: ["**/test/**"]], sw)
5757
def xml = new XmlSlurper().parseText(sw.toString())
5858
then:
5959
xml.@name == 'foo'

0 commit comments

Comments
 (0)