diff --git a/Rhino.Queues.Tests/Rhino.Queues.Tests.csproj b/Rhino.Queues.Tests/Rhino.Queues.Tests.csproj
index 6de8121..2e549a0 100644
--- a/Rhino.Queues.Tests/Rhino.Queues.Tests.csproj
+++ b/Rhino.Queues.Tests/Rhino.Queues.Tests.csproj
@@ -40,6 +40,9 @@
..\packages\Common.Logging\lib\net35\Common.Logging.dll
+
+ ..\packages\Common.Logging.Core\lib\net35\Common.Logging.Core.dll
+
..\packages\Rhino.ServiceBus.References\lib\Esent.Interop.dll
diff --git a/Rhino.Queues/Internal/QueueTransaction.cs b/Rhino.Queues/Internal/QueueTransaction.cs
index d8ace77..31f5654 100644
--- a/Rhino.Queues/Internal/QueueTransaction.cs
+++ b/Rhino.Queues/Internal/QueueTransaction.cs
@@ -4,77 +4,77 @@
namespace Rhino.Queues.Internal
{
- public class QueueTransaction : ITransaction
- {
- private readonly QueueStorage queueStorage;
- private readonly Action assertNotDisposed;
- private readonly Action onComplete;
- private readonly ILog logger = LogManager.GetCurrentClassLogger();
+ public class QueueTransaction : ITransaction
+ {
+ private readonly QueueStorage queueStorage;
+ private readonly Action assertNotDisposed;
+ private readonly Action onComplete;
+ private readonly ILog logger = LogManager.GetLogger();
- public QueueTransaction(QueueStorage queueStorage, Action onComplete, Action assertNotDisposed)
- {
- this.queueStorage = queueStorage;
- this.assertNotDisposed = assertNotDisposed;
- this.onComplete = onComplete;
- Id = Guid.NewGuid();
- }
+ public QueueTransaction(QueueStorage queueStorage, Action onComplete, Action assertNotDisposed)
+ {
+ this.queueStorage = queueStorage;
+ this.assertNotDisposed = assertNotDisposed;
+ this.onComplete = onComplete;
+ Id = Guid.NewGuid();
+ }
- public Guid Id { get; private set; }
+ public Guid Id { get; private set; }
- public void Rollback()
- {
- try
- {
- assertNotDisposed();
- logger.DebugFormat("Rolling back transaction with id: {0}", Id);
- queueStorage.Global(actions =>
- {
- actions.ReverseAllFrom(Id);
- actions.DeleteMessageToSend(Id);
- actions.Commit();
- });
- logger.DebugFormat("Rolledback transaction with id: {0}", Id);
- }
- catch (Exception e)
+ public void Rollback()
+ {
+ try
+ {
+ assertNotDisposed();
+ logger.DebugFormat("Rolling back transaction with id: {0}", Id);
+ queueStorage.Global(actions =>
+ {
+ actions.ReverseAllFrom(Id);
+ actions.DeleteMessageToSend(Id);
+ actions.Commit();
+ });
+ logger.DebugFormat("Rolledback transaction with id: {0}", Id);
+ }
+ catch (Exception e)
{
logger.Warn("Failed to rollback transaction " + Id, e);
- throw;
+ throw;
+ }
+ finally
+ {
+ onComplete();
}
- finally
- {
- onComplete();
- }
- }
+ }
- public void Commit()
- {
- try
- {
- ActualCommit();
- }
- catch (Exception e)
- {
- logger.Warn("Failed to commit transaction " + Id, e);
- throw;
- }
- finally
- {
- onComplete();
- }
- }
+ public void Commit()
+ {
+ try
+ {
+ ActualCommit();
+ }
+ catch (Exception e)
+ {
+ logger.Warn("Failed to commit transaction " + Id, e);
+ throw;
+ }
+ finally
+ {
+ onComplete();
+ }
+ }
- private void ActualCommit()
- {
- assertNotDisposed();
- logger.DebugFormat("Committing transaction with id: {0}", Id);
- queueStorage.Global(actions =>
- {
- actions.RemoveReversalsMoveCompletedMessagesAndFinishSubQueueMove(Id);
- actions.MarkAsReadyToSend(Id);
- actions.DeleteRecoveryInformation(Id);
- actions.Commit();
- });
- logger.DebugFormat("Commited transaction with id: {0}", Id);
- }
- }
+ private void ActualCommit()
+ {
+ assertNotDisposed();
+ logger.DebugFormat("Committing transaction with id: {0}", Id);
+ queueStorage.Global(actions =>
+ {
+ actions.RemoveReversalsMoveCompletedMessagesAndFinishSubQueueMove(Id);
+ actions.MarkAsReadyToSend(Id);
+ actions.DeleteRecoveryInformation(Id);
+ actions.Commit();
+ });
+ logger.DebugFormat("Commited transaction with id: {0}", Id);
+ }
+ }
}
\ No newline at end of file
diff --git a/Rhino.Queues/Rhino.Queues.csproj b/Rhino.Queues/Rhino.Queues.csproj
index cc9553a..04a46ad 100644
--- a/Rhino.Queues/Rhino.Queues.csproj
+++ b/Rhino.Queues/Rhino.Queues.csproj
@@ -44,6 +44,9 @@
..\packages\Common.Logging\lib\net35\Common.Logging.dll
+
+ ..\packages\Common.Logging.Core\lib\net35\Common.Logging.Core.dll
+
..\packages\Rhino.ServiceBus.References\lib\Esent.Interop.dll
diff --git a/default.ps1 b/default.ps1
index bef6b02..a1185f9 100644
--- a/default.ps1
+++ b/default.ps1
@@ -71,6 +71,7 @@ task Release -depends Test {
*\Rhino.Queues.dll `
*\Rhino.Queues.pdb `
*\Common.Logging.dll `
+ *\Common.Logging.Core.dll `
*\Rhino.Queues.xml `
*\Esent.Interop.dll `
*\Esent.Interop.xml `
diff --git a/psake.psm1 b/psake.psm1
index b869a8d..09d3388 100644
--- a/psake.psm1
+++ b/psake.psm1
@@ -1,5 +1,5 @@
# psake
-# Copyright (c) 2010 James Kovacs
+# Copyright (c) 2012 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
@@ -20,1277 +20,764 @@
#Requires -Version 2.0
-DATA msgs
-{
-convertfrom-stringdata @'
- error_invalid_task_name = Error: Task name should not be null or empty string
- error_task_name_does_not_exist = Error: task [{0}] does not exist
- error_circular_reference = Error: Circular reference found for task, {0}
- error_missing_action_parameter = Error: Action parameter must be specified when using PreAction or PostAction parameters
- error_corrupt_callstack = Error: CallStack was corrupt. Expected {0}, but got {1}.
- error_invalid_framework = Error: Invalid .NET Framework version, {0}, specified
- error_unknown_framework = Error: Unknown .NET Framework version, {0}, specified in {1}
- error_unknown_pointersize = Error: Unknown pointer size ({0}) returned from System.IntPtr.
- error_unknown_bitnesspart = Error: Unknown .NET Framework bitness, {0}, specified in {1}
- error_no_framework_install_dir_found = Error: No .NET Framework installation directory found at {0}
- error_bad_command = Error executing command: {0}
- error_default_task_cannot_have_action = Error: 'default' task cannot specify an action
- error_duplicate_task_name = Error: Task {0} has already been defined.
- error_invalid_include_path = Error: Unable to include {0}. File not found.
- error_build_file_not_found = Error: Could not find the build file, {0}.
- error_no_default_task = Error: default task required
- error_invalid_module_dir = "Unable to load modules from directory: {0}"
- error_invalid_module_path = "Unable to load module at path: {0}"
- error_loading_module = "Error loading module: {0}"
- postcondition_failed = Error: Postcondition failed for {0}
- precondition_was_false = Precondition was false not executing {0}
- continue_on_error = Error in Task [{0}] {1}
- build_success = Build Succeeded!
-'@
-}
-
-import-localizeddata -bindingvariable msgs -erroraction silentlycontinue
+#-- Public Module Functions --#
-#-- Private Module Functions
-function Load-Configuration
+# .ExternalHelp psake.psm1-help.xml
+function Invoke-Task
{
- $psake.config = new-object psobject -property @{
- defaultbuildfilename="default.ps1";
- tasknameformat="Executing {0}";
- exitcode="1";
- modules=(new-object psobject -property @{ autoload=$false })
- }
-
- $psakeConfigFilePath = (join-path $PSScriptRoot psake-config.ps1)
-
- if (test-path $psakeConfigFilePath)
- {
- try
- {
- . $psakeConfigFilePath
- }
- catch
- {
- throw "Error Loading Configuration from psake-config.ps1: " + $_
- }
- }
-}
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)] [string]$taskName
+ )
-function IsChildOfService
-{
- param
- (
- [int]$currentProcessID = $PID
- )
+ Assert $taskName ($msgs.error_invalid_task_name)
- $currentProcess = gwmi -Query "select * from win32_process where processid = '$currentProcessID'"
+ $taskKey = $taskName.ToLower()
- if ($currentProcess.ProcessID -eq 0) #System Idle Process
- {
- return $false
+ if ($currentContext.aliases.Contains($taskKey)) {
+ $taskName = $currentContext.aliases.$taskKey.Name
+ $taskKey = $taskName.ToLower()
}
-
- $service = Get-WmiObject -Class Win32_Service -Filter "ProcessId = '$currentProcessID'"
-
- if ($service) # We are invoked by a windows service
- {
- return $true
- }
- else
- {
- $parentProcess = gwmi -Query "select * from win32_process where processid = '$($currentProcess.ParentProcessID)'"
- return IsChildOfService $parentProcess.ProcessID
- }
-}
-
-function InNestedScope
-{
- try
- {
- $vars = get-variable -scope 1
- return $true
- }
- catch
- {
- return $false
- }
-}
-function Configure-BuildEnvironment
-{
- if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
- throw ($msgs.error_invalid_framework -f $framework)
- }
- $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 ($msgs.error_unknown_framework -f $versionPart,$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 ($msgs.error_unknown_pointersize -f $ptrSize) }
+ $currentContext = $psake.context.Peek()
+
+ Assert ($currentContext.tasks.Contains($taskKey)) ($msgs.error_task_name_does_not_exist -f $taskName)
+
+ if ($currentContext.executedTasks.Contains($taskKey)) { return }
+
+ Assert (!$currentContext.callStack.Contains($taskKey)) ($msgs.error_circular_reference -f $taskName)
+
+ $currentContext.callStack.Push($taskKey)
+
+ $task = $currentContext.tasks.$taskKey
+
+ $precondition_is_valid = & $task.Precondition
+
+ if (!$precondition_is_valid) {
+ WriteColoredOutput ($msgs.precondition_was_false -f $taskName) -foregroundcolor Cyan
+ } else {
+ if ($taskKey -ne 'default') {
+
+ if ($task.PreAction -or $task.PostAction) {
+ Assert ($task.Action -ne $null) ($msgs.error_missing_action_parameter -f $taskName)
+ }
+
+ if ($task.Action) {
+ try {
+ foreach($childTask in $task.DependsOn) {
+ Invoke-Task $childTask
+ }
+
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+ $currentContext.currentTaskName = $taskName
+
+ & $currentContext.taskSetupScriptBlock
+
+ if ($task.PreAction) {
+ & $task.PreAction
+ }
+
+ if ($currentContext.config.taskNameFormat -is [ScriptBlock]) {
+ & $currentContext.config.taskNameFormat $taskName
+ } else {
+ WriteColoredOutput ($currentContext.config.taskNameFormat -f $taskName) -foregroundcolor Cyan
+ }
+
+ foreach ($variable in $task.requiredVariables) {
+ Assert ((test-path "variable:$variable") -and ((get-variable $variable).Value -ne $null)) ($msgs.required_variable_not_set -f $variable, $taskName)
+ }
+
+ & $task.Action
+
+ if ($task.PostAction) {
+ & $task.PostAction
+ }
+
+ & $currentContext.taskTearDownScriptBlock
+ $task.Duration = $stopwatch.Elapsed
+ } catch {
+ if ($task.ContinueOnError) {
+ "-"*70
+ WriteColoredOutput ($msgs.continue_on_error -f $taskName,$_) -foregroundcolor Yellow
+ "-"*70
+ $task.Duration = $stopwatch.Elapsed
+ } else {
+ throw $_
+ }
+ }
+ } else {
+ # no action was specified but we still execute all the dependencies
+ foreach($childTask in $task.DependsOn) {
+ Invoke-Task $childTask
+ }
+ }
+ } else {
+ foreach($childTask in $task.DependsOn) {
+ Invoke-Task $childTask
+ }
}
- }
- default { throw ($msgs.error_unknown_bitnesspart -f $bitnessPart,$framework) }
- }
- }
- $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
-
- $frameworkDirs | foreach { Assert (test-path $_) ($msgs.error_no_framework_install_dir_found -f $_)}
-
- $env:path = ($frameworkDirs -join ";") + ";$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
-{
- if ($psake.context.Count -gt 0)
- {
- $currentContext = $psake.context.Peek()
- $env:path = $currentContext.originalEnvPath
- Set-Location $currentContext.originalDirectory
- $global:ErrorActionPreference = $currentContext.originalErrorActionPreference
- [void]$psake.context.Pop()
- }
-}
-
-#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
-function Resolve-Error($ErrorRecord=$Error[0])
-{
- $error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:{2}"
- $formatted_errorRecord = $ErrorRecord | format-list * -force | out-string
- $formatted_invocationInfo = $ErrorRecord.InvocationInfo | format-list * -force | out-string
- $formatted_exception = ""
- $Exception = $ErrorRecord.Exception
- for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
- {
- $formatted_exception += ("$i" * 70) + "`n"
- $formatted_exception += $Exception | format-list * -force | out-string
- $formatted_exception += "`n"
- }
-
- return $error_message -f $formatted_errorRecord,$formatted_invocationInfo,$formatted_exception
-}
-
-function Write-Documentation
-{
- $currentContext = $psake.context.Peek()
- $currentContext.tasks.Keys |
- foreach-object {
- if($_ -eq "default") { return }
-
- $task = $currentContext.tasks.$_
- new-object PsObject -property @{
- Name = $task.Name
- Description = $task.Description
- "Depends On" = $task.DependsOn -join ", "
- }
- } |
- Sort 'Name' |
- Format-Table -Auto
-}
+ Assert (& $task.Postcondition) ($msgs.postcondition_failed -f $taskName)
+ }
-function Write-TaskTimeSummary
-{
- "-"*70
- "Build Time Report"
- "-"*70
- $list = @()
- $currentContext = $psake.context.Peek()
- while ($currentContext.executedTasks.Count -gt 0)
- {
- $taskKey = $currentContext.executedTasks.Pop()
- $task = $currentContext.tasks.$taskKey
- if($taskKey -eq "default")
- {
- continue
- }
- $list += New-Object PsObject -property @{Name=$task.Name; Duration = $task.Duration}
- }
- [Array]::Reverse($list)
- $list += New-Object PsObject -property @{Name="Total:"; Duration=$stopwatch.Elapsed}
- $list | Format-Table -Auto | Out-String -Stream | ? {$_} # using "Out-String -Stream" to filter out the blank line that Format-Table prepends
-}
+ $poppedTaskKey = $currentContext.callStack.Pop()
+ Assert ($poppedTaskKey -eq $taskKey) ($msgs.error_corrupt_callstack -f $taskKey,$poppedTaskKey)
-#-- Public Module Functions
-function Invoke-Task
-{
-<#
-.SYNOPSIS
-This function allows you to call a target from another target
-
-.DESCRIPTION
-This is a function that will allow you to invoke a function from within another function
-
-.PARAMETER taskName
-The name of the task to execute
-
-.EXAMPLE
-invoke-task clean
-
-This example calls "clean" task
-
-.LINK
-Assert
-Invoke-psake
-Task
-Properties
-Include
-FormatTaskName
-TaskSetup
-TaskTearDown
-#>
- [CmdletBinding()]
- param([Parameter(Position=0,Mandatory=1)][string]$taskName)
-
- Assert $taskName ($msgs.error_invalid_task_name)
-
- $taskKey = $taskName.ToLower()
-
- $currentContext = $psake.context.Peek()
- $tasks = $currentContext.tasks
- $executedTasks = $currentContext.executedTasks
- $callStack = $currentContext.callStack
-
- Assert ($tasks.Contains($taskKey)) ($msgs.error_task_name_does_not_exist -f $taskName)
-
- if ($executedTasks.Contains($taskKey)) { return }
-
- Assert (!$callStack.Contains($taskKey)) ($msgs.error_circular_reference -f $taskName)
-
- $callStack.Push($taskKey)
-
- $task = $tasks.$taskKey
-
- $precondition_is_valid = & $task.Precondition
-
- if (!$precondition_is_valid)
- {
- $msgs.precondition_was_false -f $taskName
- }
- else
- {
- if ($taskKey -ne 'default')
- {
- $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
-
- if ($task.PreAction -or $task.PostAction)
- {
- Assert ($task.Action -ne $null) $msgs.error_missing_action_parameter
- }
-
- if ($task.Action)
- {
- try
- {
- foreach($childTask in $task.DependsOn)
- {
- Invoke-Task $childTask
- }
-
- $currentContext.currentTaskName = $taskName
-
- & $currentContext.taskSetupScriptBlock
-
- if ($task.PreAction)
- {
- & $task.PreAction
- }
-
- if ($currentContext.formatTaskName -is [ScriptBlock])
- {
- & $currentContext.formatTaskName $taskName
- }
- else
- {
- $currentContext.formatTaskName -f $taskName
- }
-
- & $task.Action
-
- if ($task.PostAction)
- {
- & $task.PostAction
- }
-
- & $currentContext.taskTearDownScriptBlock
- }
- catch
- {
- if ($task.ContinueOnError)
- {
- "-"*70
- $msgs.continue_on_error -f $taskName,$_
- "-"*70
- }
- else
- {
- throw $_
- }
- }
- } # if ($task.Action)
- else
- {
- #no Action was specified but we still execute all the dependencies
- foreach($childTask in $task.DependsOn)
- {
- Invoke-Task $childTask
- }
- }
- $stopwatch.stop()
- $task.Duration = $stopwatch.Elapsed
- } # if ($taskKey -ne 'default')
- else
- {
- foreach($childTask in $task.DependsOn)
- {
- Invoke-Task $childTask
- }
- }
-
- Assert (& $task.Postcondition) ($msgs.postcondition_failed -f $taskName)
- }
-
- $poppedTaskKey = $callStack.Pop()
- Assert ($poppedTaskKey -eq $taskKey) ($msgs.error_corrupt_callstack -f $taskKey,$poppedTaskKey)
-
- $executedTasks.Push($taskKey)
+ $currentContext.executedTasks.Push($taskKey)
}
+# .ExternalHelp psake.psm1-help.xml
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()]
-
- param(
- [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
- [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
- )
- & $cmd
- if ($lastexitcode -ne 0)
- {
- throw $errorMessage
- }
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
+ [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
+ )
+ & $cmd
+ if ($lastexitcode -ne 0) {
+ throw ("Exec: " + $errorMessage)
+ }
}
+# .ExternalHelp psake.psm1-help.xml
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()]
-
- param(
- [Parameter(Position=0,Mandatory=1)]$conditionToCheck,
- [Parameter(Position=1,Mandatory=1)]$failureMessage
- )
- if (!$conditionToCheck)
- {
- throw $failureMessage
- }
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)]$conditionToCheck,
+ [Parameter(Position=1,Mandatory=1)]$failureMessage
+ )
+ if (!$conditionToCheck) {
+ throw ("Assert: " + $failureMessage)
+ }
}
+# .ExternalHelp psake.psm1-help.xml
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
+ [CmdletBinding()]
+ 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 = {$true},
+ [Parameter(Position=5,Mandatory=0)][scriptblock]$postcondition = {$true},
+ [Parameter(Position=6,Mandatory=0)][switch]$continueOnError = $false,
+ [Parameter(Position=7,Mandatory=0)][string[]]$depends = @(),
+ [Parameter(Position=8,Mandatory=0)][string[]]$requiredVariables = @(),
+ [Parameter(Position=9,Mandatory=0)][string]$description = $null,
+ [Parameter(Position=10,Mandatory=0)][string]$alias = $null
+ )
+ if ($name -eq 'default') {
+ Assert (!$action) ($msgs.error_default_task_cannot_have_action)
+ }
-.PARAMETER ContinueOnError
-If this switch parameter is set then the task will not cause the build to fail when an exception is thrown
+ $newTask = @{
+ Name = $name
+ DependsOn = $depends
+ PreAction = $preaction
+ Action = $action
+ PostAction = $postaction
+ Precondition = $precondition
+ Postcondition = $postcondition
+ ContinueOnError = $continueOnError
+ Description = $description
+ Duration = [System.TimeSpan]::Zero
+ RequiredVariables = $requiredVariables
+ Alias = $alias
+ }
-.PARAMETER Depends
-An array of tasks that this task depends on. They will be executed before the current task is executed.
+ $taskKey = $name.ToLower()
-.PARAMETER Description
-A description of the task.
+ $currentContext = $psake.context.Peek()
-.EXAMPLE
-A sample build script is shown below:
+ Assert (!$currentContext.tasks.ContainsKey($taskKey)) ($msgs.error_duplicate_task_name -f $name)
-task default -depends Test
+ $currentContext.tasks.$taskKey = $newTask
-task Test -depends Compile, Clean {
- "This is a test"
-}
+ if($alias)
+ {
+ $aliasKey = $alias.ToLower()
-task Compile -depends Clean {
- "Compile"
-}
+ Assert (!$currentContext.aliases.ContainsKey($aliasKey)) ($msgs.error_duplicate_alias_name -f $alias)
-task Clean {
- "Clean"
+ $currentContext.aliases.$aliasKey = $newTask
+ }
}
-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
+# .ExternalHelp psake.psm1-help.xml
+function Properties {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][scriptblock]$properties
+ )
+ $psake.context.Peek().properties += $properties
}
-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()]
-
- 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 = {$true},
-
- [Parameter(Position=5,Mandatory=0)]
- [scriptblock]$postcondition = {$true},
-
- [Parameter(Position=6,Mandatory=0)]
- [switch]$continueOnError = $false,
-
- [Parameter(Position=7,Mandatory=0)]
- [string[]]$depends = @(),
-
- [Parameter(Position=8,Mandatory=0)]
- [string]$description = $null
+# .ExternalHelp psake.psm1-help.xml
+function Include {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][string]$fileNamePathToInclude
)
-
- if ($name -eq 'default')
- {
- Assert (!$action) ($msgs.error_default_task_cannot_have_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()
-
- $currentContext = $psake.context.Peek()
-
- Assert (!$currentContext.tasks.ContainsKey($taskKey)) ($msgs.error_duplicate_task_name -f $name)
-
- $currentContext.tasks.$taskKey = $newTask
+ Assert (test-path $fileNamePathToInclude -pathType Leaf) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
+ $psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
}
-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"
+# .ExternalHelp psake.psm1-help.xml
+function FormatTaskName {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)]$format
+ )
+ $psake.context.Peek().config.taskNameFormat = $format
}
-Task default -depends Test
-
-Task Test -depends Compile, Clean {
+# .ExternalHelp psake.psm1-help.xml
+function TaskSetup {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][scriptblock]$setup
+ )
+ $psake.context.Peek().taskSetupScriptBlock = $setup
}
-Task Compile -depends Clean {
+# .ExternalHelp psake.psm1-help.xml
+function TaskTearDown {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][scriptblock]$teardown
+ )
+ $psake.context.Peek().taskTearDownScriptBlock = $teardown
}
-Task Clean {
-}
+# .ExternalHelp psake.psm1-help.xml
+function Framework {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position=0,Mandatory=1)][string]$framework
+ )
+ $psake.context.Peek().config.framework = $framework
+}
+
+# .ExternalHelp psake.psm1-help.xml
+function Invoke-psake {
+ [CmdletBinding()]
+ param(
+ [Parameter(Position = 0, Mandatory = 0)][string] $buildFile,
+ [Parameter(Position = 1, Mandatory = 0)][string[]] $taskList = @(),
+ [Parameter(Position = 2, Mandatory = 0)][string] $framework,
+ [Parameter(Position = 3, Mandatory = 0)][switch] $docs = $false,
+ [Parameter(Position = 4, Mandatory = 0)][hashtable] $parameters = @{},
+ [Parameter(Position = 5, Mandatory = 0)][hashtable] $properties = @{},
+ [Parameter(Position = 6, Mandatory = 0)][alias("init")][scriptblock] $initialization = {},
+ [Parameter(Position = 7, Mandatory = 0)][switch] $nologo = $false
+ )
+ try {
+ if (-not $nologo) {
+ "psake version {0}`nCopyright (c) 2010 James Kovacs`n" -f $psake.version
+ }
+
+ # 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 ($buildFile -and !(test-path $buildFile -pathType Leaf) -and (test-path $psake.config_default.buildFileName -pathType Leaf)) {
+ $taskList = $buildFile.Split(', ')
+ $buildFile = $psake.config_default.buildFileName
+ }
-.LINK
-Invoke-psake
-Task
-Include
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-
-.NOTES
-You can have more than 1 "Properties" function defined in the script
-#>
- [CmdletBinding()]
- param([Parameter(Position=0,Mandatory=1)][scriptblock]$properties)
- $psake.context.Peek().properties += $properties
-}
+ # Execute the build file to set up the tasks and defaults
+ Assert (test-path $buildFile -pathType Leaf) ($msgs.error_build_file_not_found -f $buildFile)
+
+ $psake.build_script_file = get-item $buildFile
+ $psake.build_script_dir = $psake.build_script_file.DirectoryName
+ $psake.build_success = $false
+
+ $psake.context.push(@{
+ "taskSetupScriptBlock" = {};
+ "taskTearDownScriptBlock" = {};
+ "executedTasks" = new-object System.Collections.Stack;
+ "callStack" = new-object System.Collections.Stack;
+ "originalEnvPath" = $env:path;
+ "originalDirectory" = get-location;
+ "originalErrorActionPreference" = $global:ErrorActionPreference;
+ "tasks" = @{};
+ "aliases" = @{};
+ "properties" = @();
+ "includes" = new-object System.Collections.Queue;
+ "config" = CreateConfigurationForNewContext $buildFile $framework
+ })
+
+ LoadConfiguration $psake.build_script_dir
+
+ LoadModules
+
+ $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
+
+ set-location $psake.build_script_dir
+
+ $frameworkOldValue = $framework
+ . $psake.build_script_file.FullName
+
+ $currentContext = $psake.context.Peek()
+
+ if ($framework -ne $frameworkOldValue) {
+ writecoloredoutput $msgs.warning_deprecated_framework_variable -foregroundcolor Yellow
+ $currentContext.config.framework = $framework
+ }
-function Include
-{
-<#
-.SYNOPSIS
-Include the functions or code of another powershell script file into the current build script's scope
+ if ($docs) {
+ WriteDocumentation
+ CleanupEnvironment
+ return
+ }
-.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.
+ ConfigureBuildEnvironment
-.PARAMETER fileNamePathToInclude
-A string containing the path and name of the powershell file to include
-Required
+ while ($currentContext.includes.Count -gt 0) {
+ $includeFilename = $currentContext.includes.Dequeue()
+ . $includeFilename
+ }
-.EXAMPLE
-A sample build script is shown below:
+ 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
+ }
+ }
-Include ".\build_utils.ps1"
+ # The initial dot (.) indicates that variables initialized/modified in the propertyBlock are available in the parent scope.
+ foreach ($propertyBlock in $currentContext.properties) {
+ . $propertyBlock
+ }
-Task default -depends Test
+ foreach ($key in $properties.keys) {
+ if (test-path "variable:\$key") {
+ set-item -path "variable:\$key" -value $properties.$key | out-null
+ }
+ }
-Task Test -depends Compile, Clean {
-}
+ # Simple dot sourcing will not work. We have to force the script block into our
+ # module's scope in order to initialize variables properly.
+ . $MyInvocation.MyCommand.Module $initialization
+
+ # Execute the list of tasks or the default task
+ if ($taskList) {
+ foreach ($task in $taskList) {
+ invoke-task $task
+ }
+ } elseif ($currentContext.tasks.default) {
+ invoke-task default
+ } else {
+ throw $msgs.error_no_default_task
+ }
-Task Compile -depends Clean {
-}
+ WriteColoredOutput ("`n" + $msgs.build_success + "`n") -foregroundcolor Green
+
+ WriteTaskTimeSummary $stopwatch.Elapsed
+
+ $psake.build_success = $true
+ } catch {
+ $currentConfig = GetCurrentConfigurationOrDefault
+ if ($currentConfig.verboseError) {
+ $error_message = "{0}: An Error Occurred. See Error Details Below: `n" -f (Get-Date)
+ $error_message += ("-" * 70) + "`n"
+ $error_message += "Error: {0}`n" -f (ResolveError $_ -Short)
+ $error_message += ("-" * 70) + "`n"
+ $error_message += ResolveError $_
+ $error_message += ("-" * 70) + "`n"
+ $error_message += "Script Variables" + "`n"
+ $error_message += ("-" * 70) + "`n"
+ $error_message += get-variable -scope script | format-table | out-string
+ } else {
+ # ($_ | Out-String) gets error messages with source information included.
+ $error_message = "Error: {0}: `n{1}" -f (Get-Date), (ResolveError $_ -Short)
+ }
-Task Clean {
-}
+ $psake.build_success = $false
+ if (!$psake.run_by_psake_build_tester) {
+ # if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
+ # so that the parent script will fail otherwise the parent script will report a successful build
+ $inNestedScope = ($psake.context.count -gt 1)
+ if ( $inNestedScope ) {
+ throw $_
+ } else {
+ WriteColoredOutput $error_message -foregroundcolor Red
+ }
-.LINK
-Invoke-psake
-Task
-Properties
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-
-.NOTES
-You can have more than 1 "Include" function defined in the script
-#>
- [CmdletBinding()]
- param([Parameter(Position=0,Mandatory=1)][string]$fileNamePathToInclude)
- Assert (test-path $fileNamePathToInclude) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
- $psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
+ }
+ } finally {
+ CleanupEnvironment
+ }
}
-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:
+#-- Private Module Functions --#
+function WriteColoredOutput {
+ param(
+ [string] $message,
+ [System.ConsoleColor] $foregroundcolor
+ )
-FormatTaskName "[Task: {0}]"
+ $currentConfig = GetCurrentConfigurationOrDefault
+ if ($currentConfig.coloredOutput -eq $true) {
+ if (($Host.UI -ne $null) -and ($Host.UI.RawUI -ne $null) -and ($Host.UI.RawUI.ForegroundColor -ne $null)) {
+ $previousColor = $Host.UI.RawUI.ForegroundColor
+ $Host.UI.RawUI.ForegroundColor = $foregroundcolor
+ }
+ }
-Task default -depends Test
+ $message
-Task Test -depends Compile, Clean {
+ if ($previousColor -ne $null) {
+ $Host.UI.RawUI.ForegroundColor = $previousColor
+ }
}
-Task Compile -depends Clean {
-}
+function LoadModules {
+ $currentConfig = $psake.context.peek().config
+ if ($currentConfig.modules) {
-Task Clean {
-}
+ $scope = $currentConfig.moduleScope
-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()]
- param([Parameter(Position=0,Mandatory=1)]$format)
- $psake.context.Peek().formatTaskName = $format
+ $global = [string]::Equals($scope, "global", [StringComparison]::CurrentCultureIgnoreCase)
+
+ $currentConfig.modules | foreach {
+ resolve-path $_ | foreach {
+ "Loading module: $_"
+ $module = import-module $_ -passthru -DisableNameChecking -global:$global
+ if (!$module) {
+ throw ($msgs.error_loading_module -f $_.Name)
+ }
+ }
+ }
+ ""
+ }
}
-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:
+function LoadConfiguration {
+ param(
+ [string] $configdir = $PSScriptRoot
+ )
-Task default -depends Test
+ $psakeConfigFilePath = (join-path $configdir "psake-config.ps1")
-Task Test -depends Compile, Clean {
+ if (test-path $psakeConfigFilePath -pathType Leaf) {
+ try {
+ $config = GetCurrentConfigurationOrDefault
+ . $psakeConfigFilePath
+ } catch {
+ throw "Error Loading Configuration from psake-config.ps1: " + $_
+ }
+ }
}
-Task Compile -depends Clean {
+function GetCurrentConfigurationOrDefault() {
+ if ($psake.context.count -gt 0) {
+ return $psake.context.peek().config
+ } else {
+ return $psake.config_default
+ }
}
-Task Clean {
-}
+function CreateConfigurationForNewContext {
+ param(
+ [string] $buildFile,
+ [string] $framework
+ )
-TaskSetup {
- "Running 'TaskSetup' for task $context.Peek().currentTaskName"
-}
+ $previousConfig = GetCurrentConfigurationOrDefault
-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()]
- param([Parameter(Position=0,Mandatory=1)][scriptblock]$setup)
- $psake.context.Peek().taskSetupScriptBlock = $setup
-}
+ $config = new-object psobject -property @{
+ buildFileName = $previousConfig.buildFileName;
+ framework = $previousConfig.framework;
+ taskNameFormat = $previousConfig.taskNameFormat;
+ verboseError = $previousConfig.verboseError;
+ coloredOutput = $previousConfig.coloredOutput;
+ modules = $previousConfig.modules;
+ moduleScope = $previousConfig.moduleScope;
+ }
-function TaskTearDown
-{
-<#
-.SYNOPSIS
-Adds a scriptblock that will be executed after each task
+ if ($framework) {
+ $config.framework = $framework;
+ }
-.DESCRIPTION
-This function will accept a scriptblock that will be executed after each
-task in the build script.
+ if ($buildFile) {
+ $config.buildFileName = $buildFile;
+ }
-.PARAMETER include
-A scriptblock to execute
-Required
+ return $config
+}
-.EXAMPLE
-A sample build script is shown below:
+function ConfigureBuildEnvironment {
+ $framework = $psake.context.peek().config.framework
+ if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
+ throw ($msgs.error_invalid_framework -f $framework)
+ }
+ $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 ($msgs.error_unknown_framework -f $versionPart, $framework)
+ }
+ }
-Task default -depends Test
+ $bitness = 'Framework'
+ if ($versionPart -ne '1.0' -and $versionPart -ne '1.1') {
+ switch ($bitnessPart) {
+ 'x86' {
+ $bitness = 'Framework'
+ }
+ 'x64' {
+ $bitness = 'Framework64'
+ }
+ { [string]::IsNullOrEmpty($_) } {
+ $ptrSize = [System.IntPtr]::Size
+ switch ($ptrSize) {
+ 4 {
+ $bitness = 'Framework'
+ }
+ 8 {
+ $bitness = 'Framework64'
+ }
+ default {
+ throw ($msgs.error_unknown_pointersize -f $ptrSize)
+ }
+ }
+ }
+ default {
+ throw ($msgs.error_unknown_bitnesspart -f $bitnessPart, $framework)
+ }
+ }
+ }
+ $frameworkDirs = $versions | foreach { "$env:windir\Microsoft.NET\$bitness\$_\" }
-Task Test -depends Compile, Clean {
-}
+ $frameworkDirs | foreach { Assert (test-path $_ -pathType Container) ($msgs.error_no_framework_install_dir_found -f $_)}
-Task Compile -depends Clean {
+ $env:path = ($frameworkDirs -join ";") + ";$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"
}
-Task Clean {
+function CleanupEnvironment {
+ if ($psake.context.Count -gt 0) {
+ $currentContext = $psake.context.Peek()
+ $env:path = $currentContext.originalEnvPath
+ Set-Location $currentContext.originalDirectory
+ $global:ErrorActionPreference = $currentContext.originalErrorActionPreference
+ [void] $psake.context.Pop()
+ }
}
-TaskTearDown {
- "Running 'TaskTearDown' for task $context.Peek().currentTaskName"
-}
+function SelectObjectWithDefault
+{
+ [CmdletBinding()]
+ param(
+ [Parameter(ValueFromPipeline=$true)]
+ [PSObject]
+ $InputObject,
+ [string]
+ $Name,
+ $Value
+ )
-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()]
- param([Parameter(Position=0,Mandatory=1)][scriptblock]$teardown)
- $psake.context.Peek().taskTearDownScriptBlock = $teardown
+ process {
+ if ($_ -eq $null) { $Value }
+ elseif ($_ | Get-Member -Name $Name) {
+ $_.$Name
+ }
+ elseif (($_ -is [Hashtable]) -and ($_.Keys -contains $Name)) {
+ $_.$Name
+ }
+ else { $Value }
+ }
}
-function Invoke-psake
+# borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
+# modified to better handle SQL errors
+function ResolveError
{
-<#
-.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'
+ [CmdletBinding()]
+ param(
+ [Parameter(ValueFromPipeline=$true)]
+ $ErrorRecord=$Error[0],
+ [Switch]
+ $Short
+ )
-Runs the 'default' task in the '.build.ps1' build script
+ process {
+ if ($_ -eq $null) { $_ = $ErrorRecord }
+ $ex = $_.Exception
+
+ if (-not $Short) {
+ $error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:`n{2}"
+ $formatted_errorRecord = $_ | format-list * -force | out-string
+ $formatted_invocationInfo = $_.InvocationInfo | format-list * -force | out-string
+ $formatted_exception = ''
+
+ $i = 0
+ while ($ex -ne $null) {
+ $i++
+ $formatted_exception += ("$i" * 70) + "`n" +
+ ($ex | format-list * -force | out-string) + "`n"
+ $ex = $ex | SelectObjectWithDefault -Name 'InnerException' -Value $null
+ }
+
+ return $error_message -f $formatted_errorRecord, $formatted_invocationInfo, $formatted_exception
+ }
-.EXAMPLE
-Invoke-psake '.\build.ps1' Tests,Package
+ $lastException = @()
+ while ($ex -ne $null) {
+ $lastMessage = $ex | SelectObjectWithDefault -Name 'Message' -Value ''
+ $lastException += ($lastMessage -replace "`n", '')
+ if ($ex -is [Data.SqlClient.SqlException]) {
+ $lastException += "(Line [$($ex.LineNumber)] " +
+ "Procedure [$($ex.Procedure)] Class [$($ex.Class)] " +
+ " Number [$($ex.Number)] State [$($ex.State)] )"
+ }
+ $ex = $ex | SelectObjectWithDefault -Name 'InnerException' -Value $null
+ }
+ $shortException = $lastException -join ' --> '
+
+ $header = $null
+ $current = $_
+ $header = (($_.InvocationInfo |
+ SelectObjectWithDefault -Name 'PositionMessage' -Value '') -replace "`n", ' '),
+ ($_ | SelectObjectWithDefault -Name 'Message' -Value ''),
+ ($_ | SelectObjectWithDefault -Name 'Exception' -Value '') |
+ ? { -not [String]::IsNullOrEmpty($_) } |
+ Select -First 1
+
+ $delimiter = ''
+ if ((-not [String]::IsNullOrEmpty($header)) -and
+ (-not [String]::IsNullOrEmpty($shortException)))
+ { $delimiter = ' [<<==>>] ' }
+
+ return "$($header)$($delimiter)Exception: $($shortException)"
+ }
+}
-Runs the 'Tests' and 'Package' tasks in the '.build.ps1' build script
+function WriteDocumentation {
+ $currentContext = $psake.context.Peek()
-.EXAMPLE
-Invoke-psake Tests
+ if ($currentContext.tasks.default) {
+ $defaultTaskDependencies = $currentContext.tasks.default.DependsOn
+ } else {
+ $defaultTaskDependencies = @()
+ }
-If you have your Tasks in the .\default.ps1. This example will run the 'Tests' tasks in the 'default.ps1' build script.
+ $currentContext.tasks.Keys | foreach-object {
+ if ($_ -eq "default") {
+ return
+ }
-.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 the build script was invoked by a windows service (directly/indirectly)
- 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.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.build_script_dir # contains the fully qualified path to the current build file
-$psake.framework_version = "" # contains the framework version # for the current build
-
-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
-build_script_dir
-build_success False
-framework_version
-
-After a build is executed the following $psake values are updated (build_script_file, build_script_dir, 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
-build_script_dir C:\Users\Jorge\Documents\Projects\psake\examples
-build_success True
-framework_version 3.5
-
-.LINK
-Task
-Include
-Properties
-FormatTaskName
-TaskSetup
-TaskTearDown
-Assert
-#>
- [CmdletBinding()]
- param(
- [Parameter(Position=0,Mandatory=0)]
- [string]$buildFile = $psake.config.defaultbuildfilename,
- [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)]
- [hashtable]$parameters = @{},
- [Parameter(Position=5, Mandatory=0)]
- [hashtable]$properties = @{}
- )
-
- try
- {
- $psake.build_success = $false
- $psake.framework_version = $framework
-
- $psake.context.push(@{
- "formatTaskName" = $psake.config.tasknameformat;
- "taskSetupScriptBlock" = {};
- "taskTearDownScriptBlock" = {};
- "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;
- })
-
- $currentContext = $psake.context.Peek()
-
- $modules = $null
-
- if ($psake.config.modules.autoload -eq $true)
- {
- if ($psake.config.modules.directory)
- {
- Assert (test-path $psake.config.modules.directory) ($msgs.error_invalid_module_dir -f $psake.config.modules.directory)
- $modules = get-item (join-path $psake.config.modules.directory *.psm1)
- }
- elseif (test-path (join-path $PSScriptRoot "modules"))
- {
- $modules = get-item (join-path (join-path $PSScriptRoot "modules") "*.psm1")
- }
- }
- else
- {
- if ($psake.config.modules.module)
- {
- $modules = $psake.config.modules.module | % { Assert (test-path $_.path) ($msgs.error_invalid_module_path -f $_.path); get-item $_.path }
- }
- }
-
- if ($modules)
- {
- $modules | % { "loading module: $_"; $module = import-module $_ -passthru; if (!$module) { throw ($msgs.error_loading_module -f $_.Name)} }
- ""
- }
-
- $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 $psake.config.defaultbuildfilename ) -and !(test-path $buildFile))
- {
- $taskList = $buildFile.Split(',')
- $buildFile = $psake.config.defaultbuildfilename
- }
-
- # Execute the build file to set up the tasks and defaults
- Assert (test-path $buildFile) ($msgs.error_build_file_not_found -f $buildFile)
-
- $psake.build_script_file = Get-Item $buildFile
- $psake.build_script_dir = $psake.build_script_file.DirectoryName
- set-location $psake.build_script_dir
- . $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 ($currentContext.includes.Count -gt 0)
- {
- $includeBlock = $currentContext.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 $currentContext.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)
- {
- foreach($task in $taskList)
- {
- invoke-task $task
- }
- }
- elseif ($currentContext.tasks.default)
- {
- invoke-task default
- }
- else
- {
- throw $msgs.error_no_default_task
- }
-
- $stopwatch.Stop()
-
- "`n" + $msgs.build_success + "`n"
-
- Write-TaskTimeSummary
-
- $psake.build_success = $true
+ $task = $currentContext.tasks.$_
+ new-object PSObject -property @{
+ Name = $task.Name;
+ Alias = $task.Alias;
+ Description = $task.Description;
+ "Depends On" = $task.DependsOn -join ", "
+ Default = if ($defaultTaskDependencies -contains $task.Name) { $true }
+ }
+ } | sort 'Name' | format-list -property Name,Alias,Description,"Depends On",Default
+}
+
+function WriteTaskTimeSummary($invokePsakeDuration) {
+ "-" * 70
+ "Build Time Report"
+ "-" * 70
+ $list = @()
+ $currentContext = $psake.context.Peek()
+ while ($currentContext.executedTasks.Count -gt 0) {
+ $taskKey = $currentContext.executedTasks.Pop()
+ $task = $currentContext.tasks.$taskKey
+ if ($taskKey -eq "default") {
+ continue
+ }
+ $list += new-object PSObject -property @{
+ Name = $task.Name;
+ Duration = $task.Duration
+ }
}
- catch
- {
- $error_message = "{0}: An Error Occurred. See Error Details Below: `n" -f (Get-Date)
- $error_message += ("-" * 70) + "`n"
- $error_message += Resolve-Error $_
- $error_message += ("-" * 70) + "`n"
- $error_message += "Script Variables" + "`n"
- $error_message += ("-" * 70) + "`n"
- $error_message += get-variable -scope script | format-table | out-string
-
- $psake.build_success = $false
-
- if (!$psake.run_by_psake_build_tester)
- {
- write-host $error_message -foregroundcolor red
-
- # Need to return a non-zero DOS exit code so that CI server's (Hudson, TeamCity, etc...) can detect a failed job
- if ( (IsChildOfService) )
- {
- exit($psake.config.exitcode)
- }
-
- #if we are running in a nested scope then we need to re-throw the exception
- if ( (InNestedScope) )
- {
- throw $_
- }
- }
+ [Array]::Reverse($list)
+ $list += new-object PSObject -property @{
+ Name = "Total:";
+ Duration = $invokePsakeDuration
}
- finally
- {
- Cleanup-Environment
- }
+ # using "out-string | where-object" to filter out the blank line that format-table prepends
+ $list | format-table -autoSize -property Name,Duration | out-string -stream | where-object { $_ }
}
-$script:psake = @{}
-$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.build_script_dir = "" # contains a string with fully-qualified path to current build script
-$psake.framework_version = "" # contains the framework version # for the current build
-$psake.run_by_psake_build_tester = $false # indicates that build is being run by psake-BuildTester
-$psake.context = new-object system.collections.stack # holds onto the current state of all variables
+DATA msgs {
+convertfrom-stringdata @'
+ error_invalid_task_name = Task name should not be null or empty string.
+ error_task_name_does_not_exist = Task {0} does not exist.
+ error_circular_reference = Circular reference found for task {0}.
+ error_missing_action_parameter = Action parameter must be specified when using PreAction or PostAction parameters for task {0}.
+ error_corrupt_callstack = Call stack was corrupt. Expected {0}, but got {1}.
+ error_invalid_framework = Invalid .NET Framework version, {0} specified.
+ error_unknown_framework = Unknown .NET Framework version, {0} specified in {1}.
+ error_unknown_pointersize = Unknown pointer size ({0}) returned from System.IntPtr.
+ error_unknown_bitnesspart = Unknown .NET Framework bitness, {0}, specified in {1}.
+ error_no_framework_install_dir_found = No .NET Framework installation directory found at {0}.
+ error_bad_command = Error executing command {0}.
+ error_default_task_cannot_have_action = 'default' task cannot specify an action.
+ error_duplicate_task_name = Task {0} has already been defined.
+ error_duplicate_alias_name = Alias {0} has already been defined.
+ error_invalid_include_path = Unable to include {0}. File not found.
+ error_build_file_not_found = Could not find the build file {0}.
+ error_no_default_task = 'default' task required.
+ error_loading_module = Error loading module {0}.
+ warning_deprecated_framework_variable = Warning: Using global variable $framework to set .NET framework version used is deprecated. Instead use Framework function or configuration file psake-config.ps1.
+ required_variable_not_set = Variable {0} must be set to run task {1}.
+ postcondition_failed = Postcondition failed for task {0}.
+ precondition_was_false = Precondition was false, not executing task {0}.
+ continue_on_error = Error in task {0}. {1}
+ build_success = Build Succeeded!
+'@
+}
-Load-Configuration
+import-localizeddata -bindingvariable msgs -erroraction silentlycontinue
-export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, assert, exec -variable psake
\ No newline at end of file
+$script:psake = @{}
+$psake.version = "4.2.0" # contains the current version of psake
+$psake.context = new-object system.collections.stack # holds onto the current state of all variables
+$psake.run_by_psake_build_tester = $false # indicates that build is being run by psake-BuildTester
+$psake.config_default = new-object psobject -property @{
+ buildFileName = "default.ps1";
+ framework = "4.0";
+ taskNameFormat = "Executing {0}";
+ verboseError = $false;
+ coloredOutput = $true;
+ modules = $null;
+} # contains default configuration, can be overriden in psake-config.ps1 in directory with psake.psm1 or in directory with current build script
+
+$psake.build_success = $false # indicates that the current build was successful
+$psake.build_script_file = $null # contains a System.IO.FileInfo for the current build script
+$psake.build_script_dir = "" # contains a string with fully-qualified path to current build script
+
+LoadConfiguration
+
+export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, framework, assert, exec -variable psake
\ No newline at end of file
diff --git a/ripple.config b/ripple.config
index 4d9683c..14acd9f 100644
--- a/ripple.config
+++ b/ripple.config
@@ -13,7 +13,8 @@
-
+
+