-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a gradle task to publish pact files to a pact broker #120
- Loading branch information
Ronald Holshausen
committed
Jul 6, 2015
1 parent
11adca2
commit 5fe1698
Showing
6 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ovider-gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPluginExtension.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
package au.com.dius.pact.provider.gradle | ||
|
||
import org.gradle.api.NamedDomainObjectContainer | ||
import org.gradle.util.ConfigureUtil | ||
|
||
class PactPluginExtension { | ||
|
||
final NamedDomainObjectContainer<ProviderInfo> serviceProviders | ||
|
||
PactPublish publish | ||
|
||
public PactPluginExtension(serviceProviders) { | ||
this.serviceProviders = serviceProviders | ||
} | ||
|
||
def serviceProviders(Closure closure) { | ||
serviceProviders.configure(closure) | ||
} | ||
|
||
def publish(Closure closure) { | ||
publish = new PactPublish() | ||
ConfigureUtil.configure(closure, publish) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
pact-jvm-provider-gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPublish.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package au.com.dius.pact.provider.gradle | ||
|
||
import groovy.transform.ToString | ||
|
||
@ToString | ||
class PactPublish { | ||
def pactDirectory | ||
String pactBrokerUrl | ||
} |
43 changes: 43 additions & 0 deletions
43
...m-provider-gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPublishTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package au.com.dius.pact.provider.gradle | ||
|
||
import groovy.io.FileType | ||
import groovy.json.JsonSlurper | ||
import groovyx.net.http.HTTPBuilder | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
import static groovyx.net.http.ContentType.JSON | ||
import static groovyx.net.http.Method.PUT | ||
|
||
class PactPublishTask extends DefaultTask { | ||
|
||
@TaskAction | ||
void publishPacts() { | ||
if (!project.pact.publish) { | ||
throw new RuntimeException('You must add a pact publish configuration to your build before you can ' + | ||
'use the pactPublish task') | ||
} | ||
|
||
PactPublish pactPublish = project.pact.publish | ||
if (pactPublish.pactDirectory == null) { | ||
pactPublish.pactDirectory = project.file("${project.buildDir}/pacts") | ||
} | ||
|
||
def http = new HTTPBuilder(pactPublish.pactBrokerUrl) | ||
File pactDirectory = pactPublish.pactDirectory as File | ||
pactDirectory.eachFileMatch(FileType.FILES, ~/.*\.json/) { pactFile -> | ||
print "Publishing ${pactFile.name} ... " | ||
def pact = new JsonSlurper().parse(pactFile) | ||
http.request(PUT) { | ||
uri.path = "/pacts/provider/${pact.provider.name}/consumer/${pact.consumer.name}/version/${project.version}" | ||
requestContentType = JSON | ||
body = pactFile.text | ||
|
||
response.success = { resp -> | ||
println resp.statusLine | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters