Browse files

Fix grailsRepo URL handling.

If a plugin's name began with 'grails-', the URL mappings for the 'grailsRepo' requests failed because of some problematic logic. All types of file requested by Ivy (zips, POMs, XML descriptors, and their checksums) are not forwarded to the underlying Maven repository correctly now.
  • Loading branch information...
1 parent a2bf169 commit ef6415a614c14127cdf5e3614c5c359465e0621f @pledbrook pledbrook committed Jun 13, 2012
View
38 grails-app/conf/UrlMappings.groovy
@@ -13,22 +13,34 @@ class UrlMappings {
def populateVersion = {
pluginVersion = {
- try {
+ def version = params.version
+ if (version) {
+ // In the case of the RELEASE_* tag, we can just use
+ // the version number it provides.
+ return params.version?.replace('_','.')
+ }
+ else {
+ // For LATEST_RELEASE tags, we have to work out the
+ // version from the filename.
def fn = params.fullName
- if(fn.contains('-')) {
- if(fn.startsWith("grails-")) {
- fn = fn[7..-1]
- params.fullName = fn
- }
- return fn[params.plugin.size()+1..-1]
- }
- else {
- return params.version?.replace('_','.')
+ def pluginName = params.plugin
+ if (!fn.startsWith(pluginName) && fn.startsWith("grails-")) {
+ // This is the plugin package (zip) or its associated
+ // checksums, because the packages have a 'grails-'
+ // prefix in their names.
+ fn = fn[7..-1]
+ params.fullName = fn
}
+
+ // The full name may be no more than the plugin name, i.e.
+ // without the version. Only an invalid URL would be like this
+ // so just return null and let the URL matching return a 404.
+ // Otherwise extract the version number from the filename. Note
+ // that this may include a '-plugin' suffix in the case of the
+ // XML plugin descriptor, but that's fine as the action handles
+ // that.
+ return fn == pluginName ? null : fn.substring(pluginName.size() + 1)
}
- catch(e) {
- params.version?.replace('_','.')
- }
}
}
View
19 grails-app/controllers/org/grails/maven/RepositoryController.groovy
@@ -94,6 +94,8 @@ class RepositoryController {
*/
def artifact(String fullName, String plugin, String pluginVersion, String type) {
if(plugin && pluginVersion && type) {
+ type = getCorrectType(fullName, type)
+
String key = "artifact:$plugin:$pluginVersion:$type".toString()
def url = cacheService?.getContent(key)
if(url == null) {
@@ -233,6 +235,23 @@ class RepositoryController {
return writer.toString()
}
+
+ /**
+ * When the requested file is a checksum (.sha1 or .md5), the <em>actual</em>
+ * type is encoded in the "full name" part of the file. This method extracts
+ * the real type and appends the checksum part. For example,
+ * <tt>grails-shiro-1.0.0.zip.sha1</tt> has a type of 'sha1' and the '.zip'
+ * is included in the <tt>fullName</tt> parameter. In this case, the method
+ * will return 'zip.sha1'. For non-checksum files, the type is returned as
+ * is, e.g. if <tt>type</tt> is 'zip' the method returns 'zip'.
+ */
+ protected getCorrectType(String fullName, String type) {
+ if (type != 'md5' && type != 'sha1') return type
+
+ def pos = fullName.lastIndexOf('.')
+ if (pos != -1) return fullName.substring(pos + 1) + '.' + type
+ else return type
+ }
}
class PublishPluginCommand {
String plugin
View
8 grails-app/services/org/grails/maven/PluginDeployService.groovy
@@ -22,7 +22,7 @@ class PluginDeployService implements ApplicationListener<PluginPublishEvent>{
@Transactional
void onApplicationEvent(PluginPublishEvent event) {
PendingRelease pendingRelease = event.source
- log.debug "Recieved plugin publish event for pending release [$event.source]"
+ log.debug "Received plugin publish event for pending release [$event.source]"
deployRelease(pendingRelease)
}
@@ -56,7 +56,7 @@ class PluginDeployService implements ApplicationListener<PluginPublishEvent>{
body pendingRelease[type]
}
- log.debug "Recieved artifactory response: ${resp?.text}"
+ log.debug "Received artifactory response: ${resp?.text}"
uri = "$baseUrl/$p/$v/$p-${v}${ext}.md5"
@@ -66,7 +66,7 @@ class PluginDeployService implements ApplicationListener<PluginPublishEvent>{
body DigestUtils.md5Hex(pendingRelease[type])
}
- log.debug "Recieved artifactory response: ${resp?.text}"
+ log.debug "Received artifactory response: ${resp?.text}"
uri = "$baseUrl/$p/$v/$p-${v}${ext}.sha1"
log.debug "Uploading SHA1 checksum $uri"
@@ -75,6 +75,6 @@ class PluginDeployService implements ApplicationListener<PluginPublishEvent>{
body DigestUtils.shaHex(pendingRelease[type])
}
- log.debug "Recieved artifactory response: ${resp?.text}"
+ log.debug "Received artifactory response: ${resp?.text}"
}
}

0 comments on commit ef6415a

Please sign in to comment.