Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
powershell -NoProfile -ExecutionPolicy unrestricted -Command ".\Build\psake.ps1 .\Build\default.ps1
powershell -NoProfile -ExecutionPolicy unrestricted -Command ".\Build\psake.ps1 .\Build\default.ps1
22 changes: 11 additions & 11 deletions Build/Modules/IO.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ function Clean-Item {
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[string] $path
)
Process
Process
{
if(($path -ne $null) -and (test-path $path))
{
write-verbose ("Removing {0}" -f $path)
remove-item -force -recurse $path | Out-Null
}
}
}
}

Expand All @@ -27,7 +27,7 @@ function New-Directory
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[string] $path
)

mkdir $path -ErrorAction SilentlyContinue | out-null
}

Expand All @@ -42,23 +42,23 @@ function Copy-Files {
)

New-Directory $destination
#Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}

#Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}


$arguments = @($source, $destination, "*.*", "/e")

if(($excludeFiles -ne $null) -and ($excludeFiles.Length -gt 0)) {
$arguments += "/xf"
$arguments += $excludeFiles
}

if(($excludeDirectories -ne $null) -and ($excludeFiles.Length -gt 0)) {
$arguments += "/xd"
$arguments += $excludeDirectories
}

robocopy.exe $arguments | out-null

Expect-ExitCode -expectedExitCode 0,1 -formatMessage { param($taskName) "Copy was not successful" }
}
32 changes: 16 additions & 16 deletions Build/Modules/teamcity.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function TeamCity-TestStarted([string]$name) {

function TeamCity-TestFinished([string]$name, [int]$duration) {
$messageAttributes = @{name=$name; duration=$duration}

if ($duration -gt 0) {
$messageAttributes.duration=$duration
}
Expand All @@ -47,7 +47,7 @@ function TeamCity-TestFailed([string]$name, [string]$message, [string]$details='
if (![string]::IsNullOrEmpty($type)) {
$messageAttributes.type = $type
}

if (![string]::IsNullOrEmpty($expected)) {
$messageAttributes.expected=$expected
}
Expand Down Expand Up @@ -110,66 +110,66 @@ function TeamCity-SetBuildStatistic([string]$key, [string]$value) {

function TeamCity-Block([string]$name, [scriptblock]$cmd) {
TeamCity-WriteServiceMessage 'blockOpened' @{ name=$name }
& $cmd
& $cmd
TeamCity-WriteServiceMessage 'blockClosed' @{ name=$name }
}

function TeamCity-CreateInfoDocument([string]$buildNumber='', [boolean]$status=$true, [string[]]$statusText=$null, [System.Collections.IDictionary]$statistics=$null) {
$doc=New-Object xml;
$buildEl=$doc.CreateElement('build');

if (![string]::IsNullOrEmpty($buildNumber)) {
$buildEl.SetAttribute('number', $buildNumber);
}

$buildEl=$doc.AppendChild($buildEl);

$statusEl=$doc.CreateElement('statusInfo');
if ($status) {
$statusEl.SetAttribute('status', 'SUCCESS');
} else {
$statusEl.SetAttribute('status', 'FAILURE');
}

if ($statusText -ne $null) {
foreach ($text in $statusText) {
$textEl=$doc.CreateElement('text');
$textEl.SetAttribute('action', 'append');
$textEl.set_InnerText($text);
$textEl=$statusEl.AppendChild($textEl);
}
}
}

$statusEl=$buildEl.AppendChild($statusEl);

if ($statistics -ne $null) {
foreach ($key in $statistics.Keys) {
$val=$statistics.$key
if ($val -eq $null) {
$val=''
}

$statEl=$doc.CreateElement('statisticsValue');
$statEl.SetAttribute('key', $key);
$statEl.SetAttribute('value', $val.ToString());
$statEl=$buildEl.AppendChild($statEl);
}
}

return $doc;
}

function TeamCity-WriteInfoDocument([xml]$doc) {
$dir=(Split-Path $buildFile)
$path=(Join-Path $dir 'teamcity-info.xml')

$doc.Save($path);
}

function TeamCity-WriteServiceMessage([string]$messageName, $messageAttributesHashOrSingleValue) {
function escape([string]$value) {
([char[]] $value |
%{ switch ($_)
([char[]] $value |
%{ switch ($_)
{
"|" { "||" }
"'" { "|'" }
Expand All @@ -186,7 +186,7 @@ function TeamCity-WriteServiceMessage([string]$messageName, $messageAttributesHa
}

if ($messageAttributesHashOrSingleValue -is [hashtable]) {
$messageAttributesString = ($messageAttributesHashOrSingleValue.GetEnumerator() |
$messageAttributesString = ($messageAttributesHashOrSingleValue.GetEnumerator() |
%{ "{0}='{1}'" -f $_.Key, (escape $_.Value) }) -join ' '
} else {
$messageAttributesString = ("'{0}'" -f (escape $messageAttributesHashOrSingleValue))
Expand Down
51 changes: 25 additions & 26 deletions Build/default.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
properties {
$BaseDirectory = Resolve-Path ..
$ArtifactsDirectory = "$BaseDirectory\Artifacts\"
properties {
$BaseDirectory = Resolve-Path ..
$ArtifactsDirectory = "$BaseDirectory\Artifacts\"
$LibDir = "$BaseDirectory\Lib"
$defaultRulePrefix = "AV"
}

task default -depends Clean, ExtractVersionsFromGit, Compile, CompileCheatsheet, BuildHtml

task Clean {
task Clean {
if (Test-Path $ArtifactsDirectory) {
Get-ChildItem $ArtifactsDirectory | ForEach { Remove-Item $_.FullName -Recurse -Force }
}
}

task ExtractVersionsFromGit {
$json = . "$LibDir\GitVersion.exe"

$json = . "$LibDir\GitVersion.exe"

if ($LASTEXITCODE -eq 0) {
$version = (ConvertFrom-Json ($json -join "`n"));

$script:SemVer = $version.SemVer;
$script:CommitDate = ([datetime]$version.CommitDate).ToString("MMMM d, yyyy");
}
Expand Down Expand Up @@ -51,11 +51,11 @@ task Compile {
$outfile = "$ArtifactsDirectory\Guidelines\CSharpCodingGuidelines.md"

foreach ($file in $files) {
$rawContent = Get-Content $file | Out-String
$rawContent = Get-Content $file | Out-String

$rawContent = $rawContent.replace('%semver%', $script:Semver)
$rawContent = $rawContent.replace('%commitdate%', $script:CommitDate)
$rawContent = $rawContent.replace('![](/assets', '![](assets')
$rawContent = $rawContent.replace('%commitdate%', $script:CommitDate)
$rawContent = $rawContent.replace('![](/assets', '![](assets')

# Extract the title of the section from the Frontmatter block
$title = ""
Expand Down Expand Up @@ -86,19 +86,19 @@ task Compile {
if ($rule -match "---(.|\n)*title\: (.+)") {
$ruleTitle = $Matches[2].Trim()
}

# Extract the severity of the rule from the Frontmatter block
$ruleSeverity = ""
if ($rule -match "---(.|\n)*severity\: (.+)") {
$ruleSeverity = $Matches[2].Trim()
}

# Extract the id of the rule from the Frontmatter block
$ruleId = ""
if ($rule -match "---(.|\n)*rule_id\: (.+)") {
$ruleId = $Matches[2].Trim()
}

# Extract the id prefix of the rule from the Frontmatter block
$ruleIdPrefix = "{{ site.default_rule_prefix }}"
if ($rule -match "---(.|\n)*custom_prefix\: (.+)") {
Expand Down Expand Up @@ -126,7 +126,7 @@ task Compile {

Add-Content -Path $outfile $content
}

Copy-Item -Path "$BaseDirectory\Assets\css\guidelines.css" -Destination "$ArtifactsDirectory\Guidelines\style.css" -recurse -Force
Copy-Item -Path "$BaseDirectory\Assets\Images\" -Destination "$ArtifactsDirectory\Guidelines\Assets\Images" -recurse -Force
}
Expand All @@ -137,13 +137,13 @@ task CompileCheatsheet {
}

$outfile = "$ArtifactsDirectory\Cheatsheet\Cheatsheet.md"

$content = Get-Content "$BaseDirectory\_pages\Cheatsheet.md"
$content = ($content -replace '%semver%', $script:Semver)
$content = ($content -replace '%commitdate%', $script:CommitDate)
$content = ($content -replace '%commitdate%', $script:CommitDate)
$content = ($content -replace '{{ site.default_rule_prefix }}', $defaultRulePrefix)
Add-Content $outfile $content

Copy-Item -Path "$BaseDirectory\assets\css\CheatSheet.css" -Destination "$ArtifactsDirectory\Cheatsheet\style.css" -recurse -Force
Copy-Item -Path "$BaseDirectory\assets\Images" -Destination "$ArtifactsDirectory\Cheatsheet\Assets\Images" -recurse -Force
}
Expand All @@ -157,26 +157,25 @@ task BuildHtml {
Set-Location "$ArtifactsDirectory\Guidelines"

$outfile = "$ArtifactsDirectory\CSharpCodingGuidelines.htm"
if (Test-Path $outfile) {

if (Test-Path $outfile) {
Remove-Item $outfile
}
& "$LibDir\Pandoc\pandoc.exe" CSharpCodingGuidelines.md -f markdown_phpextra -s -o $outfile --self-contained

& "$LibDir\Pandoc\pandoc.exe" CSharpCodingGuidelines.md -f markdown_phpextra -s -o $outfile --self-contained

Set-Location "$ArtifactsDirectory\Cheatsheet\"

$outfile = "$ArtifactsDirectory\CSharpCodingGuidelinesCheatsheet.htm"

if (Test-Path $outfile) {
Remove-Item $outfile
}
& "$LibDir\Pandoc\pandoc.exe" Cheatsheet.md -f markdown+markdown_in_html_blocks -s -o $outfile --self-contained

& "$LibDir\Pandoc\pandoc.exe" Cheatsheet.md -f markdown+markdown_in_html_blocks -s -o $outfile --self-contained
}
finally
{
Set-Location $PreviousPwd
}

}
2 changes: 1 addition & 1 deletion Build/psake.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
rem Helper script for those who want to run psake from cmd.exe
rem Example run from cmd.exe:
rem psake "default.ps1" "BuildHelloWord" "4.0"
rem psake "default.ps1" "BuildHelloWord" "4.0"

if '%1'=='/?' goto help
if '%1'=='-help' goto help
Expand Down
6 changes: 3 additions & 3 deletions Build/psake.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Helper script for those who want to run psake without importing the module.
# Example run from PowerShell:
# .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0"
# .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0"

# Must match parameter definitions for psake.psm1/invoke-psake
# Must match parameter definitions for psake.psm1/invoke-psake
# otherwise named parameter binding fails
param(
[Parameter(Position=0,Mandatory=0)]
Expand Down Expand Up @@ -48,6 +48,6 @@ if ($buildFile -and (-not(test-path $buildFile))) {
if (test-path $absoluteBuildFile) {
$buildFile = $absoluteBuildFile
}
}
}

Invoke-psake $buildFile $taskList $framework $docs $parameters $properties $initialization $nologo $detailedDocs
2 changes: 1 addition & 1 deletion Build/psake.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Description = 'psake is a build automation tool written in PowerShell.'
FunctionsToExport = @('Invoke-psake',
'Invoke-Task',
'Get-PSakeScriptTasks',
'Get-PSakeScriptTasks',
'Task',
'Properties',
'Include',
Expand Down
Loading