Permalink
Browse files

Use psake and xUnit Runners nuget packages, fetched at build time. Bu…

…ild script loads first 3 parts of version number from VERSION.txt. Simplify build script.
  • Loading branch information...
1 parent 2e01d21 commit 1197bdff8751b9afaca16e77e3c61195147c6754 @plioi committed Mar 16, 2013
Showing with 46 additions and 3,456 deletions.
  1. +1 −0 VERSION.txt
  2. +5 −1 build.bat
  3. +25 −39 default.ps1
  4. +5 −0 src/.nuget/packages.config
  5. +6 −16 src/CommonAssemblyInfo.cs
  6. +3 −2 src/Rook.Test/Rook.Test.csproj
  7. +1 −1 src/Rook.Test/packages.config
  8. +0 −1 tools/psakev4/.gitattributes
  9. +0 −16 tools/psakev4/README.txt
  10. +0 −38 tools/psakev4/examples/checkvariables.ps1
  11. +0 −14 tools/psakev4/examples/continueonerror.ps1
  12. +0 −19 tools/psakev4/examples/default.ps1
  13. +0 −17 tools/psakev4/examples/nested.ps1
  14. +0 −1 tools/psakev4/examples/nested/nested1.ps1
  15. +0 −1 tools/psakev4/examples/nested/nested2.ps1
  16. +0 −9 tools/psakev4/examples/parameters.ps1
  17. +0 −3 tools/psakev4/examples/passingParametersString/build.Release.Version.bat
  18. +0 −22 tools/psakev4/examples/passingParametersString/parameters.ps1
  19. +0 −13 tools/psakev4/examples/preandpostaction.ps1
  20. +0 −13 tools/psakev4/examples/properties.ps1
  21. BIN tools/psakev4/images/SakeBottle.jpg
  22. +0 −4 tools/psakev4/images/SakeBottleLicense.txt
  23. BIN tools/psakev4/images/psake.pdn
  24. BIN tools/psakev4/images/psake.png
  25. +0 −59 tools/psakev4/psake-buildTester.ps1
  26. +0 −5 tools/psakev4/psake.ps1
  27. +0 −1,208 tools/psakev4/psake.psm1
  28. +0 −11 tools/psakev4/specs/bad_PreAndPostActions_should_fail.ps1
  29. +0 −3 tools/psakev4/specs/circular_dependency_in_tasks_should_fail.ps1
  30. +0 −5 tools/psakev4/specs/default_task_with_action_should_fail.ps1
  31. +0 −7 tools/psakev4/specs/dotNet4_should_pass.ps1
  32. +0 −3 tools/psakev4/specs/duplicate_tasks_should_fail.ps1
  33. +0 −7 tools/psakev4/specs/explicitly_specified_32bit_build_should_pass.ps1
  34. +0 −13 tools/psakev4/specs/failing_postcondition_should_fail.ps1
  35. +0 −5 tools/psakev4/specs/missing_task_should_fail.ps1
  36. +0 −6 tools/psakev4/specs/multiline_blocks_should_pass.ps1
  37. +0 −1 tools/psakev4/specs/nested/nested1.ps1
  38. +0 −1 tools/psakev4/specs/nested/nested2.ps1
  39. +0 −17 tools/psakev4/specs/nested_builds_should_pass.ps1
  40. +0 −10 tools/psakev4/specs/running_aspnet_compiler_under_dotNet35_should_pass.ps1
  41. +0 −19 tools/psakev4/specs/simple_properties_and_tasks_should_pass.ps1
  42. +0 −17 tools/psakev4/specs/tasksetup_should_pass.ps1
  43. +0 −13 tools/psakev4/specs/using_PreAndPostActions_should_pass.ps1
  44. +0 −4 tools/psakev4/specs/using_msbuild_should_pass.ps1
  45. +0 −9 tools/psakev4/specs/using_parameters_should_pass.ps1
  46. +0 −13 tools/psakev4/specs/using_postcondition_should_pass.ps1
  47. +0 −13 tools/psakev4/specs/using_precondition_should_pass.ps1
  48. +0 −13 tools/psakev4/specs/using_properties_should_pass.ps1
  49. +0 −33 tools/psakev4/specs/writing_psake_variables_should_pass.ps1
  50. +0 −23 tools/psakev4/tabexpansion/PsakeTabExpansion.ps1
  51. +0 −39 tools/psakev4/tabexpansion/Readme.PsakeTab.txt
  52. +0 −126 tools/psakev4/teamcity.ps1
  53. +0 −126 tools/xunit.runners.1.9.0.1566/HTML.xslt
  54. +0 −121 tools/xunit.runners.1.9.0.1566/NUnitXml.xslt
  55. BIN tools/xunit.runners.1.9.0.1566/xunit.console.clr4.exe
  56. +0 −21 tools/xunit.runners.1.9.0.1566/xunit.console.clr4.exe.config
  57. BIN tools/xunit.runners.1.9.0.1566/xunit.console.clr4.x86.exe
  58. +0 −21 tools/xunit.runners.1.9.0.1566/xunit.console.clr4.x86.exe.config
  59. BIN tools/xunit.runners.1.9.0.1566/xunit.console.exe
  60. +0 −21 tools/xunit.runners.1.9.0.1566/xunit.console.exe.config
  61. BIN tools/xunit.runners.1.9.0.1566/xunit.console.x86.exe
  62. +0 −21 tools/xunit.runners.1.9.0.1566/xunit.console.x86.exe.config
  63. BIN tools/xunit.runners.1.9.0.1566/xunit.gui.clr4.exe
  64. BIN tools/xunit.runners.1.9.0.1566/xunit.gui.clr4.x86.exe
  65. BIN tools/xunit.runners.1.9.0.1566/xunit.gui.exe
  66. BIN tools/xunit.runners.1.9.0.1566/xunit.gui.x86.exe
  67. BIN tools/xunit.runners.1.9.0.1566/xunit.runner.msbuild.dll
  68. BIN tools/xunit.runners.1.9.0.1566/xunit.runner.utility.dll
  69. +0 −1,212 tools/xunit.runners.1.9.0.1566/xunit.runner.utility.xml
View
1 VERSION.txt
@@ -0,0 +1 @@
+0.0.1
View
6 build.bat
@@ -1 +1,5 @@
-powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "& { Import-Module '.\tools\psakev4\psake.psm1'; invoke-psake -parameters @{"version"="'%1'"} ; if ($lastexitcode -ne 0) {write-host "ERROR: $lastexitcode" -fore RED; exit $lastexitcode} }"
+@echo off
+
+.\src\.nuget\nuget.exe install src\.nuget\packages.config -source "https://nuget.org/api/v2/" -RequireConsent -o "src\packages"
+
+powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\src\packages\psake.4.2.0.1\tools\psake.ps1' %*; if ($psake.build_success -eq $false) { write-host "Build Failed!" -fore RED; exit 1 } else { exit 0 }"
View
64 default.ps1
@@ -1,58 +1,44 @@
-properties {
- $projectName = "Rook"
-
- $projectConfig = "Release"
- $base_dir = resolve-path .\
- $source_dir = "$base_dir\src"
- $unittest_dir = "$base_dir\src\Rook.Test\bin\$projectConfig"
+Framework '4.0'
- $defaultVersion = "1.0.0.0"
+properties {
+ $project = "Rook"
+ $birthYear = 2007
+ $maintainers = "Patrick Lioi"
+ $description = "A .NET programming language"
+
+ $configuration = 'Release'
+ $src = resolve-path '.\src'
+ $build = if ($env:build_number -ne $NULL) { $env:build_number } else { '0' }
+ $version = [IO.File]::ReadAllText('.\VERSION.txt') + '.' + $build
}
-$framework = '4.0'
-
task default -depends Test
task Test -depends Compile {
- exec {
- & $base_dir\tools\xunit.runners.1.9.0.1566\xunit.console.clr4.exe "$unittest_dir\$projectName.Test.dll"
- }
+ $xunitRunner = join-path $src "packages\xunit.runners.1.9.1\tools\xunit.console.clr4.exe"
+ exec { & $xunitRunner $src\$project.Test\bin\$configuration\$project.Test.dll }
}
task Compile -depends CommonAssemblyInfo {
- msbuild /t:clean /v:q /nologo /p:Configuration=$projectConfig $source_dir\$projectName.sln
- msbuild /t:build /v:q /nologo /p:Configuration=$projectConfig $source_dir\$projectName.sln
+ exec { msbuild /t:clean /v:q /nologo /p:Configuration=$configuration $src\$project.sln }
+ exec { msbuild /t:build /v:q /nologo /p:Configuration=$configuration $src\$project.sln }
}
task CommonAssemblyInfo {
- if(-not $version)
- {
- $version = $defaultVersion
- }
- create-commonAssemblyInfo "$version" $projectName "$source_dir\CommonAssemblyInfo.cs"
-}
+ $date = Get-Date
+ $year = $date.Year
+ $copyrightSpan = if ($year -eq $birthYear) { $year } else { "$birthYear-$year" }
+ $copyright = "Copyright (c) $copyrightSpan $maintainers"
-function global:create-commonAssemblyInfo($version,$applicationName,$filename)
-{
-"using System;
-using System.Reflection;
+"using System.Reflection;
using System.Runtime.InteropServices;
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.4927
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
[assembly: ComVisible(false)]
+[assembly: AssemblyProduct(""$project"")]
[assembly: AssemblyVersion(""$version"")]
[assembly: AssemblyFileVersion(""$version"")]
-[assembly: AssemblyCopyright(""Copyright Patrick Lioi 2011"")]
-[assembly: AssemblyProduct(""$applicationName"")]
-[assembly: AssemblyConfiguration(""release"")]
-[assembly: AssemblyInformationalVersion(""$version"")]" | out-file $filename -encoding "ASCII"
+[assembly: AssemblyCopyright(""$copyright"")]
+[assembly: AssemblyCompany(""$maintainers"")]
+[assembly: AssemblyDescription(""$description"")]
+[assembly: AssemblyConfiguration(""$configuration"")]" | out-file "$src\CommonAssemblyInfo.cs" -encoding "ASCII"
}
View
5 src/.nuget/packages.config
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="psake" version="4.2.0.1" />
+ <package id="xunit.runners" version="1.9.1" />
+</packages>
View
22 src/CommonAssemblyInfo.cs
@@ -1,21 +1,11 @@
-using System;
using System.Reflection;
using System.Runtime.InteropServices;
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.4927
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
[assembly: ComVisible(false)]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: AssemblyCopyright("Copyright Patrick Lioi 2011")]
[assembly: AssemblyProduct("Rook")]
-[assembly: AssemblyConfiguration("release")]
-[assembly: AssemblyInformationalVersion("1.0.0.0")]
+[assembly: AssemblyVersion("0.0.1.0")]
+[assembly: AssemblyFileVersion("0.0.1.0")]
+[assembly: AssemblyCopyright("Copyright (c) 2007-2013 Patrick Lioi")]
+[assembly: AssemblyCompany("Patrick Lioi")]
+[assembly: AssemblyDescription("A .NET programming language")]
+[assembly: AssemblyConfiguration("Release")]
View
5 src/Rook.Test/Rook.Test.csproj
@@ -66,8 +66,9 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
- <Reference Include="xunit">
- <HintPath>..\packages\xunit.1.9.0.1566\lib\xunit.dll</HintPath>
+ <Reference Include="xunit, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\xunit.1.9.1\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
View
2 src/Rook.Test/packages.config
@@ -2,5 +2,5 @@
<packages>
<package id="Parsley" version="0.0.3" />
<package id="Should" version="1.1.12.0" />
- <package id="xunit" version="1.9.0.1566" />
+ <package id="xunit" version="1.9.1" targetFramework="net40" />
</packages>
View
1 tools/psakev4/.gitattributes
@@ -1 +0,0 @@
-* -crlf
View
16 tools/psakev4/README.txt
@@ -1,16 +0,0 @@
-
-How to get started.
-
-- Download and extract the project
-- Open up a PowerShell V2 console window
-- CD into the directory where you extracted the project (where the psake.psm1 file is)
-> Import-Module .\psake.psm1
-> Get-Help Invoke-psake -Full
- - this will show you help and examples of how to use psake
-
-
-> CD .\examples
-> Invoke-psake
- - This will execute the "default" task in the "default.ps1"
-> Invoke-psake .\default.ps1 Clean
- - will execute the single task in the default.ps1 script
View
38 tools/psakev4/examples/checkvariables.ps1
@@ -1,38 +0,0 @@
-Properties {
- $x = 1
- $y = 2
-}
-
-FormatTaskName "[{0}]"
-
-Task default -Depends Verify
-
-Task Verify -Description "This task verifies psake's variables" {
-
- $assertions = @(
- ((Test-Path 'variable:\psake'), "'psake' variable was not exported from module"),
- (($variable:psake.ContainsKey("build_success")), "psake variable does not contain 'build_success'"),
- (($variable:psake.ContainsKey("use_exit_on_error")), "psake variable does not contain 'use_exit_on_error'"),
- (($variable:psake.ContainsKey("log_error")), "psake variable does not contain 'log_error'"),
- (($variable:psake.ContainsKey("version")), "psake variable does not contain 'version'"),
- (($variable:psake.ContainsKey("build_script_file")), "psake variable does not contain 'build_script_file'"),
- (($variable:psake.ContainsKey("framework_version")), "psake variable does not contain 'framework_version'"),
- ((!$variable:psake.build_success), 'psake.build_success should be $false'),
- ((!$variable:psake.use_exit_on_error), 'psake.use_exit_on_error should be $false'),
- ((!$variable:psake.log_error), 'psake.log_error should be $false'),
- ((![string]::IsNullOrEmpty($variable:psake.version)), 'psake.version was null or empty'),
- (($variable:psake.build_script_file -ne $null), '$psake.build_script_file was null'),
- (($variable:psake.build_script_file.Name -eq "checkvariables.ps1"), ("psake variable: {0} was not equal to 'VerifyVariables.ps1'" -f $psake.build_script_file.Name)),
- ((![string]::IsNullOrEmpty($variable:psake.framework_version)), 'psake variable: $psake.framework_version was null or empty'),
- (($variable:context.Peek().tasks.Count -ne 0), 'psake variable: $tasks had length zero'),
- (($variable:context.Peek().properties.Count -ne 0), 'psake variable: $properties had length zero'),
- (($variable:context.Peek().includes.Count -eq 0), 'psake variable: $includes should have had length zero'),
- (($variable:context.Peek().formatTaskNameString -eq "[{0}]"), 'psake variable: $formatTaskNameString was not set correctly'),
- (($variable:context.Peek().currentTaskName -eq "Verify"), 'psake variable: $currentTaskName was not set correctly')
- )
-
- foreach ($assertion in $assertions)
- {
- Assert ( $assertion[0] ) $assertion[1]
- }
-}
View
14 tools/psakev4/examples/continueonerror.ps1
@@ -1,14 +0,0 @@
-Task default -Depends TaskA
-
-Task TaskA -Depends TaskB {
- "Task - A"
-}
-
-Task TaskB -Depends TaskC -ContinueOnError {
- "Task - B"
- throw "I failed on purpose!"
-}
-
-Task TaskC {
- "Task - C"
-}
View
19 tools/psakev4/examples/default.ps1
@@ -1,19 +0,0 @@
-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
17 tools/psakev4/examples/nested.ps1
@@ -1,17 +0,0 @@
-Properties {
- $x = 1
-}
-
-Task default -Depends RunNested1, RunNested2, CheckX
-
-Task RunNested1 {
- Invoke-psake .\nested\nested1.ps1
-}
-
-Task RunNested2 {
- Invoke-psake .\nested\nested2.ps1
-}
-
-Task CheckX{
- Assert ($x -eq 1) '$x was not 1'
-}
View
1 tools/psakev4/examples/nested/nested1.ps1
@@ -1 +0,0 @@
-Properties {
View
1 tools/psakev4/examples/nested/nested2.ps1
@@ -1 +0,0 @@
-Properties {
View
9 tools/psakev4/examples/parameters.ps1
@@ -1,9 +0,0 @@
-properties {
- $my_property = $p1 + $p2
-}
-
-task default -depends TestParams
-
-task TestParams {
- Assert ($my_property -ne $null) '$my_property should not be null'
-}
View
3 tools/psakev4/examples/passingParametersString/build.Release.Version.bat
@@ -1,3 +0,0 @@
-powershell -Command "& {Import-Module .\..\..\psake.psm1; Invoke-psake .\parameters.ps1 -parameters @{"buildConfiguration"='Release';} }"
-
-Pause
View
22 tools/psakev4/examples/passingParametersString/parameters.ps1
@@ -1,22 +0,0 @@
-properties {
- $buildOutputPath = ".\bin\$buildConfiguration"
-}
-
-task default -depends DoRelease
-
-task DoRelease {
- Assert ("$buildConfiguration" -ne $null) "buildConfiguration should not have been null"
- Assert ("$buildConfiguration" -eq 'Release') "buildConfiguration=[$buildConfiguration] should have been 'Release'"
-
- Write-Host ""
- Write-Host ""
- Write-Host ""
- Write-Host -NoNewline "Would build output into path "
- Write-Host -NoNewline -ForegroundColor Green "$buildOutputPath"
- Write-Host -NoNewline " for build configuration "
- Write-Host -ForegroundColor Green "$buildConfiguration"
- Write-Host -NoNewline "."
- Write-Host ""
- Write-Host ""
- Write-Host ""
-}
View
13 tools/psakev4/examples/preandpostaction.ps1
@@ -1,13 +0,0 @@
-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
13 tools/psakev4/examples/properties.ps1
@@ -1,13 +0,0 @@
-properties {
- $x = $null
- $y = $null
- $z = $null
-}
-
-task default -depends TestProperties
-
-task TestProperties {
- Assert ($x -ne $null) "x should not be null"
- Assert ($y -ne $null) "y should not be null"
- Assert ($z -eq $null) "z should be null"
-}
View
BIN tools/psakev4/images/SakeBottle.jpg
Deleted file not rendered
View
4 tools/psakev4/images/SakeBottleLicense.txt
@@ -1,4 +0,0 @@
-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
BIN tools/psakev4/images/psake.pdn
Binary file not shown.
View
BIN tools/psakev4/images/psake.png
Deleted file not rendered
View
59 tools/psakev4/psake-buildTester.ps1
@@ -1,59 +0,0 @@
-function runBuilds{
- $buildFiles = ls specs\*.ps1
- $testResults = @()
-
- #Add a fake build file to the $buildFiles array so that we can verify
- #that Invoke-psake fails
- $non_existant_buildfile = "" | select Name, FullName
- $non_existant_buildfile.Name = "specifying_a_non_existant_buildfile_should_fail.ps1"
- $non_existant_buildfile.FullName = "c:\specifying_a_non_existant_buildfile_should_fail.ps1"
- $buildFiles += $non_existant_buildfile
-
- foreach($buildFile in $buildFiles) {
- $testResult = "" | select Name, Result
- $testResult.Name = $buildFile.Name
-
- Invoke-psake $buildFile.FullName -Parameters @{'p1'='v1'; 'p2'='v2'} -Properties @{'x'='1'; 'y'='2'} | Out-Null
- $testResult.Result = (getResult $buildFile.Name $psake.build_success)
- $testResults += $testResult
- }
-
- return $testResults
-}
-
-function getResult([string]$fileName, [bool]$buildSucceeded) {
- $shouldSucceed = $null
- if ($fileName.EndsWith("_should_pass.ps1")) {
- $shouldSucceed = $true
- } elseif ($fileName.EndsWith("_should_fail.ps1")) {
- $shouldSucceed = $false
- } else {
- throw "Invalid specification syntax. Specs should end with _should_pass or _should_fail. $fileName"
- }
- if ($buildSucceeded -eq $shouldSucceed) {
- "Passed"
- } else {
- "Failed"
- }
-}
-
-Remove-Module psake -ea SilentlyContinue
-
-Import-Module .\psake.psm1
-
-$results = runBuilds
-
-Remove-Module psake
-
-""
-$results | Sort 'Name' | % { if ($_.Result -eq "Passed") { write-host ($_.Name + " (Passed)") -ForeGroundColor 'GREEN'} else { write-host ($_.Name + " (Failed)") -ForeGroundColor 'RED'}}
-""
-
-$failed = $results | ? { $_.Result -eq "Failed" }
-if ($failed) {
- write-host "One or more of the build files failed" -ForeGroundColor 'RED'
- exit 1
-} else {
- write-host "All Builds Passed" -ForeGroundColor 'GREEN'
- exit 0
-}
View
5 tools/psakev4/psake.ps1
@@ -1,5 +0,0 @@
-# Helper script for those who want to run
-# psake without importing the module.
-import-module .\psake.psm1
-invoke-psake @args
-remove-module psake
View
1,208 tools/psakev4/psake.psm1
@@ -1,1208 +0,0 @@
-# psake
-# Copyright (c) 2010 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.
-
-#Requires -Version 2.0
-
-#-- Private Module Variables (Listed here for quick reference)
-[system.collections.stack]$script:context
-
-#-- Public Module Variables -- The psake hashtable variable is initialized in the invoke-psake function
-$script:psake = @{}
-$script:psake.use_exit_on_error = $false # determines if psake uses the "exit()" function when an exception occurs
-$script:psake.log_error = $false # determines if the exception details are written to a file
-$script:psake.build_success = $false # indicates that the current build was successful
-$script:psake.version = "4.00" # contains the current version of psake
-$script:psake.build_script_file = $null # contains a System.IO.FileInfo for the current build file
-$script:psake.framework_version = "" # contains the framework version # for the current build
-$script:psake.default_build_file_name = 'default.ps1'
-
-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:context.Peek().tasks.Contains($taskKey)) "task [$taskName] does not exist"
-
- if ($script:context.Peek().executedTasks.Contains($taskKey))
- {
- return
- }
-
- Assert (!$script:context.Peek().callStack.Contains($taskKey)) "Error: Circular reference found for task, $taskName"
-
- $script:context.Peek().callStack.Push($taskKey)
-
- $task = $script:context.Peek().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:context.Peek().currentTaskName = $taskName
-
- if ($script:context.Peek().taskSetupScriptBlock -ne $null)
- {
- & $script:context.Peek().taskSetupScriptBlock
- }
-
- if ($task.PreAction -ne $null)
- {
- & $task.PreAction
- }
-
- $script:context.Peek().formatTaskNameString -f $taskName
- & $task.Action
-
- if ($task.PostAction -ne $null)
- {
- & $task.PostAction
- }
-
- if ($script:context.Peek().taskTearDownScriptBlock -ne $null)
- {
- & $script:context.Peek().taskTearDownScriptBlock
- }
- }
- catch
- {
- if ($task.ContinueOnError)
- {
- "-"*70
- "Error in Task [$taskName] $_"
- "-"*70
- }
- 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:context.Peek().callStack.Pop()
-
- Assert ($poppedTaskKey -eq $taskKey) "Error: CallStack was corrupt. Expected $taskKey, but got $poppedTaskKey."
-
- $script:context.Peek().executedTasks.Push($taskKey)
-}
-
-function Configure-BuildEnvironment
-{
- if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
- throw "Error: Invalid .NET Framework version, $framework, specified"
- }
- $versionPart = $framework.Substring(0,3)
- $bitnessPart = $framework.Substring(3)
- $versions = $null
- switch ($versionPart)
- {
- '1.0' { $versions = @('v1.0.3705') }
- '1.1' { $versions = @('v1.1.4322') }
- '2.0' { $versions = @('v2.0.50727') }
- '3.0' { $versions = @('v2.0.50727') }
- '3.5' { $versions = @('v3.5','v2.0.50727') }
- '4.0' { $versions = @('v4.0.30319') }
- default { throw "Error: Unknown .NET Framework version, $versionPart, specified in $framework" }
- }
-
- $bitness = 'Framework'
- if($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
- switch ($bitnessPart)
- {
- 'x86' { $bitness = 'Framework' }
- 'x64' { $bitness = 'Framework64' }
- $null {
- $ptrSize = [System.IntPtr]::Size
- switch ($ptrSize)
- {
- 4 { $bitness = 'Framework' }
- 8 { $bitness = 'Framework64' }
- default { throw "Error: Unknown pointer size ($ptrSize) returned from System.IntPtr." }
- }
- }
- default { throw "Error: Unknown .NET Framework bitness, $bitnessPart, specified in $framework" }
- }
- }
- $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
-
- $frameworkDirs | foreach { Assert (test-path $_) "Error: No .NET Framework installation directory found at $_" }
-
- $env:path = [string]::Join(';', $frameworkDirs) + ";$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:context.Peek().originalEnvPath
- Set-Location $script:context.Peek().originalDirectory
- $global:ErrorActionPreference = $script:context.Peek().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:context.Peek().tasks.Keys)
- {
- if($key -eq "default")
- {
- continue
- }
- $task = $script:context.Peek().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:context.Peek().executedTasks.Count -gt 0)
- {
- $taskKey = $script:context.Peek().executedTasks.Pop()
- $task = $script:context.Peek().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 Exec
-{
-<#
-.SYNOPSIS
-Helper function for executing command-line programs.
-
-.DESCRIPTION
-This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured.
-If an error is detected then an exception is thrown. This function allows you to run command-line programs without
-having to explicitly check fthe $lastexitcode variable.
-
-.PARAMETER cmd
-The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
-Required
-
-.PARAMETER errorMessage
-The error message used for the exception that is thrown.
-Optional
-
-.EXAMPLE
-exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
-
-This example calls the svn command-line client.
-
-.LINK
-Assert
-Invoke-psake
-Task
-Properties
-Include
-FormatTaskName
-TaskSetup
-TaskTearDown
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
-
- param(
- [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
- [Parameter(Position=1,Mandatory=0)][string]$errorMessage = "Error executing command: " + $cmd
- )
- & $cmd
- if ($lastexitcode -ne 0)
- {
- throw $errorMessage
- }
-}
-
-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 ( ($i % 2) -eq 0 ) "%i is not an even number"
-
-This exmaple may throw an exception if $i is not an even number
-
-.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 'conditionToCheck' 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"
-#>
-[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 creates a 'task' object 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
-A sample build script is shown below:
-
-task default -depends Test
-
-task Test -depends Compile, Clean {
- "This is a test"
-}
-
-task Compile -depends Clean {
- "Compile"
-}
-
-task Clean {
- "Clean"
-}
-
-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 'Compile' task depends on the 'Clean' task.
-
-Note:
-The 'Action' parameter is defaulted to the script block following the 'Clean' task.
-
-The equivalent 'Test' task is shown below:
-
-task Test -depends Compile, Clean -Action {
- $testMessage
-}
-
-The output for the above sample build script is shown below:
-Executing task, Clean...
-Clean
-Executing task, Compile...
-Compile
-Executing task, Test...
-This is a test
-
-Build Succeeded!
-
-----------------------------------------------------------------------
-Build Time Report
-----------------------------------------------------------------------
-Name Duration
----- --------
-Clean 00:00:00.0065614
-Compile 00:00:00.0133268
-Test 00:00:00.0225964
-Total: 00:00:00.0782496
-
-.LINK
-Invoke-psake
-Properties
-Include
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-#>
-[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:context.Peek().tasks.ContainsKey($taskKey)) "Error: Task, $name, has already been defined."
-
- $script:context.Peek().tasks.$taskKey = $newTask
-}
-
-function Properties
-{
-<#
-.SYNOPSIS
-Define a scriptblock that contains assignments to variables that will be available to all tasks in the build script
-
-.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
-A sample build script is shown below:
-
-Properties {
- $build_dir = "c:\build"
- $connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
-}
-
-Task default -depends Test
-
-Task Test -depends Compile, Clean {
-}
-
-Task Compile -depends Clean {
-}
-
-Task Clean {
-}
-
-.LINK
-Invoke-psake
-Task
-Include
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-
-.NOTES
-You can have more than 1 "Properties" function defined in the script
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [Parameter(Position=0,Mandatory=1)]
- [scriptblock]$properties
- )
- $script:context.Peek().properties += $properties
-}
-
-function Include
-{
-<#
-.SYNOPSIS
-Include the functions or code of another powershell script file into the current build script's scope
-
-.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 fileNamePathToInclude
-A string containing the path and name of the powershell file to include
-Required
-
-.EXAMPLE
-A sample build script is shown below:
-
-Include ".\build_utils.ps1"
-
-Task default -depends Test
-
-Task Test -depends Compile, Clean {
-}
-
-Task Compile -depends Clean {
-}
-
-Task Clean {
-}
-
-
-.LINK
-Invoke-psake
-Task
-Properties
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-
-.NOTES
-You can have more than 1 "Include" function defined in the script
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [Parameter(Position=0,Mandatory=1)]
- [string]$fileNamePathToInclude
- )
- Assert (test-path $fileNamePathToInclude) "Error: Unable to include $fileNamePathToInclude. File not found."
- $script:context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
-}
-
-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
-A sample build script is shown below:
-
-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
-
-.LINK
-Invoke-psake
-Include
-Task
-Properties
-TaskSetup
-TaskTearDown
-Assert
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [Parameter(Position=0,Mandatory=1)]
- [string]$format
- )
- $script:context.Peek().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
-A sample build script is shown below:
-
-Task default -depends Test
-
-Task Test -depends Compile, Clean {
-}
-
-Task Compile -depends Clean {
-}
-
-Task Clean {
-}
-
-TaskSetup {
- "Running 'TaskSetup' for task $script:context.Peek().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
-
-.LINK
-Invoke-psake
-Include
-Task
-Properties
-FormatTaskName
-TaskTearDown
-Assert
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [Parameter(Position=0,Mandatory=1)]
- [scriptblock]$setup
- )
- $script:context.Peek().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
-A sample build script is shown below:
-
-Task default -depends Test
-
-Task Test -depends Compile, Clean {
-}
-
-Task Compile -depends Clean {
-}
-
-Task Clean {
-}
-
-TaskTearDown {
- "Running 'TaskTearDown' for task $script:context.Peek().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
-
-.LINK
-Invoke-psake
-Include
-Task
-Properties
-FormatTaskName
-TaskSetup
-Assert
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
- param(
- [Parameter(Position=0,Mandatory=1)]
- [scriptblock]$teardown)
- $script:context.Peek().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 TaskList
-A comma-separated list of task names to execute
-
-.PARAMETER Framework
-The version of the .NET framework you want to build. You can append x86 or x64 to force a specific framework. If not specified, x86 or x64 will be detected based on the bitness of the PowerShell process.
-Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x64', '3.5', '3.5x86', '3.5x64', '4.0', '4.0x86', '4.0x64'
-Default = '3.5'
-
-.PARAMETER Docs
-Prints a list of tasks and their descriptions
-
-.PARAMETER Parameters
-A hashtable containing parameters to be passed into the current build script. These parameters will be processed before the 'Properties' function of the script is processed. This means you can access parameters from within the 'Properties' function!
-
-.PARAMETER Properties
-A hashtable containing properties to be passed into the current build script. These properties will override matching properties that are found in the 'Properties' function of the script.
-
-.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 Tests
-
-If you have your Tasks in the .\default.ps1. This example will run the 'Tests' tasks in the 'default.ps1' build script.
-
-.EXAMPLE
-Invoke-psake 'Tests, Package'
-
-If you have your Tasks in the .\default.ps1. This example will run the 'Tests' and 'Package' tasks in the 'default.ps1' build script.
-NOTE: the quotes around the list of tasks to execute.
-
-.EXAMPLE
-Invoke-psake '.\build.ps1' -docs
-
-Prints a report of all the tasks and their descriptions and exits
-
-.EXAMPLE
-Invoke-psake .\parameters.ps1 -parameters @{"p1"="v1";"p2"="v2"}
-
-Runs the build script called 'parameters.ps1' and passes in parameters 'p1' and 'p2' with values 'v1' and 'v2'
-
-.EXAMPLE
-Invoke-psake .\properties.ps1 -properties @{"x"="1";"y"="2"}
-
-Runs the build script called 'properties.ps1' and passes in parameters 'x' and 'y' with values '1' and '2'
-
-.OUTPUTS
- If there is an exception and '$psake.use_exit_on_error' -eq $true
- then runs exit(1) to set the DOS lastexitcode variable
- otherwise set the '$psake.build_success variable' to $true or $false depending
- on whether an exception was thrown
-
-.NOTES
-When the psake module is loaded a variabled called $psake is created it is a hashtable
-containing some variables that can be used to configure psake:
-
-$psake.use_exit_on_error = $false # determines if psake uses the "exit()" function when an exception occurs
-$psake.log_error = $false # determines if the exception details are written to a file
-$psake.build_success = $false # indicates that the current build was successful
-$psake.version = "4.00" # contains the current version of psake
-$psake.build_script_file = $null # contains a System.IO.FileInfo for the current build file
-$psake.framework_version = "" # contains the framework version # for the current build
-
-$psake.use_exit_on_error and $psake.log_error are boolean variables that can be set before you call Invoke-Psake.
-
-You should see the following when you display the contents of the $psake variable right after importing psake
-
-PS projects:\psake> Import-Module .\psake.psm1
-PS projects:\psake> $psake
-
-Name Value
----- -----
-version 4.00
-build_script_file
-use_exit_on_error False
-build_success False
-log_error False
-framework_version
-
-After a build is executed the following $psake values are updated (build_script_file, build_success, and framework_version)
-
-PS projects:\psake> Invoke-psake .\examples\default.ps1
-Executing task: Clean
-Executed Clean!
-Executing task: Compile
-Executed Compile!
-Executing task: Test
-Executed Test!
-
-Build Succeeded!
-
-----------------------------------------------------------------------
-Build Time Report
-----------------------------------------------------------------------
-Name Duration
----- --------
-Clean 00:00:00.0798486
-Compile 00:00:00.0869948
-Test 00:00:00.0958225
-Total: 00:00:00.2712414
-
-PS projects:\psake> $psake
-
-Name Value
----- -----
-version 4.00
-build_script_file C:\Users\Jorge\Documents\Projects\psake\examples\default.ps1
-use_exit_on_error False
-build_success True
-log_error False
-framework_version 3.5
-
-.LINK
-Task
-Include
-Properties
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-#>
-[CmdletBinding(
- SupportsShouldProcess=$False,
- SupportsTransactions=$False,
- ConfirmImpact="None",
- DefaultParameterSetName="")]
-
- param(
- [Parameter(Position=0,Mandatory=0)]
- [string]$buildFile = $script:psake.default_build_file_name,
- [Parameter(Position=1,Mandatory=0)]
- [string[]]$taskList = @(),
- [Parameter(Position=2,Mandatory=0)]
- [string]$framework = '3.5',
- [Parameter(Position=3,Mandatory=0)]
- [switch]$docs = $false,
- [Parameter(Position=4,Mandatory=0)]
- [System.Collections.Hashtable]$parameters = @{},
- [Parameter(Position=5, Mandatory=0)]
- [System.Collections.Hashtable]$properties = @{}
- )
-
- Begin
- {
- $script:psake.build_success = $false
- $script:psake.framework_version = $framework
-
- if ($script:context -eq $null)
- {
- $script:context = New-Object System.Collections.Stack
- }
-
- $script:context.push(@{
- "formatTaskNameString" = "Executing task: {0}";
- "taskSetupScriptBlock" = $null;
- "taskTearDownScriptBlock" = $null;
- "executedTasks" = New-Object System.Collections.Stack;
- "callStack" = New-Object System.Collections.Stack;
- "originalEnvPath" = $env:path;
- "originalDirectory" = Get-Location;
- "originalErrorActionPreference" = $global:ErrorActionPreference;
- "tasks" = @{};
- "properties" = @();
- "includes" = New-Object System.Collections.Queue;
- })
- }
-
- Process
- {
- try
- {
- $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
-
- <#
- If the default.ps1 file exists and the given "buildfile" isn't found assume that the given
- $buildFile is actually the target Tasks to execute in the default.ps1 script.
- #>
- if((Test-Path $script:psake.default_build_file_name ) -and !(test-path $buildFile)) {
- $list = New-Object System.Collections.ArrayList
- foreach($t in $buildFile.Split(',')) {
- $t1 = $t.Trim()
- if($t1 -ne $null -or $t1 -ne "") {
- $list.Add($t1)
- }
- }
- $taskList = $list.ToArray()
- $buildFile = $script:psake.default_build_file_name
- }
-
- # 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:context.Peek().includes.Count -gt 0)
- {
- $includeBlock = $script:context.Peek().includes.Dequeue()
- . $includeBlock
- }
-
- foreach($key in $parameters.keys)
- {
- if (test-path "variable:\$key")
- {
- set-item -path "variable:\$key" -value $parameters.$key | out-null
- }
- else
- {
- new-item -path "variable:\$key" -value $parameters.$key | out-null
- }
- }
-
- foreach($propertyBlock in $script:context.Peek().properties)
- {
- . $propertyBlock
- }
-
- foreach($key in $properties.keys)
- {
- if (test-path "variable:\$key")
- {
- set-item -path "variable:\$key" -value $properties.$key | out-null
- }
- }
-
- # Execute the list of tasks or the default task
- if($taskList.Length -ne 0)
- {
- foreach($task in $taskList)
- {
- ExecuteTask $task
- }
- }
- elseif ($script:context.Peek().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 and script variables to error 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
- "-" * 70 >> $errorLogFile
- "Script Variables" >> $errorLogFile
- "-" * 70 >> $errorLogFile
- Get-Variable -scope script >> $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
- [void]$script:context.Pop()
- }
-}
-
-Export-ModuleMember -Function "Invoke-psake","Task","Properties","Include","FormatTaskName","TaskSetup","TaskTearDown","Assert","Exec"
View
11 tools/psakev4/specs/bad_PreAndPostActions_should_fail.ps1
@@ -1,11 +0,0 @@
-task default -depends Test
-
-task Test -depends Compile, Clean -PreAction {"Pre-Test"} -PostAction {"Post-Test"}
-
-task Compile -depends Clean {
- "Compile"
-}
-
-task Clean {
- "Clean"
-}
View
3 tools/psakev4/specs/circular_dependency_in_tasks_should_fail.ps1
@@ -1,3 +0,0 @@
-task default -depends A
-task A -depends B { }
-task B -depends A { }
View
5 tools/psakev4/specs/default_task_with_action_should_fail.ps1
@@ -1,5 +0,0 @@
-task default {
- "Starting to do stuff..."
- "Adding stuff... 1 + 1 =" + (1+1)
- "Stuff done!"
-}
View
7 tools/psakev4/specs/dotNet4_should_pass.ps1
@@ -1,7 +0,0 @@
-$framework = '4.0'
-
-task default -depends MsBuild
-
-task MsBuild {
- exec { msbuild /version }
-}
View
3 tools/psakev4/specs/duplicate_tasks_should_fail.ps1
@@ -1,3 +0,0 @@
-task A {}
-task B {}
-task A {}
View
7 tools/psakev4/specs/explicitly_specified_32bit_build_should_pass.ps1
@@ -1,7 +0,0 @@
-$framework = '3.5x86'
-
-task default -depends MsBuild
-
-task MsBuild {
- exec { msbuild /version }
-}
View
13 tools/psakev4/specs/failing_postcondition_should_fail.ps1
@@ -1,13 +0,0 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -postcondition { return $false } {
- "TaskB"
-}
-
-task C {
- "TaskC"
-}
View
5 tools/psakev4/specs/missing_task_should_fail.ps1
@@ -1,5 +0,0 @@
-task default -depends Test
-
-task Test -depends Compile, Clean {
- Write-Host "Running PSake"
-}
View
6 tools/psakev4/specs/multiline_blocks_should_pass.ps1
@@ -1,6 +0,0 @@
-task default -depends doStuff
-task doStuff {
- "Starting to do stuff..."
- "Adding stuff... 1 + 1 =" + (1+1)
- "Stuff done!"
-}
View
1 tools/psakev4/specs/nested/nested1.ps1
@@ -1 +0,0 @@
-Properties {
View
1 tools/psakev4/specs/nested/nested2.ps1
@@ -1 +0,0 @@
-Properties {
View
17 tools/psakev4/specs/nested_builds_should_pass.ps1
@@ -1,17 +0,0 @@
-Properties {
- $x = 1
-}
-
-Task default -Depends RunNested1, RunNested2, CheckX
-
-Task RunNested1 {
- Invoke-psake .\nested\nested1.ps1
-}
-
-Task RunNested2 {
- Invoke-psake .\nested\nested2.ps1
-}
-
-Task CheckX{
- Assert ($x -eq 1) '$x was not 1'
-}
View
10 tools/psakev4/specs/running_aspnet_compiler_under_dotNet35_should_pass.ps1
@@ -1,10 +0,0 @@
-$framework = '3.5'
-
-task default -depends AspNetCompiler
-
-task AspNetCompiler {
- aspnet_compiler
- if ($LastExitCode -ne 1) {
- throw 'Error: Could not execute aspnet_compiler'
- }
-}
View
19 tools/psakev4/specs/simple_properties_and_tasks_should_pass.ps1
@@ -1,19 +0,0 @@
-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
17 tools/psakev4/specs/tasksetup_should_pass.ps1
@@ -1,17 +0,0 @@
-TaskSetup {
- "executing task setup"
-}
-
-Task default -depends Compile, Test, Deploy
-
-Task Compile {
- "Compiling"
-}
-
-Task Test -depends Compile {
- "Testing"
-}
-
-Task Deploy -depends Test {
- "Deploying"
-}
View
13 tools/psakev4/specs/using_PreAndPostActions_should_pass.ps1
@@ -1,13 +0,0 @@
-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
4 tools/psakev4/specs/using_msbuild_should_pass.ps1
@@ -1,4 +0,0 @@
-task default -depends DisplayNotice
-task DisplayNotice {
- exec { msbuild /version }
-}
View
9 tools/psakev4/specs/using_parameters_should_pass.ps1
@@ -1,9 +0,0 @@
-properties {
- $my_property = $p1 + $p2
-}
-
-task default -depends TestParams
-
-task TestParams {
- Assert ($my_property -ne $null) '$my_property should not be null'
-}
View
13 tools/psakev4/specs/using_postcondition_should_pass.ps1
@@ -1,13 +0,0 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -postcondition { return $true } {
- "TaskB"
-}
-
-task C {
- "TaskC"
-}
View
13 tools/psakev4/specs/using_precondition_should_pass.ps1
@@ -1,13 +0,0 @@
-task default -depends A,B,C
-
-task A {
- "TaskA"
-}
-
-task B -precondition { return $false } {
- "TaskB"
-}
-
-task C -precondition { return $true } {
- "TaskC"
-}
View
13 tools/psakev4/specs/using_properties_should_pass.ps1
@@ -1,13 +0,0 @@
-properties {
- $x = $null
- $y = $null
- $z = $null
-}
-
-task default -depends TestProperties
-
-task TestProperties {
- Assert ($x -ne $null) "x should not be null"
- Assert ($y -ne $null) "y should not be null"
- Assert ($z -eq $null) "z should be null"
-}
View
33 tools/psakev4/specs/writing_psake_variables_should_pass.ps1
@@ -1,33 +0,0 @@
-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 "writing_psake_variables_should_pass.ps1") ("psake variable: {0} was not equal to 'writing_psake_variables_should_pass.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
- $context.Count
- Assert ($context.Count -eq 1) 'psake variable: $context should have had a length of one (1) during script execution'
-}
View
23 tools/psakev4/tabexpansion/PsakeTabExpansion.ps1
@@ -1,23 +0,0 @@
-$global:psakeSwitches = '-docs', '-task', '-properties', '-parameters'
-
-function script:psakeSwitches($filter) {
- $psakeSwitches | where { $_ -like "$filter*" }
-}
-
-function script:psakeDocs($filter) {
- psake -docs | out-string -Stream |% { if ($_ -match "^[^ ]*") { $matches[0]} } |? { $_ -ne "Name" -and $_ -ne "----" -and $_ -like "$filter*" }
-}
-
-function PsakeTabExpansion($lastBlock) {
- switch -regex ($lastBlock) {
- '(invoke-psake|psake) .* ?\-t[^ ]* (\S*)$' {
- psakeDocs $matches[2]
- }
- '(invoke-psake|psake) .* ?(\-\S*)$' {
- psakeSwitches $matches[2]
- }
- '(invoke-psake|psake) (\S*)$' {
- ls $matches[2]*.ps1 |% { "./$_" }
- }
- }
-}
View
39 tools/psakev4/tabexpansion/Readme.PsakeTab.txt
@@ -1,39 +0,0 @@
-_________________________________________________________
-A powershell script for tab completion of psake module build commands
- - tab completion for file name: psake d<tab> -> psake .\default.ps1
- - tab completion for parameters (docs,task,parameters,properties): psake -t<tab> -> psake -task
- - tab completion for task: psake -t<tab> c -> psake -task Clean
----------------------------------------------------------
-
-_________________________________________________________
-Profile example
----------------------------------------------------------
-Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
-. ./PsakeTabExpansion.ps1
-Pop-Location
-
-if(-not (Test-Path Function:\DefaultTabExpansion)) {
- Rename-Item Function:\TabExpansion DefaultTabExpansion
-}
-
-# Set up tab expansion and include psake expansion
-function TabExpansion($line, $lastWord) {
- $lastBlock = [regex]::Split($line, '[|;]')[-1]
-
- switch -regex ($lastBlock) {
- # Execute psake tab completion for all psake-related commands
- '(Invoke-psake|psake) (.*)' { PsakeTabExpansion $lastBlock }
- # Fall back on existing tab expansion
- default { DefaultTabExpansion $line $lastWord }
- }
-}
----------------------------------------------------------
-
-_________________________________________________________
-Based on work by:
-
- - Keith Dahlby, http://solutionizing.net/
- - Mark Embling, http://www.markembling.info/
- - Jeremy Skinner, http://www.jeremyskinner.co.uk/
- - Dusty Candland, http://www.candland.net/blog
----------------------------------------------------------
View
126 tools/psakev4/teamcity.ps1
@@ -1,126 +0,0 @@
-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);
- }
- }
-