Skip to content

Commit

Permalink
When a plugin is published for the first time via the REST interface,…
Browse files Browse the repository at this point in the history
… the installation/description/faq/screenshots wiki pages are now created. Previously, users were unable to edit the plugin wiki pages for new plugins.
  • Loading branch information
pledbrook committed Feb 4, 2011
1 parent 698f866 commit 8bacf12
Showing 1 changed file with 25 additions and 5 deletions.
@@ -1,6 +1,7 @@
package org.grails.plugin

import groovyx.net.http.HTTPBuilder
import org.grails.wiki.WikiPage
import org.springframework.context.ApplicationEvent
import org.springframework.context.ApplicationListener
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -52,7 +53,7 @@ class PluginUpdateService implements ApplicationListener<PluginUpdateEvent> {
// We either need to create a new Plugin instance or update the
// existing one. Since we already have the version, we can deal
// with that too.
def plugin = fetchOrCreatePluginInstance(event.name)
def plugin = fetchOrCreatePluginInstance(event.name, event.version)
def isNewVersion = plugin.currentRelease != event.version
if (!event.snapshot) {
plugin.currentRelease = event.version
Expand All @@ -76,7 +77,7 @@ class PluginUpdateService implements ApplicationListener<PluginUpdateEvent> {

// Pull in the POM and parse it.
def parser = new XmlSlurper()
def pomUrl = new URL(baseUrl, "${plugin.name}-${plugin.currentRelease}.pom")
def pomUrl = new URL(baseUrl, "${plugin.name}-${event.version}.pom")
def xml = null
pomUrl.withReader { reader ->
xml = parser.parse(reader)
Expand All @@ -92,7 +93,7 @@ class PluginUpdateService implements ApplicationListener<PluginUpdateEvent> {
plugin.scmUrl = xml.scm.url.text()

// Now do the same with the XML plugin descriptor.
def descUrl = new URL(baseUrl, "${plugin.name}-${plugin.currentRelease}-plugin.xml")
def descUrl = new URL(baseUrl, "${plugin.name}-${event.version}-plugin.xml")
descUrl.withReader { reader ->
xml = parser.parse(reader)
}
Expand Down Expand Up @@ -126,11 +127,30 @@ class PluginUpdateService implements ApplicationListener<PluginUpdateEvent> {
* and returns it. If the plugin isn't in the database yet, this
* methods creates a new instance and returns that. Note that the
* new instance is not saved and only has the name set.
* @param pluginName The name of the plugin.
* @param version If the plugin needs to be created, it's current version
* is set to this value.
*/
Plugin fetchOrCreatePluginInstance(String pluginName) {
@Transactional
Plugin fetchOrCreatePluginInstance(String pluginName, String version) {
def plugin = Plugin.findByName(pluginName)
if (!plugin) {
plugin = new Plugin(name: pluginName, downloadUrl: "not provided")
plugin = new Plugin(name: pluginName, currentRelease: version, downloadUrl: "not provided")

// Add the wiki pages for this new plugin.
Plugin.WIKIS.each { wiki ->
def body = ''
if (wiki == 'installation') {
body = "{code}grails install-plugin ${plugin.name}{code}"
}

// Saves don't cascade from the plugin to the wiki pages, so
// we have to save them before saving the plugin.
def wikiPage = new WikiPage(title:"plugin-${plugin.name}-${wiki}", body:body)
wikiPage.save()

plugin."$wiki" = wikiPage
}
}

return plugin
Expand Down

0 comments on commit 8bacf12

Please sign in to comment.