-
Notifications
You must be signed in to change notification settings - Fork 13
/
BuildUtils.rb
148 lines (113 loc) · 4.33 KB
/
BuildUtils.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
require 'erb'
class NUnitRunner
include FileTest
def initialize(paths)
@sourceDir = paths.fetch(:source, 'source')
@resultsDir = paths.fetch(:results, 'results')
@compileTarget = paths.fetch(:compilemode, 'debug')
if ENV["teamcity.dotnet.nunitlauncher"] # check if we are running in TeamCity
# We are not using the TeamCity nunit launcher. We use NUnit with the TeamCity NUnit Addin which needs tO be copied to our NUnit addins folder
# http://blogs.jetbrains.com/teamcity/2008/07/28/unfolding-teamcity-addin-for-nunit-secrets/
# The teamcity.dotnet.nunitaddin environment variable is not available until TeamCity 4.0, so we hardcode it for now
@teamCityAddinPath = ENV["teamcity.dotnet.nunitaddin"] ? ENV["teamcity.dotnet.nunitaddin"] : 'c:/TeamCity/buildAgent/plugins/dotnetPlugin/bin/JetBrains.TeamCity.NUnitAddin-NUnit'
cp @teamCityAddinPath + '-2.4.7.dll', 'tools/nunit/addins'
end
@nunitExe = 'tools/nunit/nunit-console.exe /nologo /nothread'
end
def executeTests(assemblies, additionalCommandLine='')
Dir.mkdir @resultsDir unless exists?(@resultsDir)
assemblies.each do |assem|
file = File.expand_path("#{@sourceDir}/#{assem}/bin/#{@compileTarget}/#{assem}.dll")
sh "#{@nunitExe} #{file} #{additionalCommandLine}"
end
end
end
class MSBuildRunner
def self.compile(attributes)
compileTarget = attributes.fetch(:compilemode, 'debug')
solutionFile = attributes[:solutionfile]
attributes[:projFile] = solutionFile;
attributes[:properties] = ["Configuration=#{compileTarget}"];
attributes[:extraSwitches] = ["maxcpucount:2", "v:m", "t:rebuild"]
self.runProjFile(attributes);
end
def self.runProjFile(attributes)
version = attributes.fetch(:clrversion, 'v4.0.30319')
compileTarget = attributes.fetch(:compilemode, 'debug')
projFile = attributes[:projFile]
frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', version)
msbuildFile = File.join(frameworkDir, 'msbuild.exe')
properties = attributes.fetch(:properties, [])
switchesValue = ""
properties.each do |prop|
switchesValue += " /property:#{prop}"
end
extraSwitches = attributes.fetch(:extraSwitches, [])
extraSwitches.each do |switch|
switchesValue += " /#{switch}"
end
targets = attributes.fetch(:targets, [])
targetsValue = ""
targets.each do |target|
targetsValue += " /t:#{target}"
end
sh "#{msbuildFile} #{projFile} #{targetsValue} #{switchesValue}"
end
end
class DocuRunner
def self.document(attributes)
assemblies = attributes.fetch(:assemblies, [])
output = attributes[:output]
templates = attributes[:templates]
outputArg = (output.nil?) ? '' : "--output=#{output}"
templatesArg = (templates.nil?) ? '' : "--templates=#{templates}"
sh "tools\\docu\\docu.exe #{assemblies.join(' ')} #{outputArg} #{templatesArg}" unless assemblies.empty?
end
end
class AspNetCompilerRunner
def self.compile(attributes)
webPhysDir = attributes.fetch(:webPhysDir, '')
webVirDir = attributes.fetch(:webVirDir, '')
frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', 'v4.0.30319')
aspNetCompiler = File.join(frameworkDir, 'aspnet_compiler.exe')
sh "#{aspNetCompiler} -nologo -p #{webPhysDir} -v #{webVirDir}"
end
end
class AsmInfoBuilder
def initialize(buildnumber, properties)
@properties = properties;
@properties['Version'] = @properties['InformationalVersion'] = buildnumber;
end
def write(file)
template = %q{
using System;
using System.Reflection;
using System.Runtime.InteropServices;
<% @properties.each {|k, v| %>
[assembly: Assembly<%=k%>Attribute("<%=v%>")]
<% } %>
}.gsub(/^ /, '')
erb = ERB.new(template, 0, "%<>")
File.open(file, 'w') do |file|
file.puts erb.result(binding)
end
end
end
class InstallUtilRunner
def installServices(services, parameters)
services.each do |service|
params = ""
parameters.each_pair {|key, value| params = params + "/" + key + "=" + value + " "}
sh "tools/installutil /i #{params} #{service}"
end
end
def uninstallServices(services)
services.each do |service|
begin
sh "tools/installutil /u #{service}"
rescue Exception => e
puts 'IGNORING ERROR: ' + e
end
end
end
end