Skip to content

Commit

Permalink
chore: Fix compiler and build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Dec 2, 2024
1 parent aac59a6 commit e5efa22
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 44 deletions.
65 changes: 35 additions & 30 deletions provider/maven/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,57 @@ dependencies {
}

import org.apache.tools.ant.taskdefs.condition.Os
def isWindows() {

static def isWindows() {
Os.isFamily(Os.FAMILY_WINDOWS)
}

task generatePom(type: GenerateMavenPom, dependsOn: [":provider:publishToMavenLocal",
':core:model:publishToMavenLocal',
':core:matchers:publishToMavenLocal',
':core:pactbroker:publishToMavenLocal',
':core:support:publishToMavenLocal']) {
destination = file("${buildDir}/poms/pom.xml")
pom = publishMavenPublicationPublicationToMavenLocal.publication.pom
pom.packaging = 'maven-plugin'
pom.withXml {
def buildNode = asNode().appendNode('build')
buildNode.appendNode('directory', buildDir)
buildNode.appendNode('outputDirectory', "$buildDir/classes/kotlin/main")
//add and configure the maven-plugin-plugin so that we can use the shortened 'pact' prefix
//https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html
def pluginNode = buildNode.appendNode('plugins').appendNode('plugin')
pluginNode.appendNode('artifactId', 'maven-plugin-plugin')
pluginNode.appendNode('version', '3.5')
pluginNode.appendNode('configuration').appendNode('goalPrefix', 'pact')
}
tasks.register('generatePom', GenerateMavenPom) {
dependsOn ":provider:publishToMavenLocal",
':core:model:publishToMavenLocal',
':core:matchers:publishToMavenLocal',
':core:pactbroker:publishToMavenLocal',
':core:support:publishToMavenLocal'
destination = file("${buildDir}/poms/pom.xml")
pom = publishMavenPublicationPublicationToMavenLocal.publication.pom
pom.packaging = 'maven-plugin'
pom.withXml {
def buildNode = asNode().appendNode('build')
buildNode.appendNode('directory', buildDir)
buildNode.appendNode('outputDirectory', "$buildDir/classes/kotlin/main")
//add and configure the maven-plugin-plugin so that we can use the shortened 'pact' prefix
//https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html
def pluginNode = buildNode.appendNode('plugins').appendNode('plugin')
pluginNode.appendNode('artifactId', 'maven-plugin-plugin')
pluginNode.appendNode('version', '3.5')
pluginNode.appendNode('configuration').appendNode('goalPrefix', 'pact')
}
}

if (System.env.CI != 'true') {
task pluginDescriptor(type: Exec, dependsOn: generatePom) {
tasks.register('pluginDescriptor', Exec) {
dependsOn generatePom

def pomFile = layout.buildDirectory.file("poms/pom.xml").get().asFile.path
if (isWindows()) {
try {
// check if mvn.bat exists
def proc = new ProcessBuilder('mvn.bat', '-v')
proc.start().waitFor()

commandLine 'mvn.bat', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
} catch(Exception e) {
commandLine 'mvn.cmd', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
commandLine 'mvn.bat', '-f', pomFile, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
} catch (Exception e) {
commandLine 'mvn.cmd', '-f', pomFile, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
}
} else {
commandLine 'sh', '-c', "mvn -f ${buildDir}/poms/pom.xml -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor"
commandLine 'sh', '-c', "mvn -f ${pomFile} -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor"
}

doLast {
final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get()
final pluginDescriptor = dir.file('plugin.xml').getAsFile()
assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created"
}
doLast {
final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get()
final pluginDescriptor = dir.file('plugin.xml').getAsFile()
assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created"
}
}

pluginDescriptor.shouldRunAfter project.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Consumer(
override var packagesToScan: List<String> = emptyList(),
override var verificationType: PactVerification? = null,
override var pactSource: Any? = null,
@Deprecated("replaced with auth")
override var pactFileAuthentication: List<Any?> = emptyList()
) : ConsumerInfo(name, stateChange, stateChangeUsesBody, packagesToScan, verificationType, pactSource, pactFileAuthentication) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ open class PactProviderMojo : PactBaseMojo() {
verifier.displayFailures(failures)
val nonPending = failures.filterNot { it.pending }
if (nonPending.isNotEmpty()) {
throw MojoFailureException("There were ${nonPending.sumBy { it.failures.size }} non-pending pact failures")
throw MojoFailureException("There were ${nonPending.sumOf { it.failures.size }} non-pending pact failures")
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ open class SpringMessagePactRunner(clazz: Class<*>) : MessagePactRunner(clazz) {

override fun withBeforeClasses(statement: Statement?): Statement {
val withBeforeClasses = super.withBeforeClasses(statement)
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager)
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager!!)
}

override fun withAfterClasses(statement: Statement?): Statement {
val withAfterClasses = super.withAfterClasses(statement)
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager)
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager!!)
}

private fun initTestContextManager(clazz: Class<*>): TestContextManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ open class SpringRestPactRunner(clazz: Class<*>) : RestPactRunner(clazz) {

override fun withBeforeClasses(statement: Statement?): Statement {
val withBeforeClasses = super.withBeforeClasses(statement)
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager)
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager!!)
}

override fun withAfterClasses(statement: Statement?): Statement {
val withAfterClasses = super.withAfterClasses(statement)
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager)
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager!!)
}

private fun initTestContextManager(clazz: Class<*>): TestContextManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class WebFluxProviderVerifier : ProviderVerifier() {
val expectedResponse = interaction.response
val actualResponse = handleResponse(clientResponse)

// TODO: Add plugin config here
verifyRequestResponsePact(expectedResponse, actualResponse, interactionMessage, failures,
interaction.interactionId.orEmpty(), false)
interaction.interactionId.orEmpty(), false, emptyMap())
} catch (e: Exception) {
logger.error(e) { "Request to provider method failed" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import org.springframework.core.env.Environment
class Spring6EnvironmentResolver(private val environment: Environment) : ValueResolver {
override fun resolveValue(property: String?): String? {
val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke()
return environment.getProperty(tuple.propertyName, tuple.defaultValue)
return if (tuple.propertyName != null) {
environment.getProperty(tuple.propertyName!!, tuple.defaultValue.orEmpty())
} else {
null
}
}

override fun resolveValue(property: String?, default: String?): String? {
return environment.getProperty(property, default)
return if (property != null) {
environment.getProperty(property, default.orEmpty())
} else {
null
}
}

override fun propertyDefined(property: String) = environment.containsProperty(property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import au.com.dius.pact.provider.ProviderInfo
import au.com.dius.pact.provider.ProviderResponse
import au.com.dius.pact.provider.junit5.TestTarget
import jakarta.servlet.http.Cookie
import io.github.oshai.kotlinlogging.KLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.apache.commons.lang3.StringUtils
import org.hamcrest.core.IsAnything
import org.springframework.http.HttpHeaders
Expand All @@ -39,6 +39,8 @@ import javax.mail.internet.ContentDisposition
import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource

private val logger = KotlinLogging.logger {}

/**
* Test target for tests using Spring MockMvc.
*/
Expand Down Expand Up @@ -85,7 +87,7 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(

val requestBuilder = MockMvcRequestBuilders.get("/")
if (!servletPath.isNullOrEmpty()) {
requestBuilder.servletPath(servletPath)
requestBuilder.servletPath(servletPath!!)
}

return MockMvcBuilders.standaloneSetup(*controllers.toTypedArray())
Expand Down Expand Up @@ -120,7 +122,7 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(
} else {
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
.headers(mapHeaders(request, true))
.content(body.value)
.content(body.value!!)
}
} else {
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
Expand Down Expand Up @@ -196,7 +198,10 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(

val headers = mutableMapOf<String, List<String>>()
httpResponse.headerNames.forEach { headerName ->
headers[headerName] = listOf(httpResponse.getHeader(headerName))
val header = httpResponse.getHeader(headerName)
if (header != null) {
headers[headerName] = listOf(header)
}
}

val contentType = if (httpResponse.contentType.isNullOrEmpty()) {
Expand All @@ -218,6 +223,4 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(
}

override fun supportsInteraction(interaction: Interaction) = interaction is SynchronousRequestResponse

companion object : KLogging()
}

0 comments on commit e5efa22

Please sign in to comment.