Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:psake/psake

  • Loading branch information...
commit 42eb994078225023ca211057d262c55f3d9bff85 2 parents 68b4902 + 62c54db
@JamesKovacs JamesKovacs authored
View
209 en-US/psake.psm1-help.xml
@@ -77,8 +77,8 @@
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false (ByValue)" position="2">
<maml:name>framework</maml:name>
<maml:description>
- <maml:para>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.0x6'</maml:para>
+ <maml:para>The version of the .NET framework you want to use during 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'</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
<dev:type>
@@ -167,19 +167,22 @@ Possible values: '1.0', '1.1', '2.0', '2.0x86', '2.0x64', '3.0', '3.0x86', '3.0x
<maml:title></maml:title>
<maml:alert>
<maml:para>---- Exceptions ----</maml:para>
- <maml:para>If there is an exception thrown during the running of a build script and the build script was invoked by a windows service then psake will execute the "exit" command (with a default value of "1") which in turn sets the PowerShell $lastexitcode variable otherwise psake will set the '$psake.build_success' variable to $true or $false depending on whether an exception was thrown.</maml:para>
+ <maml:para>If there is an exception thrown during the running of a build script psake will set the '$psake.build_success' variable to $false. To detect failue outside PowerShell (for example by build server), finish PowerShell process with non-zero exit code when '$psake.build_success' is $false. Calling psake from 'cmd.exe' with 'psake.cmd' will give you that behaviour.</maml:para>
<maml:para></maml:para>
</maml:alert>
<maml:alert>
<maml:para>---- $psake variable ----</maml:para>
<maml:para>When the psake module is loaded a variable called $psake is created which is a hashtable
-containing some variables that can be used to configure psake:
+containing some variables:
-$psake.build_success = $false # indicates that the current build was successful
-$psake.version = "4.2" # 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
+$psake.version # contains the current version of psake
+$psake.context # holds onto the current state of all variables
+$psake.run_by_psake_build_tester # indicates that build is being run by psake-BuildTester
+$psake.config_default # 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 # indicates that the current build was successful
+$psake.build_script_file # contains a System.IO.FileInfo for the current build script
+$psake.build_script_dir # contains the fully qualified path to the current build script
You should see the following when you display the contents of the $psake variable right after importing psake
@@ -188,13 +191,15 @@ PS projects:\psake> $psake
Name Value
---- -----
+run_by_psake_build_tester False
version 4.2
+build_success False
build_script_file
build_script_dir
-build_success False
-framework_version
+config_default @{framework=3.5; ...
+context {}
-After a build is executed the following $psake values are updated (build_script_file, build_script_dir, build_success, and framework_version)
+After a build is executed the following $psake values are updated: build_script_file, build_script_dir, build_success
PS projects:\psake> Invoke-psake .\examples\default.ps1
Executing task: Clean
@@ -220,11 +225,14 @@ PS projects:\psake> $psake
Name Value
---- -----
+build_script_file YOUR_PATH\examples\default.ps1
+run_by_psake_build_tester False
+build_script_dir YOUR_PATH\examples
+context {}
version 4.2
-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
+config_default @{framework=3.5; ...
+
</maml:para>
<maml:para></maml:para>
</maml:alert>
@@ -427,6 +435,10 @@ task TestProperties {
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -574,6 +586,10 @@ Build Succeeded</maml:para>
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -721,11 +737,146 @@ Build Succeeded</maml:para>
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
<command:details>
+ <command:name>Framework</command:name>
+ <maml:description>
+ <maml:para>Sets the version of the .NET framework you want to use during build.</maml:para>
+ </maml:description>
+ <maml:copyright>
+ <maml:para />
+ </maml:copyright>
+ <command:verb></command:verb>
+ <command:noun></command:noun>
+ <dev:version />
+ </command:details>
+ <maml:description>
+ <maml:para>This function will accept a string containing version of the .NET framework to use during build. 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 is '3.5*', where x86 or x64 will be detected based on the bitness of the PowerShell process.</maml:para>
+ </maml:description>
+ <command:syntax>
+ <command:syntaxItem>
+ <command:name>Framework</command:name>
+ <command:parameter require="false" variableLength="false" globbing="false" pipelineInput="false" postion="0">
+ <maml:name>framework</maml:name>
+ <command:parameterValue required="true" variableLength="false">string</command:parameterValue>
+ </command:parameter>
+ </command:syntaxItem>
+ </command:syntax>
+ <command:parameters>
+ <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false (ByValue)" position="0">
+ <maml:name>framework</maml:name>
+ <maml:description>
+ <maml:para>Version of the .NET framework to use during build.</maml:para>
+ </maml:description>
+ <command:parameterValue required="true" variableLength="false">string</command:parameterValue>
+ <dev:type>
+ <maml:name>string</maml:name>
+ <maml:uri />
+ </dev:type>
+ <dev:defaultValue></dev:defaultValue>
+ </command:parameter>
+ </command:parameters>
+ <command:inputTypes>
+ <command:inputType>
+ <dev:type>
+ <maml:name>None</maml:name>
+ <maml:uri />
+ <maml:description>
+ <maml:para />
+ </maml:description>
+ </dev:type>
+ <maml:description />
+ </command:inputType>
+ </command:inputTypes>
+ <command:returnValues>
+ <command:returnValue>
+ <dev:type>
+ <maml:name>None</maml:name>
+ <maml:uri />
+ <maml:description>
+ <maml:para></maml:para>
+ </maml:description>
+ </dev:type>
+ <maml:description />
+ </command:returnValue>
+ </command:returnValues>
+ <command:terminatingErrors />
+ <command:nonTerminatingErrors />
+ <maml:alertSet>
+ <maml:title></maml:title>
+ <maml:alert>
+ <maml:para></maml:para>
+ </maml:alert>
+ </maml:alertSet>
+ <command:examples>
+ <command:example>
+ <maml:title>-------------- EXAMPLE 1 --------------</maml:title>
+ <dev:code>
+Framework "4.0"
+
+Task default -depends Compile
+
+Task Compile -depends Clean {
+ msbuild /version
+}</dev:code>
+ <dev:remarks>
+ <maml:para>Description</maml:para>
+ <maml:para>-----------</maml:para>
+ <maml:para>The script above will output detailed version of msbuid v4</maml:para>
+ <maml:para />
+ </dev:remarks>
+ <command:commandLines>
+ <command:commandLine>
+ <command:commandText />
+ </command:commandLine>
+ </command:commandLines>
+ </command:example>
+ </command:examples>
+ <maml:relatedLinks>
+ <maml:navigationLink>
+ <maml:linkText>Task</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Include</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Properties</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Invoke-psake</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>FormatTaskName</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>TaskSetup</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>TaskTearDown</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Assert</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
+ </maml:relatedLinks>
+ </command:command>
+
+ <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
+ <command:details>
<command:name>FormatTaskName</command:name>
<maml:description>
<maml:para>This function allows you to change how psake renders the task name during a build.</maml:para>
@@ -906,6 +1057,10 @@ Task TaskC {
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -1043,6 +1198,10 @@ Task Clean {
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -1185,6 +1344,10 @@ Task Clean {
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -1485,6 +1648,10 @@ Total: 00:00:00.0782496</dev:code>
<maml:linkText>Assert</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
@@ -1657,6 +1824,10 @@ The solution is to wrap the condition in () so that PS will evaluate it first.
<maml:uri />
</maml:navigationLink>
</maml:relatedLinks>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
@@ -1800,6 +1971,10 @@ The solution is to wrap the condition in () so that PS will evaluate it first.
<maml:uri />
</maml:navigationLink>
</maml:relatedLinks>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
@@ -1930,6 +2105,10 @@ The solution is to wrap the condition in () so that PS will evaluate it first.
<maml:linkText>TaskTearDown</maml:linkText>
<maml:uri />
</maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Framework</maml:linkText>
+ <maml:uri />
+ </maml:navigationLink>
</maml:relatedLinks>
</command:command>
</helpItems>
View
51 examples/checkvariables.ps1
@@ -1,34 +1,33 @@
Properties {
- $x = 1
- $y = 2
+ $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("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'),
- ((![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:psake.context.Peek().tasks.Count -ne 0), 'psake variable: $tasks had length zero'),
- (($variable:psake.context.Peek().properties.Count -ne 0), 'psake variable: $properties had length zero'),
- (($variable:psake.context.Peek().includes.Count -eq 0), 'psake variable: $includes should have had length zero'),
- (($variable:psake.context.Peek().formatTaskNameString -ne ""), 'psake variable: $formatTaskNameString was not set correctly'),
- (($variable:psake.context.Peek().currentTaskName -eq "Verify"), 'psake variable: $currentTaskName was not set correctly')
- )
-
- foreach ($assertion in $assertions)
- {
- Assert ( $assertion[0] ) $assertion[1]
- }
+Task Verify -Description "This task verifies psake's variables" {
+
+ Assert (Test-Path 'variable:\psake') "psake variable was not exported from module"
+
+ Assert ($psake.ContainsKey("version")) "psake variable does not contain 'version'"
+ Assert ($psake.ContainsKey("context")) "psake variable does not contain 'context'"
+ Assert ($psake.ContainsKey("build_success")) "psake variable does not contain 'build_success'"
+ Assert ($psake.ContainsKey("build_script_file")) "psake variable does not contain 'build_script_file'"
+ Assert ($psake.ContainsKey("build_script_dir")) "psake variable does not contain 'build_script_dir'"
+
+ Assert (![string]::IsNullOrEmpty($psake.version)) '$psake.version was null or empty'
+ Assert ($psake.context -ne $null) '$psake.context was null'
+ Assert (!$psake.build_success) '$psake.build_success should be $false'
+ Assert ($psake.build_script_file -ne $null) '$psake.build_script_file was null'
+ Assert ($psake.build_script_file.Name -eq "checkvariables.ps1") ("psake variable: {0} was not equal to 'checkvariables.ps1'" -f $psake.build_script_file.Name)
+ Assert (![string]::IsNullOrEmpty($psake.build_script_dir)) '$psake.build_script_dir was null or empty'
+
+ Assert ($psake.context.Peek().tasks.Count -ne 0) "psake context variable 'tasks' had length zero"
+ Assert ($psake.context.Peek().properties.Count -ne 0) "psake context variable 'properties' had length zero"
+ Assert ($psake.context.Peek().includes.Count -eq 0) "psake context variable 'includes' should have had length zero"
+ Assert ($psake.context.Peek().config -ne $null) "psake context variable 'config' was null"
+
+ Assert ($psake.context.Peek().currentTaskName -eq "Verify") 'psake variable: $currentTaskName was not set correctly'
}
View
8 examples/msbuild40.ps1
@@ -0,0 +1,8 @@
+Framework "4.0"
+# Framework "4.0x64"
+
+task default -depends ShowMsBuildVersion
+
+task ShowMsBuildVersion {
+ msbuild /version
+}
View
2  examples/parameters.ps1
@@ -5,5 +5,5 @@
task default -depends TestParams
task TestParams {
- Assert ($my_property -ne $null) '$my_property should not be null'
+ Assert ($my_property -ne $null) "`$my_property should not be null. Run with -parameters @{'p1' = 'v1'; 'p2' = 'v2'}"
}
View
18 examples/preandpostcondition.ps1
@@ -0,0 +1,18 @@
+properties {
+ $runTaskA = $false
+ $taskBSucceded = $true
+}
+
+task default -depends TaskC
+
+task TaskA -precondition { $runTaskA -eq $true } {
+ "TaskA executed"
+}
+
+task TaskB -postcondition { $taskBSucceded -eq $true } {
+ "TaskB executed"
+}
+
+task TaskC -depends TaskA,TaskB {
+ "TaskC executed."
+}
View
10 examples/properties.ps1
@@ -1,13 +1,13 @@
properties {
- $x = $null
- $y = $null
- $z = $null
+ $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 ($x -ne $null) "x should not be null. Run with -properties @{'x' = '1'; 'y' = '2'}"
+ Assert ($y -ne $null) "y should not be null. Run with -properties @{'x' = '1'; 'y' = '2'}"
Assert ($z -eq $null) "z should be null"
}
View
17 examples/tasksetupandteardown.ps1
@@ -0,0 +1,17 @@
+TaskSetup {
+ "Executing task setup"
+}
+
+TaskTearDown {
+ "Executing task tear down"
+}
+
+Task default -depends TaskB
+
+Task TaskA {
+ "TaskA executed"
+}
+
+Task TaskB -depends TaskA {
+ "TaskB executed"
+}
View
9 psake-config.ps1
@@ -2,12 +2,11 @@
-------------------------------------------------------------------
Defaults
-------------------------------------------------------------------
-$config.defaultBuildFileName="default.ps1";
+$config.buildFileName="default.ps1";
$config.framework = "3.5";
$config.taskNameFormat="Executing {0}";
-$config.exitCode="1";
-$config.verboseError=$true;
-$config.coloredOutput = $false;
+$config.verboseError=$false;
+$config.coloredOutput = $true;
$config.modules=(new-object psobject -property @{ autoload=$false })
-------------------------------------------------------------------
@@ -29,4 +28,4 @@ $config.modules=(new-object psobject -property @{
(new-object psobject -property @{path="c:\module1dir\module2.ps1"})
})
}
-#>
+#>
View
4 psake.cmd
@@ -8,8 +8,8 @@ if '%1'=='?' goto usage
if '%1'=='/help' goto usage
if '%1'=='help' goto usage
-powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake.ps1' %*"
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake.ps1' %*; if ($psake.build_success -eq $false) { exit 1 }"
goto :eof
:usage
-powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake-help.ps1'"
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "& '%DIR%psake-help.ps1'"
View
47 psake.ps1
@@ -5,33 +5,32 @@
# Must match parameter definitions for psake.psm1/invoke-psake
# otherwise named parameter binding fails
param(
- [Parameter(Position=0,Mandatory=0)]
- [string]$buildFile = 'default.ps1',
- [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)]
- [System.Collections.Hashtable]$parameters = @{},
- [Parameter(Position=5, Mandatory=0)]
- [System.Collections.Hashtable]$properties = @{},
- [Parameter(Position=6, Mandatory=0)]
- [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path),
- [Parameter(Position=7, Mandatory=0)]
- [switch]$nologo = $false
+ [Parameter(Position=0,Mandatory=0)]
+ [string]$buildFile = 'default.ps1',
+ [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)]
+ [System.Collections.Hashtable]$parameters = @{},
+ [Parameter(Position=5, Mandatory=0)]
+ [System.Collections.Hashtable]$properties = @{},
+ [Parameter(Position=6, Mandatory=0)]
+ [string]$scriptPath = $(Split-Path -parent $MyInvocation.MyCommand.path),
+ [Parameter(Position=7, Mandatory=0)]
+ [switch]$nologo = $false
)
-remove-module psake -ea 'SilentlyContinue'
+# '[p]sake' is the same as 'psake' but $Error is not polluted
+remove-module [p]sake
import-module (join-path $scriptPath psake.psm1)
-if (-not(test-path $buildFile))
-{
+if (-not(test-path $buildFile)) {
$absoluteBuildFile = (join-path $scriptPath $buildFile)
- if (test-path $absoluteBuildFile)
- {
- $buildFile = $absoluteBuildFile
- }
+ if (test-path $absoluteBuildFile) {
+ $buildFile = $absoluteBuildFile
+ }
}
+
invoke-psake $buildFile $taskList $framework $docs $parameters $properties $nologo
-exit $lastexitcode
View
81 psake.psm1
@@ -20,9 +20,6 @@
#Requires -Version 2.0
-#Ensure that only one instance of the psake module is loaded
-remove-module psake -erroraction silentlycontinue
-
#-- Public Module Functions --#
# .ExternalHelp psake.psm1-help.xml
@@ -239,6 +236,15 @@ function TaskTearDown {
}
# .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(
@@ -252,13 +258,11 @@ function Invoke-psake {
)
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.
- #>
-
+ "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) -and (test-path $psake.config_default.buildFileName)) {
$taskList = $buildFile.Split(', ')
$buildFile = $psake.config_default.buildFileName
@@ -271,7 +275,6 @@ function Invoke-psake {
$psake.build_script_dir = $psake.build_script_file.DirectoryName
$psake.build_success = $false
-
$psake.context.push(@{
"taskSetupScriptBlock" = {};
"taskTearDownScriptBlock" = {};
@@ -294,8 +297,16 @@ function Invoke-psake {
set-location $psake.build_script_dir
+ $frameworkOldValue = $framework
. $psake.build_script_file.FullName
+ $currentContext = $psake.context.Peek()
+
+ if ($framework -ne $frameworkOldValue) {
+ write-coloredoutput $msgs.warning_deprecated_framework_variable -foregroundcolor Yellow
+ $currentContext.config.framework = $framework
+ }
+
if ($docs) {
Write-Documentation
Cleanup-Environment
@@ -304,8 +315,6 @@ function Invoke-psake {
Configure-BuildEnvironment
- $currentContext = $psake.context.Peek()
-
while ($currentContext.includes.Count -gt 0) {
$includeFilename = $currentContext.includes.Dequeue()
. $includeFilename
@@ -360,7 +369,8 @@ function Invoke-psake {
$error_message += ("-" * 70) + "`n"
$error_message += get-variable -scope script | format-table | out-string
} else {
- $error_message = "{0}: An Error Occurred: `n{1}" -f (Get-Date), $_
+ # ($_ | Out-String) gets error messages with source information included.
+ $error_message = "{0}: An Error Occurred: `n{1}" -f (Get-Date), ($_ | Out-String)
}
$psake.build_success = $false
@@ -374,12 +384,7 @@ function Invoke-psake {
} else {
Write-ColoredOutput $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)) {
- $host.SetShouldExit($currentConfig.exitCode)
- exit($currentConfig.exitCode)
- }
+
}
} finally {
Cleanup-Environment
@@ -468,7 +473,7 @@ function Get-CurrentConfigurationOrDefault() {
function Create-ConfigurationForNewContext {
param(
- [string] $buildFileName,
+ [string] $buildFile,
[string] $framework
)
@@ -478,7 +483,6 @@ function Create-ConfigurationForNewContext {
buildFileName = $previousConfig.buildFileName;
framework = $previousConfig.framework;
taskNameFormat = $previousConfig.taskNameFormat;
- exitCode = $previousConfig.exitCode;
verboseError = $previousConfig.verboseError;
coloredOutput = $previousConfig.coloredOutput;
modules = $previousConfig.modules
@@ -495,29 +499,6 @@ function Create-ConfigurationForNewContext {
return $config
}
-function IsChildOfService {
- param(
- [int] $currentProcessID = $PID
- )
-
- $currentProcess = gwmi -Query "select * from win32_process where processid = '$currentProcessID'"
-
- #System Idle Process
- if ($currentProcess.ProcessID -eq 0) {
- return $false
- }
-
- $service = Get-WmiObject -Class Win32_Service -Filter "ProcessId = '$currentProcessID'"
-
- #We are invoked by a windows service
- if ($service) {
- return $true
- } else {
- $parentProcess = gwmi -Query "select * from win32_process where processid = '$($currentProcess.ParentProcessID)'"
- return IsChildOfService $parentProcess.ProcessID
- }
-}
-
function Configure-BuildEnvironment {
$framework = $psake.context.peek().config.framework
if ($framework.Length -ne 3 -and $framework.Length -ne 6) {
@@ -684,6 +665,7 @@ convertfrom-stringdata @'
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}
+ 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
postcondition_failed = Postcondition failed for {0}
precondition_was_false = Precondition was false not executing {0}
continue_on_error = Error in Task [{0}] {1}
@@ -701,18 +683,17 @@ $psake.config_default = new-object psobject -property @{
buildFileName = "default.ps1";
framework = "3.5";
taskNameFormat = "Executing {0}";
- exitCode = "1";
verboseError = $false;
- coloredOutput = $false;
+ coloredOutput = $true;
modules = (new-object PSObject -property @{
autoload = $false
})
-} # contains default configuration, can be overriden in psake-config.ps1 in directory with psake.psm1
+} # 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 file
+$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
Load-Configuration
-export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, assert, exec -variable psake
+export-modulemember -function invoke-psake, invoke-task, task, properties, include, formattaskname, tasksetup, taskteardown, framework, assert, exec -variable psake
View
5 specs/writing_psake_variables_should_pass.ps1
@@ -25,11 +25,10 @@ task Verify -description "This task verifies psake's variables" {
$config = $psake.context.peek().config
Assert ($config) '$psake.config is $null'
- Assert ($config.buildFileName -eq $psake.build_script_file.FullName) ('$psake.context.peek().config.buildFileName not equal to "{0}"' -f $psake.build_script_file.FullName)
+ Assert ((new-object "System.IO.FileInfo" $config.buildFileName).FullName -eq $psake.build_script_file.FullName) ('$psake.context.peek().config.buildFileName not equal to "{0}"' -f $psake.build_script_file.FullName)
Assert ($config.framework -eq "3.5") '$psake.context.peek().config.framework not equal to "3.5"'
Assert ($config.taskNameFormat -eq "Executing {0}") '$psake.context.peek().config.taskNameFormat not equal to "Executing {0}"'
- Assert ($config.exitCode -eq "1") '$psake.context.peek().config.ExitCode not equal to "1"'
Assert (!$config.verboseError) '$psake.context.peek().config.verboseError should be $false'
- Assert (!$config.coloredOutput) '$psake.context.peek().config.coloredOutput should be $false'
+ Assert ($config.coloredOutput) '$psake.context.peek().config.coloredOutput should be $false'
Assert ($config.modules) '$psake.context.peek().config.modules is $null'
}
Please sign in to comment.
Something went wrong with that request. Please try again.