Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 86cb5f2

Browse files
committed
feat: Bundle ContractCase core runtime
1 parent 42137a0 commit 86cb5f2

7 files changed

Lines changed: 389 additions & 8 deletions

File tree

copy-proto.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

install-connector.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
# Copies proto files from the main repo, assumed to be ../contract-case
5+
6+
MAIN_REPO_LOCATION=../contract-case
7+
8+
CONNECTOR_LOCATION="$MAIN_REPO_LOCATION/packages/case-connector"
9+
10+
cp "$CONNECTOR_LOCATION/proto/contract_case_stream.proto" src/main/proto
11+
cp "$CONNECTOR_LOCATION/package/"* src/main/resources/io/contract_testing/contractcase/client/server
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package io.contract_testing.contractcase.client.server;
2+
3+
import io.contract_testing.contractcase.ContractCaseCoreError;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
9+
class ConnectorExtractor {
10+
11+
private static final String CASE_CONNECTOR_FILENAME = "case-connector.js";
12+
13+
/**
14+
* Extracts a local copy of the contract case bundle from the jar's resources to a temporary
15+
* directory that will be deleted on jvm exit.
16+
*
17+
* @return The path to the extracted contract case bundle
18+
*/
19+
static String extractCaseConnector() {
20+
final var localCopy = createTemporaryDirectory().resolve(CASE_CONNECTOR_FILENAME);
21+
22+
copyResource(CASE_CONNECTOR_FILENAME, localCopy);
23+
24+
localCopy.toFile().deleteOnExit();
25+
26+
return localCopy.toString();
27+
28+
}
29+
30+
private static Path createTemporaryDirectory() {
31+
try {
32+
final var directory = Files.createTempDirectory("contract-case-connector");
33+
34+
directory.toFile().deleteOnExit();
35+
36+
return directory;
37+
} catch (IOException e) {
38+
throw new ContractCaseCoreError(
39+
"Unable to create temporary directory for ContractCase Connector executable",
40+
e
41+
);
42+
}
43+
}
44+
45+
private static void copyResource(final String resourceName, final Path target) {
46+
try (InputStream inputStream = ConnectorExtractor.class.getResourceAsStream(resourceName)) {
47+
if (inputStream == null) {
48+
throw new ContractCaseCoreError(
49+
"The resource input stream was null, and it's not supposed to be");
50+
}
51+
Files.copy(inputStream, target);
52+
} catch (IOException e) {
53+
throw new ContractCaseCoreError(
54+
"Unable to extract ContractCase Connector executable",
55+
e
56+
);
57+
}
58+
}
59+
60+
}

src/main/java/io/contract_testing/contractcase/client/server/ContractCaseProcess.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ private synchronized void startRuntimeIfNeeded() {
7070

7171
final List<String> serverStartCommand = List.of(
7272
"node",
73-
// TODO: Generate this path instead
74-
"/Users/home/office/contract-case/contract-case/node_modules/.bin/case-connector"
73+
ConnectorExtractor.extractCaseConnector()
7574
);
7675

7776
try {

src/main/resources/io/contract_testing/contractcase/client/server/case-connector.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)