kvm 0.0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. data/.gitignore +3 -0
  2. data/.rvmrc +1 -0
  3. data/AGPL-3.0 +661 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +32 -0
  6. data/LICENSE +23 -0
  7. data/README.md +73 -0
  8. data/Rakefile +48 -0
  9. data/bin/kvm +6 -0
  10. data/kvm.gemspec +28 -0
  11. data/lib/kvm.rb +286 -0
  12. data/lib/kvm/archive.rb +56 -0
  13. data/lib/kvm/artifact.rb +28 -0
  14. data/lib/kvm/db/jdbc_adapter.rb +71 -0
  15. data/lib/kvm/db/oracle.rb +23 -0
  16. data/lib/kvm/db/types.rb +11 -0
  17. data/lib/kvm/impex.rb +109 -0
  18. data/lib/kvm/log.rb +7 -0
  19. data/lib/kvm/resource.rb +72 -0
  20. data/lib/kvm/rice_release.rb +79 -0
  21. data/lib/kvm/rice_release_generated_dataset.rb +68 -0
  22. data/lib/kvm/source.rb +33 -0
  23. data/lib/kvm/subversion.rb +52 -0
  24. data/lib/kvm/version.rb +3 -0
  25. data/lib/kvm/wallet.rb +64 -0
  26. data/support/ant/INSTALL +2 -0
  27. data/support/ant/KEYS +1398 -0
  28. data/support/ant/LICENSE +272 -0
  29. data/support/ant/NOTICE +6 -0
  30. data/support/ant/README +97 -0
  31. data/support/ant/WHATSNEW +5467 -0
  32. data/support/ant/bin/ant +335 -0
  33. data/support/ant/bin/ant.bat +218 -0
  34. data/support/ant/bin/ant.cmd +93 -0
  35. data/support/ant/bin/antRun +24 -0
  36. data/support/ant/bin/antRun.bat +50 -0
  37. data/support/ant/bin/antRun.pl +66 -0
  38. data/support/ant/bin/antenv.cmd +98 -0
  39. data/support/ant/bin/complete-ant-cmd.pl +114 -0
  40. data/support/ant/bin/envset.cmd +131 -0
  41. data/support/ant/bin/lcp.bat +31 -0
  42. data/support/ant/bin/runant.pl +153 -0
  43. data/support/ant/bin/runant.py +102 -0
  44. data/support/ant/bin/runrc.cmd +60 -0
  45. data/support/ant/etc/ant-bootstrap.jar +0 -0
  46. data/support/ant/etc/changelog.xsl +148 -0
  47. data/support/ant/etc/checkstyle/checkstyle-frames.xsl +299 -0
  48. data/support/ant/etc/checkstyle/checkstyle-text.xsl +34 -0
  49. data/support/ant/etc/checkstyle/checkstyle-xdoc.xsl +130 -0
  50. data/support/ant/etc/coverage-frames.xsl +489 -0
  51. data/support/ant/etc/jdepend-frames.xsl +487 -0
  52. data/support/ant/etc/jdepend.xsl +276 -0
  53. data/support/ant/etc/junit-frames-xalan1.xsl +733 -0
  54. data/support/ant/etc/junit-frames.xsl +902 -0
  55. data/support/ant/etc/junit-noframes.xsl +478 -0
  56. data/support/ant/etc/log.xsl +203 -0
  57. data/support/ant/etc/maudit-frames.xsl +503 -0
  58. data/support/ant/etc/mmetrics-frames.xsl +1026 -0
  59. data/support/ant/etc/tagdiff.xsl +179 -0
  60. data/support/ant/fetch.xml +343 -0
  61. data/support/ant/get-m2.xml +121 -0
  62. data/support/ant/lib/README +3 -0
  63. data/support/ant/lib/ant-antlr.jar +0 -0
  64. data/support/ant/lib/ant-antlr.pom +76 -0
  65. data/support/ant/lib/ant-apache-bcel.jar +0 -0
  66. data/support/ant/lib/ant-apache-bcel.pom +72 -0
  67. data/support/ant/lib/ant-apache-bsf.jar +0 -0
  68. data/support/ant/lib/ant-apache-bsf.pom +75 -0
  69. data/support/ant/lib/ant-apache-log4j.jar +0 -0
  70. data/support/ant/lib/ant-apache-log4j.pom +70 -0
  71. data/support/ant/lib/ant-apache-oro.jar +0 -0
  72. data/support/ant/lib/ant-apache-oro.pom +75 -0
  73. data/support/ant/lib/ant-apache-regexp.jar +0 -0
  74. data/support/ant/lib/ant-apache-regexp.pom +71 -0
  75. data/support/ant/lib/ant-apache-resolver.jar +0 -0
  76. data/support/ant/lib/ant-apache-resolver.pom +70 -0
  77. data/support/ant/lib/ant-apache-xalan2.jar +0 -0
  78. data/support/ant/lib/ant-apache-xalan2.pom +95 -0
  79. data/support/ant/lib/ant-commons-logging.jar +0 -0
  80. data/support/ant/lib/ant-commons-logging.pom +71 -0
  81. data/support/ant/lib/ant-commons-net.jar +0 -0
  82. data/support/ant/lib/ant-commons-net.pom +76 -0
  83. data/support/ant/lib/ant-jai.jar +0 -0
  84. data/support/ant/lib/ant-jai.pom +85 -0
  85. data/support/ant/lib/ant-javamail.jar +0 -0
  86. data/support/ant/lib/ant-javamail.pom +79 -0
  87. data/support/ant/lib/ant-jdepend.jar +0 -0
  88. data/support/ant/lib/ant-jdepend.pom +73 -0
  89. data/support/ant/lib/ant-jmf.jar +0 -0
  90. data/support/ant/lib/ant-jmf.pom +66 -0
  91. data/support/ant/lib/ant-jsch.jar +0 -0
  92. data/support/ant/lib/ant-jsch.pom +75 -0
  93. data/support/ant/lib/ant-junit.jar +0 -0
  94. data/support/ant/lib/ant-junit.pom +101 -0
  95. data/support/ant/lib/ant-junit4.jar +0 -0
  96. data/support/ant/lib/ant-junit4.pom +71 -0
  97. data/support/ant/lib/ant-launcher.jar +0 -0
  98. data/support/ant/lib/ant-launcher.pom +58 -0
  99. data/support/ant/lib/ant-netrexx.jar +0 -0
  100. data/support/ant/lib/ant-netrexx.pom +99 -0
  101. data/support/ant/lib/ant-parent.pom +120 -0
  102. data/support/ant/lib/ant-swing.jar +0 -0
  103. data/support/ant/lib/ant-swing.pom +67 -0
  104. data/support/ant/lib/ant-testutil.jar +0 -0
  105. data/support/ant/lib/ant-testutil.pom +75 -0
  106. data/support/ant/lib/ant.jar +0 -0
  107. data/support/ant/lib/ant.pom +222 -0
  108. data/support/ant/lib/libraries.properties +65 -0
  109. data/test/data/files/rice-0.0.0.0-bin.tar.gz +0 -0
  110. data/test/data/svn/README.txt +5 -0
  111. data/test/data/svn/conf/authz +32 -0
  112. data/test/data/svn/conf/passwd +8 -0
  113. data/test/data/svn/conf/svnserve.conf +47 -0
  114. data/test/data/svn/db/current +1 -0
  115. data/test/data/svn/db/format +2 -0
  116. data/test/data/svn/db/fs-type +1 -0
  117. data/test/data/svn/db/fsfs.conf +37 -0
  118. data/test/data/svn/db/min-unpacked-rev +1 -0
  119. data/test/data/svn/db/rep-cache.db +0 -0
  120. data/test/data/svn/db/revprops/0/0 +5 -0
  121. data/test/data/svn/db/revprops/0/1 +13 -0
  122. data/test/data/svn/db/revs/0/0 +11 -0
  123. data/test/data/svn/db/revs/0/1 +0 -0
  124. data/test/data/svn/db/txn-current +1 -0
  125. data/test/data/svn/db/txn-current-lock +0 -0
  126. data/test/data/svn/db/uuid +1 -0
  127. data/test/data/svn/db/write-lock +0 -0
  128. data/test/data/svn/format +1 -0
  129. data/test/data/svn/hooks/post-commit.tmpl +50 -0
  130. data/test/data/svn/hooks/post-lock.tmpl +44 -0
  131. data/test/data/svn/hooks/post-revprop-change.tmpl +56 -0
  132. data/test/data/svn/hooks/post-unlock.tmpl +42 -0
  133. data/test/data/svn/hooks/pre-commit.tmpl +81 -0
  134. data/test/data/svn/hooks/pre-lock.tmpl +71 -0
  135. data/test/data/svn/hooks/pre-revprop-change.tmpl +66 -0
  136. data/test/data/svn/hooks/pre-unlock.tmpl +63 -0
  137. data/test/data/svn/hooks/start-commit.tmpl +65 -0
  138. data/test/data/svn/locks/db-logs.lock +3 -0
  139. data/test/data/svn/locks/db.lock +3 -0
  140. data/test/helper.rb +146 -0
  141. data/test/int_test_generate_sql.rb +58 -0
  142. data/test/test_archive.rb +35 -0
  143. data/test/test_generate_sql.rb +0 -0
  144. data/test/test_rice_release.rb +61 -0
  145. data/test/test_rice_release_generated_dataset.rb +12 -0
  146. data/test/test_source.rb +31 -0
  147. data/test/test_subversion.rb +20 -0
  148. metadata +298 -0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kvm.gemspec
4
+ gemspec
5
+
6
+ platforms :jruby do
7
+ gem 'jruby-openssl'
8
+ end
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kvm (0.0.1.pre)
5
+ thor
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ bouncy-castle-java (1.5.0146.1)
11
+ builder (3.0.0)
12
+ ci_reporter (1.6.4)
13
+ builder (>= 2.1.2)
14
+ fakeweb (1.3.0)
15
+ jruby-openssl (0.7.4)
16
+ bouncy-castle-java
17
+ rake (0.9.0)
18
+ rcov (0.9.9)
19
+ rcov (0.9.9-java)
20
+ thor (0.14.6)
21
+
22
+ PLATFORMS
23
+ java
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ ci_reporter
28
+ fakeweb
29
+ jruby-openssl
30
+ kvm!
31
+ rake
32
+ rcov
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ = KVM
2
+
3
+ Copyright (c) 2010 Incandescent Software LLC
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Affero General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Affero General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ == Additional Bundled Software
19
+
20
+ Apache Ant is licensed according to the terms of Apache License, Version 2.0. See http://www.apache.org/licenses/LICENSE-2.0 for details.
21
+
22
+ Kuali Rice datasets used in unit tests are licensed according to the terms of the Educational Community License 2.0. See http://www.opensource.org/licenses/ecl2.php for details.
23
+
@@ -0,0 +1,73 @@
1
+ Overview
2
+ ========
3
+
4
+
5
+ Requirements
6
+ ============
7
+
8
+ * JRuby (ideally through RVM)
9
+ * manual install of jruby-openssl gem: `rvm use jruby; gem install jruby-openssl gem`
10
+
11
+
12
+ Usage
13
+ =====
14
+
15
+ kvm --help
16
+
17
+ Tasks:
18
+ kvm checkout <relative repo> [path] ...
19
+ kvm config ...
20
+ kvm create-user <db options> <username> <password> ...
21
+ kvm def <db options with alias> ...
22
+ kvm drop-user <username> ...
23
+ kvm fetch <project>-<version>[-dist] ...
24
+ kvm generate-datasets <project>-<version> [-d dataset1,dataset2] [-t oracle...
25
+ kvm get <project>-<version>[-dist] ...
26
+ kvm help [TASK] ...
27
+ kvm install-dataset <db options> <project>-<version> dataset [type] ...
28
+ kvm install-testtables <db options> <project>-<version> [type] ...
29
+ kvm list ...
30
+ kvm list-datasets ...
31
+ kvm run-sql file <db options> ...
32
+ kvm undef <alias> ...
33
+ kvm update <relative repo> [path] ...
34
+
35
+ To generate dataset SQL:
36
+
37
+ kvm generate-datasets rice-1.0.3.1
38
+
39
+ To install SQL:
40
+
41
+ kvm install-dataset --url jdbc:oracle:thin:@localhost:1521:xe --username rice_test --password rice_test rice-1.0.3.1 bootstrap-server oracle
42
+
43
+ Database Arguments
44
+ ==================
45
+
46
+ Several commands take database connection arguments. A database connection consists of:
47
+
48
+ * jdbc url
49
+ * username
50
+ * password
51
+ * type (oracle or mysql)
52
+
53
+ There are two provisions for specifying these components, either directly, or via the `--db` options hash, and the two styles can be mixed.
54
+
55
+ Directly: `--url jdbc:oracle:thin:@127.0.0.1:1521:xe --username user --password password --type oracle`
56
+
57
+ Options hash: `--url jdbc:oracle:thin:@127.0.0.1:1521:xe --db username:user password:password type:oracle`
58
+
59
+ Two other options are also available:
60
+
61
+ * alias
62
+ * jar
63
+
64
+ If you have defined a db alias (via `define-db` command) then you can simply use the `--alias mydb` option to refer to the predefined db alias. This will save repetition.
65
+
66
+ Some commands also require the JDBC driver jar to be specified. This can be done via the `--jar /path/to/ojdbc14.jar` option.
67
+
68
+ Improvements
69
+ ============
70
+
71
+ * better command documentation
72
+ * better effort at automatically locating jdbc driver jars, and saving with db aliases
73
+ * secure wallet functionality is sort of lame, it would be nice to take advantage of native keychain functionality if it exists
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ #require 'test/unit'
4
+ require 'rake/testtask'
5
+ require 'rcov/rcovtask'
6
+ # to get xunit test results: rake ci:setup:testunit test
7
+ require 'ci/reporter/rake/test_unit'
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ # integration test files
12
+ INT_TEST_FILES = FileList['test/int_test*.rb']
13
+
14
+ # helper to dry up tasks
15
+ def def_test(t, opts = {})
16
+ t.libs << "test"
17
+ t.test_files = opts[:test_files] if opts[:test_files]
18
+ t.rcov_opts += opts[:rcov_opts] if opts[:rcov_opts]
19
+ t.verbose = true
20
+ end
21
+
22
+ Rake::TestTask.new do |t|
23
+ def_test(t)
24
+ end
25
+
26
+ Rake::TestTask.new(:integration) do |t|
27
+ def_test(t, :test_files => INT_TEST_FILES)
28
+ end
29
+
30
+ task :test_all => [ :test, :integration ]
31
+
32
+ RCOV_OPTS = [ '--xrefs', # comment to disable cross-references
33
+ '--html',
34
+ '--exclude /gems/' ] # '-a'
35
+
36
+ #desc "Create a cross-referenced code coverage report."
37
+ Rcov::RcovTask.new do |t|
38
+ def_test(t, :rcov_opts => RCOV_OPTS)
39
+ end
40
+
41
+ Rcov::RcovTask.new(:rcov_integration) do |t|
42
+ def_test(t, :test_files => INT_TEST_FILES, :rcov_opts => RCOV_OPTS)
43
+ end
44
+
45
+ Rcov::RcovTask.new(:rcov_all) do |t|
46
+ # test_files field not accessible on RcovTask? meh
47
+ def_test(t, :test_files => FileList['test/test*.rb'] + INT_TEST_FILES, :rcov_opts => RCOV_OPTS)
48
+ end
data/bin/kvm ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # runs kvm
3
+ # in development, use: bundle exec ./bin/kvm
4
+ require 'kvm'
5
+
6
+ KVM::App.start
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kvm/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "kvm"
7
+ s.version = KVM::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Aaron Hamid"]
10
+ s.email = ["aaron@incandescentsoftware.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Kuali Version Manager}
13
+ s.description = %q{Kuali Version Manager}
14
+
15
+ s.rubyforge_project = "kvm"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'thor'
23
+ #s.add_dependency 'rake' # for jruby ant integration
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'rcov'
26
+ s.add_development_dependency 'ci_reporter'
27
+ s.add_development_dependency 'fakeweb'
28
+ end
@@ -0,0 +1,286 @@
1
+ # jruby should be run in 1.9 mode
2
+ # if you are using RVM:
3
+ # mkdir ~/.rvm/hooks
4
+ # cat > ~/.rvm/hooks/after_use <<EOF
5
+ # case "$GEM_HOME" in
6
+ # *jruby*)
7
+ # JRUBY_OPTS="--1.9" ; export JRUBY_OPTS
8
+ # ;;
9
+ # esac
10
+ # EOF
11
+
12
+ require "rubygems" # ruby1.9 doesn't "require" it though
13
+ require "thor"
14
+ require "openssl"
15
+ require "base64"
16
+ require "digest/sha2"
17
+ require "ostruct"
18
+ require "pp"
19
+
20
+ KVM_DIR=File.expand_path('.kvm', '~')
21
+
22
+ require 'kvm/db/types'
23
+ require 'kvm/wallet'
24
+ require 'kvm/impex'
25
+ require 'kvm/rice_release'
26
+ require 'kvm/rice_release_generated_dataset'
27
+ require 'kvm/archive'
28
+ require 'kvm/source'
29
+ require 'kvm/log'
30
+
31
+ # https://wiki.kuali.org/display/KULRICE/Creating+a+New+Revision+of+Rice
32
+ class KVM::App < Thor
33
+ #SQL_TOOL = {
34
+ # # sqlplus can't deal with blank lines without 'set blanklines' option; ripping out the blank lines with sed seems to be the simplest approach
35
+ # "oracle" => lambda { |username, password, host, file| "sed '/^[ \t]*$/d' #{file} | sed '/^--.*$/d' | sqlplus -S -L #{username}/#{password}@#{host}" }
36
+
37
+ private
38
+
39
+ # class helper for defining common database arguments to a Thor command
40
+ def self.db_method_options
41
+ method_options :url => :string, :username => :string, :password => :string, :type => :string, :jar => :string, :alias => :string
42
+ end
43
+
44
+ public
45
+
46
+ desc "fetch <project>-<version>[-dist]", "download a release"
47
+ method_option :dist, :aliases => "-d", :default => "bin"
48
+ def fetch(name)
49
+ archive = KVM::Archive.new(name, options[:dist])
50
+ archive.get || puts("Archive #{name} has already been fetched: #{archive.name}")
51
+ end
52
+
53
+ desc "get <project>-<version>[-dist]", "download and expand a release"
54
+ method_option :dist, :aliases => "-d", :default => "bin"
55
+ def get(name)
56
+ release = KVM::RiceRelease.new(name, options[:dist])
57
+ release.get || puts("Release #{name} has already been downloaded: #{release.name}")
58
+ end
59
+
60
+ desc "list", "list downloaded releases"
61
+ def list
62
+ KVM::RiceRelease.list.each { |r| puts r.name }
63
+ end
64
+
65
+ desc "list-datasets", "lists generated datasets"
66
+ def list_datasets(project=nil)
67
+ datasets = KVM::RiceReleaseGeneratedDataset.list
68
+ for dataset in datasets
69
+ puts "#{dataset.project} #{dataset.ds_name} #{dataset.db_type}"
70
+ end
71
+ end
72
+
73
+ desc "generate-datasets <project>-<version> [-d dataset1,dataset2] [-t oracle|mysql]", "generates DDL for the specified project; if datasets or database type are omitted, all sets/types are generated"
74
+ method_option :datasets, :aliases => "-d", :type => :array
75
+ method_option :types, :aliases => "-t", :type => :string
76
+ def generate_datasets(project)
77
+ release = KVM::RiceRelease.new(project)
78
+ release.get
79
+
80
+ dataset_list = (options[:datasets] || release.datasets)
81
+ # generate sql of each type...
82
+ if options[:types]
83
+ db_types = options[:types].split('|')
84
+ else
85
+ db_types = KVM::Db::DB_TYPES
86
+ end
87
+ for db_type in db_types
88
+ # for each dataset
89
+ for ds_name in dataset_list
90
+ dataset = KVM::RiceReleaseGeneratedDataset.new(release.name, ds_name, db_type)
91
+ dataset.get
92
+ end
93
+ end
94
+ end
95
+
96
+ desc "install-dataset <db options> <project>-<version> dataset [type]", "installs specified dataset"
97
+ db_method_options
98
+ def install_dataset(project, ds_name, type=nil)
99
+ db_config = parse_db_options(options)
100
+ validate_db_options(db_config)
101
+ type = resolve_db_type(db_config, type)
102
+
103
+ release = KVM::RiceRelease.new(project)
104
+ release.get
105
+ # generate sql if missing
106
+ KVM::LOG.debug "DATASET: " + ds_name
107
+ dataset = KVM::RiceReleaseGeneratedDataset.new(release.name, ds_name, type)
108
+ dataset.get
109
+
110
+ KVM::LOG.debug "Dataset path:"
111
+ KVM::LOG.debug dataset.path
112
+ KVM::LOG.debug dataset.exists?
113
+
114
+ KVM::Impex::IMPEX_SOURCE.get
115
+ KVM::Impex::IMPEX.apply_sql(dataset.path, type, db_config.url, db_config.username, db_config.password)
116
+ end
117
+
118
+ # ./bin/kvm install-testtables rice-1.0.3.1 oracle --db=alias:oraclexe-system jar:$HOME/.m2/repository/com/oracle/ojdbc14/10.2.0.3.0/ojdbc14-10.2.0.3.0.jar
119
+ desc "install-testtables <db options> <project>-<version> [type]", "installs test tables"
120
+ db_method_options
121
+ def install_testtables(project, type=nil)
122
+ db_config = parse_db_options(options)
123
+ validate_db_options(db_config)
124
+ type = resolve_db_type(db_config, type)
125
+
126
+ release = KVM::RiceRelease.new(project)
127
+ release.get
128
+ run_sql_file(db_config, release.test_sql_file(type), true)
129
+ end
130
+
131
+ desc "run-sql file <db options>", "runs a sql file"
132
+ db_method_options
133
+ def run_sql(file)
134
+ db_config = parse_db_options(options)
135
+ validate_db_options(db_config)
136
+ resolve_db_type(db_config, nil)
137
+ run_sql_file(db_config, File.expand_path(file), false)
138
+ end
139
+
140
+ desc "checkout <relative repo> [path]", "checks out a Kuali project from subversion"
141
+ def checkout(repo, path="trunk")
142
+ src = Source.new(repo, path)
143
+ src.get || puts("#{repo} #{path} already checked out: #{src.path}")
144
+ end
145
+
146
+ desc "update <relative repo> [path]", "updates a checked out Kuali project"
147
+ def update(repo, path="trunk")
148
+ src = Source.new(repo, path)
149
+ src.get
150
+ src.update
151
+ end
152
+
153
+ # ./bin/kvm drop-user rice_test --db=alias:oraclexe-system jar:$HOME/.m2/repository/com/oracle/ojdbc14/10.2.0.3.0/ojdbc14-10.2.0.3.0.jar
154
+ desc "drop-user <username>", "drops a database user"
155
+ db_method_options
156
+ def drop_user(username)
157
+ db_config = parse_db_options(options)
158
+ validate_db_options(db_config)
159
+
160
+ db_type = resolve_db_type(db_config, nil, 'oracle')
161
+ db = KVM::Db::JdbcAdapter.new(db_config)
162
+ # prepared statement doesn't work for drop? http://forums.oracle.com/forums/thread.jspa?threadID=504808
163
+ db.execute_update(KVM::Db::DB_PLATFORMS[db_type].drop_user(username))
164
+ end
165
+
166
+ desc "create-user <db options> <username> <password>", "creates a database user"
167
+ db_method_options
168
+ def create_user(username, password)
169
+ db_config = parse_db_options(options)
170
+ validate_db_options(db_config)
171
+
172
+ KVM::LOG.debug db_config
173
+ db_type = resolve_db_type(db_config, nil, 'oracle')
174
+ db = KVM::Db::JdbcAdapter.new(db_config)
175
+ # oracle-specific
176
+ # prepared statement doesn't work for drop? http://forums.oracle.com/forums/thread.jspa?threadID=504808
177
+ db.execute_update(KVM::Db::DB_PLATFORMS[db_type].create_user(username, password))
178
+ end
179
+
180
+ desc "def <db options with alias>", "creates a database definition alias."
181
+ db_method_options
182
+ def def
183
+ db = parse_db_options(options)
184
+
185
+ raise "alias is required" unless db.alias
186
+
187
+ w = load_wallet
188
+ dbs = w.data['jdbc'] || {}
189
+ dbs[name] = {
190
+ 'type' => db.type,
191
+ 'url' => db.url,
192
+ 'username' => db.username,
193
+ 'password' => db.password
194
+ }
195
+ w.data['jdbc'] = dbs
196
+ w.save
197
+ puts "Saved #{name} alias:"
198
+ pp w.data
199
+ end
200
+
201
+ desc "undef <alias>", "deletes a database definition alias"
202
+ def undef(name)
203
+ w = load_wallet
204
+ dbs = w.data['jdbc'] || {}
205
+ dbs.delete(name)
206
+ w.data['jdbc'] = dbs
207
+ w.save
208
+ puts "Deleted #{name} alias:"
209
+ pp w.data
210
+ end
211
+
212
+ desc "config", "prints the kvm config"
213
+ def config
214
+ w = load_wallet
215
+ pp w.data
216
+ end
217
+
218
+ protected
219
+
220
+ # uses the db type from either the specified type or the db alias
221
+ # raises an exception if missing and default is nil
222
+ def resolve_db_type(db_config, type, default=nil)
223
+ db_config.db_type = type if type
224
+ db_config.db_type = default unless db_config.db_type
225
+ raise "Database type must be specified" unless db_config.db_type
226
+ db_config.db_type
227
+ end
228
+
229
+ def run_sql_file(db_config, file, strip_eol = false)
230
+ db = KVM::Db::JdbcAdapter.new(db_config)
231
+ statements = KVM::Db::DB_PLATFORMS[db_config.db_type].parse_sql(db, file)
232
+ # fix strange problem with test create table sql... identifier error unless eols are removed
233
+ statements.map! { |s| s.gsub(/[\r\n]+/, ' ') } if strip_eol
234
+ db.execute_update(statements)
235
+ end
236
+
237
+ # parses database command line options, consulting wallet if alias is specified
238
+ def parse_db_options(options)
239
+ # required to merge url, username, password opts into db hash
240
+ # because thor has a funky hash argument syntax that can't be used
241
+ # with jdbc urls
242
+ db = options[:db] || {}
243
+ db['url'] = options[:url]
244
+ db['username'] = options[:username]
245
+ db['password'] = options[:password]
246
+ db['type'] = options[:type]
247
+ db['jar'] = options[:jar]
248
+
249
+ raise "No database settings specified" unless db.size > 0
250
+
251
+ db_alias = db['alias']
252
+ if db_alias
253
+ w = load_wallet
254
+ db_def = nil
255
+ db_def = w.data['jdbc'][db_alias] if !w.data['jdbc'].nil?
256
+ raise "Alias not found: #{db_alias}" unless db_def
257
+ db = db.merge(db_def)
258
+ end
259
+ db_config = OpenStruct.new
260
+ db_config.alias = db['alias']
261
+ db_config.url = db['url']
262
+ db_config.username = db['username']
263
+ db_config.password = db['password']
264
+ db_config.jar = db['jar']
265
+ db_config.db_type = db['type']
266
+ db_config
267
+ end
268
+
269
+ def validate_db_options(db)
270
+ raise("Database url not specified") unless db.url
271
+ raise("Database username not specified") unless db.username
272
+ raise("Database password not specified") unless db.password
273
+ end
274
+
275
+ def load_wallet
276
+ KVM::Wallet.new(File.expand_path("~/.kvm_data"), File.expand_path("~/.ssh/id_rsa"))
277
+ end
278
+
279
+ def rice_server_bootstrap_dataset_path(version)
280
+ "#{RICE_SERVER_DB_REPO_PATH}/rice-release-#{version.gsub('\.', '-')}-br"
281
+ end
282
+
283
+ def rice_client_bootstrap_dataset_path(version)
284
+ "#{RICE_CLIENT_DB_REPO_PATH}/rice-release-#{version.gsub('\.', '-')}-br"
285
+ end
286
+ end