Skip to content

Commit 9696eb7

Browse files
committed
Merge branch 'main' of github.com:znsio/docs.specmatic.io
2 parents eaed5aa + 368a71b commit 9696eb7

6 files changed

+201
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
param(
2+
[string]$DownloadDir = "$HOME\.specmatic"
3+
)
4+
5+
function Write-Info { Write-Host "💡 [INFO] $args" -ForegroundColor Cyan }
6+
function Write-Warn { Write-Host "⚠️ [WARN] $args" -ForegroundColor Yellow }
7+
function Write-Error { Write-Host "❌ [ERROR] $args" -ForegroundColor Red }
8+
9+
$toolVersion = "{{ include.tool_version }}"
10+
$downloadTarget = "{{ include.download_target }}"
11+
$downloadUrls = @({{ download_urls | strip }})
12+
$toolName = "{{ include.tool_name | strip }}"
13+
14+
if (-not $downloadUrls -or $downloadUrls.Count -eq 0) {
15+
Write-Error "Download URLs list is empty or not defined. Exiting."
16+
exit 1
17+
}
18+
19+
$argsList = @($args)
20+
while ($argsList.Count -gt 0) {
21+
$arg = $argsList[0]
22+
switch -Regex ($arg) {
23+
'^(-h|--help)$' {
24+
Write-Host "Usage: install-specmatic-tool.ps1 [--download-dir=<dir>]"
25+
Write-Host " --download-dir: Directory where $downloadTarget.jar will be downloaded (default: $DownloadDir)"
26+
exit 0
27+
}
28+
'^--download-dir=(.+)$' {
29+
$DownloadDir = $matches[1]
30+
}
31+
default {
32+
Write-Host "Unknown argument: $arg"
33+
Write-Host "Usage: install-specmatic-tool.ps1 [--download-dir=<dir>]"
34+
exit 1
35+
}
36+
}
37+
38+
if ($argsList.Count -gt 1) {
39+
$argsList = $argsList[1..($argsList.Count - 1)]
40+
} else {
41+
$argsList = @()
42+
}
43+
}
44+
45+
46+
Write-Info "Using download directory $DownloadDir"
47+
if (-not (Test-Path -Path $DownloadDir)) {
48+
try {
49+
New-Item -ItemType Directory -Path $DownloadDir -Force | Out-Null
50+
Write-Info "Created directory $DownloadDir"
51+
} catch {
52+
Write-Error "Failed to create directory $DownloadDir"
53+
exit 1
54+
}
55+
} else {
56+
Write-Info "Using existing directory $DownloadDir"
57+
}
58+
59+
$jarPath = Join-Path $DownloadDir $downloadTarget
60+
if (Test-Path -Path $jarPath) {
61+
Remove-Item -Path $jarPath -Force
62+
Write-Info "Removed existing $downloadTarget"
63+
}
64+
65+
66+
$downloadSuccess = $false
67+
foreach ($url in $downloadUrls) {
68+
Write-Info "Downloading $toolName from $url..."
69+
try {
70+
Invoke-WebRequest -Uri $url -OutFile $jarPath -UseBasicParsing
71+
if (Test-Path $jarPath) {
72+
Write-Info "Downloaded $toolName to $jarPath"
73+
$downloadSuccess = $true
74+
break
75+
}
76+
}
77+
catch {
78+
Write-Warn "Failed to download from $url"
79+
}
80+
}
81+
82+
if (-not $downloadSuccess) {
83+
Write-Error "All download attempts failed. Exiting."
84+
exit 1
85+
}
86+
87+
88+
if (-not (Get-Command java -ErrorAction SilentlyContinue)) {
89+
Write-Warn @"
90+
========================================================================
91+
⚠️ Java is not installed or not found in your PATH.
92+
93+
💡 You can download and install a JRE from one of the following sources:
94+
95+
🔗 AdoptOpenJDK (Eclipse Temurin): [https://adoptium.net/](https://adoptium.net/)
96+
🔗 Oracle JDK: [https://www.oracle.com/java/technologies/downloads/](https://www.oracle.com/java/technologies/downloads/)
97+
📦 SDKMAN: [https://sdkman.io/jdks](https://sdkman.io/jdks)
98+
99+
After installation, ensure 'java' is available in your PATH.
100+
"@
101+
}
102+
103+
$sanitizedToolName = $toolName -replace '\s', ''
104+
$funcDef = "function $sanitizedToolName { java -jar `"$jarPath`" `$args }"
105+
Write-Host @"
106+
==================================================================
107+
👍 $toolName $toolVersion installed successfully!
108+
109+
📁 Directory: $DownloadDir
110+
📦 JAR file: $jarPath
111+
112+
Usage:
113+
Run the tool with:
114+
java -jar `"$jarPath`"
115+
116+
To use $toolName conveniently:
117+
118+
1. Add alias for the current session:
119+
function $sanitizedToolName { java -jar `"$jarPath`" `$args }
120+
121+
2. To persist alias add to your PowerShell profile file ($PROFILE):
122+
Add-Content -Path $PROFILE -Value 'function $sanitizedToolName { java -jar `"$jarPath`" `$args }'
123+
124+
3. Restart PowerShell or run:
125+
. $PROFILE
126+
127+
You can then run $sanitizedToolName directly with arguments, e.g. $sanitizedToolName --help
128+
==================================================================
129+
"@ -ForegroundColor Green

install-specmatic-kafka.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: none
3+
---
4+
{% capture tool_version %}{{ site.specmatic-async-version }}{% endcapture %}
5+
{% capture download_urls %}
6+
"https://repo.specmatic.io/releases/io/specmatic/async/specmatic-kafka-all/{{ site.specmatic-async-version }}/specmatic-kafka-all-{{ site.specmatic-async-version }}.jar"
7+
{% endcapture %}
8+
9+
{% include install-specmatic-tool.ps1
10+
main_picocli_command="io.specmatic.kafka.application.SpecmaticKafkaCommand"
11+
tool_name="Specmatic Kafka"
12+
tool_version=tool_version
13+
download_target="specmatic-kafka"
14+
download_urls=download_urls %}

install-specmatic-openapi.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: none
3+
---
4+
{% capture tool_version %}{{ site.specmatic-openapi-version }}{% endcapture %}
5+
{% capture download_urls %}
6+
"https://repo.specmatic.io/releases/io/specmatic/openapi/specmatic-openapi-all/{{ site.specmatic-openapi-version }}/specmatic-openapi-all-{{ site.specmatic-openapi-version }}.jar"
7+
{% endcapture %}
8+
9+
{% include install-specmatic-tool.ps1
10+
main_picocli_command="io.specmatic.openapi.application.SpecmaticOpenAPICommand"
11+
tool_name="Specmatic OpenAPI"
12+
tool_version=tool_version
13+
download_target="specmatic-openapi"
14+
download_urls=download_urls %}

install-specmatic-reporter.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: none
3+
---
4+
{% capture tool_version %}{{ site.specmatic-build-reporter-version }}{% endcapture %}
5+
{% capture download_urls %}
6+
"https://repo.specmatic.io/releases/io/specmatic/build-reporter/specmatic-reporter-all/{{ site.specmatic-build-reporter-version }}/specmatic-reporter-all-{{ site.specmatic-build-reporter-version }}.jar"
7+
{% endcapture %}
8+
9+
{% include install-specmatic-tool.ps1
10+
main_picocli_command="io.specmatic.reporter.commands.SendReportCommand"
11+
tool_name="Specmatic Build Reporter"
12+
tool_version=tool_version
13+
download_target="specmatic-reporter"
14+
download_urls=download_urls %}

install-specmatic-studio.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: none
3+
---
4+
{% capture tool_version %}{{ site.specmatic-studio-version }}{% endcapture %}
5+
{% capture download_urls %}
6+
"https://repo.specmatic.io/releases/io/specmatic/studio/specmatic-studio/{{ site.specmatic-studio-version }}/specmatic-studio-{{ site.specmatic-studio-version }}.jar"
7+
{% endcapture %}
8+
9+
{% include install-specmatic-tool.ps1
10+
main_picocli_command="io.specmatic.studio.application.SpecmaticStudioCommand"
11+
tool_name="Specmatic Studio"
12+
tool_version=tool_version
13+
download_target="specmatic-studio"
14+
download_urls=download_urls %}

install-specmatic.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
layout: none
3+
---
4+
{% capture tool_version %}{{ site.specmatic-core-version }}{% endcapture %}
5+
{% capture download_urls %}
6+
"https://repo1.maven.org/maven2/io/specmatic/specmatic-executable-all/{{ site.specmatic-core-version }}/specmatic-executable-all-{{ site.specmatic-core-version }}.jar"
7+
"https://github.com/specmatic/specmatic/releases/download/{{ site.specmatic-core-version }}/specmatic.jar"
8+
"https://repo.specmatic.io/releases/io/specmatic/specmatic-executable-all/{{ site.specmatic-core-version }}/specmatic-executable-all-{{ site.specmatic-core-version }}.jar"
9+
{% endcapture %}
10+
11+
{% include install-specmatic-tool.ps1
12+
main_picocli_command="application.SpecmaticCommand"
13+
tool_name="Specmatic"
14+
tool_version=tool_version
15+
download_target="specmatic"
16+
download_urls=download_urls %}

0 commit comments

Comments
 (0)