Skip to content

Commit

Permalink
fix snapshot publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Apr 17, 2012
1 parent 6fc56d6 commit 4fc0905
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class RepositoryController {
plugin.name == p && releaseVersion == v
}

if(!existing.exists()) {
if(!existing.exists() || v.endsWith("-SNAPSHOT")) {
log.debug "Plugin [$p:$v] does not existing. Creating pending release..."
def pendingRelease = new PendingRelease(pluginName:p, pluginVersion:v, zip:cmd.zip, pom:cmd.pom, xml:cmd.xml)
assert pendingRelease.save(flush:true) // assertion should never fail due to prior validation in command object
assert pendingRelease.save(flush:true) // assertion should never fail due to prior validation in command object


log.debug "Triggering plugin publish event for plugin [$p:$v]"
publishEvent(new PluginPublishEvent(pendingRelease))
Expand Down
47 changes: 46 additions & 1 deletion test/unit/org/grails/maven/RepositoryControllerSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RepositoryControllerSpec extends spock.lang.Specification{
response.status == 400
}

void "Test that publishing a publish with an existing release works"() {
void "Test that publishing a plugin with an existing release works"() {
when:"An existing plugin is created"
def tomcat = tomcatPlugin
params.plugin = "tomcat"
Expand All @@ -43,6 +43,36 @@ class RepositoryControllerSpec extends spock.lang.Specification{
response.status == 403
response.text == 'Plugin [tomcat] already published for version [1.0.0]'
}

void "Test that publishing a plugin with an existing release and snapshot version works"() {
when:"An existing plugin is created"
def tomcat = tomcatPluginSnapshot
params.plugin = "tomcat"
params.version = "1.0.0.BUILD-SNAPSHOT"
params.zip = "dummy"
params.xml = "dummy"
params.pom = "dummy"

then:"The plugin release exists"
PluginRelease.count() == 1
PluginRelease.findByPluginAndReleaseVersion(tomcat, params.version) != null
when:"publish is called"
request.method = "POST"
def event
controller.metaClass.publishEvent = {
event = it
}
controller.publish()
then:"The operation is forbidden because the plugin already exists"
event != null
event.source instanceof PendingRelease
response.status == 200
response.text == "Published"

PluginRelease.count() == 1
PluginRelease.findByPluginAndReleaseVersion(tomcat, params.version) != null

}

void "Test publish plugin without necessary files"() {
when:"publish is called without files to upload"
Expand Down Expand Up @@ -148,4 +178,19 @@ class RepositoryControllerSpec extends spock.lang.Specification{
assert !p.hasErrors()
return p
}

Plugin getTomcatPluginSnapshot() {
def p = new Plugin( name: "tomcat",
title: "Tomcat",
currentRelease: "1.0.0.BUILD-SNAPSHOT",
author: "SpringSource",
authorEmail:'foo@bar.com',
downloadUrl:"http://foo.com/tomcat-1.0.0.BUILD-SNAPSHOT.zip",
documentationUrl:"http://grails.org/plugin/tomcat",
lastReleased: new DateTime(2010, 8, 11, 22, 30))
p.releases = [ new PluginRelease(plugin:p, releaseVersion:"1.0.0.BUILD-SNAPSHOT", releaseDate:new DateTime(2010, 8, 11, 22, 30), downloadUrl:"http://foo.com/tomcat-1.0.0.BUILD-SNAPSHOT.zip")]
p.save(flush:true)
assert !p.hasErrors()
return p
}
}

0 comments on commit 4fc0905

Please sign in to comment.