Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 16 commits
  • 14 files changed
  • 0 comments
  • 4 contributors
Oct 23, 2011
Rafal Klys whut Simplified loading modules 98f110b
Rafal Klys whut Added note to Include function that code from included file will be e…
…xecuted after code from build script.
2d4e56a
Rafal Klys whut Added RequiredVariables argument to Task function
Also unified formatting in Task
5237be1
whut Fixed issue #7 - not using buildFile as taskList in Invoke-Psake, whe…
…n there is folder, not file with name as task

Added -PathType to all test-path invocations
a7aea83
Nov 04, 2011
whut Fix for issue #23 - psake.cmd should exit with 0 when build succeeded
Also use of -ExecutionPolicy Bypass, which is even less restrictive than -ExecutionPolicy Unrestricted
e17c6dd
whut Use of Cyan foreground color, instead of Blue to make it more visible…
… on darker consoles

Cyan is also commonly recommended, for example in http://blogs.msdn.com/b/abhinaba/archive/2006/01/05/509581.aspx
9d8903c
Nov 05, 2011
Rafal Klys whut Task duration shows duration of task, not of task and it's dependencies
Also added default duration of TimeSpan.Zero (to show in summary 00:00:00 instead of 0)
And added argument to Write-TaskSummary, to make it more readable where $stopwatch variable inside that function came from, and use of where-object instead of its alias ?, to also make it more readable
9f6c11e
whut Warning (yellow colored output) when task failed with -ContinueOnError
Also some small stuff, unified error messages, comment formating, etc
391cf6f
whut Added -help switch to psake.ps1 instead of psake-help.ps1 script
Simplificated psake.cmd because of that (also removed some ifs that detected if help should be displayed, because they for example make it impossible to call task with name "help")
bca24cc
Feb 10, 2012
Pedro Reys pedroreys Adds support to defining an alias to a task.
Example:
  task Task_With_Descriptive_Name -alias twdn {}

By doing that I can now call .\psake.ps1 twdn and have the
Task_With_Descriptive_Name executed
88bb811
Pedro Reys pedroreys fixes the task name when using aliases so that the casing is correct 33018d2
Mar 19, 2012
Ian Davis idavis fixing case where framework is set using 3 digits (3.0/4.0). The bit …
…substring is empty, not null. This will fix all specs.
4710deb
Mar 20, 2012
James Kovacs Merge pull request #26 from pedroreys/alias
Adds support to defining an alias to a task.
138296d
James Kovacs Defaulted psake to .NET 4.0 27cd8a7
James Kovacs Switched to semantic versioning ef6ad0a
James Kovacs Fixed formatting in .nuspec f4e8af2
18 en-US/psake.psm1-help.xml
@@ -1078,7 +1078,7 @@ Task TaskC {
1078 1078 <dev:version />
1079 1079 </command:details>
1080 1080 <maml:description>
1081   - <maml:para>A build script may declare an "includes" function which allows you to define a file containing powershell code to be included and added to the scope of the currently running build script.</maml:para>
  1081 + <maml:para>A build script may declare an "includes" function which allows you to define a file containing powershell code to be included and added to the scope of the currently running build script. Code from such file will be executed after code from build script.</maml:para>
1082 1082 </maml:description>
1083 1083 <command:syntax>
1084 1084 <command:syntaxItem>
@@ -1403,6 +1403,10 @@ Task Clean {
1403 1403 <command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
1404 1404 </command:parameter>
1405 1405 <command:parameter require="false" variableLength="false" globbing="false" pipelineInput="false" postion="0">
  1406 + <maml:name>RequiredVariables</maml:name>
  1407 + <command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
  1408 + </command:parameter>
  1409 + <command:parameter require="false" variableLength="false" globbing="false" pipelineInput="false" postion="0">
1406 1410 <maml:name>Description</maml:name>
1407 1411 <command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
1408 1412 </command:parameter>
@@ -1506,6 +1510,18 @@ Task Clean {
1506 1510 <dev:defaultValue></dev:defaultValue>
1507 1511 </command:parameter>
1508 1512 <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false (ByValue)" position="0">
  1513 + <maml:name>RequiredVariables</maml:name>
  1514 + <maml:description>
  1515 + <maml:para>An array of names of variables that must be set to run this task.</maml:para>
  1516 + </maml:description>
  1517 + <command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
  1518 + <dev:type>
  1519 + <maml:name>String[]</maml:name>
  1520 + <maml:uri />
  1521 + </dev:type>
  1522 + <dev:defaultValue></dev:defaultValue>
  1523 + </command:parameter>
  1524 + <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false (ByValue)" position="0">
1509 1525 <maml:name>Description</maml:name>
1510 1526 <maml:description>
1511 1527 <maml:para>A description of the task.</maml:para>
14 examples/requiredvariables.ps1
... ... @@ -0,0 +1,14 @@
  1 +properties {
  2 + $x = $null
  3 + $y = $null
  4 + $z = $null
  5 +}
  6 +
  7 +task default -depends TestRequiredVariables
  8 +
  9 +# you can put arguments to task in multiple lines using `
  10 +task TestRequiredVariables `
  11 + -description "This task shows how to make a variable required to run task. Run this script with -properties @{x = 1; y = 2; z = 3}" `
  12 + -requiredVariables x, y, z `
  13 +{
  14 +}
16 nuget/psake.nuspec
@@ -2,18 +2,14 @@
2 2 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3 3 <metadata>
4 4 <id>psake</id>
5   - <version>4.2</version>
  5 + <version>4.1.0</version>
6 6 <authors>James Kovacs</authors>
7   - <owners>Damian Hickey, Rob Reynolds</owners>
8   - <projectUrl>https://github.com/JamesKovacs/psake</projectUrl>
  7 + <owners>James Kovacs, Damian Hickey, Rob Reynolds</owners>
  8 + <projectUrl>https://github.com/psake/psake</projectUrl>
9 9 <requireLicenseAcceptance>false</requireLicenseAcceptance>
10   - <summary>PSake is a build automation tool written in PowerShell</summary>
11   - <description>psake is a build automation tool written in PowerShell. It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge.
12   -
13   -psake is pronounced sake � as in Japanese rice wine. It does NOT rhyme with make, bake, or rake. |
14   -You can also install with chocolatey (http://nuget.org/List/Packages/chocolatey) and have global psake.
15   - </description>
  10 + <summary>psake is a build automation tool written in PowerShell</summary>
  11 + <description>psake is a build automation tool written in PowerShell. It avoids the angle-bracket tax associated with executable XML by leveraging the PowerShell syntax in your build scripts. psake has a syntax inspired by rake (aka make in Ruby) and bake (aka make in Boo), but is easier to script because it leverages your existent command-line knowledge. psake is pronounced sake - as in Japanese rice wine. It does NOT rhyme with make, bake, or rake. You can also install with chocolatey (http://nuget.org/List/Packages/chocolatey) and have global psake.</description>
16 12 <language>en-US</language>
17 13 <tags>build powershell chocolatey</tags>
18 14 </metadata>
19   -</package>
  15 +</package>
30 psake-config.ps1
@@ -2,30 +2,20 @@
2 2 -------------------------------------------------------------------
3 3 Defaults
4 4 -------------------------------------------------------------------
5   -$config.buildFileName="default.ps1";
6   -$config.framework = "3.5";
7   -$config.taskNameFormat="Executing {0}";
8   -$config.verboseError=$false;
9   -$config.coloredOutput = $true;
10   -$config.modules=(new-object psobject -property @{ autoload=$false })
  5 +$config.buildFileName="default.ps1"
  6 +$config.framework = "4.0"
  7 +$config.taskNameFormat="Executing {0}"
  8 +$config.verboseError=$false
  9 +$config.coloredOutput = $true
  10 +$config.modules=$null
11 11
12 12 -------------------------------------------------------------------
13   -Auto-load modules from .\modules folder
  13 +Load modules from .\modules folder and from file my_module.psm1
14 14 -------------------------------------------------------------------
15   -$config.modules=(new-object psobject -property @{ autoload=$true})
  15 +$config.modules=(".\modules\*.psm1",".\my_module.psm1")
16 16
17 17 -------------------------------------------------------------------
18   -Auto-load modules from .\my_modules folder
  18 +Use scriptblock for taskNameFormat
19 19 -------------------------------------------------------------------
20   -$config.modules=(new-object psobject -property @{ autoload=$true; directory=".\my_modules" })
21   -
22   --------------------------------------------------------------------
23   -Explicitly load module(s)
24   --------------------------------------------------------------------
25   -$config.modules=(new-object psobject -property @{
26   - autoload=$false;
27   - module=(new-object psobject -property @{path="c:\module1dir\module1.ps1"}),
28   - (new-object psobject -property @{path="c:\module1dir\module2.ps1"})
29   - })
30   -}
  20 +$config.taskNameFormat= { param($taskName) "Executing $taskName at $(get-date)" }
31 21 #>
7 psake-help.ps1
... ... @@ -1,7 +0,0 @@
1   -# Helper script to return help text.
2   -
3   -remove-module psake -ea 'SilentlyContinue'
4   -$scriptPath = Split-Path -parent $MyInvocation.MyCommand.path
5   -import-module (join-path $scriptPath psake.psm1)
6   -Get-Help Invoke-psake -full
7   -exit $lastexitcode
18 psake.cmd
... ... @@ -1,15 +1,11 @@
1 1 @echo off
2 2
3   -SET DIR=%~dp0%
4   -
5   -if '%1'=='/?' goto usage
6   -if '%1'=='-?' goto usage
7   -if '%1'=='?' goto usage
8   -if '%1'=='/help' goto usage
9   -if '%1'=='help' goto usage
10   -
11   -powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 }"
  3 +if '%1'=='/?' goto help
  4 +if '%1'=='-help' goto help
  5 +if '%1'=='-h' goto help
12 6
  7 +powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 } else { exit 0 }"
13 8 goto :eof
14   -:usage
15   -powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake-help.ps1'"
  9 +
  10 +:help
  11 +powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\psake.ps1' -help"
11 psake.ps1
@@ -18,14 +18,21 @@ param(
18 18 [Parameter(Position=5, Mandatory=0)]
19 19 [System.Collections.Hashtable]$properties = @{},
20 20 [Parameter(Position=6, Mandatory=0)]
21   - [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path),
  21 + [switch]$nologo = $false,
22 22 [Parameter(Position=7, Mandatory=0)]
23   - [switch]$nologo = $false
  23 + [switch]$help = $false,
  24 + [Parameter(Position=8, Mandatory=0)]
  25 + [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path)
24 26 )
25 27
26 28 # '[p]sake' is the same as 'psake' but $Error is not polluted
27 29 remove-module [p]sake
28 30 import-module (join-path $scriptPath psake.psm1)
  31 +if ($help) {
  32 + Get-Help Invoke-psake -full
  33 + return
  34 +}
  35 +
29 36 if (-not(test-path $buildFile)) {
30 37 $absoluteBuildFile = (join-path $scriptPath $buildFile)
31 38 if (test-path $absoluteBuildFile) {
202 psake.psm1
@@ -34,31 +34,32 @@ function Invoke-Task
34 34
35 35 $taskKey = $taskName.ToLower()
36 36
  37 + if ($currentContext.aliases.Contains($taskKey)) {
  38 + $taskName = $currentContext.aliases.$taskKey.Name
  39 + $taskKey = $taskName.ToLower()
  40 + }
  41 +
37 42 $currentContext = $psake.context.Peek()
38   - $tasks = $currentContext.tasks
39   - $executedTasks = $currentContext.executedTasks
40   - $callStack = $currentContext.callStack
41 43
42   - Assert ($tasks.Contains($taskKey)) ($msgs.error_task_name_does_not_exist -f $taskName)
  44 + Assert ($currentContext.tasks.Contains($taskKey)) ($msgs.error_task_name_does_not_exist -f $taskName)
43 45
44   - if ($executedTasks.Contains($taskKey)) { return }
  46 + if ($currentContext.executedTasks.Contains($taskKey)) { return }
45 47
46   - Assert (!$callStack.Contains($taskKey)) ($msgs.error_circular_reference -f $taskName)
  48 + Assert (!$currentContext.callStack.Contains($taskKey)) ($msgs.error_circular_reference -f $taskName)
47 49
48   - $callStack.Push($taskKey)
  50 + $currentContext.callStack.Push($taskKey)
49 51
50   - $task = $tasks.$taskKey
  52 + $task = $currentContext.tasks.$taskKey
51 53
52 54 $precondition_is_valid = & $task.Precondition
53 55
54 56 if (!$precondition_is_valid) {
55   - Write-ColoredOutput ($msgs.precondition_was_false -f $taskName) -foregroundcolor Blue
  57 + Write-ColoredOutput ($msgs.precondition_was_false -f $taskName) -foregroundcolor Cyan
56 58 } else {
57 59 if ($taskKey -ne 'default') {
58   - $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
59 60
60 61 if ($task.PreAction -or $task.PostAction) {
61   - Assert ($task.Action -ne $null) $msgs.error_missing_action_parameter
  62 + Assert ($task.Action -ne $null) ($msgs.error_missing_action_parameter -f $taskName)
62 63 }
63 64
64 65 if ($task.Action) {
@@ -67,6 +68,7 @@ function Invoke-Task
67 68 Invoke-Task $childTask
68 69 }
69 70
  71 + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
70 72 $currentContext.currentTaskName = $taskName
71 73
72 74 & $currentContext.taskSetupScriptBlock
@@ -78,7 +80,11 @@ function Invoke-Task
78 80 if ($currentContext.config.taskNameFormat -is [ScriptBlock]) {
79 81 & $currentContext.config.taskNameFormat $taskName
80 82 } else {
81   - Write-ColoredOutput ($currentContext.config.taskNameFormat -f $taskName) -foregroundcolor Blue
  83 + Write-ColoredOutput ($currentContext.config.taskNameFormat -f $taskName) -foregroundcolor Cyan
  84 + }
  85 +
  86 + foreach ($variable in $task.requiredVariables) {
  87 + Assert ((test-path "variable:$variable") -and ((get-variable $variable).Value -ne $null)) ($msgs.required_variable_not_set -f $variable, $taskName)
82 88 }
83 89
84 90 & $task.Action
@@ -88,23 +94,23 @@ function Invoke-Task
88 94 }
89 95
90 96 & $currentContext.taskTearDownScriptBlock
  97 + $task.Duration = $stopwatch.Elapsed
91 98 } catch {
92 99 if ($task.ContinueOnError) {
93   - "-"*70
94   - $msgs.continue_on_error -f $taskName,$_
95 100 "-"*70
  101 + Write-ColoredOutput ($msgs.continue_on_error -f $taskName,$_) -foregroundcolor Yellow
  102 + "-"*70
  103 + $task.Duration = $stopwatch.Elapsed
96 104 } else {
97 105 throw $_
98 106 }
99 107 }
100 108 } else {
101   - #no Action was specified but we still execute all the dependencies
  109 + # no action was specified but we still execute all the dependencies
102 110 foreach($childTask in $task.DependsOn) {
103 111 Invoke-Task $childTask
104 112 }
105 113 }
106   - $stopwatch.stop()
107   - $task.Duration = $stopwatch.Elapsed
108 114 } else {
109 115 foreach($childTask in $task.DependsOn) {
110 116 Invoke-Task $childTask
@@ -114,10 +120,10 @@ function Invoke-Task
114 120 Assert (& $task.Postcondition) ($msgs.postcondition_failed -f $taskName)
115 121 }
116 122
117   - $poppedTaskKey = $callStack.Pop()
  123 + $poppedTaskKey = $currentContext.callStack.Pop()
118 124 Assert ($poppedTaskKey -eq $taskKey) ($msgs.error_corrupt_callstack -f $taskKey,$poppedTaskKey)
119 125
120   - $executedTasks.Push($taskKey)
  126 + $currentContext.executedTasks.Push($taskKey)
121 127 }
122 128
123 129 # .ExternalHelp psake.psm1-help.xml
@@ -152,17 +158,18 @@ function Task
152 158 {
153 159 [CmdletBinding()]
154 160 param(
155   - [Parameter(Position=0,Mandatory=1)] [string]$name = $null,
156   - [Parameter(Position=1,Mandatory=0)] [scriptblock]$action = $null,
157   - [Parameter(Position=2,Mandatory=0)] [scriptblock]$preaction = $null,
158   - [Parameter(Position=3,Mandatory=0)] [scriptblock]$postaction = $null,
159   - [Parameter(Position=4,Mandatory=0)] [scriptblock]$precondition = {$true},
160   - [Parameter(Position=5,Mandatory=0)] [scriptblock]$postcondition = {$true},
161   - [Parameter(Position=6,Mandatory=0)] [switch]$continueOnError = $false,
162   - [Parameter(Position=7,Mandatory=0)] [string[]]$depends = @(),
163   - [Parameter(Position=8,Mandatory=0)] [string]$description = $null
  161 + [Parameter(Position=0,Mandatory=1)][string]$name = $null,
  162 + [Parameter(Position=1,Mandatory=0)][scriptblock]$action = $null,
  163 + [Parameter(Position=2,Mandatory=0)][scriptblock]$preaction = $null,
  164 + [Parameter(Position=3,Mandatory=0)][scriptblock]$postaction = $null,
  165 + [Parameter(Position=4,Mandatory=0)][scriptblock]$precondition = {$true},
  166 + [Parameter(Position=5,Mandatory=0)][scriptblock]$postcondition = {$true},
  167 + [Parameter(Position=6,Mandatory=0)][switch]$continueOnError = $false,
  168 + [Parameter(Position=7,Mandatory=0)][string[]]$depends = @(),
  169 + [Parameter(Position=8,Mandatory=0)][string[]]$requiredVariables = @(),
  170 + [Parameter(Position=9,Mandatory=0)][string]$description = $null,
  171 + [Parameter(Position=10,Mandatory=0)][string]$alias = $null
164 172 )
165   -
166 173 if ($name -eq 'default') {
167 174 Assert (!$action) ($msgs.error_default_task_cannot_have_action)
168 175 }
@@ -177,16 +184,27 @@ function Task
177 184 Postcondition = $postcondition
178 185 ContinueOnError = $continueOnError
179 186 Description = $description
180   - Duration = 0
  187 + Duration = [System.TimeSpan]::Zero
  188 + RequiredVariables = $requiredVariables
  189 + Alias = $alias
181 190 }
182 191
183   - $taskKey = $name.ToLower()
  192 + $taskKey = $name.ToLower()
184 193
185 194 $currentContext = $psake.context.Peek()
186 195
187 196 Assert (!$currentContext.tasks.ContainsKey($taskKey)) ($msgs.error_duplicate_task_name -f $name)
188 197
189 198 $currentContext.tasks.$taskKey = $newTask
  199 +
  200 + if($alias)
  201 + {
  202 + $aliasKey = $alias.ToLower()
  203 +
  204 + Assert (!$currentContext.aliases.ContainsKey($aliasKey)) ($msgs.error_duplicate_alias_name -f $alias)
  205 +
  206 + $currentContext.aliases.$aliasKey = $newTask
  207 + }
190 208 }
191 209
192 210 # .ExternalHelp psake.psm1-help.xml
@@ -204,7 +222,7 @@ function Include {
204 222 param(
205 223 [Parameter(Position=0,Mandatory=1)][string]$fileNamePathToInclude
206 224 )
207   - Assert (test-path $fileNamePathToInclude) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
  225 + Assert (test-path $fileNamePathToInclude -pathType Leaf) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
208 226 $psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
209 227 }
210 228
@@ -263,13 +281,13 @@ function Invoke-psake {
263 281
264 282 # If the default.ps1 file exists and the given "buildfile" isn 't found assume that the given
265 283 # $buildFile is actually the target Tasks to execute in the default.ps1 script.
266   - if ($buildFile -and !(test-path $buildFile) -and (test-path $psake.config_default.buildFileName)) {
  284 + if ($buildFile -and !(test-path $buildFile -pathType Leaf) -and (test-path $psake.config_default.buildFileName -pathType Leaf)) {
267 285 $taskList = $buildFile.Split(', ')
268 286 $buildFile = $psake.config_default.buildFileName
269 287 }
270 288
271 289 # Execute the build file to set up the tasks and defaults
272   - Assert (test-path $buildFile) ($msgs.error_build_file_not_found -f $buildFile)
  290 + Assert (test-path $buildFile -pathType Leaf) ($msgs.error_build_file_not_found -f $buildFile)
273 291
274 292 $psake.build_script_file = get-item $buildFile
275 293 $psake.build_script_dir = $psake.build_script_file.DirectoryName
@@ -284,6 +302,7 @@ function Invoke-psake {
284 302 "originalDirectory" = get-location;
285 303 "originalErrorActionPreference" = $global:ErrorActionPreference;
286 304 "tasks" = @{};
  305 + "aliases" = @{};
287 306 "properties" = @();
288 307 "includes" = new-object System.Collections.Queue;
289 308 "config" = Create-ConfigurationForNewContext $buildFile $framework
@@ -328,8 +347,7 @@ function Invoke-psake {
328 347 }
329 348 }
330 349
331   - # N.B. The initial dot (.) indicates that variables initialized/modified
332   - # in the propertyBlock are available in the parent scope.
  350 + # The initial dot (.) indicates that variables initialized/modified in the propertyBlock are available in the parent scope.
333 351 foreach ($propertyBlock in $currentContext.properties) {
334 352 . $propertyBlock
335 353 }
@@ -351,11 +369,9 @@ function Invoke-psake {
351 369 throw $msgs.error_no_default_task
352 370 }
353 371
354   - $stopwatch.Stop()
355   -
356 372 Write-ColoredOutput ("`n" + $msgs.build_success + "`n") -foregroundcolor Green
357 373
358   - Write-TaskTimeSummary
  374 + Write-TaskTimeSummary $stopwatch.Elapsed
359 375
360 376 $psake.build_success = $true
361 377 } catch {
@@ -376,8 +392,8 @@ function Invoke-psake {
376 392 $psake.build_success = $false
377 393
378 394 if (!$psake.run_by_psake_build_tester) {
379   - #if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
380   - #so that the parent script will fail otherwise the parent script will report a successful build
  395 + # if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
  396 + # so that the parent script will fail otherwise the parent script will report a successful build
381 397 $inNestedScope = ($psake.context.count -gt 1)
382 398 if ( $inNestedScope ) {
383 399 throw $_
@@ -389,7 +405,7 @@ function Invoke-psake {
389 405 } finally {
390 406 Cleanup-Environment
391 407 }
392   -} #Invoke-psake
  408 +}
393 409
394 410 #-- Private Module Functions --#
395 411 function Write-ColoredOutput {
@@ -414,32 +430,15 @@ function Write-ColoredOutput {
414 430 }
415 431
416 432 function Load-Modules {
417   - $modules = $null
418   -
419 433 $currentConfig = $psake.context.peek().config
420   - if ($currentConfig.modules.autoload) {
421   - if ($currentConfig.modules.directory) {
422   - Assert (test-path $currentConfig.modules.directory) ($msgs.error_invalid_module_dir -f $currentConfig.modules.directory)
423   - $modules = get-item(join-path $currentConfig.modules.directory "*.psm1")
424   - }
425   - elseif (test-path (join-path $PSScriptRoot "modules")) {
426   - $modules = get-item (join-path (join-path $PSScriptRoot "modules") "*.psm1")
427   - }
428   - } else {
429   - if ($currentConfig.modules.module) {
430   - $modules = $currentConfig.modules.module | % {
431   - Assert (test-path $_.path) ($msgs.error_invalid_module_path -f $_.path);
432   - get-item $_.path
433   - }
434   - }
435   - }
436   -
437   - if ($modules) {
438   - $modules | % {
439   - "loading module: $_";
440   - $module = import-module $_ -passthru;
441   - if (!$module) {
442   - throw ($msgs.error_loading_module -f $_.Name)
  434 + if ($currentConfig.modules) {
  435 + $currentConfig.modules | foreach {
  436 + resolve-path $_ | foreach {
  437 + "Loading module: $_"
  438 + $module = import-module $_ -passthru
  439 + if (!$module) {
  440 + throw ($msgs.error_loading_module -f $_.Name)
  441 + }
443 442 }
444 443 }
445 444 ""
@@ -453,7 +452,7 @@ function Load-Configuration {
453 452
454 453 $psakeConfigFilePath = (join-path $configdir "psake-config.ps1")
455 454
456   - if (test-path $psakeConfigFilePath) {
  455 + if (test-path $psakeConfigFilePath -pathType Leaf) {
457 456 try {
458 457 $config = Get-CurrentConfigurationOrDefault
459 458 . $psakeConfigFilePath
@@ -540,7 +539,7 @@ function Configure-BuildEnvironment {
540 539 'x64' {
541 540 $bitness = 'Framework64'
542 541 }
543   - $null {
  542 + { [string]::IsNullOrEmpty($_) } {
544 543 $ptrSize = [System.IntPtr]::Size
545 544 switch ($ptrSize) {
546 545 4 {
@@ -561,11 +560,11 @@ function Configure-BuildEnvironment {
561 560 }
562 561 $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
563 562
564   - $frameworkDirs | foreach { Assert (test-path $_) ($msgs.error_no_framework_install_dir_found -f $_)}
  563 + $frameworkDirs | foreach { Assert (test-path $_ -pathType Container) ($msgs.error_no_framework_install_dir_found -f $_)}
565 564
566 565 $env:path = ($frameworkDirs -join ";") + ";$env:path"
567   - #if any error occurs in a PS function then "stop" processing immediately
568   - #this does not effect any external programs that return a non-zero exit code
  566 + # if any error occurs in a PS function then "stop" processing immediately
  567 + # this does not effect any external programs that return a non-zero exit code
569 568 $global:ErrorActionPreference = "Stop"
570 569 }
571 570
@@ -579,7 +578,7 @@ function Cleanup-Environment {
579 578 }
580 579 }
581 580
582   -#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
  581 +# borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
583 582 function Resolve-Error($ErrorRecord = $Error[0]) {
584 583 $error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:{2}"
585 584 $formatted_errorRecord = $ErrorRecord | format-list * -force | out-string
@@ -616,10 +615,10 @@ function Write-Documentation {
616 615 "Depends On" = $task.DependsOn -join ", "
617 616 Default = if ($defaultTaskDependencies -contains $task.Name) { $true }
618 617 }
619   - } | sort 'Name' | format-table -Auto -Property Name,Description,"Depends On",Default
  618 + } | sort 'Name' | format-table -autoSize -property Name,Description,"Depends On",Default
620 619 }
621 620
622   -function Write-TaskTimeSummary {
  621 +function Write-TaskTimeSummary($invokePsakeDuration) {
623 622 "-" * 70
624 623 "Build Time Report"
625 624 "-" * 70
@@ -639,36 +638,37 @@ function Write-TaskTimeSummary {
639 638 [Array]::Reverse($list)
640 639 $list += new-object PSObject -property @{
641 640 Name = "Total:";
642   - Duration = $stopwatch.Elapsed
  641 + Duration = $invokePsakeDuration
643 642 }
644   - $list | format-table -auto -Property Name,Duration | out-string -stream | ? { $_ } #using "Out-String -Stream" to filter out the blank line that Format-Table prepends
  643 + # using "out-string | where-object" to filter out the blank line that format-table prepends
  644 + $list | format-table -autoSize -property Name,Duration | out-string -stream | where-object { $_ }
645 645 }
646 646
647 647 DATA msgs {
648 648 convertfrom-stringdata @'
649   - error_invalid_task_name = Task name should not be null or empty string
650   - error_task_name_does_not_exist = task [{0}] does not exist
651   - error_circular_reference = Circular reference found for task, {0}
652   - error_missing_action_parameter = Action parameter must be specified when using PreAction or PostAction parameters
653   - error_corrupt_callstack = CallStack was corrupt. Expected {0}, but got {1}.
654   - error_invalid_framework = Invalid .NET Framework version, {0}, specified
655   - error_unknown_framework = Unknown .NET Framework version, {0}, specified in {1}
  649 + error_invalid_task_name = Task name should not be null or empty string.
  650 + error_task_name_does_not_exist = Task {0} does not exist.
  651 + error_circular_reference = Circular reference found for task {0}.
  652 + error_missing_action_parameter = Action parameter must be specified when using PreAction or PostAction parameters for task {0}.
  653 + error_corrupt_callstack = Call stack was corrupt. Expected {0}, but got {1}.
  654 + error_invalid_framework = Invalid .NET Framework version, {0} specified.
  655 + error_unknown_framework = Unknown .NET Framework version, {0} specified in {1}.
656 656 error_unknown_pointersize = Unknown pointer size ({0}) returned from System.IntPtr.
657   - error_unknown_bitnesspart = Unknown .NET Framework bitness, {0}, specified in {1}
658   - error_no_framework_install_dir_found = No .NET Framework installation directory found at {0}
659   - error_bad_command = Error executing command: {0}
660   - error_default_task_cannot_have_action = 'default' task cannot specify an action
  657 + error_unknown_bitnesspart = Unknown .NET Framework bitness, {0}, specified in {1}.
  658 + error_no_framework_install_dir_found = No .NET Framework installation directory found at {0}.
  659 + error_bad_command = Error executing command {0}.
  660 + error_default_task_cannot_have_action = 'default' task cannot specify an action.
661 661 error_duplicate_task_name = Task {0} has already been defined.
  662 + error_duplicate_alias_name = Alias {0} has already been defined.
662 663 error_invalid_include_path = Unable to include {0}. File not found.
663   - error_build_file_not_found = Could not find the build file, {0}.
664   - error_no_default_task = default task required
665   - error_invalid_module_dir = Unable to load modules from directory: {0}
666   - error_invalid_module_path = Unable to load module at path: {0}
667   - error_loading_module = Error loading module: {0}
668   - warning_deprecated_framework_variable = Warning: Using global variable $framework to set .NET framework version used is deprecated. Instead use Framework function or configuration file psake-config.ps1
669   - postcondition_failed = Postcondition failed for {0}
670   - precondition_was_false = Precondition was false not executing {0}
671   - continue_on_error = Error in Task [{0}] {1}
  664 + error_build_file_not_found = Could not find the build file {0}.
  665 + error_no_default_task = 'default' task required.
  666 + error_loading_module = Error loading module {0}.
  667 + warning_deprecated_framework_variable = Warning: Using global variable $framework to set .NET framework version used is deprecated. Instead use Framework function or configuration file psake-config.ps1.
  668 + required_variable_not_set = Variable {0} must be set to run task {1}.
  669 + postcondition_failed = Postcondition failed for task {0}.
  670 + precondition_was_false = Precondition was false, not executing task {0}.
  671 + continue_on_error = Error in task {0}. {1}
672 672 build_success = Build Succeeded!
673 673 '@
674 674 }
@@ -676,18 +676,16 @@ convertfrom-stringdata @'
676 676 import-localizeddata -bindingvariable msgs -erroraction silentlycontinue
677 677
678 678 $script:psake = @{}
679   -$psake.version = "4.00" # contains the current version of psake
  679 +$psake.version = "4.1.0" # contains the current version of psake
680 680 $psake.context = new-object system.collections.stack # holds onto the current state of all variables
681 681 $psake.run_by_psake_build_tester = $false # indicates that build is being run by psake-BuildTester
682 682 $psake.config_default = new-object psobject -property @{
683 683 buildFileName = "default.ps1";
684   - framework = "3.5";
  684 + framework = "4.0";
685 685 taskNameFormat = "Executing {0}";
686 686 verboseError = $false;
687 687 coloredOutput = $true;
688   - modules = (new-object PSObject -property @{
689   - autoload = $false
690   - })
  688 + modules = $null;
691 689 } # contains default configuration, can be overriden in psake-config.ps1 in directory with psake.psm1 or in directory with current build script
692 690
693 691 $psake.build_success = $false # indicates that the current build was successful
4 specs/duplicate_alias_should_fail.ps1
... ... @@ -0,0 +1,4 @@
  1 +task default
  2 +task A -alias a {}
  3 +task B -alias b {}
  4 +task C -alias a {}
5 specs/task_with_alias_and_dependencies_should_pass.ps1
... ... @@ -0,0 +1,5 @@
  1 +task default -depends Task_With_Alias
  2 +
  3 +task Task_With_Alias -depends Task_Dependency -alias twa {}
  4 +
  5 +task Task_Dependency {}
3  specs/task_with_alias_should_pass.ps1
... ... @@ -0,0 +1,3 @@
  1 +task Task_With_Big_Descriptve_Name -alias twbdn {
  2 + "Doing stuff inside task with alias"
  3 +}
10 specs/using_required_when_not_set_should_fail.ps1
... ... @@ -0,0 +1,10 @@
  1 +properties {
  2 + $x = $null
  3 + $y = $null
  4 + $z = $null
  5 +}
  6 +
  7 +task default -depends TestProperties
  8 +
  9 +task TestProperties -requiredVariables z{
  10 +}
9 specs/using_required_when_set_should_pass.ps1
... ... @@ -0,0 +1,9 @@
  1 +properties {
  2 + $x = $null
  3 + $y = $null
  4 +}
  5 +
  6 +task default -depends TestRequired
  7 +
  8 +task TestRequired -requiredVariables x, y {
  9 +}
2  specs/writing_psake_variables_should_pass.ps1
@@ -30,5 +30,5 @@ task Verify -description "This task verifies psake's variables" {
30 30 Assert ($config.taskNameFormat -eq "Executing {0}") '$psake.context.peek().config.taskNameFormat not equal to "Executing {0}"'
31 31 Assert (!$config.verboseError) '$psake.context.peek().config.verboseError should be $false'
32 32 Assert ($config.coloredOutput) '$psake.context.peek().config.coloredOutput should be $false'
33   - Assert ($config.modules) '$psake.context.peek().config.modules is $null'
  33 + Assert ($config.modules -eq $null) '$psake.context.peek().config.modules is not $null'
34 34 }

No commit comments for this range

Something went wrong with that request. Please try again.