build-tool 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +28 -1
  3. data/Manifest.txt +91 -52
  4. data/README.txt +63 -0
  5. data/Rakefile +20 -23
  6. data/bin/build-tool +53 -0
  7. data/lib/build-tool.rb +7 -0
  8. data/lib/build-tool/GUI.rb +360 -0
  9. data/lib/build-tool/application.rb +84 -0
  10. data/lib/build-tool/build-system/autoconf.rb +60 -0
  11. data/lib/build-tool/build-system/base.rb +142 -0
  12. data/lib/build-tool/build-system/cmake.rb +119 -0
  13. data/lib/build-tool/build-system/custom.rb +115 -0
  14. data/lib/build-tool/build-system/qt.rb +113 -0
  15. data/lib/build-tool/cfg/lexer.rb +558 -0
  16. data/lib/build-tool/cfg/lexer.rex +248 -0
  17. data/lib/build-tool/cfg/lexer_base.rb +82 -0
  18. data/lib/build-tool/cfg/node.rb +94 -0
  19. data/lib/build-tool/cfg/parser.rb +871 -0
  20. data/lib/build-tool/cfg/parser.y +279 -0
  21. data/lib/build-tool/cfg/visitor.rb +471 -0
  22. data/lib/build-tool/commands.rb +639 -0
  23. data/lib/build-tool/commands/build.rb +120 -0
  24. data/lib/build-tool/commands/configure.rb +73 -0
  25. data/lib/build-tool/commands/ctags.rb +46 -0
  26. data/lib/build-tool/commands/environments.rb +29 -0
  27. data/lib/build-tool/commands/environments/list.rb +37 -0
  28. data/lib/build-tool/commands/environments/set.rb +33 -0
  29. data/lib/build-tool/commands/fetch.rb +50 -0
  30. data/lib/build-tool/commands/files.rb +73 -0
  31. data/lib/build-tool/commands/help.rb +22 -0
  32. data/lib/build-tool/commands/info.rb +48 -0
  33. data/lib/build-tool/commands/install.rb +56 -0
  34. data/lib/build-tool/commands/modules.rb +29 -0
  35. data/lib/build-tool/commands/modules/info.rb +75 -0
  36. data/lib/build-tool/commands/modules/list.rb +49 -0
  37. data/lib/build-tool/commands/modules/shell.rb +40 -0
  38. data/lib/build-tool/commands/rebase.rb +46 -0
  39. data/lib/build-tool/commands/recipes.rb +32 -0
  40. data/lib/build-tool/commands/recipes/info.rb +46 -0
  41. data/lib/build-tool/commands/recipes/install.rb +184 -0
  42. data/lib/build-tool/commands/recipes/list.rb +33 -0
  43. data/lib/build-tool/configuration.rb +115 -0
  44. data/lib/build-tool/environment.rb +119 -0
  45. data/lib/build-tool/errors.rb +9 -0
  46. data/lib/build-tool/module.rb +366 -0
  47. data/lib/build-tool/pluginbase.rb +43 -0
  48. data/lib/build-tool/recipe.rb +180 -0
  49. data/lib/build-tool/repository.rb +59 -0
  50. data/lib/build-tool/server.rb +43 -0
  51. data/lib/build-tool/singleton.rb +50 -0
  52. data/lib/build-tool/sshkey.rb +22 -0
  53. data/lib/build-tool/vcs/base.rb +105 -0
  54. data/lib/build-tool/vcs/git-svn.rb +154 -0
  55. data/lib/build-tool/vcs/git.rb +187 -0
  56. data/lib/build-tool/vcs/svn.rb +136 -0
  57. data/lib/mj/logging.rb +31 -0
  58. data/lib/mj/tools/ssh.rb +64 -0
  59. data/lib/{kde-build → mj/tools}/subprocess.rb +21 -16
  60. data/lib/mj/visitor.rb +21 -0
  61. data/recipes/kde/files/finish_installation.sh +16 -0
  62. data/recipes/kde/files/kde4.desktop +22 -0
  63. data/recipes/kde/files/xsession +89 -0
  64. data/recipes/kde/info.yaml +10 -0
  65. data/recipes/kde/recipe +585 -0
  66. data/recipes/kde/recipe-local +90 -0
  67. data/recipes/kde/settings.yaml +52 -0
  68. data/recipes/kde43/info.yaml +10 -0
  69. data/recipes/kde43/recipe +256 -0
  70. data/recipes/kde43/recipe-local +90 -0
  71. data/recipes/kde43/settings.yaml +32 -0
  72. data/recipes/kdeqt4.6/custom/qt/qtscriptgenerator/compile.sh +77 -0
  73. data/recipes/kdeqt4.6/custom/qt/qtscriptgenerator/configure.sh +70 -0
  74. data/recipes/kdeqt4.6/custom/qt/qtscriptgenerator/install.sh +39 -0
  75. data/recipes/kdeqt4.6/info.yaml +7 -0
  76. data/recipes/kdeqt4.6/recipe +155 -0
  77. data/recipes/kdeqt4.6/recipe-local +30 -0
  78. data/recipes/kdeqt4.6/settings.yaml +27 -0
  79. data/tags +745 -0
  80. data/tasks/genfiles.rake +28 -0
  81. data/tasks/rdoc.rake +34 -0
  82. data/tasks/rspec.rake +21 -0
  83. data/test.rb +28 -0
  84. data/test/commands/test_build.rb +29 -0
  85. data/test/test_build_system.rb +98 -0
  86. data/test/test_cli.rb +61 -0
  87. data/test/test_command.rb +175 -0
  88. data/test/test_configuration_parser.rb +542 -0
  89. data/test/test_environment.rb +82 -0
  90. data/test/test_helper.rb +39 -7
  91. data/test/test_module.rb +158 -0
  92. data/test/test_repository.rb +75 -0
  93. data/test/test_singleton.rb +51 -0
  94. data/test/test_ssh_key.rb +14 -0
  95. data/test/test_svn_parser.rb +28 -0
  96. data/test/test_vcs.rb +33 -0
  97. metadata +139 -90
  98. metadata.gz.sig +0 -0
  99. data/PostInstall.txt +0 -3
  100. data/TODO +0 -2
  101. data/bin/kde-build.rb +0 -21
  102. data/config/website.yml +0 -2
  103. data/config/website.yml.sample +0 -2
  104. data/lib/kde-build.rb +0 -18
  105. data/lib/kde-build/application.rb +0 -270
  106. data/lib/kde-build/build_system.rb +0 -28
  107. data/lib/kde-build/build_system/autoconf.rb +0 -108
  108. data/lib/kde-build/build_system/base.rb +0 -139
  109. data/lib/kde-build/build_system/cmake.rb +0 -94
  110. data/lib/kde-build/build_system/qtcopy.rb +0 -127
  111. data/lib/kde-build/command.rb +0 -42
  112. data/lib/kde-build/command/build.rb +0 -106
  113. data/lib/kde-build/command/compile.rb +0 -39
  114. data/lib/kde-build/command/configure.rb +0 -48
  115. data/lib/kde-build/command/ctags.rb +0 -41
  116. data/lib/kde-build/command/fetch.rb +0 -33
  117. data/lib/kde-build/command/help.rb +0 -71
  118. data/lib/kde-build/command/info.rb +0 -45
  119. data/lib/kde-build/command/install.rb +0 -39
  120. data/lib/kde-build/command/module_based.rb +0 -44
  121. data/lib/kde-build/command/rebase.rb +0 -50
  122. data/lib/kde-build/command/version.rb +0 -43
  123. data/lib/kde-build/configuration.rb +0 -209
  124. data/lib/kde-build/exception.rb +0 -6
  125. data/lib/kde-build/metaaid.rb +0 -18
  126. data/lib/kde-build/module.rb +0 -227
  127. data/lib/kde-build/module_configuration.rb +0 -107
  128. data/lib/kde-build/moduleregistry.rb +0 -85
  129. data/lib/kde-build/tools/ctags.rb +0 -59
  130. data/lib/kde-build/tools/logging.rb +0 -49
  131. data/lib/kde-build/tools/make.rb +0 -58
  132. data/lib/kde-build/tools/ssh.rb +0 -47
  133. data/lib/kde-build/vcs.rb +0 -28
  134. data/lib/kde-build/vcs/base.rb +0 -85
  135. data/lib/kde-build/vcs/git-svn.rb +0 -139
  136. data/lib/kde-build/vcs/git.rb +0 -121
  137. data/lib/kde-build/vcs/svn.rb +0 -102
  138. data/script/console +0 -10
  139. data/script/destroy +0 -14
  140. data/script/generate +0 -14
  141. data/script/txt2html +0 -71
  142. data/test.yaml.tmpl +0 -632
  143. data/test/test_kde-build.rb +0 -11
  144. data/test/test_vcs_svn.rb +0 -44
  145. data/website/index.html +0 -84
  146. data/website/index.txt +0 -59
  147. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  148. data/website/stylesheets/screen.css +0 -159
  149. data/website/template.html.erb +0 -50
Binary file
@@ -1,4 +1,31 @@
1
- == 0.0.1 2009-06-14
1
+ == 0.1.0 2009-10-08
2
+ * Major rewrite
3
+ * Substitute the yaml format for a tailormade file format with
4
+ handmade lexer and parser
5
+ * This release is a major backstep in case of functionality but it is
6
+ usable for everyday use.
7
+
8
+ == 0.0.3 2009-07-07
9
+ * New commands:
10
+ * ctags - Create tags file for module(s)
11
+ * compile - Just compile the module(s)
12
+ * configure - Just configure the module(s)
13
+ * install - install the module(s)
14
+ * fetch - Only fetch remote changes. Do not update only if vcs supports
15
+ it.
16
+ * rebase - Rebase the checkout against already fetched remote changes.
17
+ This command will not fetch.
18
+ * info - Print out some usefule information about a module.
19
+ * Example Config File
20
+ * Set PKG_CONFIG_PATH
21
+ * Fix lensfun receipt
22
+ * Fix some packages and orders
23
+ * General Bugfixing
24
+ * Fix subversion repository initialization.
25
+ * Improve the documentation strings
26
+
27
+
28
+ == 0.0.2 2009-06-14
2
29
  * Improved example configuration file
3
30
  * Checkout the 4.5 version by default. Not trunk.
4
31
  * Some bugfixes
@@ -1,56 +1,95 @@
1
1
  History.txt
2
2
  Manifest.txt
3
- PostInstall.txt
3
+ README.txt
4
4
  Rakefile
5
- TODO
6
- bin/kde-build.rb
7
- config/website.yml
8
- config/website.yml.sample
9
- lib/kde-build.rb
10
- lib/kde-build/application.rb
11
- lib/kde-build/build_system.rb
12
- lib/kde-build/build_system/autoconf.rb
13
- lib/kde-build/build_system/base.rb
14
- lib/kde-build/build_system/cmake.rb
15
- lib/kde-build/build_system/qtcopy.rb
16
- lib/kde-build/command.rb
17
- lib/kde-build/command/build.rb
18
- lib/kde-build/command/compile.rb
19
- lib/kde-build/command/configure.rb
20
- lib/kde-build/command/ctags.rb
21
- lib/kde-build/command/fetch.rb
22
- lib/kde-build/command/help.rb
23
- lib/kde-build/command/info.rb
24
- lib/kde-build/command/install.rb
25
- lib/kde-build/command/module_based.rb
26
- lib/kde-build/command/rebase.rb
27
- lib/kde-build/command/version.rb
28
- lib/kde-build/configuration.rb
29
- lib/kde-build/exception.rb
30
- lib/kde-build/metaaid.rb
31
- lib/kde-build/module.rb
32
- lib/kde-build/module_configuration.rb
33
- lib/kde-build/moduleregistry.rb
34
- lib/kde-build/subprocess.rb
35
- lib/kde-build/tools/ctags.rb
36
- lib/kde-build/tools/logging.rb
37
- lib/kde-build/tools/make.rb
38
- lib/kde-build/tools/ssh.rb
39
- lib/kde-build/vcs.rb
40
- lib/kde-build/vcs/base.rb
41
- lib/kde-build/vcs/git-svn.rb
42
- lib/kde-build/vcs/git.rb
43
- lib/kde-build/vcs/svn.rb
44
- script/console
45
- script/destroy
46
- script/generate
47
- script/txt2html
48
- test.yaml.tmpl
5
+ bin/build-tool
6
+ lib/build-tool.rb
7
+ lib/build-tool/GUI.rb
8
+ lib/build-tool/application.rb
9
+ lib/build-tool/build-system/autoconf.rb
10
+ lib/build-tool/build-system/base.rb
11
+ lib/build-tool/build-system/cmake.rb
12
+ lib/build-tool/build-system/custom.rb
13
+ lib/build-tool/build-system/qt.rb
14
+ lib/build-tool/cfg/lexer.rb
15
+ lib/build-tool/cfg/lexer.rex
16
+ lib/build-tool/cfg/lexer_base.rb
17
+ lib/build-tool/cfg/node.rb
18
+ lib/build-tool/cfg/parser.rb
19
+ lib/build-tool/cfg/parser.y
20
+ lib/build-tool/cfg/visitor.rb
21
+ lib/build-tool/commands.rb
22
+ lib/build-tool/commands/build.rb
23
+ lib/build-tool/commands/configure.rb
24
+ lib/build-tool/commands/ctags.rb
25
+ lib/build-tool/commands/environments.rb
26
+ lib/build-tool/commands/environments/list.rb
27
+ lib/build-tool/commands/environments/set.rb
28
+ lib/build-tool/commands/fetch.rb
29
+ lib/build-tool/commands/files.rb
30
+ lib/build-tool/commands/help.rb
31
+ lib/build-tool/commands/info.rb
32
+ lib/build-tool/commands/install.rb
33
+ lib/build-tool/commands/modules.rb
34
+ lib/build-tool/commands/modules/info.rb
35
+ lib/build-tool/commands/modules/list.rb
36
+ lib/build-tool/commands/modules/shell.rb
37
+ lib/build-tool/commands/rebase.rb
38
+ lib/build-tool/commands/recipes.rb
39
+ lib/build-tool/commands/recipes/info.rb
40
+ lib/build-tool/commands/recipes/install.rb
41
+ lib/build-tool/commands/recipes/list.rb
42
+ lib/build-tool/configuration.rb
43
+ lib/build-tool/environment.rb
44
+ lib/build-tool/errors.rb
45
+ lib/build-tool/module.rb
46
+ lib/build-tool/pluginbase.rb
47
+ lib/build-tool/recipe.rb
48
+ lib/build-tool/repository.rb
49
+ lib/build-tool/server.rb
50
+ lib/build-tool/singleton.rb
51
+ lib/build-tool/sshkey.rb
52
+ lib/build-tool/vcs/base.rb
53
+ lib/build-tool/vcs/git-svn.rb
54
+ lib/build-tool/vcs/git.rb
55
+ lib/build-tool/vcs/svn.rb
56
+ lib/mj/logging.rb
57
+ lib/mj/tools/ssh.rb
58
+ lib/mj/tools/subprocess.rb
59
+ lib/mj/visitor.rb
60
+ recipes/kde/files/finish_installation.sh
61
+ recipes/kde/files/kde4.desktop
62
+ recipes/kde/files/xsession
63
+ recipes/kde/info.yaml
64
+ recipes/kde/recipe
65
+ recipes/kde/recipe-local
66
+ recipes/kde/settings.yaml
67
+ recipes/kde43/info.yaml
68
+ recipes/kde43/recipe
69
+ recipes/kde43/recipe-local
70
+ recipes/kde43/settings.yaml
71
+ recipes/kdeqt4.6/custom/qt/qtscriptgenerator/compile.sh
72
+ recipes/kdeqt4.6/custom/qt/qtscriptgenerator/configure.sh
73
+ recipes/kdeqt4.6/custom/qt/qtscriptgenerator/install.sh
74
+ recipes/kdeqt4.6/info.yaml
75
+ recipes/kdeqt4.6/recipe
76
+ recipes/kdeqt4.6/recipe-local
77
+ recipes/kdeqt4.6/settings.yaml
78
+ tags
79
+ tasks/genfiles.rake
80
+ tasks/rdoc.rake
81
+ tasks/rspec.rake
82
+ test.rb
83
+ test/commands/test_build.rb
84
+ test/test_build_system.rb
85
+ test/test_cli.rb
86
+ test/test_command.rb
87
+ test/test_configuration_parser.rb
88
+ test/test_environment.rb
49
89
  test/test_helper.rb
50
- test/test_kde-build.rb
51
- test/test_vcs_svn.rb
52
- website/index.html
53
- website/index.txt
54
- website/javascripts/rounded_corners_lite.inc.js
55
- website/stylesheets/screen.css
56
- website/template.html.erb
90
+ test/test_module.rb
91
+ test/test_repository.rb
92
+ test/test_singleton.rb
93
+ test/test_ssh_key.rb
94
+ test/test_svn_parser.rb
95
+ test/test_vcs.rb
@@ -0,0 +1,63 @@
1
+ = build-tool
2
+
3
+ * http://build-tool.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ This project is inspired by kdesvn-build[http://kdesvn-build.kde.org/].
8
+
9
+ It help in building and maintaining a development environment. It downloads
10
+ and configures sources and updates them later.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ * This is major rewrite version. Use at your own risk.
15
+
16
+ The tool uses recipes to build software from scratch. It does
17
+ - Check out the sources from the repository (git, git-svn, svn).
18
+ - Update the sources.
19
+ - Set the build environment.
20
+ - Configure (qt, cmake, custom)
21
+ - Build
22
+ - Install
23
+
24
+ It's main purpose is supporting me developing kde while having a
25
+ complete kde workspace from trunk. I would like to have reliable and
26
+ reproducable build so i'm sure the code is the problem and not my environment
27
+ if something fails to build.
28
+
29
+ Additional features are:
30
+ - Open a shell with the environment used to build the sources.
31
+ - Provide sample xessions and kde.desktop files to use the result.
32
+
33
+ Currently the following recipes are provided:
34
+ - Qt 4.6 (either from the kde-qt or qtsoftware repositories.
35
+ - KDE 4.3
36
+ - KDE Trunk
37
+
38
+ == SYNOPSIS:
39
+
40
+ # Install a recipe
41
+ > build-tool recipe install kde
42
+ ...
43
+ # Adapt the configuration
44
+ > vim ~/.build-tool/kde.yaml
45
+
46
+ # Build kdesupport/ modules and the base kde workspace
47
+ kde-build build kdesupport/ KDE/
48
+
49
+ == REQUIREMENTS:
50
+
51
+ * logging > 1.2.2
52
+ * hoe > 2.3.3
53
+
54
+ == INSTALL:
55
+
56
+ gem install build-tool
57
+
58
+ == LICENSE:
59
+
60
+ (The GPL LICENSE)
61
+
62
+ Copyright (c) 2009 Michael Jansen
63
+
data/Rakefile CHANGED
@@ -1,32 +1,29 @@
1
- require 'rubygems' unless ENV['NO_RUBYGEMS']
2
- %w[rake rake/clean fileutils newgem rubigen hoe].each { |f| require f }
3
- require File.dirname(__FILE__) + '/lib/kde-build'
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require 'fileutils'
6
+ require './lib/build-tool'
4
7
 
5
8
  # Generate all the Rake tasks
6
9
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
- Hoe.spec 'build-tool' do |p|
8
- p.developer( 'Michael Jansen', 'kde@michael-jansen.biz' )
9
- p.name = "build-tool"
10
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
11
- p.post_install_message = 'PostInstall.txt'
12
- p.rubyforge_name = p.name
13
- p.extra_deps = [
14
- ['cmdparse','>= 2.0.2'],
15
- ['log4r','>= 1.0.5'],
16
- ]
17
- p.extra_dev_deps = [
18
- ['newgem', ">= #{::Newgem::VERSION}"],
19
- ['hoe', ">= 2.3.0"]
20
- ]
10
+ Hoe.spec 'build-tool' do
11
+ self.developer 'Michael Jansen', 'info@michael-jansen.biz'
12
+ self.post_install_message = <<-EOS
13
+ To start with build-tool try the following commands:
14
+ > build-tool recipe list
15
+ > build-tool recipe install <recipe>
16
+ EOS
17
+ self.rubyforge_name = self.name
21
18
 
22
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
23
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
24
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
25
- p.rsync_args = '-av --delete --ignore-errors'
19
+ self.extra_deps = [
20
+ ['logging','>= 1.2.2'],
21
+ ['hoe', ">= 2.3.3"], # -> hoe, rubigen
22
+ ]
26
23
  end
27
24
 
28
- require 'newgem/tasks' # load /tasks/*.rake
29
25
  Dir['tasks/**/*.rake'].each { |t| load t }
30
26
 
31
- # TODO - want other tests/tasks run by default? Add them to the list
27
+ # Want other tests/tasks run by default
28
+ # remove_task :default
32
29
  # task :default => [:spec, :features]
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Michael Jansen on 2009-8-31.
4
+ # Copyright (c) 2009. All rights reserved.
5
+
6
+ require 'pathname'
7
+ require 'rubygems'
8
+ require 'logging'
9
+
10
+ # libs relative to the link target
11
+ if File.symlink?(__FILE__)
12
+ root_directory = File.dirname(File.readlink(__FILE__))
13
+ else
14
+ root_directory = File.dirname(__FILE__)
15
+ end
16
+ root_directory = Pathname.new( root_directory ).join( '..' )
17
+ require File.expand_path( root_directory + "lib/build-tool")
18
+ require 'mj/logging'
19
+
20
+ #
21
+ # CONFIGURE LOGGING
22
+ #
23
+ Logging.init :debug, :trace, :verbose, :info, :warn, :error
24
+ include Logging.globally
25
+ Logging.logger.root.level = :debug
26
+ # Special case for the configurationParser. It is very verbose if active.
27
+ Logging.logger['BuildTool::Cfg::Parser'].level = :info
28
+ Logging.logger.root.appenders = Logging.appenders.stdout(
29
+ :layout => MJ::Logging::BasicLayout.new(),
30
+ :level => :info)
31
+
32
+ # if the name we were called with is a symbolic link we have to search for our
33
+
34
+
35
+ require "build-tool/application"
36
+ require "build-tool/errors"
37
+
38
+ begin
39
+ app = BuildTool::Application.new( $0, root_directory )
40
+ rc = app.execute( ARGV )
41
+ rescue Interrupt => e
42
+ logger.info "User interrupt!"
43
+ rc = 0
44
+ rescue BuildTool::Error => e
45
+ logger.error e.message
46
+ logger.verbose e.backtrace.join("\n")
47
+ rc = -1
48
+ rescue Exception => e
49
+ logger.error e
50
+ rc = -1
51
+ end
52
+
53
+ exit rc
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module BuildTool
5
+ VERSION = '0.1.0'
6
+ end
7
+
@@ -0,0 +1,360 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ module Gem
8
+
9
+ ##
10
+ # Module that defines the default UserInteraction. Any class including this
11
+ # module will have access to the +ui+ method that returns the default UI.
12
+
13
+ module DefaultUserInteraction
14
+
15
+ ##
16
+ # The default UI is a class variable of the singleton class for this
17
+ # module.
18
+
19
+ @ui = nil
20
+
21
+ ##
22
+ # Return the default UI.
23
+
24
+ def self.ui
25
+ @ui ||= Gem::ConsoleUI.new
26
+ end
27
+
28
+ ##
29
+ # Set the default UI. If the default UI is never explicitly set, a simple
30
+ # console based UserInteraction will be used automatically.
31
+
32
+ def self.ui=(new_ui)
33
+ @ui = new_ui
34
+ end
35
+
36
+ ##
37
+ # Use +new_ui+ for the duration of +block+.
38
+
39
+ def self.use_ui(new_ui)
40
+ old_ui = @ui
41
+ @ui = new_ui
42
+ yield
43
+ ensure
44
+ @ui = old_ui
45
+ end
46
+
47
+ ##
48
+ # See DefaultUserInteraction::ui
49
+
50
+ def ui
51
+ DefaultUserInteraction.ui
52
+ end
53
+
54
+ ##
55
+ # See DefaultUserInteraction::ui=
56
+
57
+ def ui=(new_ui)
58
+ DefaultUserInteraction.ui = new_ui
59
+ end
60
+
61
+ ##
62
+ # See DefaultUserInteraction::use_ui
63
+
64
+ def use_ui(new_ui, &block)
65
+ DefaultUserInteraction.use_ui(new_ui, &block)
66
+ end
67
+
68
+ end
69
+
70
+ ##
71
+ # Make the default UI accessable without the "ui." prefix. Classes
72
+ # including this module may use the interaction methods on the default UI
73
+ # directly. Classes may also reference the ui and ui= methods.
74
+ #
75
+ # Example:
76
+ #
77
+ # class X
78
+ # include Gem::UserInteraction
79
+ #
80
+ # def get_answer
81
+ # n = ask("What is the meaning of life?")
82
+ # end
83
+ # end
84
+
85
+ module UserInteraction
86
+
87
+ include DefaultUserInteraction
88
+
89
+ [:alert,
90
+ :alert_error,
91
+ :alert_warning,
92
+ :ask,
93
+ :ask_yes_no,
94
+ :choose_from_list,
95
+ :say,
96
+ :terminate_interaction ].each do |methname|
97
+ class_eval %{
98
+ def #{methname}(*args)
99
+ ui.#{methname}(*args)
100
+ end
101
+ }, __FILE__, __LINE__
102
+ end
103
+ end
104
+
105
+ ##
106
+ # StreamUI implements a simple stream based user interface.
107
+
108
+ class StreamUI
109
+
110
+ attr_reader :ins, :outs, :errs
111
+
112
+ def initialize(in_stream, out_stream, err_stream=STDERR)
113
+ @ins = in_stream
114
+ @outs = out_stream
115
+ @errs = err_stream
116
+ end
117
+
118
+ ##
119
+ # Choose from a list of options. +question+ is a prompt displayed above
120
+ # the list. +list+ is a list of option strings. Returns the pair
121
+ # [option_name, option_index].
122
+
123
+ def choose_from_list(question, list)
124
+ @outs.puts question
125
+
126
+ list.each_with_index do |item, index|
127
+ @outs.puts " #{index+1}. #{item}"
128
+ end
129
+
130
+ @outs.print "> "
131
+ @outs.flush
132
+
133
+ result = @ins.gets
134
+
135
+ return nil, nil unless result
136
+
137
+ result = result.strip.to_i - 1
138
+ return list[result], result
139
+ end
140
+
141
+ ##
142
+ # Ask a question. Returns a true for yes, false for no. If not connected
143
+ # to a tty, raises an exception if default is nil, otherwise returns
144
+ # default.
145
+
146
+ def ask_yes_no(question, default=nil)
147
+ unless @ins.tty? then
148
+ if default.nil? then
149
+ raise Gem::OperationNotSupportedError,
150
+ "Not connected to a tty and no default specified"
151
+ else
152
+ return default
153
+ end
154
+ end
155
+
156
+ qstr = case default
157
+ when nil
158
+ 'yn'
159
+ when true
160
+ 'Yn'
161
+ else
162
+ 'yN'
163
+ end
164
+
165
+ result = nil
166
+
167
+ while result.nil?
168
+ result = ask("#{question} [#{qstr}]")
169
+ result = case result
170
+ when /^[Yy].*/
171
+ true
172
+ when /^[Nn].*/
173
+ false
174
+ when /^$/
175
+ default
176
+ else
177
+ nil
178
+ end
179
+ end
180
+
181
+ return result
182
+ end
183
+
184
+ ##
185
+ # Ask a question. Returns an answer if connected to a tty, nil otherwise.
186
+
187
+ def ask(question)
188
+ return nil if not @ins.tty?
189
+
190
+ @outs.print(question + " ")
191
+ @outs.flush
192
+
193
+ result = @ins.gets
194
+ result.chomp! if result
195
+ result
196
+ end
197
+
198
+ ##
199
+ # Display a statement.
200
+
201
+ def say(statement="")
202
+ @outs.puts statement
203
+ end
204
+
205
+ ##
206
+ # Display an informational alert. Will ask +question+ if it is not nil.
207
+
208
+ def alert(statement, question=nil)
209
+ @outs.puts "INFO: #{statement}"
210
+ ask(question) if question
211
+ end
212
+
213
+ ##
214
+ # Display a warning in a location expected to get error messages. Will
215
+ # ask +question+ if it is not nil.
216
+
217
+ def alert_warning(statement, question=nil)
218
+ @errs.puts "WARNING: #{statement}"
219
+ ask(question) if question
220
+ end
221
+
222
+ ##
223
+ # Display an error message in a location expected to get error messages.
224
+ # Will ask +question+ if it is not nil.
225
+
226
+ def alert_error(statement, question=nil)
227
+ @errs.puts "ERROR: #{statement}"
228
+ ask(question) if question
229
+ end
230
+
231
+ ##
232
+ # Terminate the application with exit code +status+, running any exit
233
+ # handlers that might have been defined.
234
+
235
+ def terminate_interaction(status = 0)
236
+ raise Gem::SystemExitException, status
237
+ end
238
+
239
+ ##
240
+ # Return a progress reporter object chosen from the current verbosity.
241
+
242
+ def progress_reporter(*args)
243
+ case Gem.configuration.verbose
244
+ when nil, false
245
+ SilentProgressReporter.new(@outs, *args)
246
+ when true
247
+ SimpleProgressReporter.new(@outs, *args)
248
+ else
249
+ VerboseProgressReporter.new(@outs, *args)
250
+ end
251
+ end
252
+
253
+ ##
254
+ # An absolutely silent progress reporter.
255
+
256
+ class SilentProgressReporter
257
+ attr_reader :count
258
+
259
+ def initialize(out_stream, size, initial_message, terminal_message = nil)
260
+ end
261
+
262
+ def updated(message)
263
+ end
264
+
265
+ def done
266
+ end
267
+ end
268
+
269
+ ##
270
+ # A basic dotted progress reporter.
271
+
272
+ class SimpleProgressReporter
273
+ include DefaultUserInteraction
274
+
275
+ attr_reader :count
276
+
277
+ def initialize(out_stream, size, initial_message,
278
+ terminal_message = "complete")
279
+ @out = out_stream
280
+ @total = size
281
+ @count = 0
282
+ @terminal_message = terminal_message
283
+
284
+ @out.puts initial_message
285
+ end
286
+
287
+ ##
288
+ # Prints out a dot and ignores +message+.
289
+
290
+ def updated(message)
291
+ @count += 1
292
+ @out.print "."
293
+ @out.flush
294
+ end
295
+
296
+ ##
297
+ # Prints out the terminal message.
298
+
299
+ def done
300
+ @out.puts "\n#{@terminal_message}"
301
+ end
302
+
303
+ end
304
+
305
+ ##
306
+ # A progress reporter that prints out messages about the current progress.
307
+
308
+ class VerboseProgressReporter
309
+ include DefaultUserInteraction
310
+
311
+ attr_reader :count
312
+
313
+ def initialize(out_stream, size, initial_message,
314
+ terminal_message = 'complete')
315
+ @out = out_stream
316
+ @total = size
317
+ @count = 0
318
+ @terminal_message = terminal_message
319
+
320
+ @out.puts initial_message
321
+ end
322
+
323
+ ##
324
+ # Prints out the position relative to the total and the +message+.
325
+
326
+ def updated(message)
327
+ @count += 1
328
+ @out.puts "#{@count}/#{@total}: #{message}"
329
+ end
330
+
331
+ ##
332
+ # Prints out the terminal message.
333
+
334
+ def done
335
+ @out.puts @terminal_message
336
+ end
337
+ end
338
+ end
339
+
340
+ ##
341
+ # Subclass of StreamUI that instantiates the user interaction using STDIN,
342
+ # STDOUT, and STDERR.
343
+
344
+ class ConsoleUI < StreamUI
345
+ def initialize
346
+ super(STDIN, STDOUT, STDERR)
347
+ end
348
+ end
349
+
350
+ ##
351
+ # SilentUI is a UI choice that is absolutely silent.
352
+
353
+ class SilentUI
354
+ def method_missing(sym, *args, &block)
355
+ self
356
+ end
357
+ end
358
+
359
+ end
360
+