From 3e281f692747ddb60aa6a176756046f62236f932 Mon Sep 17 00:00:00 2001 From: Kyle Florence Date: Mon, 25 Jan 2021 19:35:38 -0600 Subject: [PATCH] Fixes #212: ensure pact path is consistent between root project and sub-projects --- .../itv/scalapact/ScalaPactContractWriter.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scalapact-scalatest/src/main/scala/com/itv/scalapact/ScalaPactContractWriter.scala b/scalapact-scalatest/src/main/scala/com/itv/scalapact/ScalaPactContractWriter.scala index bff02a01e..12e71bfbc 100644 --- a/scalapact-scalatest/src/main/scala/com/itv/scalapact/ScalaPactContractWriter.scala +++ b/scalapact-scalatest/src/main/scala/com/itv/scalapact/ScalaPactContractWriter.scala @@ -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 => { @@ -29,10 +30,13 @@ 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() @@ -40,7 +44,7 @@ private[scalapact] object ScalaPactContractWriter { file.createNewFile() - new PrintWriter(relativePath) { + new PrintWriter(file) { write(producePactJson(pactDescription)) close() }