Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved psake-ps2 changes from master to psake-ps2 branch.

  • Loading branch information...
commit 62b5b17bf0adc126f83f4e7e02b95f2dc7337471 1 parent 705a723
@jmatos jmatos authored JamesKovacs committed
View
24 examples/PreAndPostActions.ps1
@@ -1,13 +1,13 @@
-task default -depends Test
-
-task Test -depends Compile, Clean -PreAction {"Pre-Test"} -Action {
- "Test"
-} -PostAction {"Post-Test"}
-
-task Compile -depends Clean {
- "Compile"
-}
-
-task Clean {
- "Clean"
+task default -depends Test
+
+task Test -depends Compile, Clean -PreAction {"Pre-Test"} -Action {
+ "Test"
+} -PostAction {"Post-Test"}
+
+task Compile -depends Clean {
+ "Compile"
+}
+
+task Clean {
+ "Clean"
}
View
36 examples/VerifyVariables.ps1
@@ -0,0 +1,36 @@
+properties {
+ $x = 1
+}
+
+FormatTaskName "[{0}]"
+
+task default -depends Verify
+
+task Verify -description "This task verifies psake's variables" {
+
+ #Verify the exported module variables
+ cd variable:
+ Assert (Test-Path "psake") "variable psake was not exported from module"
+
+ Assert ($psake.ContainsKey("build_success")) "psake variable does not contain 'build_success'"
+ Assert ($psake.ContainsKey("use_exit_on_error")) "psake variable does not contain 'use_exit_on_error'"
+ Assert ($psake.ContainsKey("log_error")) "psake variable does not contain 'log_error'"
+ Assert ($psake.ContainsKey("version")) "psake variable does not contain 'version'"
+ Assert ($psake.ContainsKey("build_script_file")) "psake variable does not contain 'build_script_file'"
+ Assert ($psake.ContainsKey("framework_version")) "psake variable does not contain 'framework_version'"
+
+ Assert (!$psake.build_success) 'psake.build_success should be $false'
+ Assert (!$psake.use_exit_on_error) 'psake.use_exit_on_error should be $false'
+ Assert (!$psake.log_error) 'psake.log_error should be $false'
+ Assert (![string]::IsNullOrEmpty($psake.version)) 'psake.version was null or empty'
+ Assert ($psake.build_script_file -ne $null) '$psake.build_script_file was null'
+ Assert ($psake.build_script_file.Name -eq "VerifyVariables.ps1") ("psake variable: {0} was not equal to 'VerifyVariables.ps1'" -f $psake.build_script_file.Name)
+ Assert (![string]::IsNullOrEmpty($psake.framework_version)) 'psake variable: $psake.framework_version was null or empty'
+
+ #Verify script-level variables
+ Assert ($tasks.Count -ne 0) 'psake variable: $tasks had length zero'
+ Assert ($properties.Count -ne 0) 'psake variable: $properties had length zero'
+ Assert ($includes.Count -eq 0) 'psake variable: $includes should have had length zero'
+ Assert ($formatTaskNameString -eq "[{0}]") 'psake variable: $formatTaskNameString was not set correctly'
+ Assert ($currentTaskName -eq "Verify") 'psake variable: $currentTaskName was not set correctly'
+}
View
20 examples/bad-PreAndPostActions.ps1
@@ -1,11 +1,11 @@
-task default -depends Test
-
-task Test -depends Compile, Clean -PreAction {"Pre-Test"} -PostAction {"Post-Test"}
-
-task Compile -depends Clean {
- "Compile"
-}
-
-task Clean {
- "Clean"
+task default -depends Test
+
+task Test -depends Compile, Clean -PreAction {"Pre-Test"} -PostAction {"Post-Test"}
+
+task Compile -depends Clean {
+ "Compile"
+}
+
+task Clean {
+ "Clean"
}
View
8 examples/bad-defaultWithAction.ps1
@@ -1,5 +1,5 @@
-task default {
- "Starting to do stuff..."
- "Adding stuff... 1 + 1 =" + (1+1)
- "Stuff done!"
+task default {
+ "Starting to do stuff..."
+ "Adding stuff... 1 + 1 =" + (1+1)
+ "Stuff done!"
}
View
5 examples/bad-missingTasks.ps1
@@ -0,0 +1,5 @@
+task default -depends Test
+
+task Test -depends Compile, Clean {
+ Write-Host "Running PSake"
+}
View
24 examples/bad-postcondition.ps1
@@ -1,13 +1,13 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -postcondition { return $false } {
- "TaskB"
-}
-
-task C {
- "TaskC"
+task default -depends A,B,C
+
+task A {
+ "TaskA"
+}
+
+task B -postcondition { return $false } {
+ "TaskB"
+}
+
+task C {
+ "TaskC"
}
View
36 examples/default.ps1
@@ -1,19 +1,19 @@
-properties {
- $testMessage = 'Executed Test!'
- $compileMessage = 'Executed Compile!'
- $cleanMessage = 'Executed Clean!'
-}
-
-task default -depends Test
-
-task Test -depends Compile, Clean {
- $testMessage
-}
-
-task Compile -depends Clean {
- $compileMessage
-}
-
-task Clean {
- $cleanMessage
+properties {
+ $testMessage = 'Executed Test!'
+ $compileMessage = 'Executed Compile!'
+ $cleanMessage = 'Executed Clean!'
+}
+
+task default -depends Test
+
+task Test -depends Compile, Clean {
+ $testMessage
+}
+
+task Compile -depends Clean {
+ $compileMessage
+}
+
+task Clean {
+ $cleanMessage
}
View
6 examples/displayMsBuildNotice.ps1
@@ -1,4 +1,4 @@
-task default -depends DisplayNotice
-task DisplayNotice {
- msbuild /version
+task default -depends DisplayNotice
+task DisplayNotice {
+ msbuild /version
}
View
10 examples/multilineBlocks.ps1
@@ -1,6 +1,6 @@
-task default -depends doStuff
-task doStuff {
- "Starting to do stuff..."
- "Adding stuff... 1 + 1 =" + (1+1)
- "Stuff done!"
+task default -depends doStuff
+task doStuff {
+ "Starting to do stuff..."
+ "Adding stuff... 1 + 1 =" + (1+1)
+ "Stuff done!"
}
View
24 examples/postcondition.ps1
@@ -1,13 +1,13 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -postcondition { return $true } {
- "TaskB"
-}
-
-task C {
- "TaskC"
+task default -depends A,B,C
+
+task A {
+ "TaskA"
+}
+
+task B -postcondition { return $true } {
+ "TaskB"
+}
+
+task C {
+ "TaskC"
}
View
24 examples/precondition.ps1
@@ -1,13 +1,13 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -precondition { return $false } {
- "TaskB"
-}
-
-task C -precondition { return $true } {
- "TaskC"
+task default -depends A,B,C
+
+task A {
+ "TaskA"
+}
+
+task B -precondition { return $false } {
+ "TaskB"
+}
+
+task C -precondition { return $true } {
+ "TaskC"
}
View
17 examples/tasksetup.ps1
@@ -0,0 +1,17 @@
+TaskSetup {
+ "executing task setup"
+}
+
+Task default -depends Compile, Test, Deploy
+
+Task Compile {
+ "Compiling"
+}
+
+Task Test -depends Compile {
+ "Testing"
+}
+
+Task Deploy -depends Test {
+ "Deploying"
+}
View
6 images/SakeBottleLicense.txt
@@ -1,4 +1,4 @@
-SakeBottle.jpg
-An American produced bottle of Ginjo Sake.
-Shawn Clark Lazyeights Photography http://lazyeights.net/cpg/displayimage.php?pos=-122
+SakeBottle.jpg
+An American produced bottle of Ginjo Sake.
+Shawn Clark Lazyeights Photography http://lazyeights.net/cpg/displayimage.php?pos=-122
This work is licensed under the Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/).
View
10 package/Excluded.txt
@@ -1,6 +1,6 @@
-.svn
-package
-images\.svn
-images\psake.pdn
-images\SakeBottle.jpg
+.svn
+package
+images\.svn
+images\psake.pdn
+images\SakeBottle.jpg
examples\.svn
View
4 package/default.ps1
@@ -1,3 +1,3 @@
-include 'psake_packager.ps1'
-
+include 'psake_packager.ps1'
+
task default -depends validate-psake,package-psake,deploy-psake
View
82 package/psake_packager.ps1
@@ -1,42 +1,42 @@
-task validate-psake -description 'Run example psake scripts to validate behavior' {
- trap {
- Set-Location 'package'
- throw;
- }
- Set-Location '..\'
- .\psake-buildTester.ps1
- Set-Location 'package'
-}
-
-task package-psake -description 'Packages all psake scripts, docs, and example scripts into a zip file' -depends update-psake-version {
- $version = (cat Version.inc)
- $zipFile = "psake v$version.zip"
-
- if (test-path $zipFile) {
- Remove-Item $zipFile
- }
-
- .\7za a "$zipFile" ..\ -r "-x@Excluded.txt"
-}
-
-task update-psake-version -description 'Updates version references in psake script' {
- $previousVersion = New-Object System.Version (cat Version.inc)
- $newVersion = New-Object System.Version $previousVersion.Major,($previousVersion.Minor+1)
-
- $first = $true
- $outputFile = '..\psake.ps1'
- foreach ($line in (cat ..\psake.ps1)) {
- $fileLine = [regex]::Replace($line, $previousVersion, $newVersion);
- if ($first) {
- $fileLine | Out-File $outputFile
- $first = $false
- } else {
- $fileLine | Out-File $outputFile -append
- }
- }
-
- $newVersion.ToString() | Out-File Version.inc
-}
-
-task deploy-psake -description 'Deploys to code.google.com/p/psake' {
+task validate-psake -description 'Run example psake scripts to validate behavior' {
+ trap {
+ Set-Location 'package'
+ throw;
+ }
+ Set-Location '..\'
+ .\psake-buildTester.ps1
+ Set-Location 'package'
+}
+
+task package-psake -description 'Packages all psake scripts, docs, and example scripts into a zip file' -depends update-psake-version {
+ $version = (cat Version.inc)
+ $zipFile = "psake v$version.zip"
+
+ if (test-path $zipFile) {
+ Remove-Item $zipFile
+ }
+
+ .\7za a "$zipFile" ..\ -r "-x@Excluded.txt"
+}
+
+task update-psake-version -description 'Updates version references in psake script' {
+ $previousVersion = New-Object System.Version (cat Version.inc)
+ $newVersion = New-Object System.Version $previousVersion.Major,($previousVersion.Minor+1)
+
+ $first = $true
+ $outputFile = '..\psake.ps1'
+ foreach ($line in (cat ..\psake.ps1)) {
+ $fileLine = [regex]::Replace($line, $previousVersion, $newVersion);
+ if ($first) {
+ $fileLine | Out-File $outputFile
+ $first = $false
+ } else {
+ $fileLine | Out-File $outputFile -append
+ }
+ }
+
+ $newVersion.ToString() | Out-File Version.inc
+}
+
+task deploy-psake -description 'Deploys to code.google.com/p/psake' {
}
View
96 psake-buildTester.ps1
@@ -1,43 +1,53 @@
-function runBuilds{
- $buildFiles = dir examples\*.ps1
- $testResults = @()
-
- foreach($buildFile in $buildFiles) {
- $testResult = "" | select Name, Result
- $testResult.Name = $buildFile.Name
- Run-psake $buildFile -noexit | Out-Null
- $testResult.Result = (getResult $buildFile.Name $global:psake_buildSucceeded)
- $testResults += $testResult
- }
- return $testResults
-}
-
-function getResult([string]$fileName, [bool]$buildSucceeded) {
- if ($fileName.StartsWith("bad")) {
- if (!$buildSucceeded) {
- "Passed"
- }
- else {
- "Failed"
- }
- }
- else {
- if ($buildSucceeded) {
- "Passed"
- }
- else {
- "Failed"
- }
- }
-}
-
-$results = runBuilds
-$results | ft -auto
-
-$failed = $results | ? { $_.Result -eq "Failed" }
-if ($failed) {
- "One of the builds failed"
- exit 1
-} else {
- exit 0
-}
+function runBuilds{
+ $buildFiles = dir examples\*.ps1
+ $testResults = @()
+
+ $non_existant_buildfile = "" | select Name, FullName
+ $non_existant_buildfile.Name = "bad-non_existant_buildfile.ps1"
+ $non_existant_buildfile.FullName = "c:\bad-non_existant_buildfile.ps1"
+ $buildFiles += $non_existant_buildfile
+
+ foreach($buildFile in $buildFiles) {
+ $testResult = "" | select Name, Result
+ $testResult.Name = $buildFile.Name
+ Invoke-psake $buildFile.FullName | Out-Null
+ $testResult.Result = (getResult $buildFile.Name $psake.build_success)
+ $testResults += $testResult
+ }
+ return $testResults
+}
+
+function getResult([string]$fileName, [bool]$buildSucceeded) {
+ if ($fileName.StartsWith("bad")) {
+ if (!$buildSucceeded) {
+ "Passed"
+ }
+ else {
+ "Failed"
+ }
+ }
+ else {
+ if ($buildSucceeded) {
+ "Passed"
+ }
+ else {
+ "Failed"
+ }
+ }
+}
+
+Import-Module .\psake.psm1
+
+$results = runBuilds
+
+Remove-Module psake
+
+$results | Sort 'Name' | Format-Table -Auto
+
+$failed = $results | ? { $_.Result -eq "Failed" }
+if ($failed) {
+ write-host "One of the builds failed" -ForeGroundColor 'RED'
+ exit 1
+} else {
+ exit 0
+}
View
1,513 psake.psm1
@@ -1,591 +1,922 @@
-# psake v0.23
-# Copyright © 2009 James Kovacs
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-#-- Start Exported Functions
-function Task
-{
-<#
-.Synopsis
- Defines a build task to be executed by psake
-.Description
- This function contains parameters that will be used by the psake engine to execute a build task.
- Note: There must be at least one task called 'default' in the build script
-.Parameter Name
- The name of the task
- Required
-.Parameter Action
- A scriptblock containing the statements to execute
- Optional
-.Parameter PreAction
- A scriptblock to be executed before the 'Action' scriptblock.
- Note: This parameter is ignored if the 'Action' scriptblock is not defined.
- Optional
-.Parameter PostAction
- A scriptblock to be executed after the 'Action' scriptblock.
- Note: This parameter is ignored if the 'Action' scriptblock is not defined.
- Optional
-.Parameter Precondition
- A scriptblock that is executed to determine if the task is executed or skipped.
- This scriptblock should return $true or $false
- Optional
-.Parameter Postcondition
- A scriptblock that is executed to determine if the task completed its job correctly.
- An exception is thrown if the scriptblock returns false.
- Optional
-.Parameter ContinueOnError
- If this switch parameter is set then the task will not cause the build to fail when an exception is thrown
-.Parameter Depends
- An array of tasks that this task depends on. They will be executed before the current task is executed.
-.Parameter Description
- A description of the task.
-.Example
- task default -depends Test
-
- This is the 'default' task and should not contain an 'Action' parameter.
- Uses the 'depends' parameter to specify that 'Test' is a dependency
-
-.Example
- task Test -depends Compile, Clean {
- $testMessage
- }
-
- This task uses the 'depends' parameter to specify that 'Compile' and 'Clean' are dependencies
-
- The 'Action' parameter is defaulted to the script block following the 'Clean'.
- The equivalen is shown below:
-
- task Test -depends Compile, Clean -Action {
- $testMessage
- }
-
-.ReturnValue
-
-.Link
- Run-psake
-.Notes
- NAME: Run-psake
- AUTHOR: Jorge Matos
- LASTEDIT: 05/12/2009
-#Requires -Version 2.0
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [string]$name = $null,
- [scriptblock]$action = $null,
- [scriptblock]$preaction = $null,
- [scriptblock]$postaction = $null,
- [scriptblock]$precondition = $null,
- [scriptblock]$postcondition = $null,
- [switch]$continueOnError = $false,
- [string[]]$depends = @(),
- [string]$description = $null
- )
- if ([string]::IsNullOrEmpty($name))
- {
- throw "Error: Task must have a name"
- }
- if (($name.ToLower() -eq 'default') -and ($action -ne $null))
- {
- throw "Error: Default task cannot specify an action"
- }
- $newTask = @{
- Name = $name
- DependsOn = $depends
- PreAction = $preaction
- Action = $action
- PostAction = $postaction
- Precondition = $precondition
- Postcondition = $postcondition
- ContinueOnError = $continueOnError
- Description = $description
- Duration = 0
- }
- if ($global:tasks.$name -ne $null)
- {
- throw "Error: Task, $name, has already been defined."
- }
- $global:tasks.$name = $newTask
-}
-
-function Properties
-{
- param([scriptblock]$propertyBlock)
- $global:properties += $propertyBlock
-}
-
-function Include
-{
- param([string]$include)
- if (!(test-path $include))
- {
- throw "Error: $include not found."
- }
- $global:includes.Enqueue((Resolve-Path $include));
-}
-
-function FormatTaskName
-{
- param([string]$format)
- $global:formatTaskNameString = $format
-}
-
-function TaskSetup
-{
- param([scriptblock]$setup)
- $global:taskSetupScriptBlock = $setup
-}
-
-function TaskTearDown
-{
- param([scriptblock]$teardown)
- $global:taskTearDownScriptBlock = $teardown
-}
-#-- END Exported Functions
-
-function ExecuteTask
-{
- param([string]$name)
-
- if (!$global:tasks.Contains($name))
- {
- throw "task [$name] does not exist"
- }
-
- if ($global:executedTasks.Contains($name))
- {
- return
- }
-
- if ($global:callStack.Contains($name))
- {
- throw "Error: Circular reference found for task, $name"
- }
-
- $global:callStack.Push($name)
-
- $task = $global:tasks.$name
-
- $precondition_is_valid = if ($task.Precondition -ne $null) {& $task.Precondition} else {$true}
-
- if (!$precondition_is_valid)
- {
- "Precondition was false not executing $name"
- }
- else
- {
- if ($name.ToLower() -ne 'default')
- {
- $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
-
- if ( ($task.PreAction -ne $null) -or ($task.PostAction -ne $null) -and ($task.Action -eq $null) )
- {
- throw "Error: Action must be specified when using PreAction or PostAction parameters"
- }
-
- if ($task.Action -ne $null)
- {
- try
- {
- foreach($childTask in $task.DependsOn)
- {
- ExecuteTask $childTask
- }
-
- if ($global:formatTaskNameString -ne $null)
- {
- $global:formatTaskNameString -f $name
- }
- else
- {
- "Executing task, $name..."
- }
-
- if ($global:taskSetupScriptBlock -ne $null)
- {
- & $global:taskSetupScriptBlock
- }
-
- if ($task.PreAction -ne $null)
- {
- & $task.PreAction
- }
-
- & $task.Action
-
- if ($task.PostAction -ne $null)
- {
- & $task.PostAction
- }
-
- if ($global:taskTearDownScriptBlock -ne $null)
- {
- & $global:taskTearDownScriptBlock
- }
- }
- catch
- {
- if ($task.ContinueOnError)
- {
- "-"*70
- "Error in Task [$name] $_"
- "-"*70
- continue
- }
- else
- {
- throw $_
- }
- }
- } # if ($task.Action -ne $null)
- else
- {
- #no Action was specified but we still execute all the dependencies
- foreach($childTask in $task.DependsOn)
- {
- ExecuteTask $childTask
- }
- }
- $stopwatch.stop()
- $task.Duration = $stopwatch.Elapsed
- } # if ($name.ToLower() -ne 'default')
- else
- {
- foreach($childTask in $task.DependsOn)
- {
- ExecuteTask $childTask
- }
- }
-
- $postcondition = if ($task.Postcondition -ne $null) {(& $task.Postcondition)} else {$true}
-
- if (!$postcondition)
- {
- throw "Error: Postcondition failed for $name"
- }
- }
-
- $poppedTask = $global:callStack.Pop()
- if($poppedTask -ne $name)
- {
- throw "Error: CallStack was corrupt. Expected $name, but got $poppedTask."
- }
- $global:executedTasks.Push($name)
-}
-
-function Configure-BuildEnvironment
-{
- $version = $null
- switch ($framework)
- {
- '1.0' { $version = 'v1.0.3705' }
- '1.1' { $version = 'v1.1.4322' }
- '2.0' { $version = 'v2.0.50727' }
- '3.0' { $version = 'v2.0.50727' } # .NET 3.0 uses the .NET 2.0 compilers
- '3.5' { $version = 'v3.5' }
- default { throw "Error: Unknown .NET Framework version, $framework" }
- }
- $frameworkDir = "$env:windir\Microsoft.NET\Framework\$version\"
- if(!(test-path $frameworkDir))
- {
- throw "Error: No .NET Framework installation directory found at $frameworkDir"
- }
- $env:path = "$frameworkDir;$env:path"
- $global:ErrorActionPreference = "Stop"
-}
-
-function Cleanup-Environment
-{
- $env:path = $global:originalEnvPath
- Set-Location $global:originalDirectory
- $global:ErrorActionPreference = $originalErrorActionPreference
- remove-variable tasks -scope "global" -ErrorAction SilentlyContinue
- remove-variable properties -scope "global" -ErrorAction SilentlyContinue
- remove-variable includes -scope "global" -ErrorAction SilentlyContinue
- remove-variable psake_version -scope "global" -ErrorAction SilentlyContinue
- remove-variable psake_buildScript -scope "global" -ErrorAction SilentlyContinue
- remove-variable formatTaskNameString -scope "global" -ErrorAction SilentlyContinue
- remove-variable taskSetupScriptBlock -scope "global" -ErrorAction SilentlyContinue
- remove-variable taskTearDownScriptBlock -scope "global" -ErrorAction SilentlyContinue
- remove-variable psake_frameworkVersion -scope "global" -ErrorAction SilentlyContinue
- if (!$noexit)
- {
- remove-variable psake_buildSucceeded -scope "global" -ErrorAction SilentlyContinue
- }
-}
-
-#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
-function Resolve-Error($ErrorRecord=$Error[0])
-{
- $ErrorRecord | Format-List * -Force
- $ErrorRecord.InvocationInfo | Format-List *
- $Exception = $ErrorRecord.Exception
- for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
- {
- "$i" * 70
- $Exception | Format-List * -Force
- }
-}
-
-function Write-Documentation
-{
- $list = New-Object System.Collections.ArrayList
- foreach($key in $global:tasks.Keys)
- {
- if($key -eq "default")
- {
- continue
- }
- $task = $global:tasks.$key
- $content = "" | Select-Object Name, Description
- $content.Name = $task.Name
- $content.Description = $task.Description
- $index = $list.Add($content)
- }
-
- $list | Sort 'Name' | Format-Table -Auto
-}
-
-function Write-TaskTimeSummary
-{
- "-"*70
- "Build Time Report"
- "-"*70
- $list = @()
- while ($global:executedTasks.Count -gt 0)
- {
- $name = $global:executedTasks.Pop()
- $task = $global:tasks.$name
- if($name -eq "default")
- {
- continue
- }
- $list += "" | Select-Object @{Name="Name";Expression={$name}}, @{Name="Duration";Expression={$task.Duration}}
- }
- [Array]::Reverse($list)
- $list += "" | Select-Object @{Name="Name";Expression={"Total:"}}, @{Name="Duration";Expression={$stopwatch.Elapsed}}
- $list | Format-Table -Auto | Out-String -Stream | ? {$_} # using "Out-String -Stream" to filter out the blank line that Format-Table prepends
-}
-
-function Run-psake
-{
-<#
-.Synopsis
- Runs a psake build script.
-.Description
- This function runs a psake build script
-.Parameter BuildFile
- The psake build script to execute (default: default.ps1).
-.Parameter Framework
- The version of the .NET framework you want to build
- Possible values: '1.0', '1.1', '2.0', '3.0', '3.5'
- Default = '3.5'
-.Parameter ShowFullError
- Displays detailed error information when an error occurs
-.Parameter Timing
- Prints a report showing how long each task took to execute
-.Parameter Docs
- Prints a list of tasks and their descriptions
-.Parameter NoExit
- Does not use 'exit' command when an error occurs or when printing documentation - useful when running a build interactively
-
-.Example
- Run-psake
-
- Runs the 'default' task in the 'default.ps1' build script in the current directory
-.Example
- Run-psake '.\build.ps1'
-
- Runs the 'default' task in the '.build.ps1' build script
-.Example
- Run-psake '.\build.ps1' Tests, Package
-
- Runs the 'Tests' and 'Package' tasks in the '.build.ps1' build script
-.Example
- Run-psake '.\build.ps1' -timing
-
- Runs the 'default' task in the '.build.ps1' build script and prints a timing report
-.Example
- Run-psake '.\build.ps1' -debuginfo
-
- Runs the 'default' task in the '.build.ps1' build script and prints a report of what includes, properties and tasks are in the build script
-.Example
- Run-psake '.\build.ps1' -docs
-
- Prints a report of all the tasks and their descriptions and exits
-
-.ReturnValue
- Calls exit() function with 0 for success and 1 for failure
- If $noexit is $true then exit() is not called and no value is returned
-.Link
-.Notes
- NAME: Run-psake
- AUTHOR: Jorge Matos
- LASTEDIT: 05/04/2009
-#Requires -Version 2.0
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
-
- param(
- [string]$buildFile = 'default.ps1',
- [string[]]$taskList = @(),
- [string]$framework = '3.5',
- [switch]$showFullError = $false,
- [switch]$timing = $false,
- [switch]$docs = $false,
- [switch]$noexit = $false
- )
-
- Begin
- {
- $global:tasks = @{}
- $global:properties = @()
- $global:includes = New-Object System.Collections.Queue
- $global:psake_version = "0.23"
- $global:psake_buildScript = $buildFile
- $global:psake_frameworkVersion = $framework
- $global:psake_buildSucceeded = $true
- $global:formatTaskNameString = $null
- $global:taskSetupScriptBlock = $null
- $global:taskTearDownScriptBlock = $null
-
- $global:executedTasks = New-Object System.Collections.Stack
- $global:callStack = New-Object System.Collections.Stack
- $global:originalEnvPath = $env:path
- $global:originalDirectory = Get-Location
- $originalErrorActionPreference = $Global:ErrorActionPreference
- }
-
- Process
- {
- try
- {
- $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
-
- # Execute the build file to set up the tasks and defaults
- if(test-path $buildFile)
- {
- $buildFile = resolve-path $buildFile
- set-location (split-path $buildFile)
- & $buildFile
- }
- else
- {
- throw "Error: Could not find the build file, $buildFile."
- }
-
- Configure-BuildEnvironment
-
- # N.B. The initial dot (.) indicates that variables initialized/modified
- # in the propertyBlock are available in the parent scope.
- while ($global:includes.Count -gt 0)
- {
- $includeBlock = $global:includes.Dequeue()
- . $includeBlock;
- }
- foreach($propertyBlock in $global:properties)
- {
- . $propertyBlock
- }
-
- if($docs)
- {
- Write-Documentation
- Cleanup-Environment
- if ($noexit)
- {
- return
- }
- else
- {
- exit(0)
- }
- }
-
- # Execute the list of tasks or the default task
- if($taskList.Length -ne 0)
- {
- foreach($task in $taskList)
- {
- ExecuteTask $task
- }
- }
- elseif ($global:tasks.default -ne $null)
- {
- ExecuteTask default
- }
- else
- {
- throw 'Error: default task required'
- }
-
- $stopwatch.Stop()
-
- if ($timing)
- {
- Write-TaskTimeSummary
- }
-
- $global:psake_buildSucceeded = $true
- }
- catch
- {
- if ($showFullError)
- {
- "-" * 70
- "{0}: An Error Occurred. See Error Details Below: " -f [DateTime]::Now
- "-" * 70
- Resolve-Error $_
- "-" * 70
- }
- else
- {
- $file = split-path $global:psake_buildScript -leaf
- Write-Host -foregroundcolor Red ($file + ":" + $_)
- }
-
- Cleanup-Environment
-
- if ($noexit)
- {
- $global:psake_buildSucceeded = $false
- }
- else
- {
- exit(1)
- }
- }
- } #Process
-
- End
- {
- # Clear out any global variables
- Cleanup-Environment
- }
-}
-
-Export-ModuleMember "Run-psake","Task","Properties","Include","FormatTaskName","TaskSetup","TaskTearDown"
+# psake v0.24
+# Copyright © 2009 James Kovacs
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+#-- Private Module Variables
+[string]$script:originalEnvPath
+[string]$script:originalDirectory
+[string]$script:formatTaskNameString
+[string]$script:currentTaskName
+[hashtable]$script:tasks
+[array]$script:properties
+[scriptblock]$script:taskSetupScriptBlock
+[scriptblock]$script:taskTearDownScriptBlock
+[system.collections.queue]$script:includes
+[system.collections.stack]$script:executedTasks
+[system.collections.stack]$script:callStack
+
+#-- Public Module Variables
+$script:psake = @{}
+Export-ModuleMember -Variable "psake"
+
+#-- Private Module Functions
+function ExecuteTask
+{
+ param([string]$taskName)
+
+ Assert (![string]::IsNullOrEmpty($taskName)) "Task name should not be null or empty string"
+
+ $taskKey = $taskName.Tolower()
+
+ Assert ($script:tasks.Contains($taskKey)) "task [$taskName] does not exist"
+
+ if ($script:executedTasks.Contains($taskKey))
+ {
+ return
+ }
+
+ Assert (!$script:callStack.Contains($taskKey)) "Error: Circular reference found for task, $taskName"
+
+ $script:callStack.Push($taskKey)
+
+ $task = $script:tasks.$taskKey
+
+ $taskName = $task.Name
+
+ $precondition_is_valid = if ($task.Precondition -ne $null) {& $task.Precondition} else {$true}
+
+ if (!$precondition_is_valid)
+ {
+ "Precondition was false not executing $name"
+ }
+ else
+ {
+ if ($taskKey -ne 'default')
+ {
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+
+ if ( ($task.PreAction -ne $null) -or ($task.PostAction -ne $null) )
+ {
+ Assert ($task.Action -ne $null) "Error: Action parameter must be specified when using PreAction or PostAction parameters"
+ }
+
+ if ($task.Action -ne $null)
+ {
+ try
+ {
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+
+ $script:currentTaskName = $taskName
+
+ if ($script:taskSetupScriptBlock -ne $null)
+ {
+ & $script:taskSetupScriptBlock
+ }
+
+ if ($task.PreAction -ne $null)
+ {
+ & $task.PreAction
+ }
+
+ $script:formatTaskNameString -f $taskName
+ & $task.Action
+
+ if ($task.PostAction -ne $null)
+ {
+ & $task.PostAction
+ }
+
+ if ($script:taskTearDownScriptBlock -ne $null)
+ {
+ & $script:taskTearDownScriptBlock
+ }
+ }
+ catch
+ {
+ if ($task.ContinueOnError)
+ {
+ "-"*70
+ "Error in Task [$taskName] $_"
+ "-"*70
+ continue
+ }
+ else
+ {
+ throw $_
+ }
+ }
+ } # if ($task.Action -ne $null)
+ else
+ {
+ #no Action was specified but we still execute all the dependencies
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+ }
+ $stopwatch.stop()
+ $task.Duration = $stopwatch.Elapsed
+ } # if ($name.ToLower() -ne 'default')
+ else
+ {
+ foreach($childTask in $task.DependsOn)
+ {
+ ExecuteTask $childTask
+ }
+ }
+
+ if ($task.Postcondition -ne $null)
+ {
+ Assert (& $task.Postcondition) "Error: Postcondition failed for $taskName"
+ }
+ }
+
+ $poppedTaskKey = $script:callStack.Pop()
+
+ Assert ($poppedTaskKey -eq $taskKey) "Error: CallStack was corrupt. Expected $taskKey, but got $poppedTaskKey."
+
+ $script:executedTasks.Push($taskKey)
+}
+
+function Configure-BuildEnvironment
+{
+ $version = $null
+ switch ($framework)
+ {
+ '1.0' { $version = 'v1.0.3705' }
+ '1.1' { $version = 'v1.1.4322' }
+ '2.0' { $version = 'v2.0.50727' }
+ '3.0' { $version = 'v2.0.50727' } # .NET 3.0 uses the .NET 2.0 compilers
+ '3.5' { $version = 'v3.5' }
+ default { throw "Error: Unknown .NET Framework version, $framework" }
+ }
+ $frameworkDir = "$env:windir\Microsoft.NET\Framework\$version\"
+
+ Assert (test-path $frameworkDir) "Error: No .NET Framework installation directory found at $frameworkDir"
+
+ $env:path = "$frameworkDir;$env:path"
+ #if any error occurs in a PS function then "stop" processing immediately
+ # this does not effect any external programs that return a non-zero exit code
+ $global:ErrorActionPreference = "Stop"
+}
+
+function Cleanup-Environment
+{
+ $env:path = $script:originalEnvPath
+ Set-Location $script:originalDirectory
+ $global:ErrorActionPreference = $originalErrorActionPreference
+}
+
+#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
+function Resolve-Error($ErrorRecord=$Error[0])
+{
+ "ErrorRecord"
+ $ErrorRecord | Format-List * -Force | Out-String -Stream | ? {$_}
+ ""
+ "ErrorRecord.InvocationInfo"
+ $ErrorRecord.InvocationInfo | Format-List * | Out-String -Stream | ? {$_}
+ ""
+ "Exception"
+ $Exception = $ErrorRecord.Exception
+ for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
+ {
+ "$i" * 70
+ $Exception | Format-List * -Force | Out-String -Stream | ? {$_}
+ ""
+ }
+}
+
+function Write-Documentation
+{
+ $list = New-Object System.Collections.ArrayList
+ foreach($key in $script:tasks.Keys)
+ {
+ if($key -eq "default")
+ {
+ continue
+ }
+ $task = $script:tasks.$key
+ $content = "" | Select-Object Name, Description
+ $content.Name = $task.Name
+ $content.Description = $task.Description
+ $index = $list.Add($content)
+ }
+
+ $list | Sort 'Name' | Format-Table -Auto
+}
+
+function Write-TaskTimeSummary
+{
+ "-"*70
+ "Build Time Report"
+ "-"*70
+ $list = @()
+ while ($script:executedTasks.Count -gt 0)
+ {
+ $taskKey = $script:executedTasks.Pop()
+ $task = $script:tasks.$taskKey
+ if($taskKey -eq "default")
+ {
+ continue
+ }
+ $list += "" | Select-Object @{Name="Name";Expression={$task.Name}}, @{Name="Duration";Expression={$task.Duration}}
+ }
+ [Array]::Reverse($list)
+ $list += "" | Select-Object @{Name="Name";Expression={"Total:"}}, @{Name="Duration";Expression={$stopwatch.Elapsed}}
+ $list | Format-Table -Auto | Out-String -Stream | ? {$_} # using "Out-String -Stream" to filter out the blank line that Format-Table prepends
+}
+
+#-- Public Module Functions
+function Assert
+{
+<#
+.Synopsis
+ Helper function for "Design by Contract" assertion checking.
+.Description
+ This is a helper function that makes the code less noisy by eliminating many of the "if" statements
+ that are normally required to verify assumptions in the code.
+.Parameter conditionToCheck
+ The boolean condition to evaluate
+ Required
+.Parameter failureMessage
+ The error message used for the exception if the conditionToCheck parameter is false
+ Required
+.Example
+ Assert $false "This always throws an exception"
+
+ This example always throws an exception
+.Example
+ Assert (1 -eq 2) "1 doesn't equal 2"
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Task
+ Properties
+ Include
+ FormatTaskName
+ TaskSetup
+ TaskTearDown
+.Notes
+ It might be necessary to wrap the condition with paranthesis to force PS to evaluate the condition
+ so that a boolean value is calculated and passed into the parameter.
+
+ Example:
+ Assert 1 -eq 2 "1 doesn't equal 2"
+
+ PS will pass 1 into the condtionToCheck variable and PS will look for a parameter called "eq" and
+ throw an exception with the following message "A parameter cannot be found that matches parameter name 'eq'"
+
+ The solution is to wrap the condition in () so that PS will evaluate it first.
+
+ Assert (1 -eq 2) "1 doesn't equal 2"
+
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+
+ param(
+ [Parameter(Position=0,Mandatory=1)]$conditionToCheck,
+ [Parameter(Position=1,Mandatory=1)]$failureMessage
+ )
+ if (!$conditionToCheck) { throw $failureMessage }
+}
+
+function Task
+{
+<#
+.Synopsis
+ Defines a build task to be executed by psake
+.Description
+ This function contains parameters that will be used by the psake engine to execute a build task.
+ Note: There must be at least one task called 'default' in the build script
+.Parameter Name
+ The name of the task
+ Required
+.Parameter Action
+ A scriptblock containing the statements to execute
+ Optional
+.Parameter PreAction
+ A scriptblock to be executed before the 'Action' scriptblock.
+ Note: This parameter is ignored if the 'Action' scriptblock is not defined.
+ Optional
+.Parameter PostAction
+ A scriptblock to be executed after the 'Action' scriptblock.
+ Note: This parameter is ignored if the 'Action' scriptblock is not defined.
+ Optional
+.Parameter Precondition
+ A scriptblock that is executed to determine if the task is executed or skipped.
+ This scriptblock should return $true or $false
+ Optional
+.Parameter Postcondition
+ A scriptblock that is executed to determine if the task completed its job correctly.
+ An exception is thrown if the scriptblock returns false.
+ Optional
+.Parameter ContinueOnError
+ If this switch parameter is set then the task will not cause the build to fail when an exception is thrown
+.Parameter Depends
+ An array of tasks that this task depends on. They will be executed before the current task is executed.
+.Parameter Description
+ A description of the task.
+.Example
+ task default -depends Test
+
+ task Test -depends Compile, Clean {
+ $testMessage
+ }
+
+ The 'default' task is required and should not contain an 'Action' parameter.
+ It uses the 'depends' parameter to specify that 'Test' is a dependency
+
+ The 'Test' task uses the 'depends' parameter to specify that 'Compile' and 'Clean' are dependencies
+
+ The 'Action' parameter is defaulted to the script block following the 'Clean'.
+
+ The equivalent is shown below:
+
+ task Test -depends Compile, Clean -Action {
+ $testMessage
+ }
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Properties
+ Include
+ FormatTaskName
+ TaskSetup
+ TaskTearDown
+ Assert
+.Notes
+
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$name = $null,
+ [Parameter(Position=1,Mandatory=0)]
+ [scriptblock]$action = $null,
+ [Parameter(Position=2,Mandatory=0)]
+ [scriptblock]$preaction = $null,
+ [Parameter(Position=3,Mandatory=0)]
+ [scriptblock]$postaction = $null,
+ [Parameter(Position=4,Mandatory=0)]
+ [scriptblock]$precondition = $null,
+ [Parameter(Position=5,Mandatory=0)]
+ [scriptblock]$postcondition = $null,
+ [Parameter(Position=6,Mandatory=0)]
+ [switch]$continueOnError = $false,
+ [Parameter(Position=7,Mandatory=0)]
+ [string[]]$depends = @(),
+ [Parameter(Position=8,Mandatory=0)]
+ [string]$description = $null
+ )
+
+ if ($name.ToLower() -eq 'default')
+ {
+ Assert ($action -eq $null) "Error: 'default' task cannot specify an action"
+ }
+
+ $newTask = @{
+ Name = $name
+ DependsOn = $depends
+ PreAction = $preaction
+ Action = $action
+ PostAction = $postaction
+ Precondition = $precondition
+ Postcondition = $postcondition
+ ContinueOnError = $continueOnError
+ Description = $description
+ Duration = 0
+ }
+
+ $taskKey = $name.ToLower()
+
+ Assert (!$script:tasks.ContainsKey($taskKey)) "Error: Task, $name, has already been defined."
+
+ $script:tasks.$taskKey = $newTask
+}
+
+function Properties
+{
+<#
+.Synopsis
+ Adds a scriptblock to the module varible "properies"
+.Description
+ A build script may declare a "Properies" function which allows you to define
+ variables that will be available to all the "Task" functions in the build script.
+.Parameter properties
+ The script block containing all the variable assignment statements
+ Required
+.Example
+ Properties {
+ $build_dir = "c:\build"
+ $connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
+ }
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Task
+ Include
+ FormatTaskName
+ TaskSetup
+ TaskTearDown
+ Assert
+.Notes
+ You can have more than 1 "Properties" function defined in the script
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$properties
+ )
+ $script:properties += $properties
+}
+
+function Include
+{
+<#
+.Synopsis
+ Adds a scriptblock to the module varible "includes"
+.Description
+ 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.
+.Parameter include
+ A string containing the path and name of the powershell file to include
+ Required
+.Example
+ Include "c:\utils.ps1"
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Task
+ Properties
+ FormatTaskName
+ TaskSetup
+ TaskTearDown
+ Assert
+.Notes
+ You can have more than 1 "Include" function defined in the script
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$include
+ )
+ Assert (test-path $include) "Error: Unable to include $include. File not found."
+ $script:includes.Enqueue((Resolve-Path $include));
+}
+
+function FormatTaskName
+{
+<#
+.Synopsis
+ Allows you to define a format mask that will be used when psake displays
+ the task name
+.Description
+ Allows you to define a format mask that will be used when psake displays
+ the task name. The default is "Executing task, {0}..."
+.Parameter format
+ A string containing the format mask to use, it should contain a placeholder ({0})
+ that will be used to substitute the task name.
+ Required
+.Example
+ For the following build script:
+ -------------------------------
+
+ FormatTaskName "[Task: {0}]"
+
+ Task default -depends Test
+
+ Task Test -depends Compile, Clean {
+ }
+
+ Task Compile -depends Clean {
+ }
+
+ Task Clean {
+ }
+
+ You should get the following output:
+ ------------------------------------
+
+ [Task: Clean]
+ [Task: Compile]
+ [Task: Test]
+
+ Build Succeeded
+
+ ----------------------------------------------------------------------
+ Build Time Report
+ ----------------------------------------------------------------------
+ Name Duration
+ ---- --------
+ Clean 00:00:00.0043477
+ Compile 00:00:00.0102130
+ Test 00:00:00.0182858
+ Total: 00:00:00.0698071
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Include
+ Task
+ Properties
+ TaskSetup
+ TaskTearDown
+ Assert
+.Notes
+
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [string]$format
+ )
+ $script:formatTaskNameString = $format
+}
+
+function TaskSetup
+{
+<#
+.Synopsis
+ Adds a scriptblock that will be executed before each task
+.Description
+ This function will accept a scriptblock that will be executed before each
+ task in the build script.
+.Parameter include
+ A scriptblock to execute
+ Required
+.Example
+ For the following build script:
+ -------------------------------
+ Task default -depends Test
+
+ Task Test -depends Compile, Clean {
+ }
+
+ Task Compile -depends Clean {
+ }
+
+ Task Clean {
+ }
+
+ TaskSetup {
+ "Running 'TaskSetup' for task $script:currentTaskName"
+ }
+
+ You should get the following output:
+ ------------------------------------
+
+ Running 'TaskSetup' for task Clean
+ Executing task, Clean...
+ Running 'TaskSetup' for task Compile
+ Executing task, Compile...
+ Running 'TaskSetup' for task Test
+ Executing task, Test...
+
+ Build Succeeded
+
+ ----------------------------------------------------------------------
+ Build Time Report
+ ----------------------------------------------------------------------
+ Name Duration
+ ---- --------
+ Clean 00:00:00.0054018
+ Compile 00:00:00.0123085
+ Test 00:00:00.0236915
+ Total: 00:00:00.0739437
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Include
+ Task
+ Properties
+ FormatTaskName
+ TaskTearDown
+ Assert
+.Notes
+
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$setup
+ )
+ $script:taskSetupScriptBlock = $setup
+}
+
+function TaskTearDown
+{
+<#
+.Synopsis
+ Adds a scriptblock that will be executed after each task
+.Description
+ This function will accept a scriptblock that will be executed after each
+ task in the build script.
+.Parameter include
+ A scriptblock to execute
+ Required
+.Example
+ For the following build script:
+ -------------------------------
+ Task default -depends Test
+
+ Task Test -depends Compile, Clean {
+ }
+
+ Task Compile -depends Clean {
+ }
+
+ Task Clean {
+ }
+
+ TaskTearDown {
+ "Running 'TaskTearDown' for task $script:currentTaskName"
+ }
+
+ You should get the following output:
+ ------------------------------------
+
+ Executing task, Clean...
+ Running 'TaskTearDown' for task Clean
+ Executing task, Compile...
+ Running 'TaskTearDown' for task Compile
+ Executing task, Test...
+ Running 'TaskTearDown' for task Test
+
+ Build Succeeded
+
+ ----------------------------------------------------------------------
+ Build Time Report
+ ----------------------------------------------------------------------
+ Name Duration
+ ---- --------
+ Clean 00:00:00.0064555
+ Compile 00:00:00.0218902
+ Test 00:00:00.0309151
+ Total: 00:00:00.0858301
+
+.ReturnValue
+
+.Link
+ Invoke-psake
+ Include
+ Task
+ Properties
+ FormatTaskName
+ TaskSetup
+ Assert
+.Notes
+
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+ param(
+ [Parameter(Position=0,Mandatory=1)]
+ [scriptblock]$teardown)
+ $script:taskTearDownScriptBlock = $teardown
+}
+
+function Invoke-psake
+{
+<#
+.Synopsis
+ Runs a psake build script.
+.Description
+ This function runs a psake build script
+.Parameter BuildFile
+ The psake build script to execute (default: default.ps1).
+.Parameter Framework
+ The version of the .NET framework you want to build
+ Possible values: '1.0', '1.1', '2.0', '3.0', '3.5'
+ Default = '3.5'
+.Parameter Docs
+ Prints a list of tasks and their descriptions
+
+.Example
+ Invoke-psake
+
+ Runs the 'default' task in the 'default.ps1' build script in the current directory
+
+.Example
+ Invoke-psake '.\build.ps1'
+
+ Runs the 'default' task in the '.build.ps1' build script
+
+.Example
+ Invoke-psake '.\build.ps1' Tests,Package
+
+ Runs the 'Tests' and 'Package' tasks in the '.build.ps1' build script
+
+.Example
+ Invoke-psake '.\build.ps1' -docs
+
+ Prints a report of all the tasks and their descriptions and exits
+
+.ReturnValue
+ No return value unless there is an exception and $psake.use_exit_on_error -eq $true
+ then runs exit(1) to set the lastexitcode value in the OS
+ otherwise set the $script:psake.build_success variable to $true or $false depending
+ on whether an exception was thrown
+
+.Link
+.Notes
+#Requires -Version 2.0
+#>
+[CmdletBinding(
+ SupportsShouldProcess=$False,
+ SupportsTransactions=$False,
+ ConfirmImpact="None",
+ DefaultParameterSetName="")]
+
+ param(
+ [Parameter(Position=0,Mandatory=0)]
+ [string]$buildFile = 'default.ps1',
+ [Parameter(Position=1,Mandatory=0)]
+ [string[]]$taskList = @(),
+ [Parameter(Position=2,Mandatory=0)]
+ [string]$framework = '3.5',
+ [Parameter(Position=3,Mandatory=0)]
+ [switch]$docs = $false
+ )
+
+ Begin
+ {
+ $script:psake.build_success = $false
+ $script:psake.use_exit_on_error = $false
+ $script:psake.log_error = $false
+ $script:psake.version = "0.24"
+ $script:psake.build_script_file = $null
+ $script:psake.framework_version = $framework
+
+ $script:formatTaskNameString = "Executing task, {0}..."
+ $script:taskSetupScriptBlock = $null
+ $script:taskTearDownScriptBlock = $null
+ $script:executedTasks = New-Object System.Collections.Stack
+ $script:callStack = New-Object System.Collections.Stack
+ $script:originalEnvPath = $env:path
+ $script:originalDirectory = Get-Location
+ $originalErrorActionPreference = $global:ErrorActionPreference
+
+ $script:tasks = @{}
+ $script:properties = @()
+ $script:includes = New-Object System.Collections.Queue
+ }
+
+ Process
+ {
+ try
+ {
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+
+ # Execute the build file to set up the tasks and defaults
+ Assert (test-path $buildFile) "Error: Could not find the build file, $buildFile."
+
+ $script:psake.build_script_file = dir $buildFile
+ set-location $script:psake.build_script_file.Directory
+ . $script:psake.build_script_file.FullName
+
+ if ($docs)
+ {
+ Write-Documentation
+ Cleanup-Environment
+ return
+ }
+
+ Configure-BuildEnvironment
+
+ # N.B. The initial dot (.) indicates that variables initialized/modified
+ # in the propertyBlock are available in the parent scope.
+ while ($script:includes.Count -gt 0)
+ {
+ $includeBlock = $script:includes.Dequeue()
+ . $includeBlock
+ }
+ foreach($propertyBlock in $script:properties)
+ {
+ . $propertyBlock
+ }
+
+ # Execute the list of tasks or the default task
+ if($taskList.Length -ne 0)
+ {
+ foreach($task in $taskList)
+ {
+ ExecuteTask $task
+ }
+ }
+ elseif ($script:tasks.default -ne $null)
+ {
+ ExecuteTask default
+ }
+ else
+ {
+ throw 'Error: default task required'
+ }
+
+ $stopwatch.Stop()
+
+ "`nBuild Succeeded!`n"
+
+ Write-TaskTimeSummary
+
+ $script:psake.build_success = $true
+ }
+ catch
+ {
+ #Append detailed exception to log file
+ if ($script:psake.log_error)
+ {
+ $errorLogFile = "psake-error-log-{0}.log" -f ([DateTime]::Now.ToString("yyyyMMdd"))
+ "-" * 70 >> $errorLogFile
+ "{0}: An Error Occurred. See Error Details Below: " -f [DateTime]::Now >>$errorLogFile
+ "-" * 70 >> $errorLogFile
+ Resolve-Error $_ >> $errorLogFile
+ }
+
+ $buildFileName = Split-Path $buildFile -leaf
+ if (test-path $buildFile) { $buildFileName = $script:psake.build_script_file.Name }
+ Write-Host -foregroundcolor Red ($buildFileName + ":" + $_)
+
+ if ($script:psake.use_exit_on_error)
+ {
+ exit(1)
+ }
+ else
+ {
+ $script:psake.build_success = $false
+ }
+ }
+ } #Process
+
+ End
+ {
+ # Clear out any global variables
+ Cleanup-Environment
+ }
+}
+
+Export-ModuleMember -Function "Invoke-psake","Task","Properties","Include","FormatTaskName","TaskSetup","TaskTearDown","Assert"
View
250 teamcity.ps1
@@ -1,126 +1,126 @@
-function TeamCity-TestSuiteStarted([string]$name) {
- Write-Output "##teamcity[testSuiteStarted name='$name']"
-}
-
-function TeamCity-TestSuiteFinished([string]$name) {
- Write-Output "##teamcity[testSuiteFinished name='$name']"
-}
-
-function TeamCity-TestStarted([string]$name) {
- Write-Output "##teamcity[testStarted name='$name']"
-}
-
-function TeamCity-TestFinished([string]$name) {
- Write-Output "##teamcity[testFinished name='$name']"
-}
-
-function TeamCity-TestIgnored([string]$name, [string]$message='') {
- Write-Output "##teamcity[testIgnored name='$name' message='$message']"
-}
-
-function TeamCity-TestOutput([string]$name, [string]$output) {
- Write-Output "##teamcity[testStdOut name='$name' out='$output']"
-}
-
-function TeamCity-TestError([string]$name, [string]$output) {
- Write-Output "##teamcity[testStdErr name='$name' out='$output']"
-}
-
-function TeamCity-TestFailed([string]$name, [string]$message, [string]$details='', [string]$type='', [string]$expected='', [string]$actual='') {
- $output="##teamcity[testFailed ";
- if (![string]::IsNullOrEmpty($type)) {
- $output += " type='$type'"
- }
-
- $output += " name='$name' message='$message' details='$details'"
-
- if (![string]::IsNullOrEmpty($expected)) {
- $output += " expected='$expected'"
- }
- if (![string]::IsNullOrEmpty($actual)) {
- $output += " actual='$actual'"
- }
-
- $output += ']'
- Write-Output $output
-}
-
-function TeamCity-PublishArtifact([string]$path) {
- Write-Output "##teamcity[publishArtifacts '$path']"
-}
-
-function TeamCity-ReportBuildStart([string]$message) {
- Write-Output "##teamcity[progessStart '$message']"
-}
-
-function TeamCity-ReportBuildProgress([string]$message) {
- Write-Output "##teamcity[progessMessage '$message']"
-}
-
-function TeamCity-ReportBuildFinish([string]$message) {
- Write-Output "##teamcity[progessFinish '$message']"
-}
-
-function TeamCity-ReportBuildStatus([string]$status, [string]$text='') {
- Write-Output "##teamcity[buildStatus '$status' text='$text']"
-}
-
-function TeamCity-SetBuildNumber([string]$buildNumber) {
- Write-Output "##teamcity[buildNumber '$buildNumber']"
-}
-
-function TeamCity-SetBuildStatistic([string]$key, [string]$value) {
- Write-Output "##teamcity[buildStatisticValue key='$key' value='$value']"
-}
-
-function TeamCity-CreateInfoDocument([string]$buildNumber='', [boolean]$status=$true, [string[]]$statusText=$null, [System.Collections.IDictionary]$statistics=$null) {
- $doc=New-Object xml;
- $buildEl=$doc.CreateElement('build');
-
- if (![string]::IsNullOrEmpty($buildNumber)) {
- $buildEl.SetAttribute('number', $buildNumber);
- }
-
- $buildEl=$doc.AppendChild($buildEl);
-
- $statusEl=$doc.CreateElement('statusInfo');
- if ($status) {
- $statusEl.SetAttribute('status', 'SUCCESS');
- } else {
- $statusEl.SetAttribute('status', 'FAILURE');
- }
-
- if ($statusText -ne $null) {
- foreach ($text in $statusText) {
- $textEl=$doc.CreateElement('text');
- $textEl.SetAttribute('action', 'append');
- $textEl.set_InnerText($text);
- $textEl=$statusEl.AppendChild($textEl);
- }
- }
-
- $statusEl=$buildEl.AppendChild($statusEl);
-
- if ($statistics -ne $null) {
- foreach ($key in $statistics.Keys) {
- $val=$statistics.$key
- if ($val -eq $null) {
- $val=''
- }
-
- $statEl=$doc.CreateElement('statisticsValue');
- $statEl.SetAttribute('key', $key);
- $statEl.SetAttribute('value', $val.ToString());
- $statEl=$buildEl.AppendChild($statEl);
- }
- }
-
- return $doc;
-}
-
-function TeamCity-WriteInfoDocument([xml]$doc) {
- $dir=(Split-Path $buildFile)
- $path=(Join-Path $dir 'teamcity-info.xml')
-
- $doc.Save($path);
+function TeamCity-TestSuiteStarted([string]$name) {
+ Write-Output "##teamcity[testSuiteStarted name='$name']"
+}
+
+function TeamCity-TestSuiteFinished([string]$name) {
+ Write-Output "##teamcity[testSuiteFinished name='$name']"
+}
+
+function TeamCity-TestStarted([string]$name) {
+ Write-Output "##teamcity[testStarted name='$name']"
+}
+
+function TeamCity-TestFinished([string]$name) {
+ Write-Output "##teamcity[testFinished name='$name']"
+}
+
+function TeamCity-TestIgnored([string]$name, [string]$message='') {
+ Write-Output "##teamcity[testIgnored name='$name' message='$message']"
+}
+
+function TeamCity-TestOutput([string]$name, [string]$output) {
+ Write-Output "##teamcity[testStdOut name='$name' out='$output']"
+}
+
+function TeamCity-TestError([string]$name, [string]$output) {
+ Write-Output "##teamcity[testStdErr name='$name' out='$output']"
+}
+
+function TeamCity-TestFailed([string]$name, [string]$message, [string]$details='', [string]$type='', [string]$expected='', [string]$actual='') {
+ $output="##teamcity[testFailed ";
+ if (![string]::IsNullOrEmpty($type)) {
+ $output += " type='$type'"
+ }
+
+ $output += " name='$name' message='$message' details='$details'"
+
+ if (![string]::IsNullOrEmpty($expected)) {
+ $output += " expected='$expected'"
+ }
+ if (![string]::IsNullOrEmpty($actual)) {
+ $output += " actual='$actual'"
+ }
+
+ $output += ']'
+ Write-Output $output
+}
+
+function TeamCity-PublishArtifact([string]$path) {
+ Write-Output "##teamcity[publishArtifacts '$path']"
+}
+
+function TeamCity-ReportBuildStart([string]$message) {
+ Write-Output "##teamcity[progessStart '$message']"
+}
+
+function TeamCity-ReportBuildProgress([string]$message) {
+ Write-Output "##teamcity[progessMessage '$message']"
+}
+
+function TeamCity-ReportBuildFinish([string]$message) {
+ Write-Output "##teamcity[progessFinish '$message']"
+}
+
+function TeamCity-ReportBuildStatus([string]$status, [string]$text='') {
+ Write-Output "##teamcity[buildStatus '$status' text='$text']"
+}
+
+function TeamCity-SetBuildNumber([string]$buildNumber) {
+ Write-Output "##teamcity[buildNumber '$buildNumber']"
+}
+
+function TeamCity-SetBuildStatistic([string]$key, [string]$value) {
+ Write-Output "##teamcity[buildStatisticValue key='$key' value='$value']"
+}
+
+function TeamCity-CreateInfoDocument([string]$buildNumber='', [boolean]$status=$true, [string[]]$statusText=$null, [System.Collections.IDictionary]$statistics=$null) {
+ $doc=New-Object xml;
+ $buildEl=$doc.CreateElement('build');
+
+ if (![string]::IsNullOrEmpty($buildNumber)) {
+ $buildEl.SetAttribute('number', $buildNumber);
+ }
+
+ $buildEl=$doc.AppendChild($buildEl);
+
+ $statusEl=$doc.CreateElement('statusInfo');
+ if ($status) {
+ $statusEl.SetAttribute('status', 'SUCCESS');
+ } else {
+ $statusEl.SetAttribute('status', 'FAILURE');
+ }
+
+ if ($statusText -ne $null) {
+ foreach ($text in $statusText) {
+ $textEl=$doc.CreateElement('text');
+ $textEl.SetAttribute('action', 'append');
+ $textEl.set_InnerText($text);
+ $textEl=$statusEl.AppendChild($textEl);
+ }
+ }
+
+ $statusEl=$buildEl.AppendChild($statusEl);
+
+ if ($statistics -ne $null) {
+ foreach ($key in $statistics.Keys) {
+ $val=$statistics.$key
+ if ($val -eq $null) {
+ $val=''
+ }
+
+ $statEl=$doc.CreateElement('statisticsValue');
+ $statEl.SetAttribute('key', $key);
+ $statEl.SetAttribute('value', $val.ToString());
+ $statEl=$buildEl.AppendChild($statEl);
+ }
+ }
+
+ return $doc;
+}
+
+function TeamCity-WriteInfoDocument([xml]$doc) {
+ $dir=(Split-Path $buildFile)
+ $path=(Join-Path $dir 'teamcity-info.xml')
+
+ $doc.Save($path);
}
Please sign in to comment.
Something went wrong with that request. Please try again.