Skip to content

Commit

Permalink
fix: call the updated selector method from the Gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
uglyog committed Jun 28, 2022
1 parent f927119 commit 60712c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.com.dius.pact.provider.gradle

import groovy.transform.CompileStatic
import org.gradle.api.GradleScriptException
import org.gradle.api.Project

Expand Down Expand Up @@ -80,6 +81,7 @@ class PactPlugin extends PactPluginBase {
}

@SuppressWarnings('CatchRuntimeException')
@CompileStatic
private void setupPactConsumersFromBroker(GradleProviderInfo provider, Project project, PactPluginExtension ext) {
if (provider.brokerConfig && project.gradle.startParameter.taskNames.any {
it.toLowerCase().contains(PACT_VERIFY.toLowerCase()) }) {
Expand All @@ -94,7 +96,7 @@ class PactPlugin extends PactPluginBase {
options.providerTags = provider.brokerConfig.providerTags
}
try {
provider.consumers = provider.hasPactsFromPactBrokerWithSelectors(options, ext.broker.pactBrokerUrl,
provider.consumers = provider.hasPactsFromPactBrokerWithSelectorsV2(options, ext.broker.pactBrokerUrl,
provider.brokerConfig.selectors)
} catch (RuntimeException ex) {
throw new GradleScriptException("Failed to fetch pacts from pact broker ${ext.broker.pactBrokerUrl}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.dius.pact.provider.gradle

import au.com.dius.pact.core.pactbroker.ConsumerVersionSelector
import au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors
import au.com.dius.pact.provider.ConsumerInfo
import au.com.dius.pact.provider.ConsumersGroup
import au.com.dius.pact.provider.IConsumerInfo
Expand Down Expand Up @@ -137,6 +138,25 @@ open class GradleProviderInfo(override var name: String, val project: Project) :
}
}

fun hasPactsFromPactBrokerWithSelectorsV2(
options: Map<String, Any?>,
pactBrokerUrl: String,
selectors: List<ConsumerVersionSelectors>
): List<IConsumerInfo> {
return try {
provider.hasPactsFromPactBrokerWithSelectorsV2(options, pactBrokerUrl, selectors)
} catch (e: Exception) {
val verifyTaskName = PACT_VERIFY.lowercase()
if (project.gradle.startParameter.taskNames.any { it.lowercase().contains(verifyTaskName) }) {
logger.error(e) { "Failed to access Pact Broker" }
throw e
} else {
logger.warn { "Failed to access Pact Broker, no provider tasks will be configured - ${e.message}" }
emptyList()
}
}
}

open fun url(path: String) = URL(path)

open fun fromPactBroker(closure: Closure<PactBrokerConsumerConfig>) {
Expand Down

0 comments on commit 60712c4

Please sign in to comment.