| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| lib/buildr/shell.rb | 185 | 114 | 36.22%
|
41.23%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 # Licensed to the Apache Software Foundation (ASF) under one or more |
2 # contributor license agreements. See the NOTICE file distributed with this |
3 # work for additional information regarding copyright ownership. The ASF |
4 # licenses this file to you under the Apache License, Version 2.0 (the |
5 # "License"); you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at |
7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # |
10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 # License for the specific language governing permissions and limitations under |
14 # the License. |
15 |
16 |
17 module Buildr |
18 module Shell |
19 include Extension |
20 |
21 class << self |
22 def providers |
23 @providers ||= [] |
24 end |
25 |
26 def select_by_lang(lang) |
27 fail 'Unable to define shell task for nil language' if lang.nil? |
28 providers.detect { |e| e.languages.nil? ? false : e.languages.include?(lang.to_sym) } |
29 end |
30 |
31 alias_method :select, :select_by_lang |
32 |
33 def select_by_name(name) |
34 fail 'Unable to define run task for nil' if name.nil? |
35 providers.detect { |e| e.to_sym == name.to_sym } |
36 end |
37 |
38 def define_task(project, name, provider = nil) |
39 ShellTask.define_task(name).tap do |t| |
40 t.send(:associate_with, project) |
41 t.enhance([project.compile]) do |t| |
42 # double-enhance to execute the provider last |
43 t.enhance { |t| t.run } |
44 end |
45 t.using provider.to_sym if provider |
46 end |
47 end |
48 end |
49 |
50 first_time do |
51 Project.local_task 'shell' |
52 |
53 providers.each { |provider| Project.local_task "shell:#{provider.to_sym}" } |
54 end |
55 |
56 before_define(:shell => :compile) do |project| |
57 define_task(project, "shell") |
58 providers.each { |provider| define_task(project, "shell:#{provider.to_sym}", provider) } |
59 end |
60 |
61 after_define(:shell => :compile) do |project| |
62 unless project.shell.provider |
63 provider = providers.find { |p| p.languages.include? project.compile.language if p.languages } |
64 if provider |
65 project.shell.using provider.to_sym |
66 project.shell.with project.test.compile.dependencies |
67 end |
68 end |
69 end |
70 |
71 # Base class for any shell provider. |
72 class Base |
73 attr_reader :project # :nodoc: |
74 |
75 class << self |
76 attr_accessor :shell_name, :languages |
77 |
78 def specify(options) |
79 @shell_name ||= options[:name] |
80 @languages ||= options[:languages] |
81 end |
82 |
83 def to_sym |
84 @shell_name || name.split('::').last.downcase.to_sym |
85 end |
86 end |
87 |
88 def initialize(project) |
89 @project = project |
90 end |
91 |
92 def launch(task) |
93 fail 'Not implemented' |
94 end |
95 |
96 end |
97 |
98 class ShellTask < Rake::Task |
99 attr_reader :project # :nodoc: |
100 |
101 # Classpath dependencies. |
102 attr_accessor :classpath |
103 |
104 # Returns the run options. |
105 attr_reader :options |
106 |
107 # Underlying shell provider |
108 attr_reader :provider |
109 |
110 def initialize(*args) # :nodoc: |
111 super |
112 @options = {} |
113 @classpath = [] |
114 end |
115 |
116 # :call-seq: |
117 # with(*artifacts) => self |
118 # |
119 # Adds files and artifacts as classpath dependencies, and returns self. |
120 def with(*specs) |
121 @classpath |= Buildr.artifacts(specs.flatten).uniq |
122 self |
123 end |
124 |
125 # :call-seq: |
126 # using(options) => self |
127 # |
128 # Sets the run options from a hash and returns self. |
129 # |
130 # For example: |
131 # shell.using :properties => {'foo' => 'bar'} |
132 # shell.using :bsh |
133 def using(*args) |
134 if Hash === args.last |
135 args.pop.each { |key, value| @options[key.to_sym] = value } |
136 end |
137 |
138 until args.empty? |
139 new_shell = Shell.select_by_name(args.pop) |
140 @provider = new_shell.new(project) unless new_shell.nil? |
141 end |
142 |
143 self |
144 end |
145 |
146 def run |
147 fail "No shell provider defined in project '#{project.name}' for language '#{project.compile.language.inspect}'" unless provider |
148 provider.launch(self) |
149 end |
150 |
151 def prerequisites #:nodoc: |
152 super + classpath |
153 end |
154 |
155 def java_args |
156 @options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split |
157 end |
158 |
159 def properties |
160 @options[:properties] || {} |
161 end |
162 |
163 private |
164 def associate_with(project) |
165 @project ||= project |
166 end |
167 |
168 end |
169 |
170 # :call-seq: |
171 # shell(&block) => ShellTask |
172 # |
173 # This method returns the project's shell task. It also accepts a block to be executed |
174 # when the shell task is invoked. |
175 def shell(&block) |
176 task('shell').tap do |t| |
177 t.enhance &block if block |
178 end |
179 end |
180 end |
181 |
182 class Project |
183 include Shell |
184 end |
185 end |
Generated on 2011-07-06 23:35:38 -0700 with rcov 0.9.8