|
| 1 | +require 'erb' |
| 2 | + |
| 3 | +class NUnitRunner |
| 4 | + include FileTest |
| 5 | + |
| 6 | + def initialize(paths) |
| 7 | + @sourceDir = paths.fetch(:source, 'source') |
| 8 | + @resultsDir = paths.fetch(:results, 'results') |
| 9 | + @compilePlatform = paths.fetch(:platform, 'x86') |
| 10 | + @compileTarget = paths.fetch(:compilemode, 'debug') |
| 11 | + |
| 12 | + if ENV["teamcity.dotnet.nunitlauncher"] # check if we are running in TeamCity |
| 13 | + # 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 |
| 14 | + # http://blogs.jetbrains.com/teamcity/2008/07/28/unfolding-teamcity-addin-for-nunit-secrets/ |
| 15 | + # The teamcity.dotnet.nunitaddin environment variable is not available until TeamCity 4.0, so we hardcode it for now |
| 16 | + @teamCityAddinPath = ENV["teamcity.dotnet.nunitaddin"] ? ENV["teamcity.dotnet.nunitaddin"] : 'c:/TeamCity/buildAgent/plugins/dotnetPlugin/bin/JetBrains.TeamCity.NUnitAddin-NUnit' |
| 17 | + cp @teamCityAddinPath + '-2.4.7.dll', 'tools/nunit/addins' |
| 18 | + end |
| 19 | + |
| 20 | + @nunitExe = "tools/nunit/nunit-console#{(@compilePlatform.nil? ? '' : "-#{@compilePlatform}")}.exe /nothread" |
| 21 | + end |
| 22 | + |
| 23 | + def executeTests(assemblies) |
| 24 | + Dir.mkdir @resultsDir unless exists?(@resultsDir) |
| 25 | + |
| 26 | + assemblies.each do |assem| |
| 27 | + file = File.expand_path("#{@sourceDir}/#{assem}/bin/#{(@compilePlatform.nil? ? '' : "#{@compilePlatform}/")}#{@compileTarget}/#{assem}.dll") |
| 28 | + sh "#{@nunitExe} #{file}" |
| 29 | + end |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +class MSBuildRunner |
| 34 | + def self.compile(attributes) |
| 35 | + version = attributes.fetch(:clrversion, 'v3.5') |
| 36 | + compileTarget = attributes.fetch(:compilemode, 'debug') |
| 37 | + solutionFile = attributes[:solutionfile] |
| 38 | + |
| 39 | + frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', version) |
| 40 | + msbuildFile = File.join(frameworkDir, 'msbuild.exe') |
| 41 | + |
| 42 | + sh "#{msbuildFile} #{solutionFile} /maxcpucount /v:m /property:BuildInParallel=false /property:Configuration=#{compileTarget} /t:Rebuild" |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +class AspNetCompilerRunner |
| 47 | + def self.compile(attributes) |
| 48 | + |
| 49 | + webPhysDir = attributes.fetch(:webPhysDir, '') |
| 50 | + webVirDir = attributes.fetch(:webVirDir, '') |
| 51 | + |
| 52 | + frameworkDir = File.join(ENV['windir'].dup, 'Microsoft.NET', 'Framework', 'v2.0.50727') |
| 53 | + aspNetCompiler = File.join(frameworkDir, 'aspnet_compiler.exe') |
| 54 | + |
| 55 | + sh "#{aspNetCompiler} -p #{webPhysDir} -v #{webVirDir}" |
| 56 | + end |
| 57 | +end |
| 58 | + |
| 59 | +class AsmInfoBuilder |
| 60 | + attr_reader :buildnumber |
| 61 | + |
| 62 | + def initialize(baseVersion, properties) |
| 63 | + @properties = properties; |
| 64 | + |
| 65 | + @buildnumber = baseVersion + (ENV["CCNetLabel"].nil? ? '0' : ENV["CCNetLabel"].to_s) |
| 66 | + @properties['Version'] = @properties['InformationalVersion'] = buildnumber; |
| 67 | + end |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + def write(file) |
| 72 | + template = %q{ |
| 73 | +using System; |
| 74 | +using System.Reflection; |
| 75 | +using System.Runtime.InteropServices; |
| 76 | +
|
| 77 | +<% @properties.each {|k, v| %> |
| 78 | +[assembly: Assembly<%=k%>Attribute("<%=v%>")] |
| 79 | +<% } %> |
| 80 | + }.gsub(/^ /, '') |
| 81 | + |
| 82 | + erb = ERB.new(template, 0, "%<>") |
| 83 | + |
| 84 | + File.open(file, 'w') do |file| |
| 85 | + file.puts erb.result(binding) |
| 86 | + end |
| 87 | + end |
| 88 | +end |
| 89 | + |
| 90 | +class InstallUtilRunner |
| 91 | + def installServices(services, parameters) |
| 92 | + services.each do |service| |
| 93 | + params = "" |
| 94 | + parameters.each_pair {|key, value| params = params + "/" + key + "=" + value + " "} |
| 95 | + sh "tools/installutil /i #{params} #{service}" |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + def uninstallServices(services) |
| 100 | + services.each do |service| |
| 101 | + begin |
| 102 | + sh "tools/installutil /u #{service}" |
| 103 | + rescue Exception => e |
| 104 | + puts 'IGNORING ERROR: ' + e |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | +end |
| 110 | + |
| 111 | + |
| 112 | + |
0 commit comments