-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall-local.ps1
More file actions
60 lines (48 loc) · 2.23 KB
/
install-local.ps1
File metadata and controls
60 lines (48 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# install-local.ps1 ----------------------------------------------------------
# Installs the newest cloudmersive-java-api-client-*.jar found in build\libs
# into your local Maven repository ( %USERPROFILE%\.m2\repository ).
# ---------------------------------------------------------------------------
Set-StrictMode -Version Latest
function Fail([string]$msg) { Write-Error $msg; exit 1 }
# 1. Script location and JAR discovery --------------------------------------
$scriptRoot = $PSScriptRoot # ← robust, no Split‑Path needed
$jarDir = Join-Path $scriptRoot 'build\libs'
if (-not (Test-Path -LiteralPath $jarDir)) {
Fail "Folder '$jarDir' not found. Run this script from the project root."
}
$jar = Get-ChildItem -Path $jarDir -Filter 'cloudmersive-java-api-client-*.jar' |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if (-not $jar) { Fail "No cloudmersive‑java‑api‑client JAR found in $jarDir." }
$JarPath = $jar.FullName
$ArtifactId = 'cloudmersive-java-api-client'
$GroupId = 'com.cloudmersive'
# Extract version from file name: cloudmersive-java-api-client-<ver>.jar
$regex = [regex]::Escape($ArtifactId) + '-(?<ver>.+)\.jar$'
$match = [regex]::Match($jar.Name, $regex)
if (-not $match.Success) { Fail "Cannot extract version from '$($jar.Name)'." }
$Version = $match.Groups['ver'].Value
# 2. Maven presence check ----------------------------------------------------
if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) {
Fail "'mvn' executable not found. Install Maven or add it to PATH."
}
# 3. Install into local Maven cache -----------------------------------------
Write-Host "Installing ${GroupId}:${ArtifactId}:${Version} …`n"
$mvnArgs = @(
'install:install-file',
"-Dfile=$JarPath",
"-DgroupId=$GroupId",
"-DartifactId=$ArtifactId",
"-Dversion=$Version",
'-Dpackaging=jar'
)
& mvn @mvnArgs
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$repoPath = Join-Path "$Env:USERPROFILE\.m2\repository" `
((($GroupId -replace '\.', '\') + "\$ArtifactId\$Version").TrimStart('\'))
Write-Host "`n✅ Successfully installed to:"
Write-Host " $repoPath"
} else {
Fail "Maven exited with code $exitCode."
}