mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,516 @@
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', '--parents', 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
+ # Use this to specify the next version number to replace VERSION_NUMBER with in the buildfile.
243
+ # You can set the next version or a proc that will be called with the current version number.
244
+ # For example, with the following buildfile:
245
+ # THIS_VERSION = "1.0.0-rc1"
246
+ # Release.next_version = lambda { |version|
247
+ # version[-1] = version[-1].to_i + 1
248
+ # version
249
+ # }
250
+ #
251
+ # Release.next_version will return "1.0.0-rc2", so at the end of the release, the buildfile will contain VERSION_NUMBER = "1.0.0-rc2"
252
+ #
253
+ attr_accessor :next_version
254
+
255
+ # :call-seq:
256
+ # add(MyReleaseClass)
257
+ #
258
+ # Add a Release implementation to the list of available Release classes.
259
+ def add(release)
260
+ @list ||= []
261
+ @list |= [release]
262
+ end
263
+ alias :<< :add
264
+
265
+ # The list of supported Release implementations
266
+ def list
267
+ @list ||= []
268
+ end
269
+
270
+ # Finds and returns the Release instance for this project.
271
+ def find
272
+ unless @release
273
+ klass = list.detect { |impl| impl.applies_to? }
274
+ @release = klass.new if klass
275
+ end
276
+ @release
277
+ end
278
+
279
+ end
280
+
281
+ # :call-seq:
282
+ # make()
283
+ #
284
+ # Make a release.
285
+ def make
286
+ @this_version = extract_version
287
+ check
288
+ with_release_candidate_version do |release_candidate_buildfile|
289
+ args = '-S', 'buildr', "_#{Buildr::VERSION}_", '--buildfile', release_candidate_buildfile
290
+ args << '--environment' << Buildr.environment unless Buildr.environment.to_s.empty?
291
+ args << 'clean' << 'upload' << 'DEBUG=no'
292
+ ruby *args
293
+ end
294
+ tag_release resolve_tag
295
+ update_version_to_next if this_version != resolve_next_version(this_version)
296
+ end
297
+
298
+ def check
299
+ if this_version == resolve_next_version(this_version) && this_version.match(/-SNAPSHOT$/)
300
+ fail "The next version can't be equal to the current version #{this_version}.\nUpdate THIS_VERSION/VERSION_NUMBER, specify Release.next_version or use NEXT_VERSION env var"
301
+ end
302
+ end
303
+
304
+ # :call-seq:
305
+ # extract_version() => this_version
306
+ #
307
+ # Extract the current version number from the buildfile.
308
+ # Raise an error if not found.
309
+ def extract_version
310
+ buildfile = File.read(Buildr.application.buildfile.to_s)
311
+ buildfile.scan(THIS_VERSION_PATTERN)[0][2]
312
+ rescue
313
+ fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found'
314
+ end
315
+
316
+ # Use this to specify a different tag name for tagging the release in source control.
317
+ # You can set the tag name or a proc that will be called with the version number,
318
+ # for example:
319
+ # Release.find.tag_name = lambda { |ver| "foo-#{ver}" }
320
+ # Deprecated: you should use Release.tag_name instead
321
+ def tag_name=(tag_proc)
322
+ Buildr.application.deprecated "Release.find.tag_name is deprecated. You should use Release.tag_name instead"
323
+ Release.tag_name=(tag_proc)
324
+ end
325
+
326
+ protected
327
+
328
+ # the initial value of THIS_VERSION
329
+ attr_accessor :this_version
330
+
331
+ # :call-seq:
332
+ # with_release_candidate_version() { |filename| ... }
333
+ #
334
+ # Yields to block with release candidate buildfile, before committing to use it.
335
+ #
336
+ # We need a Buildfile with upgraded version numbers to run the build, but we don't want the
337
+ # Buildfile modified unless the build succeeds. So this method updates the version number in
338
+ # a separate (Buildfile.next) file, yields to the block with that filename, and if successful
339
+ # copies the new file over the existing one.
340
+ #
341
+ # The release version is the current version without '-SNAPSHOT'. So:
342
+ # THIS_VERSION = 1.1.0-SNAPSHOT
343
+ # becomes:
344
+ # THIS_VERSION = 1.1.0
345
+ # for the release buildfile.
346
+ def with_release_candidate_version
347
+ release_candidate_buildfile = Buildr.application.buildfile.to_s + '.next'
348
+
349
+ release_candidate_buildfile_contents = change_version { |version|
350
+ version.gsub(/-SNAPSHOT$/, "")
351
+ }
352
+ File.open(release_candidate_buildfile, 'w') { |file| file.write release_candidate_buildfile_contents }
353
+ begin
354
+ yield release_candidate_buildfile
355
+ mv release_candidate_buildfile, Buildr.application.buildfile.to_s
356
+ ensure
357
+ rm release_candidate_buildfile rescue nil
358
+ end
359
+ end
360
+
361
+ # :call-seq:
362
+ # change_version() { |this_version| ... } => buildfile
363
+ #
364
+ # Change version number in the current Buildfile, but without writing a new file (yet).
365
+ # Returns the contents of the Buildfile with the modified version number.
366
+ #
367
+ # This method yields to the block with the current (this) version number and expects
368
+ # the block to return the updated version.
369
+ def change_version
370
+ current_version = extract_version
371
+ new_version = yield(current_version)
372
+ buildfile = File.read(Buildr.application.buildfile.to_s)
373
+ buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{new_version}"}) }
374
+ end
375
+
376
+ # Return the name of the tag to tag the release with.
377
+ def resolve_tag
378
+ version = extract_version
379
+ tag = Release.tag_name || version
380
+ tag = tag.call(version) if Proc === tag
381
+ tag
382
+ end
383
+
384
+ # Return the new value of THIS_VERSION based on the version passed.
385
+ #
386
+ # This method receives the existing value of THIS_VERSION
387
+ def resolve_next_version(current_version)
388
+ next_version = Release.next_version
389
+ next_version ||= lambda { |v|
390
+ snapshot = v.match(/-SNAPSHOT$/)
391
+ version = v.gsub(/-SNAPSHOT$/, "").split(/\./)
392
+ if snapshot
393
+ version[-1] = sprintf("%0#{version[-1].size}d", version[-1].to_i + 1) + '-SNAPSHOT'
394
+ end
395
+ version.join('.')
396
+ }
397
+ next_version = ENV['NEXT_VERSION'] if ENV['NEXT_VERSION']
398
+ next_version = ENV['next_version'] if ENV['next_version']
399
+ next_version = next_version.call(current_version) if Proc === next_version
400
+ next_version
401
+ end
402
+
403
+ # Move the version to next and save the updated buildfile
404
+ def update_buildfile
405
+ buildfile = change_version { |version| # THIS_VERSION minus SNAPSHOT
406
+ resolve_next_version(this_version) # THIS_VERSION
407
+ }
408
+ File.open(Buildr.application.buildfile.to_s, 'w') { |file| file.write buildfile }
409
+ end
410
+
411
+ # Return the message to use to commit the buildfile with the next version
412
+ def message
413
+ version = extract_version
414
+ msg = Release.commit_message || "Changed version number to #{version}"
415
+ msg = msg.call(version) if Proc === msg
416
+ msg
417
+ end
418
+
419
+ def update_version_to_next
420
+ update_buildfile
421
+ end
422
+ end
423
+
424
+
425
+ class GitRelease < Release
426
+ class << self
427
+ def applies_to?
428
+ if File.exist? '.git/config'
429
+ true
430
+ else
431
+ curr_pwd = Dir.pwd
432
+ Dir.chdir('..') do
433
+ return false if curr_pwd == Dir.pwd # Means going up one level is not possible.
434
+ applies_to?
435
+ end
436
+ end
437
+ end
438
+ end
439
+
440
+ # Fails if one of theses 2 conditions are not met:
441
+ # 1. the repository is clean: no content staged or unstaged
442
+ # 2. some remote repositories are defined but the current branch does not track any
443
+ def check
444
+ super
445
+ uncommitted = Git.uncommitted_files
446
+ fail "Uncommitted files violate the First Principle Of Release!\n#{uncommitted.join("\n")}" unless uncommitted.empty?
447
+ fail "You are releasing from a local branch that does not track a remote!" unless Git.remote
448
+ end
449
+
450
+ # Add a tag reference in .git/refs/tags and push it to the remote if any.
451
+ # If a tag with the same name already exists it will get deleted (in both local and remote repositories).
452
+ def tag_release(tag)
453
+ unless this_version == extract_version
454
+ info "Committing buildfile with version number #{extract_version}"
455
+ Git.commit File.basename(Buildr.application.buildfile.to_s), message
456
+ Git.push if Git.remote
457
+ end
458
+ info "Tagging release #{tag}"
459
+ Git.git 'tag', '-d', tag rescue nil
460
+ Git.git 'push', Git.remote, ":refs/tags/#{tag}" rescue nil if Git.remote
461
+ Git.git 'tag', '-a', tag, '-m', "[buildr] Cutting release #{tag}"
462
+ Git.git 'push', Git.remote, 'tag', tag if Git.remote
463
+ end
464
+
465
+ def update_version_to_next
466
+ super
467
+ info "Current version is now #{extract_version}"
468
+ Git.commit File.basename(Buildr.application.buildfile.to_s), message
469
+ Git.push if Git.remote
470
+ end
471
+ end
472
+
473
+
474
+ class SvnRelease < Release
475
+ class << self
476
+ def applies_to?
477
+ File.exist?('.svn')
478
+ end
479
+ end
480
+
481
+ def check
482
+ super
483
+ fail "Uncommitted files violate the First Principle Of Release!\n"+Svn.uncommitted_files.join("\n") unless Svn.uncommitted_files.empty?
484
+ fail "SVN URL must contain 'trunk' or 'branches/...'" unless Svn.repo_url =~ /(trunk)|(branches.*)$/
485
+ end
486
+
487
+ def tag_release(tag)
488
+ # Unlike Git, committing the buildfile with the released version is not necessary.
489
+ # svn tag does commit & tag.
490
+ info "Tagging release #{tag}"
491
+ Svn.tag tag
492
+ end
493
+
494
+ def update_version_to_next
495
+ super
496
+ info "Current version is now #{extract_version}"
497
+ Svn.commit Buildr.application.buildfile.to_s, message
498
+ end
499
+ end
500
+
501
+ Release.add SvnRelease
502
+ Release.add GitRelease
503
+
504
+ desc 'Make a release'
505
+ task 'release' do |task|
506
+ release = Release.find
507
+ fail 'Unable to detect the Version Control System.' unless release
508
+ release.make
509
+ end
510
+
511
+ end
512
+
513
+
514
+ class Buildr::Project
515
+ include Buildr::Build
516
+ end