Buildr C0 Coverage Information - RCov

lib/buildr/core/common.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/buildr/core/common.rb 151 56
7.95%
16.07%

Key

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.

Coverage Details

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 require 'rake'
18 require 'buildr/core/util'
19 
20 
21 module Buildr
22 
23   # :call-seq:
24   #   struct(hash) => Struct
25   #
26   # Convenience method for creating an anonymous Struct.
27   #
28   # For example:
29   #   COMMONS             = struct(
30   #     :collections      =>'commons-collections:commons-collections:jar:3.1',
31   #     :lang             =>'commons-lang:commons-lang:jar:2.1',
32   #     :logging          =>'commons-logging:commons-logging:jar:1.0.3',
33   #   )
34   #
35   #   compile.with COMMONS.logging
36   def struct(hash)
37     Struct.new(nil, *hash.keys).new(*hash.values)
38   end
39 
40   # :call-seq:
41   #   write(name, content)
42   #   write(name) { ... }
43   #
44   # Write the contents into a file. The second form calls the block and writes the result.
45   #
46   # For example:
47   #   write 'TIMESTAMP', Time.now
48   #   write('TIMESTAMP') { Time.now }
49   #
50   # Yields to the block before writing the file, so you can chain read and write together.
51   # For example:
52   #   write('README') { read('README').sub("${build}", Time.now) }
53   def write(name, content = nil)
54     mkpath File.dirname(name)
55     content = yield if block_given?
56     File.open(name.to_s, 'wb') { |file| file.write content.to_s }
57     content.to_s
58   end
59 
60   # :call-seq:
61   #   read(args) => string
62   #   read(args) { |string| ... } => result
63   #
64   # Reads and returns the contents of a file. The second form yields to the block and returns
65   # the result of the block. The args passed to read are passed on to File.open.
66   #
67   # For example:
68   #   puts read('README')
69   #   read('README') { |text| puts text }
70   def read(*args)
71     args[0] = args[0].to_s
72     contents = File.open(*args) { |f| f.read }
73     if block_given?
74       yield contents
75     else
76       contents
77     end
78   end
79 
80   # :call-seq:
81   #    download(url_or_uri) => task
82   #    download(path=>url_or_uri) =>task
83   #
84   # Create a task that will download a file from a URL.
85   #
86   # Takes a single argument, a hash with one pair. The key is the file being
87   # created, the value if the URL to download. The task executes only if the
88   # file does not exist; the URL is not checked for updates.
89   #
90   # The task will show download progress on the console; if there are MD5/SHA1
91   # checksums on the server it will verify the download before saving it.
92   #
93   # For example:
94   #   download 'image.jpg'=>'http://example.com/theme/image.jpg'
95   def download(args)
96     args = URI.parse(args) if String === args
97     if URI === args
98       # Given only a download URL, download into a temporary file.
99       # You can infer the file from task name.
100       temp = Tempfile.open(File.basename(args.to_s))
101       file(temp.path).tap do |task|
102         # Since temporary file exists, force a download.
103         class << task ; def needed? ; true ; end ; end
104         task.sources << args
105         task.enhance { args.download temp }
106       end
107     else
108       # Download to a file created by the task.
109       fail unless args.keys.size == 1
110       uri = URI.parse(args.values.first.to_s)
111       file(args.keys.first.to_s).tap do |task|
112         task.sources << uri
113         task.enhance { uri.download task.name }
114       end
115     end
116 
117   end
118 
119   # A file task that concatenates all its prerequisites to create a new file.
120   #
121   # For example:
122   #   concat("master.sql"=>["users.sql", "orders.sql", reports.sql"]
123   #
124   # See also Buildr#concat.
125   class ConcatTask < Rake::FileTask
126     def initialize(*args) #:nodoc:
127       super
128       enhance do |task|
129         content = prerequisites.inject("") do |content, prereq|
130           content << File.read(prereq.to_s) if File.exists?(prereq) && !File.directory?(prereq)
131           content
132         end
133         File.open(task.name, "wb") { |file| file.write content }
134       end
135     end
136   end
137 
138   # :call-seq:
139   #    concat(target=>files) => task
140   #
141   # Creates and returns a file task that concatenates all its prerequisites to create
142   # a new file. See #ConcatTask.
143   #
144   # For example:
145   #   concat("master.sql"=>["users.sql", "orders.sql", reports.sql"]
146   def concat(args)
147     file, arg_names, deps = Buildr.application.resolve_args([args])
148     ConcatTask.define_task(File.expand_path(file)=>deps)
149   end
150 
151 end

Generated on 2011-07-06 23:35:37 -0700 with rcov 0.9.8