forked from kszmigie/nbdn_store
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_utilities.rb
141 lines (115 loc) · 3.37 KB
/
build_utilities.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
include FileTest
class SqlRunner
def initialize(settings = Hash.new("Not found"))
@sql_tool = settings.fetch(:sql_tool,File.join(ENV['SYSTEMDRIVE'],'program files','microsoft sql server','100','tools','binn','osql.exe'))
@command_line_args = settings.fetch(:command_line_args, '-b -i')
@connection_string = settings.fetch(:connection_string,"-E")
end
def process_sql_files(files)
files.each do|file|
begin
sh "#{@sql_tool} #{@connection_string} #{@command_line_args} #{file}"
rescue
puts("Error processing sql file:#{file}")
raise
end
end
end
end
class LocalSettings
attr_reader :settings
def [](setting)
@settings[setting]
end
def each_pair
@settings.each_key do|key,value|
yield key,@settings[key]
end
end
end
class TemplateFile
attr_reader :template_file_name
attr_reader :output_file_name
def initialize(template_file_name)
@template_file_name = template_file_name
@output_file_name = template_file_name.gsub('.template','')
end
def generate(settings_dictionary)
generate_to(@output_file_name,settings_dictionary)
end
def generate_to_directory(output_directory,settings_dictionary)
generate_to(File.join(output_directory,File.basename(@output_file_name)),settings_dictionary)
end
def generate_to_directories(output_directories,settings_dictionary)
output_directories.each do |directory|
generate_to_directory(directory,settings_dictionary)
end
end
def generate_to(output_file,settings_dictionary)
File.delete?(output_file)
File.open_for_write(output_file) do|generated_file|
File.open_for_read(@template_file_name) do|template_line|
settings_dictionary.each_key do|key|
template_line = template_line.gsub("@#{key}@","#{settings_dictionary[key]}")
end
generated_file.puts(template_line)
end
end
end
def to_s()
"Template File- Template:#{@template_file_name} : Output:#{@output_file_name}"
end
end
class TemplateFileList
@template_files
def initialize(files_pattern)
@template_files = []
FileList.new(files_pattern).each do|file|
@template_files.push(TemplateFile.new(file))
end
end
def each()
@template_files.each do |file|
yield file
end
end
def generate_all_output_files(settings)
@template_files.each do |file|
file.generate(settings)
end
end
end
class MSBuildRunner
def self.compile(attributes)
version = attributes.fetch(:clrversion, 'v3.5')
compile_target = attributes.fetch(:compile_target, 'debug')
solution_file = attributes[:solution_file]
framework_dir = File.join(ENV['WINDIR'].dup, 'Microsoft.NET', 'Framework', 'v3.5')
msbuild_file = File.join(framework_dir, 'msbuild.exe')
sh "#{msbuild_file} #{solution_file} /property:Configuration=#{compile_target} /t:Rebuild"
end
end
class File
def self.open_for_read(file)
File.open(file,'r').each do|line|
yield line
end
end
def self.read_all_text(file)
contents = ''
File.open_for_read(file) do |line|
contents += line
end
end
def self.delete?(file)
File.delete(file) if File.exists?(file)
end
def self.open_for_write(file)
File.open(file,'w') do|new_file|
yield new_file
end
end
def self.base_name_without_extensions(file)
File.basename(file,'.*')
end
end