forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-ModuleVersion.ps1
More file actions
107 lines (94 loc) · 3.78 KB
/
Copy pathTest-ModuleVersion.ps1
File metadata and controls
107 lines (94 loc) · 3.78 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<#
.SYNOPSIS
Validate that the version of a module passed in via the $currentVersion
parameter is valid based on the criteria specified by the following
parameters.
.DESCRIPTION
This function is used to determine whether or not a given module is within
the version bounds specified by the parameters passed in. Psake will use
this information to determine if the module it has found will contain the
proper version of the shared task it has been asked to import.
This function should allow bounds that are only on the lower limit, only on
the upper, within a range, or if no bounds are supplied, the current module
will be accepted without question.
.PARAMETER currentVersion
The version of the module in the current session to be subjected to comparison
.PARAMETER minimumVersion
The lower bound of the version that will be accepted. This comparison should
be inclusive, meaning an input version greater than or equal to this version
should be accepted.
.PARAMETER maximumVersion
The upper bound of the version that will be accepted. This comparison should
be inclusive, meaning an input version less than or equal to this version
should be accepted.
.PARAMETER lessThanVersion
The upper bound of the version that will be accepted. This comparison should
be exclusive. Meaning an input version that is less than only, not equal to
this version, will be accepted.
.INPUTS
A $currentVersion of type [System.Version] or a convertable string.
A set of version criteria, each of type [System.Version] or a convertable string.
.OUTPUTS
boolean - Pass/Fail
#>
function Test-ModuleVersion {
[CmdletBinding()]
param (
[string]$currentVersion,
[string]$minimumVersion,
[string]$maximumVersion,
[string]$lessThanVersion
)
begin {
}
process {
$result = $true
# If no version is specified simply return true and allow the module to pass.
if("$minimumVersion$maximumVersion$lessthanVersion" -eq ''){
return $true
}
# Single integer values cannot be converted to type system.version.
# We convert to a string, and if there is a single character we know that
# we need to add a '.0' to the integer to make it convertable to a version.
if(![string]::IsNullOrEmpty($currentVersion)) {
if($currentVersion.ToString().Length -eq 1) {
[version]$currentVersion = "$currentVersion.0"
} else {
[version]$currentVersion = $currentVersion
}
}
if(![string]::IsNullOrEmpty($minimumVersion)) {
if($minimumVersion.ToString().Length -eq 1){
[version]$minimumVersion = "$minimumVersion.0"
} else {
[version]$minimumVersion = $minimumVersion
}
if($currentVersion.CompareTo($minimumVersion) -lt 0){
$result = $false
}
}
if(![string]::IsNullOrEmpty($maximumVersion)) {
if($maximumVersion.ToString().Length -eq 1) {
[version]$maximumVersion = "$maximumVersion.0"
} else {
[version]$maximumVersion = $maximumVersion
}
if ($currentVersion.CompareTo($maximumVersion) -gt 0) {
$result = $false
}
}
if(![string]::IsNullOrEmpty($lessThanVersion)) {
if($lessThanVersion.ToString().Length -eq 1) {
[version]$lessThanVersion = "$lessThanVersion.0"
} else {
[version]$lessThanVersion = $lessThanVersion
}
if($currentVersion.CompareTo($lessThanVersion) -ge 0) {
$result = $false
}
}
Write-Output $result
}
end {
}
}