rakedotnet 1.1.51
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/TODO-publish.rb +2 -0
- data/lib/TODO-settingsfiles.rb +11 -0
- data/lib/base_config.rb +83 -0
- data/lib/basetask.rb +70 -0
- data/lib/bcp.rb +136 -0
- data/lib/config.rb +25 -0
- data/lib/database.rb +59 -0
- data/lib/dotframeworksymbolhelp.rb +8 -0
- data/lib/iis.rb +37 -0
- data/lib/jstest.rb +98 -0
- data/lib/minifyjs.rb +41 -0
- data/lib/msbuild.rb +101 -0
- data/lib/mstest.rb +35 -0
- data/lib/nunit.rb +102 -0
- data/lib/registry_accessor.rb +38 -0
- data/lib/sqlcmd.rb +195 -0
- data/lib/tools.rb +3 -0
- data/lib/windowspaths.rb +28 -0
- data/spec/base.rb +32 -0
- data/spec/basetask_spec.rb +66 -0
- data/spec/basetaskmocking.rb +44 -0
- data/spec/bcp_spec.rb +137 -0
- data/spec/config_spec.rb +43 -0
- data/spec/config_testdata/defaultpartialuser_default.rb +17 -0
- data/spec/config_testdata/defaultpartialuser_user.rb +9 -0
- data/spec/config_testdata/local_properties.rb +13 -0
- data/spec/config_testdata/local_properties_default.rb +15 -0
- data/spec/config_testdata/onlydefault.rb +17 -0
- data/spec/db_spec.rb +88 -0
- data/spec/iis_spec.rb +49 -0
- data/spec/jstest_spec.rb +114 -0
- data/spec/minifyjs_spec.rb +27 -0
- data/spec/msbuild_spec.rb +127 -0
- data/spec/mstest_spec.rb +25 -0
- data/spec/nunit_spec.rb +118 -0
- data/spec/registry_accessor_spec.rb +31 -0
- data/spec/sqlcmd_spec.rb +323 -0
- data/spec/windowspaths_spec.rb +39 -0
- metadata +118 -0
data/lib/jstest.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module BradyW
|
5
|
+
# Executes Javascript tests using Google's JS Test. By default, the task outputs test results in
|
6
|
+
# plain text to stdout.
|
7
|
+
class JsTest < BaseTask
|
8
|
+
|
9
|
+
# *Required* Which Javascript files should be passed on to JS Test driver?
|
10
|
+
attr_accessor :files
|
11
|
+
|
12
|
+
# *Required* List of browser paths to run the test on. (surrounded in quotes on Windows)
|
13
|
+
attr_accessor :browsers
|
14
|
+
|
15
|
+
# *Optional* Google JS Test Driver in use (defaults to 1.2.1)
|
16
|
+
attr_accessor :version
|
17
|
+
|
18
|
+
# *Optional* If XML output is enabled, what directory should it go to (default is current)
|
19
|
+
attr_accessor :outpath
|
20
|
+
|
21
|
+
# *Optional* Should XML output be enabled? By default the task looks for the CCNetProject environment
|
22
|
+
# variable to decide this
|
23
|
+
attr_accessor :xmloutput
|
24
|
+
|
25
|
+
# Where is the Test driver JAR located (defaults to "lib/")
|
26
|
+
attr_accessor :jarpath
|
27
|
+
|
28
|
+
# *Optional* Which port should the Test Driver Server run on (defaults to 9876)
|
29
|
+
attr_accessor :port
|
30
|
+
|
31
|
+
# *Optional* Where should the server be running? Default is localhost, which causes the server to launch
|
32
|
+
# when this task is run. If you specify another server here, then this task will NOT
|
33
|
+
# launch a server and will instead only run the tests.
|
34
|
+
attr_accessor :server
|
35
|
+
|
36
|
+
private
|
37
|
+
def exectask
|
38
|
+
genConfigFile
|
39
|
+
cmd = "java -jar #{jarpath}jsTestDriver-#{version}.jar#{portparam}#{browsers} --tests all#{testoutput}"
|
40
|
+
shell cmd do |ok,status|
|
41
|
+
# We want to clean up our temp file in case we fail
|
42
|
+
rm_safe configFile
|
43
|
+
ok or
|
44
|
+
fail "Command failed with status (#{status.exitstatus}):"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def genConfigFile
|
49
|
+
# This will include internal Rake FileList exclusion stuff if we don't do this
|
50
|
+
onlyFiles = []
|
51
|
+
@files.each { |f| onlyFiles << f}
|
52
|
+
config = {"server" => "http://#{server}:#{port}",
|
53
|
+
"load" => onlyFiles}
|
54
|
+
File.open configFile, 'w' do |file|
|
55
|
+
YAML.dump config, file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def testoutput
|
60
|
+
if xmloutput
|
61
|
+
" --testOutput " + (@outpath || ".")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def xmloutput
|
66
|
+
@xmloutput || ENV["CCNetProject"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def configFile
|
70
|
+
"jsTestDriver.conf"
|
71
|
+
end
|
72
|
+
|
73
|
+
def browsers
|
74
|
+
" --browser "+@browsers.join(",") unless @server
|
75
|
+
end
|
76
|
+
|
77
|
+
def version
|
78
|
+
@version || "1.2.1"
|
79
|
+
end
|
80
|
+
|
81
|
+
def server
|
82
|
+
@server || "localhost"
|
83
|
+
end
|
84
|
+
|
85
|
+
def jarpath
|
86
|
+
@jarpath || "lib/"
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def portparam
|
91
|
+
" --port #{port}" unless @server
|
92
|
+
end
|
93
|
+
|
94
|
+
def port
|
95
|
+
@port || "9876"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/minifyjs.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
|
3
|
+
module BradyW
|
4
|
+
|
5
|
+
# Minifies Javascript files using the Yahoo YUI tool
|
6
|
+
class MinifyJs < BaseTask
|
7
|
+
|
8
|
+
# *Required* Which files do you want to minify (in place)?
|
9
|
+
attr_accessor :files
|
10
|
+
|
11
|
+
# *Optional* Version of YUI tool to use (defaults to 2.4.2)
|
12
|
+
attr_accessor :version
|
13
|
+
|
14
|
+
# *Optional* Charset to use (defaults to "utf-8")
|
15
|
+
attr_accessor :charset
|
16
|
+
|
17
|
+
# *Optional* Where is the YUI compressor JAR? (defaults to "lib/")
|
18
|
+
attr_accessor :path
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def exectask
|
23
|
+
puts "YUI Javscript Minify: Minifying these files: #{files}"
|
24
|
+
files.each do |j|
|
25
|
+
shell "java -jar #{path}yuicompressor-#{version}.jar --charset #{charset} #{j} -o #{j}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def charset
|
30
|
+
@charset || "utf-8"
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
@version || "2.4.2"
|
35
|
+
end
|
36
|
+
|
37
|
+
def path
|
38
|
+
@path || "lib/"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/msbuild.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
require 'windowspaths'
|
3
|
+
require 'dotframeworksymbolhelp'
|
4
|
+
|
5
|
+
module BradyW
|
6
|
+
|
7
|
+
# Launches a build using MSBuild
|
8
|
+
class MSBuild < BaseTask
|
9
|
+
include WindowsPaths
|
10
|
+
include Dotframeworksymbolhelp
|
11
|
+
|
12
|
+
# *Optional* Targets to build. Can be a single target or an array of targets
|
13
|
+
attr_accessor :targets
|
14
|
+
|
15
|
+
# *Optional* Version of the MSBuild binary to use. Defaults to :v4_5
|
16
|
+
# Other options are :v2_0, :v3_5, :v4_0
|
17
|
+
attr_accessor :dotnet_bin_version
|
18
|
+
|
19
|
+
# *Optional* Solution file to build
|
20
|
+
attr_accessor :solution
|
21
|
+
|
22
|
+
# *Optional* .NET compilation version (what should MSBuild compile code to, NOT what version
|
23
|
+
# of MSBuild to use). Defaults to :v4_5). Other options are :v2_0, :v3_5, :v4_0
|
24
|
+
attr_accessor :compile_version
|
25
|
+
|
26
|
+
# *Optional* Properties to pass along to MSBuild. By default 'Configuration' and
|
27
|
+
# 'TargetFrameworkVersion' will be set based on the other attributes of this class.
|
28
|
+
attr_accessor :properties
|
29
|
+
|
30
|
+
# *Optional* Do a release build? By default, this is false.
|
31
|
+
attr_accessor :release
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
DOTNET4_REG_PATH = "v4\\Client"
|
36
|
+
DOTNET35_REGPATH = "v3.5"
|
37
|
+
DOTNET2_HARDCODEDPATH = "C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\"
|
38
|
+
|
39
|
+
def exectask
|
40
|
+
shell "#{path}msbuild.exe#{targets}#{propstr}#{solution}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def compile_version
|
44
|
+
symbol = @compile_version || :v4_5
|
45
|
+
ver = convertToNumber symbol
|
46
|
+
"v#{ver}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def solution
|
50
|
+
if @solution
|
51
|
+
" " + @solution
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def targets
|
56
|
+
if @targets
|
57
|
+
" /target:#{flatTargets}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def flatTargets
|
62
|
+
return nil unless @targets
|
63
|
+
@targets.is_a?(Array) ? @targets.join(",") : @targets
|
64
|
+
end
|
65
|
+
|
66
|
+
def debugOrRelease
|
67
|
+
@release ? "Release" : "Debug"
|
68
|
+
end
|
69
|
+
|
70
|
+
def propsmerged
|
71
|
+
default = {}
|
72
|
+
default['Configuration'] = debugOrRelease
|
73
|
+
default['TargetFrameworkVersion'] = compile_version
|
74
|
+
default.merge @properties || {}
|
75
|
+
end
|
76
|
+
|
77
|
+
def propstr
|
78
|
+
keyvalue = []
|
79
|
+
propsmerged.each do |prop, set|
|
80
|
+
keyvalue << "#{prop}=#{set}"
|
81
|
+
end
|
82
|
+
" /property:"+keyvalue.join(";")
|
83
|
+
end
|
84
|
+
|
85
|
+
def path
|
86
|
+
symbol = @dotnet_bin_version || :v4_5
|
87
|
+
case symbol
|
88
|
+
when :v4_0
|
89
|
+
dotnet DOTNET4_REG_PATH
|
90
|
+
when :v4_5
|
91
|
+
dotnet DOTNET4_REG_PATH
|
92
|
+
when :v3_5
|
93
|
+
dotnet DOTNET35_REGPATH
|
94
|
+
when :v2_0
|
95
|
+
DOTNET2_HARDCODEDPATH
|
96
|
+
else
|
97
|
+
fail "You supplied a .NET MSBuild binary version that's not supported. Please use :v4_0, :v3_5, or :v2_0"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/mstest.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
require 'windowspaths'
|
3
|
+
|
4
|
+
module BradyW
|
5
|
+
# Runs MSTest tests using Visual Studio's MSTest runner
|
6
|
+
class MSTest < BaseTask
|
7
|
+
include BradyW::WindowsPaths
|
8
|
+
|
9
|
+
# *Required* Files/test containers to test
|
10
|
+
attr_accessor :files
|
11
|
+
|
12
|
+
# *Optional* Version of Visual Studio/MSTest to use, defaults to 10.0
|
13
|
+
attr_accessor :version
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def exectask
|
18
|
+
shell "\"#{path}MSTest.exe\"#{testcontainers}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def testcontainers
|
22
|
+
specifier = " /testcontainer:"
|
23
|
+
mainstr = files.join(specifier)
|
24
|
+
specifier+mainstr
|
25
|
+
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
visual_studio version
|
29
|
+
end
|
30
|
+
|
31
|
+
def version
|
32
|
+
@version || "10.0"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/nunit.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
require 'dotframeworksymbolhelp'
|
3
|
+
|
4
|
+
module BradyW
|
5
|
+
class Nunit < BaseTask
|
6
|
+
include Dotframeworksymbolhelp
|
7
|
+
|
8
|
+
# *Required* Files/assemblies to test
|
9
|
+
attr_accessor :files
|
10
|
+
|
11
|
+
# *Optional* Version of NUnit in use, defaults to 2.6.2
|
12
|
+
attr_accessor :version
|
13
|
+
|
14
|
+
# *Optional* What version of the .NET framework to use for the tests? :v2_0, :v3_5, :v4_0, :v4_5, defaults to :v4_5
|
15
|
+
attr_accessor :framework_version
|
16
|
+
|
17
|
+
# *Optional* Location of nunit-console.exe, defaults to C:\Program Files (x86)\NUnit ${version}\bin
|
18
|
+
attr_accessor :path
|
19
|
+
|
20
|
+
# *Optional* Timeout for each test case in milliseconds, by default the timeout is 35 seconds
|
21
|
+
attr_accessor :timeout
|
22
|
+
|
23
|
+
# *Optional* Which tests should be run (specify namespace+class), can be multiple, defaults to all in class
|
24
|
+
attr_accessor :tests
|
25
|
+
|
26
|
+
# *Optional* Should XML be outputted? By default the answer is no, but set this to :enabled if you want XML output
|
27
|
+
attr_accessor :xml_output
|
28
|
+
|
29
|
+
# *Optional* Should labels be printed in the test output, default is :include_labels, can also say :exclude_labels
|
30
|
+
attr_accessor :labels
|
31
|
+
|
32
|
+
# *Optional* Where should test output be stored? Default is console
|
33
|
+
attr_accessor :output
|
34
|
+
|
35
|
+
# *Optional* Where should test errors be stored? Default is console
|
36
|
+
attr_accessor :errors
|
37
|
+
|
38
|
+
# *Optional* Should :x86 or :anycpu archiecture be used? Default is :anycpu
|
39
|
+
attr_accessor :arch
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def exectask
|
44
|
+
assemblies = files.uniq.join(" ")
|
45
|
+
shell "\"#{path}\\#{executable}\"#{output}#{errors}#{labels_flat}#{xml_output_flat}/framework=#{framework_version} /timeout=#{timeout}#{testsparam}#{assemblies}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def executable
|
49
|
+
arch == :anycpu ? "nunit-console.exe" : "nunit-console-x86.exe"
|
50
|
+
end
|
51
|
+
|
52
|
+
def arch
|
53
|
+
@arch || :anycpu
|
54
|
+
end
|
55
|
+
|
56
|
+
def xml_output_flat
|
57
|
+
xml_output == :disabled ? " /noxml " : " "
|
58
|
+
end
|
59
|
+
|
60
|
+
def xml_output
|
61
|
+
@xml_output || :disabled
|
62
|
+
end
|
63
|
+
|
64
|
+
def output
|
65
|
+
@output ? " /output=#{@output}" : ""
|
66
|
+
end
|
67
|
+
|
68
|
+
def errors
|
69
|
+
@errors ? " /err=#{@errors}" : ""
|
70
|
+
end
|
71
|
+
|
72
|
+
def version
|
73
|
+
@version || "2.6.2"
|
74
|
+
end
|
75
|
+
|
76
|
+
def labels
|
77
|
+
@labels || :include_labels
|
78
|
+
end
|
79
|
+
|
80
|
+
def labels_flat
|
81
|
+
labels == :include_labels ? " /labels" : ""
|
82
|
+
end
|
83
|
+
|
84
|
+
def testsparam
|
85
|
+
return " " unless @tests
|
86
|
+
flat = @tests.is_a?(Array) ? @tests.join(",") : @tests
|
87
|
+
" /run=#{flat} "
|
88
|
+
end
|
89
|
+
|
90
|
+
def framework_version
|
91
|
+
convertToNumber(@framework_version || :v4_5)
|
92
|
+
end
|
93
|
+
|
94
|
+
def path
|
95
|
+
@path || "C:\\Program Files (x86)\\NUnit #{version}\\bin"
|
96
|
+
end
|
97
|
+
|
98
|
+
def timeout
|
99
|
+
@timeout || 35000
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'win32/registry'
|
2
|
+
|
3
|
+
module BradyW
|
4
|
+
class RegistryAccessor
|
5
|
+
def regvalue(key, value)
|
6
|
+
keyAndVal = "#{key}\\#{value}"
|
7
|
+
begin
|
8
|
+
regvalue64(key, value)
|
9
|
+
rescue
|
10
|
+
begin
|
11
|
+
regvalue32(key, value)
|
12
|
+
rescue
|
13
|
+
raise "Unable to find registry value in either 32 or 64 bit mode: #{keyAndVal}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def regvalue64(key, value)
|
21
|
+
# workaround to make sure we have 64 bit registry access
|
22
|
+
ourKeyRead = Win32::Registry::Constants::KEY_READ |
|
23
|
+
Windows::Registry::KEY_WOW64_64KEY
|
24
|
+
Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,
|
25
|
+
key,
|
26
|
+
ourKeyRead) do |reg|
|
27
|
+
return reg[value]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def regvalue32(key, value)
|
32
|
+
Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,
|
33
|
+
key) do |reg|
|
34
|
+
return reg[value]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/sqlcmd.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'basetask'
|
2
|
+
require 'windowspaths'
|
3
|
+
require 'database'
|
4
|
+
|
5
|
+
module BradyW
|
6
|
+
|
7
|
+
# Runs SQLcmd to run supplied SQL scripts. This task will roll up all supplied SQL script files
|
8
|
+
# into 1 SQL file before running it in order to speed up the tasks. The "-e" flag is used so that
|
9
|
+
# all statements are echo'ed to stdout.
|
10
|
+
class Sqlcmd < BaseTask
|
11
|
+
include WindowsPaths
|
12
|
+
|
13
|
+
# *Required* Which SQL scripts do you want to run? Everything in this path will be run with this script.
|
14
|
+
# It's recommended that you arrange your structure like the one below. If you do, the generated
|
15
|
+
# meta script will have nice comments that indicate what it's currently running
|
16
|
+
# somedirectory
|
17
|
+
# 01-tables
|
18
|
+
# 01-table1.sql
|
19
|
+
# 02-table2.sql
|
20
|
+
# 02-indexes
|
21
|
+
attr_accessor :files
|
22
|
+
|
23
|
+
# *Optional* Version of SQL Server's sqlcmd to use. Defaults to SQL Server 2008.
|
24
|
+
attr_accessor :version
|
25
|
+
|
26
|
+
# *Optional* By default, several variables are passed into SQLCMD based on the config file.
|
27
|
+
# Add yours in here as key value pairs if you want to send more.
|
28
|
+
# The following will be set by default:
|
29
|
+
# * dbname - all credentials
|
30
|
+
# * sqlserverdatadirectory - only when using :system credentials
|
31
|
+
# * dbuser -> general user, all credentials
|
32
|
+
# * dbpassword - > general password, only when using :system credentials
|
33
|
+
attr_accessor :variables
|
34
|
+
|
35
|
+
# *Optional* Setting this to true will NOT execute sqlcmd at all, but instead will go through
|
36
|
+
# the source files supplied and replace any hard coded host names, database names, or any other
|
37
|
+
# variables with sqlcmd style $(variable)s to make scripts more dynamic. It's useful when
|
38
|
+
# taking scripts creating on a single developer machine and prepping them for checkin.
|
39
|
+
# Default is false.
|
40
|
+
attr_accessor :makedynamic
|
41
|
+
|
42
|
+
# *Optional* Which set of DB credentials should be used?
|
43
|
+
# :system - for creation/deletion of databases
|
44
|
+
# :objectcreation - for adding/creating objects within a database
|
45
|
+
# :general - DEFAULT - for adding/deleting rows within a database (use this for code)
|
46
|
+
def credentials=(value)
|
47
|
+
BaseTask.validate value, "credentials", Database::CREDENTIALS
|
48
|
+
@credentials = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def credentials
|
52
|
+
@credentials || :general
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def credentialsString
|
58
|
+
credentials.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
HEADER = "-- *************************************************************"
|
62
|
+
CONNECT_STRING_WINAUTH = "-E -S %s"
|
63
|
+
CONNECT_STRING_SQLAUTH = "-U %s -P %s -S %s"
|
64
|
+
|
65
|
+
def initialize (parameters = :task)
|
66
|
+
super parameters
|
67
|
+
@dbprops = Database.new
|
68
|
+
@config = Config.instance.values
|
69
|
+
# We don't want the temp file/time changing on us during the run
|
70
|
+
@tempfile = Sqlcmd.generatetempfilename
|
71
|
+
end
|
72
|
+
|
73
|
+
def exectask
|
74
|
+
if makedynamic
|
75
|
+
processdynamic
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
createtempfile
|
80
|
+
exe = "\"#{path}sqlcmd.exe\""
|
81
|
+
args = "#{connect} -e -b#{variables_flat} -i #{@tempfile}"
|
82
|
+
cmd = "#{exe} #{args}"
|
83
|
+
shell cmd do |ok,status|
|
84
|
+
# We want to clean up our temp file in case we fail
|
85
|
+
removetempfile
|
86
|
+
ok or
|
87
|
+
fail "Command failed with status (#{status.exitstatus}):"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def processdynamic
|
92
|
+
vars = variables
|
93
|
+
@files.each do |fileName|
|
94
|
+
next if File.directory? fileName
|
95
|
+
text = File.read(fileName)
|
96
|
+
vars.each do |setting,value|
|
97
|
+
text.gsub!(value,
|
98
|
+
"$(#{setting})")
|
99
|
+
end
|
100
|
+
File.open fileName, "w" do |newFile|
|
101
|
+
newFile.puts text
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def Sqlcmd.getdir directory
|
107
|
+
parentDir = File.dirname directory
|
108
|
+
directory[parentDir.length+1..-1]
|
109
|
+
end
|
110
|
+
|
111
|
+
def createtempfile
|
112
|
+
File.open(@tempfile, "w") do |file|
|
113
|
+
file.puts HEADER
|
114
|
+
file.puts "-- BEGIN BATCH SQL RUN"
|
115
|
+
file.puts HEADER
|
116
|
+
file.puts
|
117
|
+
|
118
|
+
@files.each do |input|
|
119
|
+
if File.directory? input
|
120
|
+
containingdir = Sqlcmd.getdir input
|
121
|
+
|
122
|
+
file.puts
|
123
|
+
file.puts
|
124
|
+
file.puts HEADER
|
125
|
+
file.puts "-- Directory: #{containingdir}..."
|
126
|
+
file.puts HEADER
|
127
|
+
file.puts
|
128
|
+
file.puts
|
129
|
+
|
130
|
+
else
|
131
|
+
file.puts "-- Script: #{input}"
|
132
|
+
file.puts ":r #{input}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
file.puts
|
137
|
+
file.puts
|
138
|
+
file.puts
|
139
|
+
file.puts HEADER
|
140
|
+
file.puts "-- COMPLETED BATCH SQL RUN"
|
141
|
+
file.puts HEADER
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def removetempfile
|
146
|
+
rm_safe @tempfile
|
147
|
+
end
|
148
|
+
|
149
|
+
def Sqlcmd.generatetempfilename
|
150
|
+
"sqlload_"+DateTime.now.strftime("%Y%m%d%H%M%S") +".sql"
|
151
|
+
end
|
152
|
+
|
153
|
+
def path
|
154
|
+
p = @version || "100"
|
155
|
+
sql_tool p
|
156
|
+
end
|
157
|
+
|
158
|
+
def connect
|
159
|
+
# TODO: Use better class structure in the config file
|
160
|
+
prefix = "db_#{credentialsString}_"
|
161
|
+
authMode = @config.send("#{prefix}authmode")
|
162
|
+
if authMode == :winauth
|
163
|
+
CONNECT_STRING_WINAUTH % [@dbprops.host]
|
164
|
+
else
|
165
|
+
CONNECT_STRING_SQLAUTH % [@config.send("#{prefix}user"),
|
166
|
+
@config.send("#{prefix}password"),
|
167
|
+
@dbprops.host]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def variables_flat
|
172
|
+
keyvalue = []
|
173
|
+
variables.each do |variable, setting|
|
174
|
+
setting = setting.include?(' ') ? "\"#{setting}\"" : setting
|
175
|
+
keyvalue << "#{variable}=#{setting}"
|
176
|
+
end
|
177
|
+
" -v " + keyvalue.join(" ") unless variables.empty?
|
178
|
+
end
|
179
|
+
|
180
|
+
def variables
|
181
|
+
# when we have usernames in SQL scripts, we're probably granting to a general purpose user, so that's why
|
182
|
+
# we use gen and not something else
|
183
|
+
default =
|
184
|
+
{'dbname' => @dbprops.name,
|
185
|
+
'dbuser' => @dbprops.user}
|
186
|
+
|
187
|
+
if (credentials == :system || makedynamic)
|
188
|
+
default['sqlserverdatadirectory'] = "\"#{@config.db_system_datadir}\""
|
189
|
+
default['dbpassword'] = @dbprops.password
|
190
|
+
end
|
191
|
+
|
192
|
+
default.merge @variables || {}
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|