Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #212: ensure pact path is consistent #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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