methadone-rehab 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/CHANGES.md +66 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +201 -0
  9. data/README.rdoc +179 -0
  10. data/Rakefile +98 -0
  11. data/TODO.md +3 -0
  12. data/bin/methadone +157 -0
  13. data/features/bootstrap.feature +169 -0
  14. data/features/license.feature +43 -0
  15. data/features/multilevel_commands.feature +125 -0
  16. data/features/readme.feature +26 -0
  17. data/features/rspec_support.feature +27 -0
  18. data/features/step_definitions/bootstrap_steps.rb +47 -0
  19. data/features/step_definitions/license_steps.rb +30 -0
  20. data/features/step_definitions/readme_steps.rb +26 -0
  21. data/features/step_definitions/version_steps.rb +4 -0
  22. data/features/support/env.rb +26 -0
  23. data/features/version.feature +17 -0
  24. data/lib/methadone.rb +15 -0
  25. data/lib/methadone/argv_parser.rb +50 -0
  26. data/lib/methadone/cli.rb +124 -0
  27. data/lib/methadone/cli_logger.rb +133 -0
  28. data/lib/methadone/cli_logging.rb +138 -0
  29. data/lib/methadone/cucumber.rb +174 -0
  30. data/lib/methadone/error.rb +32 -0
  31. data/lib/methadone/execution_strategy/base.rb +34 -0
  32. data/lib/methadone/execution_strategy/jvm.rb +37 -0
  33. data/lib/methadone/execution_strategy/mri.rb +16 -0
  34. data/lib/methadone/execution_strategy/open_3.rb +16 -0
  35. data/lib/methadone/execution_strategy/open_4.rb +22 -0
  36. data/lib/methadone/execution_strategy/rbx_open_4.rb +12 -0
  37. data/lib/methadone/exit_now.rb +40 -0
  38. data/lib/methadone/main.rb +1039 -0
  39. data/lib/methadone/process_status.rb +45 -0
  40. data/lib/methadone/sh.rb +223 -0
  41. data/lib/methadone/version.rb +3 -0
  42. data/methadone-rehab.gemspec +32 -0
  43. data/templates/full/.gitignore.erb +4 -0
  44. data/templates/full/README.rdoc.erb +25 -0
  45. data/templates/full/Rakefile.erb +74 -0
  46. data/templates/full/_license_head.txt.erb +2 -0
  47. data/templates/full/apache_LICENSE.txt.erb +203 -0
  48. data/templates/full/bin/executable.erb +47 -0
  49. data/templates/full/custom_LICENSE.txt.erb +0 -0
  50. data/templates/full/features/executable.feature.erb +13 -0
  51. data/templates/full/features/step_definitions/executable_steps.rb.erb +1 -0
  52. data/templates/full/features/support/env.rb.erb +16 -0
  53. data/templates/full/gplv2_LICENSE.txt.erb +14 -0
  54. data/templates/full/gplv3_LICENSE.txt.erb +15 -0
  55. data/templates/full/mit_LICENSE.txt.erb +7 -0
  56. data/templates/multicommand/bin/executable.erb +52 -0
  57. data/templates/multicommand/lib/command.rb.erb +40 -0
  58. data/templates/multicommand/lib/commands.rb.erb +7 -0
  59. data/templates/rspec/spec/something_spec.rb.erb +5 -0
  60. data/templates/test_unit/test/tc_something.rb.erb +7 -0
  61. data/test/base_test.rb +20 -0
  62. data/test/command_for_tests.sh +7 -0
  63. data/test/execution_strategy/test_base.rb +24 -0
  64. data/test/execution_strategy/test_jvm.rb +77 -0
  65. data/test/execution_strategy/test_mri.rb +32 -0
  66. data/test/execution_strategy/test_open_3.rb +70 -0
  67. data/test/execution_strategy/test_open_4.rb +86 -0
  68. data/test/execution_strategy/test_rbx_open_4.rb +25 -0
  69. data/test/test_cli_logger.rb +219 -0
  70. data/test/test_cli_logging.rb +243 -0
  71. data/test/test_exit_now.rb +37 -0
  72. data/test/test_main.rb +1213 -0
  73. data/test/test_multi.rb +405 -0
  74. data/test/test_sh.rb +404 -0
  75. metadata +321 -0
@@ -0,0 +1,45 @@
1
+ module Methadone
2
+ # <b>Methadone Internal - treat as private</b>
3
+ #
4
+ # A wrapper/enhancement of Process::Status that handles coersion and expected
5
+ # nonzero statuses
6
+ class ProcessStatus
7
+
8
+ # The exit status, either directly from a Process::Status or derived from a non-Int value.
9
+ attr_reader :exitstatus
10
+
11
+ # Create the ProcessStatus with the given status.
12
+ #
13
+ # status:: if this responds to #exitstatus, that method is used to extract the exit code. If it's
14
+ # and Int, that is used as the exit code. Otherwise,
15
+ # it's truthiness is used: 0 for truthy, 1 for falsey.
16
+ # expected:: an Int or Array of Int representing the expected exit status, other than zero,
17
+ # that represent "success".
18
+ def initialize(status,expected)
19
+ @exitstatus = derive_exitstatus(status)
20
+ @success = ([0] + Array(expected)).include?(@exitstatus)
21
+ end
22
+
23
+ # True if the exit status was a successul (i.e. expected) one.
24
+ def success?
25
+ @success
26
+ end
27
+
28
+ private
29
+
30
+ def derive_exitstatus(status)
31
+ status = if status.respond_to? :exitstatus
32
+ status.exitstatus
33
+ else
34
+ status
35
+ end
36
+ if status.kind_of? Fixnum
37
+ status
38
+ elsif status
39
+ 0
40
+ else
41
+ 1
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,223 @@
1
+ if RUBY_PLATFORM == 'java'
2
+ require 'java'
3
+ require 'ostruct'
4
+ elsif RUBY_VERSION =~ /^1.8/
5
+ begin
6
+ require 'open4'
7
+ rescue LoadError
8
+ warn "For Ruby #{RUBY_VERSION}, the open4 library must be installed or SH won't work"
9
+ end
10
+ else
11
+ require 'open3'
12
+ end
13
+
14
+ require 'methadone/process_status'
15
+
16
+ module Methadone
17
+ # Module with various helper methods for executing external commands.
18
+ # In most cases, you can use #sh to run commands and have decent logging
19
+ # done. You will likely use this in a class that also mixes-in
20
+ # Methadone::CLILogging (remembering that Methadone::Main mixes this in for you).
21
+ # If you <b>don't</b>, you must provide a logger via #set_sh_logger.
22
+ #
23
+ # == Examples
24
+ #
25
+ # include Methadone::SH
26
+ #
27
+ # sh 'cp foo.txt /tmp'
28
+ # # => logs the command to DEBUG, executes the command, logs its output to DEBUG and its
29
+ # # error output to WARN, returns 0
30
+ #
31
+ # sh 'cp non_existent_file.txt /nowhere_good'
32
+ # # => logs the command to DEBUG, executes the command, logs its output to INFO and
33
+ # # its error output to WARN, returns the nonzero exit status of the underlying command
34
+ #
35
+ # sh! 'cp non_existent_file.txt /nowhere_good'
36
+ # # => same as above, EXCEPT, raises a Methadone::FailedCommandError
37
+ #
38
+ # sh 'cp foo.txt /tmp' do
39
+ # # Behaves exactly as before, but this block is called after
40
+ # end
41
+ #
42
+ # sh 'cp non_existent_file.txt /nowhere_good' do
43
+ # # This block isn't called, since the command failed
44
+ # end
45
+ #
46
+ # sh 'ls -l /tmp/' do |stdout|
47
+ # # stdout contains the output of the command
48
+ # end
49
+ # sh 'ls -l /tmp/ /non_existent_dir' do |stdout,stderr|
50
+ # # stdout contains the output of the command,
51
+ # # stderr contains the standard error output.
52
+ # end
53
+ #
54
+ # == Handling process execution
55
+ #
56
+ # In order to work on as many Rubies as possible, this class defers the actual execution
57
+ # to an execution strategy. See #set_execution_strategy if you think you'd like to override
58
+ # that, or just want to know how it works.
59
+ #
60
+ # == More complex execution and subprocess management
61
+ #
62
+ # This is not intended to be a complete replacement for Open3 or an enhanced means of managing subprocesses.
63
+ # This is to make it easy for you to shell-out to external commands and have your app be robust and
64
+ # easy to maintain.
65
+ module SH
66
+ def self.included(k)
67
+ k.extend(self)
68
+ end
69
+ # Run a shell command, capturing and logging its output.
70
+ # If the command completed successfully, it's output is logged at DEBUG.
71
+ # If not, its output as logged at INFO. In either case, its
72
+ # error output is logged at WARN.
73
+ #
74
+ # command:: the command to run as a String or Array of String. The String form is simplest, but
75
+ # is open to injection. If you need to execute a command that is assembled from some portion
76
+ # of user input, consider using an Array of String. This form prevents tokenization that occurs
77
+ # in the String form. The first element is the command to execute,
78
+ # and the remainder are the arguments. See Methadone::ExecutionStrategy::Base for more info.
79
+ # options:: options to control the call. Currently responds to:
80
+ # +:expected+:: an Int or Array of Int representing error codes, <b>in addition to 0</b>, that are
81
+ # expected and therefore constitute success. Useful for commands that don't use
82
+ # exit codes the way you'd like
83
+ # block:: if provided, will be called if the command exited nonzero. The block may take 0, 1, 2, or 3 arguments.
84
+ # The arguments provided are the standard output as a string, standard error as a string, and
85
+ # the exitstatus as an Int.
86
+ # You should be safe to pass in a lambda instead of a block, as long as your
87
+ # lambda doesn't take more than three arguments
88
+ #
89
+ # Example
90
+ #
91
+ # sh "cp foo /tmp"
92
+ # sh "ls /tmp" do |stdout|
93
+ # # stdout contains the output of ls /tmp
94
+ # end
95
+ # sh "ls -l /tmp foobar" do |stdout,stderr|
96
+ # # ...
97
+ # end
98
+ #
99
+ # Returns the exit status of the command. Note that if the command doesn't exist, this returns 127.
100
+ def sh(command,options={},&block)
101
+ sh_logger.debug("Executing '#{command}'")
102
+
103
+ stdout,stderr,status = execution_strategy.run_command(command)
104
+ process_status = Methadone::ProcessStatus.new(status,options[:expected])
105
+
106
+ sh_logger.warn("stderr output of '#{command}': #{stderr}") unless stderr.strip.length == 0
107
+
108
+ if process_status.success?
109
+ sh_logger.debug("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
110
+ call_block(block,stdout,stderr,process_status.exitstatus) unless block.nil?
111
+ else
112
+ sh_logger.info("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
113
+ sh_logger.warn("Error running '#{command}'")
114
+ end
115
+
116
+ process_status.exitstatus
117
+ rescue *exception_meaning_command_not_found => ex
118
+ sh_logger.error("Error running '#{command}': #{ex.message}")
119
+ 127
120
+ end
121
+
122
+ # Run a command, throwing an exception if the command exited nonzero.
123
+ # Otherwise, behaves exactly like #sh.
124
+ #
125
+ # options:: options hash, responding to:
126
+ # <tt>:expected</tt>:: same as for #sh
127
+ # <tt>:on_fail</tt>:: a custom error message. This allows you to have your
128
+ # app exit on shell command failures, but customize the error
129
+ # message that they see.
130
+ #
131
+ # Raises Methadone::FailedCommandError if the command exited nonzero.
132
+ #
133
+ # Examples:
134
+ #
135
+ # sh!("rsync foo bar")
136
+ # # => if command fails, app exits and user sees: "error: Command 'rsync foo bar' exited 12"
137
+ # sh!("rsync foo bar", :on_fail => "Couldn't rsync, check log for details")
138
+ # # => if command fails, app exits and user sees: "error: Couldn't rsync, check log for details
139
+ def sh!(command,options={},&block)
140
+ sh(command,options,&block).tap do |exitstatus|
141
+ process_status = Methadone::ProcessStatus.new(exitstatus,options[:expected])
142
+ unless process_status.success?
143
+ raise Methadone::FailedCommandError.new(exitstatus,command,options[:on_fail])
144
+ end
145
+ end
146
+ end
147
+
148
+ # Override the default logger (which is the one provided by CLILogging).
149
+ # You would do this if you want a custom logger or you aren't mixing-in
150
+ # CLILogging.
151
+ #
152
+ # Note that this method is *not* called <tt>sh_logger=</tt> to avoid annoying situations
153
+ # where Ruby thinks you are setting a local variable
154
+ def set_sh_logger(logger)
155
+ @sh_logger = logger
156
+ end
157
+
158
+ # Set the strategy to use for executing commands. In general, you don't need to set this
159
+ # since this module chooses an appropriate implementation based on your Ruby platform:
160
+ #
161
+ # 1.8 Rubies, including 1.8, and REE:: Open4 is used via Methadone::ExecutionStrategy::Open_4. <b><tt>open4</tt> will not be
162
+ # installed as a dependency</b>. RubyGems doesn't allow conditional dependencies,
163
+ # so make sure that your app declares it as a dependency if you think you'll be
164
+ # running on 1.8 or REE.
165
+ # Rubinius:: Open4 is used, but we handle things a bit differently; see Methadone::ExecutionStrategy::RBXOpen_4.
166
+ # Same warning on dependencies applies.
167
+ # JRuby:: Use JVM calls to +Runtime+ via Methadone::ExecutionStrategy::JVM
168
+ # Windows:: Currently no support for Windows
169
+ # All others:: we use Open3 from the standard library, via Methadone::ExecutionStrategy::Open_3
170
+ #
171
+ # See Methadone::ExecutionStrategy::Base for how to implement your own.
172
+ def set_execution_strategy(strategy)
173
+ @execution_strategy = strategy
174
+ end
175
+
176
+ private
177
+
178
+ def exception_meaning_command_not_found
179
+ execution_strategy.exception_meaning_command_not_found
180
+ end
181
+
182
+ def self.default_execution_strategy_class
183
+ if RUBY_PLATFORM == 'java'
184
+ Methadone::ExecutionStrategy::JVM
185
+ elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
186
+ Methadone::ExecutionStrategy::RBXOpen_4
187
+ elsif RUBY_VERSION =~ /^1.8/
188
+ Methadone::ExecutionStrategy::Open_4
189
+ else
190
+ Methadone::ExecutionStrategy::Open_3
191
+ end
192
+ end
193
+
194
+ def execution_strategy
195
+ @execution_strategy ||= SH.default_execution_strategy_class.new
196
+ end
197
+
198
+ def sh_logger
199
+ @sh_logger ||= begin
200
+ raise StandardError, "No logger set! Please include Methadone::CLILogging or provide your own via #set_sh_logger." unless self.respond_to?(:logger)
201
+ self.logger
202
+ end
203
+ end
204
+
205
+ # Safely call our block, even if the user passed in a lambda
206
+ def call_block(block,stdout,stderr,exitstatus)
207
+ # blocks that take no arguments have arity -1. Or 0. Ugh.
208
+ if block.arity > 0
209
+ case block.arity
210
+ when 1
211
+ block.call(stdout)
212
+ when 2
213
+ block.call(stdout,stderr)
214
+ else
215
+ # Let it fail for lambdas
216
+ block.call(stdout,stderr,exitstatus)
217
+ end
218
+ else
219
+ block.call
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,3 @@
1
+ module Methadone #:nodoc:
2
+ VERSION = "1.9.2" #:nodoc:
3
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "methadone/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "methadone-rehab"
7
+ s.version = Methadone::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["davetron5000","dennisjbell", "juhazi", "matti"]
10
+ s.email = ["davetron5000 at gmail.com","dennis.j.bell at gmail.com", "juha.suuraho at enemy.fi", "matti.paksula at enemy.fi"]
11
+ s.homepage = "http://github.com/enemy/methadone-rehab"
12
+ s.summary = %q{Kick the bash habit and start your command-line apps off right}
13
+ s.description = %q{Improvement to Methadone Clinic [http://github.com/dennisjbell/methadone-clinic] that adds subcommands, option interaction rules (requires/excludes), and improved argument handling, while continuing to provide a lot of small but useful features for developing a command-line app, including an opinionated bootstrapping process, some helpful cucumber steps, and some classes to bridge logging and output into a simple, unified, interface that was in Methadone 1.9}
14
+ s.rubyforge_project = "methadone-rehab"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.add_dependency("bundler")
21
+ s.add_development_dependency("rake")
22
+ s.add_development_dependency("rdoc","~> 3.9")
23
+ s.add_development_dependency("cucumber")
24
+ s.add_development_dependency("aruba")
25
+ s.add_development_dependency("simplecov", "~> 0.5")
26
+ s.add_development_dependency("clean_test")
27
+ s.add_development_dependency("mocha", "0.13.2")
28
+ s.add_development_dependency("sdoc")
29
+ s.add_development_dependency("pry")
30
+ s.add_development_dependency("rspec", "~> 3")
31
+ s.add_development_dependency("i18n", "= 0.6.1")
32
+ end
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
@@ -0,0 +1,25 @@
1
+ = <%= gemname %> - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) <%= Time.now.year %> YOUR NAME
5
+ <% if license %>
6
+ <% if license == 'custom' %>
7
+ License:: INSERT LICENSE HERE
8
+ <% else %>
9
+ License:: <%= license %>, see LICENSE.txt
10
+ <% end %>
11
+ <% end %>
12
+
13
+ DESCRIBE YOUR GEM HERE
14
+
15
+ == Links
16
+
17
+ * {Source on Github}[LINK TO GITHUB]
18
+ * RDoc[LINK TO RDOC.INFO]
19
+
20
+ == Install
21
+
22
+ == Examples
23
+
24
+ == Contributing
25
+
@@ -0,0 +1,74 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+ <% if rspec %>
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+ <% else %>
36
+ require 'rake/testtask'
37
+ <% end %>
38
+ require 'cucumber'
39
+ require 'cucumber/rake/task'
40
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
41
+ require 'rdoc/task'
42
+
43
+ include Rake::DSL
44
+
45
+ Bundler::GemHelper.install_tasks
46
+
47
+ <% if rspec %>
48
+ RSpec::Core::RakeTask.new do |t|
49
+ # Put spec opts in a file named .rspec in root
50
+ end
51
+ <% else %>
52
+ Rake::TestTask.new do |t|
53
+ t.pattern = 'test/tc_*.rb'
54
+ end
55
+ <% end %>
56
+
57
+ CUKE_RESULTS = 'results.html'
58
+ CLEAN << CUKE_RESULTS
59
+ Cucumber::Rake::Task.new(:features) do |t|
60
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
61
+ t.fork = false
62
+ end
63
+
64
+ Rake::RDocTask.new do |rd|
65
+ <% if using_readme %>
66
+ rd.main = "README.rdoc"
67
+ <% end %>
68
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
69
+ end
70
+ <% if rspec %>
71
+ task :default => [:spec,:features]
72
+ <% else %>
73
+ task :default => [:test,:features]
74
+ <% end %>
@@ -0,0 +1,2 @@
1
+ Name: <%= gemspec.name %><%#TODO: Get program name more efficiently -%>
2
+ Copyright (c) <%= Time.now.year %> <%=`git config user.name`.strip %>
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Name: <%= gemspec.name %><%#TODO: Get program name more efficiently -%>
191
+ Copyright <%= Time.now.year %> <%=`git config user.name` %>
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.