Skip to content

Commit

Permalink
Fixes ITV#212: ensure pact path is consistent between root project an…
Browse files Browse the repository at this point in the history
…d sub-projects
  • Loading branch information
solarmosaic-kflorence committed Jan 26, 2021
1 parent 69bd4c3 commit 3e281f6
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.itv.scalapact

import java.io.{File, PrintWriter}
import java.nio.charset.StandardCharsets

import com.itv.scalapact.model.ScalaPactMatchingRule._
import com.itv.scalapact.model.{ScalaPactDescriptionFinal, ScalaPactInteractionFinal, ScalaPactMatchingRule}
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.json.IPactWriter

import java.nio.file.Paths

private[scalapact] object ScalaPactContractWriter {
def writePactContracts(outputPath: String)(implicit pactWriter: IPactWriter): ScalaPactDescriptionFinal => Unit =
pactDescription => {
Expand All @@ -29,18 +30,21 @@ private[scalapact] object ScalaPactContractWriter {
.map("%02x".format(_))
.mkString

val relativePath = outputPath + "/" + simplifyName(pactDescription.consumer) + "_" + simplifyName(
pactDescription.provider
) + "_" + sha1 + "_tmp.json"
val file = new File(relativePath)
val path = Paths.get(
// #212: ensure a consistent path is used between projects and sub-projects
dirFile.getAbsolutePath,
simplifyName(pactDescription.consumer) + "_" +
simplifyName(pactDescription.provider) + "_" + sha1 + "_tmp.json"
)
val file = new File(path.toUri)

if (file.exists()) {
file.delete()
}

file.createNewFile()

new PrintWriter(relativePath) {
new PrintWriter(file) {
write(producePactJson(pactDescription))
close()
}
Expand Down

0 comments on commit 3e281f6

Please sign in to comment.