novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +245 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +90 -0
  40. data/doc/extending.textile +205 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +265 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +287 -0
  68. data/doc/testing.textile +233 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +662 -0
  73. data/lib/buildr/core/build.rb +463 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +363 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,463 @@
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 'buildr/core/project'
18
+ require 'buildr/core/common'
19
+ require 'buildr/core/checks'
20
+ require 'buildr/core/environment'
21
+
22
+
23
+ module Buildr
24
+
25
+ class Options
26
+
27
+ # Runs the build in parallel when true (defaults to false). You can force a parallel build by
28
+ # setting this option directly, or by running the parallel task ahead of the build task.
29
+ #
30
+ # This option only affects recursive tasks. For example:
31
+ # buildr parallel package
32
+ # will run all package tasks (from the sub-projects) in parallel, but each sub-project's package
33
+ # task runs its child tasks (prepare, compile, resources, etc) in sequence.
34
+ attr_accessor :parallel
35
+
36
+ end
37
+
38
+ task('parallel') { Buildr.options.parallel = true }
39
+
40
+
41
+ module Build
42
+
43
+ include Extension
44
+
45
+ first_time do
46
+ desc 'Build the project'
47
+ Project.local_task('build') { |name| "Building #{name}" }
48
+ desc 'Clean files generated during a build'
49
+ Project.local_task('clean') { |name| "Cleaning #{name}" }
50
+
51
+ desc 'The default task is build'
52
+ task 'default'=>'build'
53
+ end
54
+
55
+ before_define(:build => [:compile, :test]) do |project|
56
+ project.recursive_task 'build'
57
+ project.recursive_task 'clean'
58
+ project.clean do
59
+ rm_rf project.path_to(:target)
60
+ rm_rf project.path_to(:reports)
61
+ end
62
+ end
63
+
64
+ after_define(:build)
65
+
66
+ # *Deprecated:* Use +path_to(:target)+ instead.
67
+ def target
68
+ Buildr.application.deprecated 'Use path_to(:target) instead'
69
+ layout.expand(:target)
70
+ end
71
+
72
+ # *Deprecated:* Use Layout instead.
73
+ def target=(dir)
74
+ Buildr.application.deprecated 'Use Layout instead'
75
+ layout[:target] = _(dir)
76
+ end
77
+
78
+ # *Deprecated:* Use +path_to(:reports)+ instead.
79
+ def reports()
80
+ Buildr.application.deprecated 'Use path_to(:reports) instead'
81
+ layout.expand(:reports)
82
+ end
83
+
84
+ # *Deprecated:* Use Layout instead.
85
+ def reports=(dir)
86
+ Buildr.application.deprecated 'Use Layout instead'
87
+ layout[:reports] = _(dir)
88
+ end
89
+
90
+ # :call-seq:
91
+ # build(*prereqs) => task
92
+ # build { |task| .. } => task
93
+ #
94
+ # Returns the project's build task. With arguments or block, also enhances that task.
95
+ def build(*prereqs, &block)
96
+ task('build').enhance prereqs, &block
97
+ end
98
+
99
+ # :call-seq:
100
+ # clean(*prereqs) => task
101
+ # clean { |task| .. } => task
102
+ #
103
+ # Returns the project's clean task. With arguments or block, also enhances that task.
104
+ def clean(*prereqs, &block)
105
+ task('clean').enhance prereqs, &block
106
+ end
107
+
108
+ end
109
+
110
+
111
+ module Git #:nodoc:
112
+ module_function
113
+
114
+ # :call-seq:
115
+ # git(*args)
116
+ #
117
+ # Executes a Git command and returns the output. Throws exception if the exit status
118
+ # is not zero. For example:
119
+ # git 'commit'
120
+ # git 'remote', 'show', 'origin'
121
+ def git(*args)
122
+ cmd = "git #{args.shift} #{args.map { |arg| arg.inspect }.join(' ')}"
123
+ output = `#{cmd}`
124
+ fail "GIT command \"#{cmd}\" failed with status #{$?.exitstatus}\n#{output}" unless $?.exitstatus == 0
125
+ return output
126
+ end
127
+
128
+ # Returns list of uncommited/untracked files as reported by git status.
129
+ def uncommitted_files
130
+ `git status`.scan(/^#(\t|\s{7})(\S.*)$/).map { |match| match.last.split.last }
131
+ end
132
+
133
+ # Commit the given file with a message.
134
+ # The file has to be known to Git meaning that it has either to have been already committed in the past
135
+ # or freshly added to the index. Otherwise it will fail.
136
+ def commit(file, message)
137
+ git 'commit', '-m', message, file
138
+ end
139
+
140
+ # Update the remote refs using local refs
141
+ #
142
+ # By default, the "remote" destination of the push is the the remote repo linked to the current branch.
143
+ # The default remote branch is the current local branch.
144
+ def push(remote_repo = remote, remote_branch = current_branch)
145
+ git 'push', remote, current_branch
146
+ end
147
+
148
+ # Return the name of the remote repository whose branch the current local branch tracks,
149
+ # or nil if none.
150
+ def remote(branch = current_branch)
151
+ remote = git('config', '--get', "branch.#{branch}.remote").to_s.strip
152
+ remote if !remote.empty? && git('remote').include?(remote)
153
+ end
154
+
155
+ # Return the name of the current branch
156
+ def current_branch
157
+ git('branch')[/^\* (.*)$/, 1]
158
+ end
159
+ end
160
+
161
+
162
+ module Svn #:nodoc:
163
+ module_function
164
+
165
+ # :call-seq:
166
+ # svn(*args)
167
+ #
168
+ # Executes a SVN command and returns the output. Throws exception if the exit status
169
+ # is not zero. For example:
170
+ # svn 'commit'
171
+ def svn(*args)
172
+ output = `svn #{args.shift} #{args.map { |arg| arg.inspect }.join(' ')}`
173
+ fail "SVN command failed with status #{$?.exitstatus}" unless $?.exitstatus == 0
174
+ return output
175
+ end
176
+
177
+ def tag(tag_name)
178
+ url = tag_url repo_url, tag_name
179
+ remove url, 'Removing old copy' rescue nil
180
+ copy Dir.pwd, url, "Release #{tag_name}"
181
+ end
182
+
183
+ # Status check reveals modified files, but also SVN externals which we can safely ignore.
184
+ def uncommitted_files
185
+ svn('status', '--ignore-externals').split("\n").reject { |line| line =~ /^X\s/ }
186
+ end
187
+
188
+ def commit(file, message)
189
+ svn 'commit', '-m', message, file
190
+ end
191
+
192
+ # :call-seq:
193
+ # tag_url(svn_url, version) => tag_url
194
+ #
195
+ # Returns the SVN url for the tag.
196
+ # Can tag from the trunk or from branches.
197
+ # Can handle the two standard repository layouts.
198
+ # - http://my.repo/foo/trunk => http://my.repo/foo/tags/1.0.0
199
+ # - http://my.repo/trunk/foo => http://my.repo/tags/foo/1.0.0
200
+ def tag_url(svn_url, tag)
201
+ trunk_or_branches = Regexp.union(%r{^(.*)/trunk(.*)$}, %r{^(.*)/branches(.*)/([^/]*)$})
202
+ match = trunk_or_branches.match(svn_url)
203
+ prefix = match[1] || match[3]
204
+ suffix = match[2] || match[4]
205
+ prefix + '/tags' + suffix + '/' + tag
206
+ end
207
+
208
+ # Return the current SVN URL
209
+ def repo_url
210
+ svn('info', '--xml')[/<url>(.*?)<\/url>/, 1].strip
211
+ end
212
+
213
+ def copy(dir, url, message)
214
+ svn 'copy', dir, url, '-m', message
215
+ end
216
+
217
+ def remove(url, message)
218
+ svn 'remove', url, '-m', message
219
+ end
220
+
221
+ end
222
+
223
+
224
+ class Release #:nodoc:
225
+
226
+ THIS_VERSION_PATTERN = /(THIS_VERSION|VERSION_NUMBER)\s*=\s*(["'])(.*)\2/
227
+
228
+ class << self
229
+
230
+ # Use this to specify a different tag name for tagging the release in source control.
231
+ # You can set the tag name or a proc that will be called with the version number,
232
+ # for example:
233
+ # Release.tag_name = lambda { |ver| "foo-#{ver}" }
234
+ attr_accessor :tag_name
235
+
236
+ # Use this to specify a different commit message to commit the buildfile with the next version in source control.
237
+ # You can set the commit message or a proc that will be called with the next version number,
238
+ # for example:
239
+ # Release.commit_message = lambda { |ver| "Changed version number to #{ver}" }
240
+ attr_accessor :commit_message
241
+
242
+ # :call-seq:
243
+ # add(MyReleaseClass)
244
+ #
245
+ # Add a Release implementation to the list of available Release classes.
246
+ def add(release)
247
+ @list ||= []
248
+ @list |= [release]
249
+ end
250
+ alias :<< :add
251
+
252
+ # The list of supported Release implementations
253
+ def list
254
+ @list ||= []
255
+ end
256
+
257
+ # Finds and returns the Release instance for this project.
258
+ def find
259
+ unless @release
260
+ klass = list.detect { |impl| impl.applies_to? }
261
+ @release = klass.new if klass
262
+ end
263
+ @release
264
+ end
265
+
266
+ end
267
+
268
+ # :call-seq:
269
+ # make()
270
+ #
271
+ # Make a release.
272
+ def make
273
+ check
274
+ with_release_candidate_version do |release_candidate_buildfile|
275
+ args = '-S', 'buildr', "_#{Buildr::VERSION}_", '--buildfile', release_candidate_buildfile
276
+ args << '--environment' << Buildr.environment unless Buildr.environment.to_s.empty?
277
+ args << 'clean' << 'upload' << 'DEBUG=no'
278
+ ruby *args
279
+ end
280
+ tag_release resolve_tag
281
+ update_version_to_next
282
+ end
283
+
284
+ # :call-seq:
285
+ # extract_version() => this_versin
286
+ #
287
+ # Extract the current version number from the buildfile.
288
+ # Raise an error if not found.
289
+ def extract_version
290
+ buildfile = File.read(Buildr.application.buildfile.to_s)
291
+ buildfile.scan(THIS_VERSION_PATTERN)[0][2]
292
+ rescue
293
+ fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found'
294
+ end
295
+
296
+ # Use this to specify a different tag name for tagging the release in source control.
297
+ # You can set the tag name or a proc that will be called with the version number,
298
+ # for example:
299
+ # Release.find.tag_name = lambda { |ver| "foo-#{ver}" }
300
+ # Deprecated: you should use Release.tag_name instead
301
+ def tag_name(tag_proc)
302
+ warn("Release.find.tag_name is deprecated. You should use Release.tag_name instead")
303
+ Release.tag_name(tag_proc)
304
+ end
305
+
306
+ protected
307
+
308
+ # :call-seq:
309
+ # with_release_candidate_version() { |filename| ... }
310
+ #
311
+ # Yields to block with release candidate buildfile, before committing to use it.
312
+ #
313
+ # We need a Buildfile with upgraded version numbers to run the build, but we don't want the
314
+ # Buildfile modified unless the build succeeds. So this method updates the version number in
315
+ # a separate (Buildfile.next) file, yields to the block with that filename, and if successful
316
+ # copies the new file over the existing one.
317
+ #
318
+ # The release version is the current version without '-SNAPSHOT'. So:
319
+ # THIS_VERSION = 1.1.0-SNAPSHOT
320
+ # becomes:
321
+ # THIS_VERSION = 1.1.0
322
+ # for the release buildfile.
323
+ def with_release_candidate_version
324
+ release_candidate_buildfile = Buildr.application.buildfile.to_s + '.next'
325
+ release_candidate_buildfile_contents = change_version { |version| version[-1] = version[-1].split('-')[0] }
326
+ File.open(release_candidate_buildfile, 'w') { |file| file.write release_candidate_buildfile_contents }
327
+ begin
328
+ yield release_candidate_buildfile
329
+ mv release_candidate_buildfile, Buildr.application.buildfile.to_s
330
+ ensure
331
+ rm release_candidate_buildfile rescue nil
332
+ end
333
+ end
334
+
335
+ # :call-seq:
336
+ # change_version() { |this_version| ... } => buildfile
337
+ #
338
+ # Change version number in the current Buildfile, but without writing a new file (yet).
339
+ # Returns the contents of the Buildfile with the modified version number.
340
+ #
341
+ # This method yields to the block with the current (this) version number as an array and expects
342
+ # the block to update it.
343
+ def change_version
344
+ this_version = extract_version
345
+ new_version = this_version.split('.')
346
+ yield(new_version)
347
+ new_version = new_version.join('.')
348
+ buildfile = File.read(Buildr.application.buildfile.to_s)
349
+ buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{new_version}"}) }
350
+ end
351
+
352
+ # Return the name of the tag to tag the release with.
353
+ def resolve_tag
354
+ version = extract_version
355
+ tag = Release.tag_name || version
356
+ tag = tag.call(version) if Proc === tag
357
+ tag
358
+ end
359
+
360
+ # Move the version to next and save the updated buildfile
361
+ def update_buildfile
362
+ buildfile = change_version { |version| version[-1] = sprintf("%0#{version[-1].size}d", version[-1].to_i + 1) + '-SNAPSHOT' }
363
+ File.open(Buildr.application.buildfile.to_s, 'w') { |file| file.write buildfile }
364
+ end
365
+
366
+ # Return the message to use to cimmit the buildfile with the next version
367
+ def message
368
+ version = extract_version
369
+ msg = Release.commit_message || "Changed version number to #{version}"
370
+ msg = msg.call(version) if Proc === msg
371
+ msg
372
+ end
373
+
374
+ def update_version_to_next
375
+ update_buildfile
376
+ end
377
+ end
378
+
379
+
380
+ class GitRelease < Release
381
+ class << self
382
+ def applies_to?
383
+ if File.exist? '.git/config'
384
+ true
385
+ else
386
+ File.expand_path(Dir.pwd) != '/' && Dir.chdir('..') do
387
+ applies_to?
388
+ end
389
+ end
390
+ end
391
+ end
392
+
393
+ # Fails if one of theses 2 conditions are not met:
394
+ # 1. the repository is clean: no content staged or unstaged
395
+ # 2. some remote repositories are defined but the current branch does not track any
396
+ def check
397
+ uncommitted = Git.uncommitted_files
398
+ fail "Uncommitted files violate the First Principle Of Release!\n#{uncommitted.join("\n")}" unless uncommitted.empty?
399
+ fail "You are releasing from a local branch that does not track a remote!" unless Git.remote
400
+ end
401
+
402
+ # Add a tag reference in .git/refs/tags and push it to the remote if any.
403
+ # If a tag with the same name already exists it will get deleted (in both local and remote repositories).
404
+ def tag_release(tag)
405
+ info "Committing buildfile with version number #{extract_version}"
406
+ Git.commit File.basename(Buildr.application.buildfile.to_s), message
407
+ Git.push if Git.remote
408
+ info "Tagging release #{tag}"
409
+ Git.git 'tag', '-d', tag rescue nil
410
+ Git.git 'push', Git.remote, ":refs/tags/#{tag}" rescue nil if Git.remote
411
+ Git.git 'tag', '-a', tag, '-m', "[buildr] Cutting release #{tag}"
412
+ Git.git 'push', Git.remote, 'tag', tag if Git.remote
413
+ end
414
+
415
+ def update_version_to_next
416
+ super
417
+ info "Current version is now #{extract_version}"
418
+ Git.commit File.basename(Buildr.application.buildfile.to_s), message
419
+ Git.push if Git.remote
420
+ end
421
+ end
422
+
423
+
424
+ class SvnRelease < Release
425
+ class << self
426
+ def applies_to?
427
+ File.exist?('.svn')
428
+ end
429
+ end
430
+
431
+ def check
432
+ fail "Uncommitted files violate the First Principle Of Release!\n"+Svn.uncommitted_files.join("\n") unless Svn.uncommitted_files.empty?
433
+ fail "SVN URL must contain 'trunk' or 'branches/...'" unless Svn.repo_url =~ /(trunk)|(branches.*)$/
434
+ end
435
+
436
+ def tag_release(tag)
437
+ info "Tagging release #{tag}"
438
+ Svn.tag tag
439
+ end
440
+
441
+ def update_version_to_next
442
+ super
443
+ info "Current version is now #{extract_version}"
444
+ Svn.commit Buildr.application.buildfile.to_s, message
445
+ end
446
+ end
447
+
448
+ Release.add SvnRelease
449
+ Release.add GitRelease
450
+
451
+ desc 'Make a release'
452
+ task 'release' do |task|
453
+ release = Release.find
454
+ fail 'Unable to detect the Version Control System.' unless release
455
+ release.make
456
+ end
457
+
458
+ end
459
+
460
+
461
+ class Buildr::Project
462
+ include Buildr::Build
463
+ end