Skip to content

Commit e5efa22

Browse files
committed
chore: Fix compiler and build warnings
1 parent aac59a6 commit e5efa22

File tree

8 files changed

+62
-44
lines changed

8 files changed

+62
-44
lines changed

provider/maven/build.gradle

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,57 @@ dependencies {
2323
}
2424

2525
import org.apache.tools.ant.taskdefs.condition.Os
26-
def isWindows() {
26+
27+
static def isWindows() {
2728
Os.isFamily(Os.FAMILY_WINDOWS)
2829
}
2930

30-
task generatePom(type: GenerateMavenPom, dependsOn: [":provider:publishToMavenLocal",
31-
':core:model:publishToMavenLocal',
32-
':core:matchers:publishToMavenLocal',
33-
':core:pactbroker:publishToMavenLocal',
34-
':core:support:publishToMavenLocal']) {
35-
destination = file("${buildDir}/poms/pom.xml")
36-
pom = publishMavenPublicationPublicationToMavenLocal.publication.pom
37-
pom.packaging = 'maven-plugin'
38-
pom.withXml {
39-
def buildNode = asNode().appendNode('build')
40-
buildNode.appendNode('directory', buildDir)
41-
buildNode.appendNode('outputDirectory', "$buildDir/classes/kotlin/main")
42-
//add and configure the maven-plugin-plugin so that we can use the shortened 'pact' prefix
43-
//https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html
44-
def pluginNode = buildNode.appendNode('plugins').appendNode('plugin')
45-
pluginNode.appendNode('artifactId', 'maven-plugin-plugin')
46-
pluginNode.appendNode('version', '3.5')
47-
pluginNode.appendNode('configuration').appendNode('goalPrefix', 'pact')
48-
}
31+
tasks.register('generatePom', GenerateMavenPom) {
32+
dependsOn ":provider:publishToMavenLocal",
33+
':core:model:publishToMavenLocal',
34+
':core:matchers:publishToMavenLocal',
35+
':core:pactbroker:publishToMavenLocal',
36+
':core:support:publishToMavenLocal'
37+
destination = file("${buildDir}/poms/pom.xml")
38+
pom = publishMavenPublicationPublicationToMavenLocal.publication.pom
39+
pom.packaging = 'maven-plugin'
40+
pom.withXml {
41+
def buildNode = asNode().appendNode('build')
42+
buildNode.appendNode('directory', buildDir)
43+
buildNode.appendNode('outputDirectory', "$buildDir/classes/kotlin/main")
44+
//add and configure the maven-plugin-plugin so that we can use the shortened 'pact' prefix
45+
//https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html
46+
def pluginNode = buildNode.appendNode('plugins').appendNode('plugin')
47+
pluginNode.appendNode('artifactId', 'maven-plugin-plugin')
48+
pluginNode.appendNode('version', '3.5')
49+
pluginNode.appendNode('configuration').appendNode('goalPrefix', 'pact')
50+
}
4951
}
5052

5153
if (System.env.CI != 'true') {
52-
task pluginDescriptor(type: Exec, dependsOn: generatePom) {
54+
tasks.register('pluginDescriptor', Exec) {
55+
dependsOn generatePom
56+
57+
def pomFile = layout.buildDirectory.file("poms/pom.xml").get().asFile.path
5358
if (isWindows()) {
5459
try {
5560
// check if mvn.bat exists
5661
def proc = new ProcessBuilder('mvn.bat', '-v')
5762
proc.start().waitFor()
5863

59-
commandLine 'mvn.bat', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
60-
} catch(Exception e) {
61-
commandLine 'mvn.cmd', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
64+
commandLine 'mvn.bat', '-f', pomFile, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
65+
} catch (Exception e) {
66+
commandLine 'mvn.cmd', '-f', pomFile, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor'
6267
}
6368
} else {
64-
commandLine 'sh', '-c', "mvn -f ${buildDir}/poms/pom.xml -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor"
69+
commandLine 'sh', '-c', "mvn -f ${pomFile} -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor"
6570
}
6671

67-
doLast {
68-
final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get()
69-
final pluginDescriptor = dir.file('plugin.xml').getAsFile()
70-
assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created"
71-
}
72+
doLast {
73+
final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get()
74+
final pluginDescriptor = dir.file('plugin.xml').getAsFile()
75+
assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created"
76+
}
7277
}
7378

7479
pluginDescriptor.shouldRunAfter project.jar

provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/Consumer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Consumer(
1515
override var packagesToScan: List<String> = emptyList(),
1616
override var verificationType: PactVerification? = null,
1717
override var pactSource: Any? = null,
18+
@Deprecated("replaced with auth")
1819
override var pactFileAuthentication: List<Any?> = emptyList()
1920
) : ConsumerInfo(name, stateChange, stateChangeUsesBody, packagesToScan, verificationType, pactSource, pactFileAuthentication) {
2021

provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactProviderMojo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ open class PactProviderMojo : PactBaseMojo() {
152152
verifier.displayFailures(failures)
153153
val nonPending = failures.filterNot { it.pending }
154154
if (nonPending.isNotEmpty()) {
155-
throw MojoFailureException("There were ${nonPending.sumBy { it.failures.size }} non-pending pact failures")
155+
throw MojoFailureException("There were ${nonPending.sumOf { it.failures.size }} non-pending pact failures")
156156
}
157157
}
158158
} finally {

provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringMessagePactRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ open class SpringMessagePactRunner(clazz: Class<*>) : MessagePactRunner(clazz) {
2626

2727
override fun withBeforeClasses(statement: Statement?): Statement {
2828
val withBeforeClasses = super.withBeforeClasses(statement)
29-
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager)
29+
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager!!)
3030
}
3131

3232
override fun withAfterClasses(statement: Statement?): Statement {
3333
val withAfterClasses = super.withAfterClasses(statement)
34-
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager)
34+
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager!!)
3535
}
3636

3737
private fun initTestContextManager(clazz: Class<*>): TestContextManager {

provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringRestPactRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ open class SpringRestPactRunner(clazz: Class<*>) : RestPactRunner(clazz) {
2727

2828
override fun withBeforeClasses(statement: Statement?): Statement {
2929
val withBeforeClasses = super.withBeforeClasses(statement)
30-
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager)
30+
return RunBeforeTestClassCallbacks(withBeforeClasses, testContextManager!!)
3131
}
3232

3333
override fun withAfterClasses(statement: Statement?): Statement {
3434
val withAfterClasses = super.withAfterClasses(statement)
35-
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager)
35+
return RunAfterTestClassCallbacks(withAfterClasses, testContextManager!!)
3636
}
3737

3838
private fun initTestContextManager(clazz: Class<*>): TestContextManager {

provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/WebFluxProviderVerifier.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class WebFluxProviderVerifier : ProviderVerifier() {
5050
val expectedResponse = interaction.response
5151
val actualResponse = handleResponse(clientResponse)
5252

53+
// TODO: Add plugin config here
5354
verifyRequestResponsePact(expectedResponse, actualResponse, interactionMessage, failures,
54-
interaction.interactionId.orEmpty(), false)
55+
interaction.interactionId.orEmpty(), false, emptyMap())
5556
} catch (e: Exception) {
5657
logger.error(e) { "Request to provider method failed" }
5758

provider/spring6/src/main/kotlin/au/com/dius/pact/provider/spring/spring6/Spring6EnvironmentResolver.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ import org.springframework.core.env.Environment
77
class Spring6EnvironmentResolver(private val environment: Environment) : ValueResolver {
88
override fun resolveValue(property: String?): String? {
99
val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke()
10-
return environment.getProperty(tuple.propertyName, tuple.defaultValue)
10+
return if (tuple.propertyName != null) {
11+
environment.getProperty(tuple.propertyName!!, tuple.defaultValue.orEmpty())
12+
} else {
13+
null
14+
}
1115
}
1216

1317
override fun resolveValue(property: String?, default: String?): String? {
14-
return environment.getProperty(property, default)
18+
return if (property != null) {
19+
environment.getProperty(property, default.orEmpty())
20+
} else {
21+
null
22+
}
1523
}
1624

1725
override fun propertyDefined(property: String) = environment.containsProperty(property)

provider/spring6/src/main/kotlin/au/com/dius/pact/provider/spring/spring6/Spring6MockMvcTestTarget.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import au.com.dius.pact.provider.ProviderInfo
1313
import au.com.dius.pact.provider.ProviderResponse
1414
import au.com.dius.pact.provider.junit5.TestTarget
1515
import jakarta.servlet.http.Cookie
16-
import io.github.oshai.kotlinlogging.KLogging
16+
import io.github.oshai.kotlinlogging.KotlinLogging
1717
import org.apache.commons.lang3.StringUtils
1818
import org.hamcrest.core.IsAnything
1919
import org.springframework.http.HttpHeaders
@@ -39,6 +39,8 @@ import javax.mail.internet.ContentDisposition
3939
import javax.mail.internet.MimeMultipart
4040
import javax.mail.util.ByteArrayDataSource
4141

42+
private val logger = KotlinLogging.logger {}
43+
4244
/**
4345
* Test target for tests using Spring MockMvc.
4446
*/
@@ -85,7 +87,7 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(
8587

8688
val requestBuilder = MockMvcRequestBuilders.get("/")
8789
if (!servletPath.isNullOrEmpty()) {
88-
requestBuilder.servletPath(servletPath)
90+
requestBuilder.servletPath(servletPath!!)
8991
}
9092

9193
return MockMvcBuilders.standaloneSetup(*controllers.toTypedArray())
@@ -120,7 +122,7 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(
120122
} else {
121123
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
122124
.headers(mapHeaders(request, true))
123-
.content(body.value)
125+
.content(body.value!!)
124126
}
125127
} else {
126128
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
@@ -196,7 +198,10 @@ class Spring6MockMvcTestTarget @JvmOverloads constructor(
196198

197199
val headers = mutableMapOf<String, List<String>>()
198200
httpResponse.headerNames.forEach { headerName ->
199-
headers[headerName] = listOf(httpResponse.getHeader(headerName))
201+
val header = httpResponse.getHeader(headerName)
202+
if (header != null) {
203+
headers[headerName] = listOf(header)
204+
}
200205
}
201206

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

220225
override fun supportsInteraction(interaction: Interaction) = interaction is SynchronousRequestResponse
221-
222-
companion object : KLogging()
223226
}

0 commit comments

Comments
 (0)