Permalink
Browse files

fix broken plugin update logic for authors aka "The Marc Palmer Bug"

  • Loading branch information...
graemerocher committed Dec 19, 2012
1 parent 8b08026 commit 04d7591dd548e763c6ea281c695277c0b58bab28
@@ -352,13 +352,16 @@ class PluginUpdater {
protected addAuthors(pomDevelopersXml) {
plugin.authors?.clear()
for (developer in pomDevelopersXml.developer) {
- def user = UserInfo.findOrCreateWhere(email: developer.email.text())
+ def email = developer.email.text()
+
+ def user = email ? UserInfo.findOrCreateWhere(email: email) : new UserInfo()
if (!user.name) {
user.name = developer.name.text()
}
user.save(failOnError: true)
-
- plugin.addToAuthors(user)
+ def existing = plugin.authors?.find { it.name == user.name}
+ if(!existing)
+ plugin.addToAuthors(user)
}
}
@@ -19,6 +19,35 @@ class PluginUpdateServiceSpec extends Specification {
service.twitterLimit = 80
}
+ def "Test that updating authors from POM data works correctly"() {
+ given:"A plugin updater and a POM"
+ def updater = new PluginUpdater("1.0", "com.mycompany", "http://foobar.com", false)
+ updater.@plugin = new Plugin()
+ def xml = new XmlSlurper().parseText("""\
+<?xml version='1.0' encoding='UTF-8'?>
+<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'>
+ <developers>
+ <developer>
+ <name>Graeme Rocher</name>
+ <email>123@springsource.com</email>
+ </developer>
+ <developer>
+ <name>Graeme Rocher</name>
+ <email>123@vmware.com</email>
+ </developer>
+ </developers>
+</project>
+ """)
+
+ when:"The authors are updated from the POM xml"
+ mockDomain(org.grails.meta.UserInfo)
+ updater.addAuthors(xml.developers)
+
+ then:"The authors are populated correctly"
+ updater.@plugin.authors.size() == 1
+ updater.@plugin.authors[0].name == "Graeme Rocher"
+ updater.@plugin.authors[0].email == "123@springsource.com"
+ }
def "Test plugin update event processing"() {
given:"A plugin update event"

0 comments on commit 04d7591

Please sign in to comment.