Permalink
Browse files

Remove master plugin list synchronisation code.

  • Loading branch information...
1 parent c583825 commit 63a1e652a4363f05fe0ecdec16fa33d4009c7cfc @pledbrook pledbrook committed May 18, 2012
Showing with 0 additions and 232 deletions.
  1. +0 −232 grails-app/services/org/grails/plugin/PluginService.groovy
@@ -155,245 +155,13 @@ class PluginService {
searchableService.startMirroring()
}
}
-
-
- @CacheFlush('pluginMetaList')
- def runMasterUpdate() {
- translateMasterPlugins(generateMasterPlugins())
- }
-
- /**
- * Reads the plugin list and returns XML as a Gpath result
- */
- def readPluginList() {
- def pluginLoc = grailsApplication.config?.plugins?.pluginslist
- def listFile = new URL(pluginLoc)
- def listText = listFile.text
- // remove the first line of <?xml blah/>
- listText = listText.replaceAll(/\<\?xml ([^\<\>]*)\>/, '')
- new XmlSlurper().parseText(listText)
- }
-
- def generateMasterPlugins() {
- try {
- def plugins = readPluginList()
- log.debug "Found ${plugins.plugin.size()} master plugins."
-
- return plugins.plugin.inject([]) { pluginsList, pxml ->
- if (!pxml.release.size()) return pluginsList
- def latestRelease = pxml.@'latest-release'
- def latestReleaseNode = pxml.release.find { releaseNode ->
- releaseNode.@version == latestRelease
- }
- def p = new Plugin()
- p.with {
- name = pxml.@name
- grailsVersion = getGrailsVersion(p)
- title = latestReleaseNode.title.toString() ?: pxml.@name
- description = new PluginTab(body:latestReleaseNode.description.toString() ?: '')
- author = latestReleaseNode.author
- authorEmail = latestReleaseNode.authorEmail
- documentationUrl = replaceOldDocsWithNewIfNecessary(latestReleaseNode.documentation, name)
- downloadUrl = latestReleaseNode.file
- currentRelease = latestRelease
- }
-
- log.debug "Found plugin [$p.name] with current release [$p.currentRelease]"
- Set releases = []
- pxml.release.each { r ->
- def pr = new PluginRelease(plugin:p)
- def file = r.file.text()
- if(file) {
- pr.downloadUrl = file
- pr.releaseVersion = r.@version.text()
- releases << pr
- }
-
- }
-
- p.releases = releases
- pluginsList << p
- }
- }
- catch(e) {
- log.error "Error parsing master plugin list: ${e.message}",e
- return []
- }
-
- }
-
- private def replaceOldDocsWithNewIfNecessary(oldDocs, name) {
- boolean match = oldDocs =~ /http:\/\/(www\.)?grails.org\//
- return match ? "http://grails.org/plugin/${name}" : oldDocs
- }
-
- def translateMasterPlugins(masters) {
- log.debug "Updating plugins from master versions..."
- Plugin.withSession { session ->
- masters.each { master ->
- try {
-
- def plugin = Plugin.findByName(master.name)
- log.debug "Checking plugin [$master.name]"
- if (!plugin) {
- log.debug "Plugin [$master.name] doesn't exist, creating new one..."
-
- // injecting a unique wiki page name for description
- // pull off the desc so we don't try to save it
- def descWiki = master.description
- master.description = null
-
- // obtain release dates
- master.releases?.each { pr ->
- pr.releaseDate = fetchPluginReleaseDate(pr)
- }
- // so we need to save the master first to get its id
- if (!master.save()) {
- log.error "Could not save master plugin: $master.name ($master.title), version $master.currentRelease"
- master.errors.allErrors.each { log.error "\t$it" }
-
- }
- // put the wiki page back with a unique title
- descWiki.title = "description-${master.id}"
- master.description = descWiki
- log.debug "No existing plugin, creating new ==> ${master.name}"
- // before saving the master, we need to save the description wiki page
- if (!master.description.save() && master.description.hasErrors()) {
- master.description.errors.allErrors.each { log.error it }
- } else {
- def v = master.description.createVersion()
- v.author = User.findByLogin('admin')
- if(!v.save(flush:true)) {
- log.warn "Can't save version ${v.title} (${v.number})"
- v.errors.allErrors.each { log.warn it }
- }
- }
- //inject dummy wikis for users to fill in
- (Plugin.WIKIS - 'description').each { wiki ->
- master."$wiki" = new PluginTab(title:"$wiki-${master.id}", body:'')
- assert master."$wiki".save()
- }
- // give an initial release date of now
- master.lastReleased = new DateTime()
- if (!master.groupId) {
- master.groupId = "org.grails.plugins"
- }
-
- // so we need to save the master first to get its id
- //
- // save new master plugin
- if (!master.save()) {
- log.error "Could not save master plugin: $master.name ($master.title), version $master.currentRelease"
- master.errors.allErrors.each { log.error "\t$it" }
- } else {
- log.info "New plugin was saved from master: $master.name"
- log.info "There are now ${Plugin.count()} plugins."
- }
- } else {
- // update existing plugin
- log.debug "Plugin [$master.name] already exists, updating..."
- updatePlugin(plugin, master)
- synchronizePluginReleases(plugin, master)
- }
-
- }
- finally {
- session.flush()
- session.clear()
- }
- }
-
- }
- }
-
- def updatePlugin(plugin, master) {
- // Don't update the plugin if the version hasn't changed.
- if (plugin.currentRelease == master.currentRelease) return
-
- log.info "Updating plugin \"$plugin.name\"..."
-
- // these attributes are overriden by local plugin domain changes
- updatePluginAttribute('title', plugin, master)
- updatePluginAttribute('author', plugin, master)
- updatePluginAttribute('authorEmail', plugin, master)
-
- // these are always overridden by the master list
- plugin.name = master.name
- plugin.documentationUrl = master.documentationUrl
- plugin.downloadUrl = master.downloadUrl
- // if this was a release update, also update the date of release
- if (plugin.currentRelease != master.currentRelease) {
- plugin.lastReleased = new DateTime()
- }
- plugin.currentRelease = master.currentRelease
- plugin.grailsVersion = master.grailsVersion
-
- if (!plugin.save()) {
- log.warn "Local plugin '$plugin.name' was not updated properly... errors follow:"
- plugin.errors.allErrors.each { log.warn it }
- // I don't know why new versions need to be created here, but it's causing
- // problems because each new Version has the same number as the current
- // wiki page version. PAL
-// } else {
-// def v = plugin.description.createVersion()
-// v.author = User.findByLogin('admin')
-// if(!v.save(flush:true)) {
-// log.warn "Can't save version ${v.title} (${v.number})"
-// v.errors.allErrors.each { log.warn it }
-// }
- }
-
- log.info "Local plugin '$plugin.name' was updated with master version."
- }
-
- def updatePluginAttribute(propName, plugin, master) {
- if (master."$propName" && !plugin."$propName") {
- plugin."$propName" = master."$propName"
- }
- }
def compareVersions(v1, v2) {
def v1Num = new PluginVersion(version:v1)
def v2Num = new PluginVersion(version:v2)
v1Num.compareTo(v2Num)
}
- def getGrailsVersion(plugin) {
- def xmlLoc = "${grailsApplication.config?.plugins?.location}/grails-${plugin.name}/tags/LATEST_RELEASE/plugin.xml"
- def xmlUrl = new URL(xmlLoc)
-
- try {
- def xmlText = xmlUrl.text
-
- def pluginXml = new XmlSlurper().parseText(xmlText)
- return pluginXml.@grailsVersion.toString()
- }
- catch (FileNotFoundException ex) {
- // If the file doesn't exist, then the plugin was published using
- // the portal 'ping'.
- return ''
- }
- }
-
- protected synchronizePluginReleases(plugin, master) {
- for (release in master.releases) {
- def existing = PluginRelease.findByPluginAndReleaseVersion(plugin, release.releaseVersion)
- if(!existing) {
- release.releaseDate = fetchPluginReleaseDate(release)
- release.plugin = plugin
- release.save()
- plugin.addToReleases(release)
- }
- }
- }
-
- protected DateTime fetchPluginReleaseDate(pluginRelease) {
- log.debug "Found release [$pluginRelease.downloadUrl], obtaining last modified date"
- def conn = new URL(pluginRelease.downloadUrl).openConnection()
- conn.connectTimeout = 5000
- return new DateTime(conn.lastModified)
- }
-
/**
* Text-based search using the given Lucene-compatible query string.
* Returns a list of Plugin instances, although they may not be fully

0 comments on commit 63a1e65

Please sign in to comment.