assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,286 @@
1
+ h1. More Stuff
2
+
3
+
4
+ h2. Using Gems
5
+
6
+ The purpose of the buildfile is to define your projects, and the various tasks and functions used for building them. Some of these are specific to your projects, others are more general in nature, and you may want to share them across projects.
7
+
8
+ There are several mechanisms for developing extensions and build features across projects which we cover in more details in the section "Extending Buildr":extending.html. Here we will talk about using extensions that are distributed in the form of RubyGems.
9
+
10
+ "RubyGems":http://rubygems.rubyforge.org provides the @gem@ command line tool that you can use to search, install, upgrade, package and distribute gems. It installs all gems into a local repository that is shared across your builds and all other Ruby applications you may have running. You can install a gem from a local file, or download and install it from any number of remote repositories.
11
+
12
+ RubyGems is preconfigured to use the "RubyForge":http://rubyforge.org repository. You'll find a large number of open source Ruby libraries there, including Buildr itself and all its dependencies. RubyForge provides a free account that you can use to host your projects and distribute your gems (you can use RubyForge strictly for distribution, as we do with Buildr).
13
+
14
+ You can also set up your own private repository and use it instead or in addition to RubyForge. Use the @gem sources@ command to add repositories, and the @gem server@ command to run a remote repository. You can see all available options by running @gem help@.
15
+
16
+ If your build depends on other gems, you will want to specify these dependencies as part of your build and check that configuration into source control. That way you can have a specific environment that will guarantee repeatable builds, whether you're building a particular version, moving between branches, or joining an existing project. Buildr will take care of installing all the necessary dependencies, which you can then manage with the @gem@ command.
17
+
18
+ Use the @build.yaml@ file to specify these dependencies (see "Build Settings":settings_profiles.html#build_settings for more information), for example:
19
+
20
+ {{{!yaml
21
+ # This project requires the following gems
22
+ gems:
23
+ # Suppose we want to notify developers when testcases fail.
24
+ - buildr-twitter-notifier-addon >=1
25
+ # we test with ruby mock objects
26
+ - mocha
27
+ - ci_reporter
28
+ }}}
29
+
30
+ Gems contain executable code, and for that reason Buildr will not install gems without your permission. When you run a build that includes any dependencies that are not already installed on your machine, Buildr will ask for permission before installing them. On Unix-based operating systems, you will also need sudo privileges and will be asked for your password before proceeding.
31
+
32
+ Since this step requires your input, it will only happen when running Buildr interactively from the command line. In all other cases, Buildr will fail and report the missing dependencies. If you have an automated build environment, make sure to run the build once manually to install all the necessary dependencies.
33
+
34
+ When installing a gem for the first time, Buildr will automatically look for the latest available version. You can specify a particular version number, or a set of version numbers known to work with that build. You can use equality operations to specify a range of versions, for example, @1.2.3@ to install only version 1.2.3, and @=> 1.2.3@ to install version 1.2.3 or later.
35
+
36
+ You can also specify a range up to one version bump, for example, @~> 1.2.3@ is the same as @>= 1.2.3 < 1.3.0@, and @~> 1.2@ is the same as @>= 1.2.0 < 2.0.0@. If necessary, you can exclude a particular version number, for example, @~> 1.2.3 != 1.2.7@.
37
+
38
+ Buildr will install the latest version that matches the version requirement. To keep up with newer versions, execute the @gem update@ command periodically. You can also use @gem outdated@ to determine which new versions are available.
39
+
40
+ Most gems include documentation that you can access in several forms. You can use the @ri@ command line tool to find out more about a class, module or specific method. For example:
41
+
42
+ {{{!sh
43
+ $ ri Buildr::Jetty
44
+ $ ri Buildr::Jetty.start
45
+ }}}
46
+
47
+ You can also access documentation from a Web browser by running @gem server@ and pointing your browser to "http://localhost:8808":http://localhost:8808. Note that after installing a new gem, you will need to restart the gem server to see its documentation.
48
+
49
+
50
+ h2. Using Java Libraries
51
+
52
+ Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows you to access Java classes and create Java objects.
53
+
54
+ Java classes are accessed as static methods on the @Java@ module, for example:
55
+
56
+ {{{!ruby
57
+ str = Java.java.lang.String.new('hai!')
58
+ str.toUpperCase
59
+ => 'HAI!'
60
+ Java.java.lang.String.isInstance(str)
61
+ => true
62
+ Java.com.sun.tools.javac.Main.compile(args)
63
+ }}}
64
+
65
+ The @classpath@ attribute allows Buildr to add JARs and directories to the classpath, for example, we use it to load Ant and various Ant tasks, code generators, test frameworks, and so forth.
66
+
67
+ When using an artifact specification, Buildr will automatically download and install the artifact before adding it to the classpath.
68
+
69
+ For example, Ant is loaded as follows:
70
+
71
+ {{{!ruby
72
+ Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
73
+ }}}
74
+
75
+ Artifacts can only be downloaded after the Buildfile has loaded, giving it a chance to specify which remote repositories to use, so adding to classpath does not by itself load any libraries. You must call @Java.load@ before accessing any Java classes to give Buildr a chance to load the libraries specified in the classpath.
76
+
77
+ When building an extension, make sure to follow these rules:
78
+
79
+ # Add to the @classpath@ when the extension is loaded (i.e. in module or class definition), so the first call to @Java.load@ anywhere in the code will include the libraries you specify.
80
+ # Call @Java.load@ once before accessing any Java classes, allowing Buildr to set up the classpath.
81
+ # Only call @Java.load@ when invoked, otherwise you may end up loading the JVM with a partial classpath, or before all remote repositories are listed.
82
+ # Check on a clean build with empty local repository.
83
+
84
+
85
+ h2. Nailgun
86
+
87
+ "Nailgun":http://www.martiansoftware.com/nailgun/index.html is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead. Nailgun integration is available only when running Buildr within JRuby.
88
+
89
+ Buildr provides a custom nailgun server, allowing you to start a single JVM and let buildr create a queue of runtimes. These JRuby runtimes can be cached (indexed by buildfile path) and are automatically reloaded when the buildfile has been modified. Runtime caching allows you to execute tasks without spending time creating the buildr environment.
90
+
91
+ Start the BuildrServer by executing
92
+
93
+ {{{!ruby
94
+ $ jruby -S buildr -rbuildr/nailgun nailgun:start
95
+ }}}
96
+
97
+ Server output will display a message when it becomes ready, you will also see messages when the JRuby runtimes are being created, or when a new buildr environment is being loaded on them. After the runtime queues have been populated, you can start calling buildr as you normally do, by invoking the $NAILGUN_HOME/ng binary:
98
+
99
+ {{{!sh
100
+ # on another terminal, change directory to a project.
101
+ # if this project is the same nailgun:start was invoked on, it's
102
+ # runtime has been cached, so no loading is performed unless
103
+ # the buildfile has been modified. otherwise the buildfile
104
+ # will be loaded on a previously loaded fresh-buildr runtime
105
+ # and it will be cached.
106
+ cd /some/buildr/project
107
+ ng nailgun:help # display nailgun help
108
+ ng nailgun:tasks # display overview of ng tasks
109
+ ng clean compile # just invoke those two tasks
110
+ }}}
111
+
112
+ Some nailgun tasks have been provided to manage the cached runtimes, to get an overview of them execute the @nailgun:tasks@ task.
113
+
114
+ Be sure to read the nailgun help by executing the @nailgun:help@ task.
115
+
116
+
117
+ h2. Growl, Qube
118
+
119
+ For OS X users, Buildr supports "Growl":http://growl.info/ out of the box to send "completed and "failed" notifications to the user.
120
+
121
+ For other platforms or if you want to notify the user differently, Buildr offers two extension points:
122
+
123
+ * @Buildr.application.on_completion@
124
+ * @Buildr.application.on_failure@
125
+
126
+ Here is an example using these extension points to send notifications using "Qube":http://launchpad.net/qube:
127
+
128
+ {{{!ruby
129
+ # Send notifications using Qube
130
+ notify = lambda do |type, title, message|
131
+ param = case type
132
+ when 'completed'; '-i'
133
+ when 'failed'; '-e'
134
+ else '-i'
135
+ end
136
+ system "qube #{param} #{title.inspect} #{message.inspect}"
137
+ end
138
+
139
+ Buildr.application.on_completion do |title, message|
140
+ notify['completed', title, message]
141
+ end
142
+ Buildr.application.on_failure do |title, message, ex|
143
+ notify['failed', title, message]
144
+ end
145
+ }}}
146
+
147
+ You can place this code inside @buildr.rb@ in your home directory.
148
+
149
+ h2. Eclipse, IDEA
150
+
151
+ If you're using Eclipse, you can generate @.classpath@ and @.project@ from your Buildfile and use them to create a project in your workspace:
152
+
153
+ {{{!sh
154
+ $ buildr eclipse
155
+ }}}
156
+
157
+ The @eclipse@ task will generate a @.classpath@ and @.project@ file for each of projects (and sub-project) that compiles source code. It will not generate files for other projects, for examples, projects you use strictly for packaging a distribution, or creating command line scripts, etc.
158
+
159
+ If you add a new project, change the dependencies, or make any other change to your Buildfile, just run the @eclipse@ task again to re-generate the Eclipse project files.
160
+
161
+ If you prefer IntelliJ IDEA, you can always:
162
+
163
+ {{{!sh
164
+ $ buildr idea
165
+ }}}
166
+
167
+ It will generate a @.iml@ file for every project (or subproject) and a @.ipr@ that you can directly open for the root project. To allow IntelliJ Idea to resolve external dependencies properly, you will need to add a @M2_REPO@ variable pointing to your Maven2 repository directory (@Settings / Path Variables@).
168
+
169
+ If you're using IDEA 7 or later, use the @buildr idea7x@ task instead. This task creates the proper @.ipr@ and @.iml@ files for IDEA version 7. It includes the @-7x@ suffix in the generated files, so you can use the @idea@ and @idea7x@ tasks side by side on the same project.
170
+
171
+ Also, check out the "Buildr plugin for IDEA":http://www.digitalsanctum.com/buildr-plug-in/ (IDEA 7 and later). Once installed, open your project with IDEA. If IDEA finds that you have Buildr installed and finds a buildfile in the project's directory, it will show all the tasks available for that project. To run a task, double-click it. When the task completes, IDEA will show the results in the Buildr Output window.
172
+
173
+
174
+ h2. Cobertura, Emma, JDepend
175
+
176
+ You can use "Cobertura":http://cobertura.sourceforge.net/ or "Emma":http://emma.sourceforge.net/ to instrument your code, run the tests and create a test coverage report in either HTML or XML format.
177
+
178
+ There are two tasks for each tool, both of which generate a test coverage report in the @reports/cobertura@ (respectively @reports/emma@) directory. For example:
179
+
180
+ {{{!sh
181
+ $ buildr test cobertura:html
182
+ }}}
183
+
184
+ As you can guess, the other tasks are @cobertura:xml@, @emma:html@ and @emma:xml@.
185
+
186
+ If you want to generate a test coverage report only for a specific project, you can do so by using the project name as prefix to the tasks.
187
+
188
+ {{{!sh
189
+ $ buildr subModule:cobertura:html
190
+ }}}
191
+
192
+ Each project can specify which classes to include or exclude from cobertura instrumentation by giving a class-name regexp to the @cobertura.include@ or @cobertura.exclude@ methods:
193
+
194
+ {{{!ruby
195
+ define 'someModule' do
196
+ cobertura.include 'some.package.*'
197
+ cobertura.include /some.(foo|bar).*/
198
+ cobertura.exclude 'some.foo.util.SimpleUtil'
199
+ cobertura.exclude /*.Const(ants)?/i
200
+ end
201
+ }}}
202
+
203
+ Emma has @include@ and @exclude@ methods too, but they take glob patterns instead of regexps.
204
+
205
+ You can use "JDepend":http://clarkware.com/software/JDepend.html on to generate design quality metrics. There are three tasks this time, the eye candy one:
206
+
207
+ {{{!sh
208
+ $ buildr jdepend:swing
209
+ }}}
210
+
211
+ The other two tasks are @jdepend:text@ and @jdepend:xml@.
212
+
213
+ We want Buildr to load fast, and not everyone cares for these tasks, so we don't include them by default. If you want to use one of them, you need to require it explicitly. The proper way to do it in Ruby:
214
+
215
+ {{{!ruby
216
+ require 'buildr/cobertura'
217
+ require 'buildr/emma'
218
+ require 'buildr/jdepend'
219
+ }}}
220
+
221
+ You may want to add those to the Buildfile. Alternatively, you can use these tasks for all your projects without modifying the Buildfile. One convenient method is to add these lines to the @buildr.rb@ file in your home directory.
222
+
223
+ Another option is to require it from the command line (@--require@ or @-r@), for example:
224
+
225
+ {{{!sh
226
+ $ buildr --require buildr/jdepend jdepend:swing
227
+ $ buildr -rbuildr/cobertura cobertura:html
228
+ }}}
229
+
230
+
231
+ h2. Anything Ruby Can Do
232
+
233
+ Buildr is Ruby code. That's an implementation detail for some, but a useful features for others. You can use Ruby to keep your build scripts simple and DRY, tackle ad hoc tasks and write reusable features without the complexity of "plugins".
234
+
235
+ We already showed you one example where Ruby could help. You can use Ruby to manage dependency by setting constants and reusing them, grouping related dependencies into arrays and structures.
236
+
237
+ You can use Ruby to perform ad hoc tasks. For example, Buildr doesn't have any pre-canned task for setting file permissions. But Ruby has a method for that, so it's just a matter of writing a task:
238
+
239
+ {{{!ruby
240
+ bins = file('target/bin'=>FileList[_('src/main/dist/bin/*')]) do |task|
241
+ mkpath task.name
242
+ cp task.prerequisites, task.name
243
+ chmod 0755, FileList[task.name + '/*.sh'], :verbose=>false
244
+ end
245
+ }}}
246
+
247
+ You can use functions to keep your code simple. For example, in the ODE project we create two binary distributions, both of which contain a common set of files, and one additional file unique to each distribution. We use a method to define the common distribution:
248
+
249
+ {{{!ruby
250
+ def distro(project, id)
251
+ project.package(:zip, :id=>id).path("#{id}-#{version}").tap do |zip|
252
+ zip.include meta_inf + ['RELEASE_NOTES', 'README'].map { |f| path_to(f) }
253
+ zip.path('examples').include project.path_to(:source, :examples), :as=>'.'
254
+ zip.merge project('ode:tools-bin').package(:zip)
255
+ zip.path('lib').include artifacts(COMMONS.logging, COMMONS.codec,
256
+ COMMONS.httpclient, COMMONS.pool, COMMONS.collections, JAXEN, SAXON,
257
+ LOG4J, WSDL4J, XALAN, XERCES)
258
+ project('ode').projects('utils', 'tools', 'bpel-compiler', 'bpel-api',
259
+ 'bpel-obj', 'bpel-schemas').map(&:packages).flatten.each do |pkg|
260
+ zip.include(pkg.to_s, :as=>"#{pkg.id}.#{pkg.type}", :path=>'lib')
261
+ end
262
+ yield zip
263
+ end
264
+ end
265
+ }}}
266
+
267
+ And then use it in the project definition:
268
+
269
+ {{{!ruby
270
+ define 'distro-axis2' do
271
+ parent.distro(self, "#{parent.id}-war") { |zip|
272
+ zip.include project('ode:axis2-war').package(:war), :as=>'ode.war' }
273
+ end
274
+ }}}
275
+
276
+ Ruby's functional style and blocks make some task extremely easy. For example, let's say we wanted to count how many source files we have, and total number of lines:
277
+
278
+ {{{!ruby
279
+ sources = projects.map { |prj| prj.compile.sources.
280
+ map { |src| FileList["#{src}/**/*.java"] } }.flatten
281
+ puts "There are #{source.size} source files"
282
+ lines = sources.inject(0) { |lines, src| lines += File.readlines(src).size }
283
+ puts "That contain #{lines} lines"
284
+ }}}
285
+
286
+
@@ -0,0 +1,427 @@
1
+ h1. Packaging
2
+
3
+ For our next trick, we're going to try and create an artifact ourselves. We're going to start with:
4
+
5
+ {{{!ruby
6
+ package :jar
7
+ }}}
8
+
9
+ We just told the project to create a JAR file in the @target@ directory, including all the classes (and resources) that we previously compiled into @target/classes@. Or we can create a WAR file:
10
+
11
+ {{{!ruby
12
+ package :war
13
+ }}}
14
+
15
+ The easy case is always easy, but sometimes we have more complicated use cases which we'll address through the rest of this section.
16
+
17
+ Now let's run the build, test cases and create these packages:
18
+
19
+ {{{!sh
20
+ $ buildr package
21
+ }}}
22
+
23
+ The @package@ task runs the @build@ task (remember: @compile@ and @test@) and then runs each of the packaging tasks, creating packages in the projects' target directories.
24
+
25
+ p(tip). The @package@ task and @package@ methods are related, but that relation is different from other task/method pairs. The @package@ method creates a file task that points to the package in the @target@ directory and knows how to create it. It then adds itself as a prerequisite to the @package@ task. Translation: you can create multiple packages from the same project.
26
+
27
+
28
+ h2. Specifying And Referencing Packages
29
+
30
+ Buildr supports several packaging types, and so when dealing with packages, you have to indicate the desired package type. The packaging type can be the first argument, or the value of the @:type@ argument. The following two are equivalent:
31
+
32
+ {{{!ruby
33
+ package :jar
34
+ package :type=>:jar
35
+ }}}
36
+
37
+ If you do not specify a package type, Buildr will attempt to infer one.
38
+
39
+ In the documentation you will find a number of tasks dealing with specific packaging types (@ZipTask@, @JarTask@, etc). The @package@ method is a convenience mechanism that sets up the package for you associates it with various project life cycle tasks.
40
+
41
+ To package a particular file, use the @:file@ argument, for example:
42
+
43
+ {{{!ruby
44
+ package :zip, :file=>_('target/interesting.zip')
45
+ }}}
46
+
47
+ This returns a file task that will run as part of the project's @package@ task (generating all packages). It will invoke the @build@ task to generate any necessary prerequisites, before creating the specified file.
48
+
49
+ The package type does not have to be the same as the file name extension, but if you don't specify the package type, it will be inferred from the extension.
50
+
51
+ Most often you will want to use the second form to generate packages that are also artifacts. These packages have an artifact specification, which you can use to reference them from other projects (and buildfiles). They are also easier to share across projects: artifacts install themselves in the local repository when running the @install@ task, and upload to the remote repository when running the @upload@ task (see "Installing and Uploading":#installing_and_uploading).
52
+
53
+ The artifact specification is based on the project name (using dashes instead of colons), group identifier and version number, all three obtained from the project definition. You can specify different values using the @:id@, @:group@, @:version@ and @:classifier@ arguments. For example:
54
+
55
+ {{{!ruby
56
+ define 'killer-app', :version=>'1.0' do
57
+ # Generates silly-1.0.jar
58
+ package :jar, :id=>'silly'
59
+
60
+ # Generates killer-app-la-web-1.x.war
61
+ project 'la-web' do
62
+ package :war, :version=>'1.x'
63
+ end
64
+
65
+ # Generates killer-app-the-api-1.0-sources.zip
66
+ project 'teh-api' do
67
+ package :zip, :classifier=>'sources'
68
+ end
69
+ end
70
+ }}}
71
+
72
+ The file name is determined from the identifier, version number, classifier and extension associated with that packaging type.
73
+
74
+ If you do not specify the packaging type, Buildr attempt to infer it from the project definition. In the general case it will use the default packaging type, ZIP. A project that compiles Java classes will default to JAR packaging; for other languages, consult the specific documentation.
75
+
76
+ A single project can create multiple packages. For example, a Java project may generate a JAR package for the runtime library and another JAR containing just the API; a ZIP file for the source code and another ZIP for the documentation. Make sure to always call @package@ with enough information to identify the specific package you are referencing. Even if the project only defines a single package, calling the @package@ method with no arguments does not necessarily refer to that one.
77
+
78
+ You can use the @packages@ method to obtain a list of all packages defined in the project, for example:
79
+
80
+ {{{!ruby
81
+ project('killer-app:teh-impl').packages.first
82
+ project('killer-app:teh-impl').packages.select { |pkg| pkg.type == :zip }
83
+ }}}
84
+
85
+
86
+ h2. Packaging ZIPs
87
+
88
+ ZIP is the most common form of packaging, used by default when no other packaging type applies. It also forms the basis for many other packaging types (e.g. JAR and WAR). Most of what you'll find here applies to other packaging types.
89
+
90
+ Let's start by including additional files in the ZIP package. We're going to include the @target/docs@ directory and @README@ file:
91
+
92
+ {{{!ruby
93
+ package(:zip).include _('target/docs'), 'README'
94
+ }}}
95
+
96
+ The @include@ method accepts files, directories and file tasks. You can also use file pattern to match multiple files and directories. File patterns include asterisk (@*@) to match any file name or part of a file name, double asterisk (@**@) to match directories recursively, question mark (@?@) to match any character, square braces (@[]@) to match a set of characters, and curly braces (@{}@) to match one of several names.
97
+
98
+ And the same way you @include@, you can also @exclude@ specific files you don't want showing up in the ZIP. For example, to exclude @.draft@ and @.raw@ files:
99
+
100
+ {{{!ruby
101
+ package(:zip).include('target/docs').
102
+ exclude('target/docs/**/*.{draft,raw}')
103
+ }}}
104
+
105
+ So far we've included files under the root of the ZIP. Let's include some files under a given path using the @:path@ option:
106
+
107
+ {{{!ruby
108
+ package(:zip).include 'target/docs', :path=>"#{id}-#{version}"
109
+ }}}
110
+
111
+ If you need to use the @:path@ option repeatedly, consider using the @tap@ method instead. For example:
112
+
113
+ {{{!ruby
114
+ package(:zip).path("#{id}-#{version}").tap do |path|
115
+ path.include 'target/docs'
116
+ path.include 'README'
117
+ end
118
+ }}}
119
+
120
+ p(tip). The @tap@ method is not part of the core library, but a very useful extension. It takes an object, yields to the block with that object, and then returns that object.
121
+
122
+ p(note). To allow you to spread files across different paths, the include/exclude patterns are specific to a path. So in the above example, if you want to exclude some files from the "target/docs" directory, make sure to call @exclude@ on the path, not on the ZIP task itself.
123
+
124
+ If you need to include a file or directory under a different name, use the @:as@ option. For example:
125
+
126
+ {{{!ruby
127
+ package(:zip).include('corporate-logo-350x240.png', :as=>'logo.png')
128
+ }}}
129
+
130
+ You can also use @:as=>'.'@ to include all files from the given directory. For example:
131
+
132
+ {{{!ruby
133
+ package(:zip).include 'target/docs/*'
134
+ package(:zip).include 'target/docs', :as=>'.'
135
+ }}}
136
+
137
+ These two are almost identical. They both include all the files from the @target/docs@ directory, but not the directory itself. But they operate differently. The first line expands to include all the files in @target/docs@. If you don't already have files in @target/docs@, well, then it won't do anything interesting. Your ZIP will come up empty. The second file includes the directory itself, but strips the path during inclusion. You can define it now, create these files later, and then ZIP them all up.
138
+
139
+ For example, when @package :jar@ decides to include all the files from @target/classes@, it's still working on the project definition, and has yet to compile anything. Since @target/classes@ may be empty, may not even exist, it uses @:as=>'.'@.
140
+
141
+ If you need to get rid of all the included files, call the @clean@ method. Some packaging types default to adding various files and directories, for example, JAR packaging will include all the compiled classes and resources.
142
+
143
+ You can also merge two ZIP files together, expanding the content of one ZIP into the other. For example:
144
+
145
+ {{{!ruby
146
+ package(:zip).merge 'part1.zip', 'part2.zip'
147
+ }}}
148
+
149
+ If you need to be more selective, you can apply the include/exclude pattern to the expanded ZIP. For example:
150
+
151
+ {{{!ruby
152
+ # Everything but the libs
153
+ package(:zip).merge('bigbad.war').exclude('libs/**/*')
154
+ }}}
155
+
156
+
157
+ h2. Packaging JARs
158
+
159
+ JAR packages extend ZIP packages with support for Manifest files and the META-INF directory. They also default to include the class files found in the @target/classes@ directory.
160
+
161
+ You can tell the JAR package to include a particular Manifest file:
162
+
163
+ {{{!ruby
164
+ package(:jar).with :manifest=>_('src/main/MANIFEST.MF')
165
+ }}}
166
+
167
+ Or generate a manifest from a hash:
168
+
169
+ {{{!ruby
170
+ package(:jar).with :manifest=>{ 'Copyright'=>'Acme Inc (C) 2007' }
171
+ }}}
172
+
173
+ You can also generate a JAR with no manifest with the value @false@, create a manifest with several sections using an array of hashes, or create it from a proc.
174
+
175
+ In large projects, where all the packages use the same manifest, it's easier to set it once on the top project using the @manifest@ project property. Sub-projects inherit the property from their parents, and the @package@ method uses that property if you don't override it, as we do above.
176
+
177
+ For example, we can get the same result by specifying this at the top project:
178
+
179
+ {{{!ruby
180
+ manifest['Copyright'] = 'Acme Inc (C) 2007'
181
+ }}}
182
+
183
+ If you need to mix-in the project's manifest with values that only one package uses, you can do so easily:
184
+
185
+ {{{!ruby
186
+ package(:jar).with :manifest=>manifest.merge('Main-Class'=>'com.acme.Main')
187
+ }}}
188
+
189
+ If you need to include more files in the @META-INF@ directory, you can use the @:meta_inf@ option. You can give it a file, or array of files. And yes, there is a @meta_inf@ project property you can set once to include the same set of file in all the JARs. It works like this:
190
+
191
+ {{{!ruby
192
+ meta_inf << file('DISCLAIMER') << file('NOTICE')
193
+ }}}
194
+
195
+ If you have a @LICENSE@ file, it's already included in the @meta_inf@ list of files.
196
+
197
+ Other than that, @package :jar@ includes the contents of the compiler's target directory and resources, which most often is exactly what you intend it to do. If you want to include other files in the JAR, instead or in addition, you can do so using the @include@ and @exclude@ methods. If you do not want the target directory included in your JAR, simply call the @clean@ method on it:
198
+
199
+ {{{!ruby
200
+ package(:jar).clean.include( only_these_files )
201
+ }}}
202
+
203
+
204
+ h2. Packaging WARs
205
+
206
+ Pretty much everything you know about JARs works the same way for WARs, so let's just look at the differences.
207
+
208
+ Without much prompting, @package :war@ picks the contents of the @src/main/webapp@ directory and places it at the root of the WAR, copies the compiler target directory into the @WEB-INF/classes@ path, and copies any compiled dependencies into the @WEB-INF/libs@ paths.
209
+
210
+ Again, you can use the @include@ and @exclude@ methods to change the contents of the WAR. There are two convenience options you can use to make the more common changes. If you need to include a classes directory other than the default:
211
+
212
+ {{{!ruby
213
+ package(:war).with :classes=>_('target/additional')
214
+ }}}
215
+
216
+ If you want to include a different set of libraries other than the default:
217
+
218
+ {{{!ruby
219
+ package(:war).with :libs=>MYSQL_JDBC
220
+ }}}
221
+
222
+ Both options accept a single value or an array. The @:classes@ option accepts the name of a directory containing class files, initially set to @compile.target@ and @resources.target@. The @:libs@ option accepts artifact specifications, file names and tasks, initially set to include everything in @compile.dependencies@.
223
+
224
+ As you can guess, the package task has two attributes called @classes@ and @libs@; the @with@ method merely sets their value. If you need more precise control over these arrays, you can always work with them directly, for example:
225
+
226
+ {{{!ruby
227
+ # Add an artifact to the existing set:
228
+ package(:war).libs += artifacts(MYSQL_JDBC)
229
+ # Remove an artifact from the existing set:
230
+ package(:war).libs -= artifacts(LOG4J)
231
+ # List all the artifacts:
232
+ puts 'Artifacts included in WAR package:'
233
+ puts package(:war).libs.map(&:to_spec)
234
+ }}}
235
+
236
+
237
+ h2. Packaging AARs
238
+
239
+ Axis2 service archives are similar to JAR's (compiled classes go into the root of the archive) but they can embed additional libraries under /lib and include @services.xml@ and WSDL files.
240
+
241
+ {{{!ruby
242
+ package(:aar).with(:libs=>'log4j:log4j:jar:1.1')
243
+ package(:aar).with(:services_xml=>_('target/services.xml'), :wsdls=>_('target/*.wsdl'))
244
+ }}}
245
+
246
+ The @libs@ attribute is a list of .jar artifacts to be included in the archive under /lib. The default is no artifacts; compile dependencies are not included by default.
247
+
248
+ The @services_xml@ attribute points to an Axis2 services configuration file called @services.xml@ that will be placed in the @META-INF@ directory inside the archive. The default behavior is to point to the @services.xml@ file in the project's @src/main/axis2@ directory. In the second example above we set it explicitly.
249
+
250
+ The @wsdls@ attribute is a collection of file names or glob patterns for WSDL files that get included in the @META-INF@ directory. In the second example we include WSDL files from the @target@ directory, presumably created by an earlier build task. In addition, AAR packaging will include all files ending with @.wsdl@ from the @src/main/axis2@ directory.
251
+
252
+ If you already have WSDL files in the @src/main/axis2@ directory but would like to perform some filtering, for example, to set the HTTP port number, consider ignoring the originals and including only the filtered files, for example:
253
+
254
+ {{{!ruby
255
+ # Host name depends on environment.
256
+ host = ENV['ENV'] == 'test' ? 'test.host' : 'ws.example.com'
257
+ filter.from('src/main/axis2').into('target').
258
+ include('services.xml', '*.wsdl').using('http_port'=>'8080', 'http_host'=>host)
259
+ package(:aar).wsdls.clear
260
+ package(:aar).with(:services_xml=>_('target/services.xml'), :wsdls=>_('target/*.wsdl'))
261
+ }}}
262
+
263
+
264
+ h2. Packaging EARs
265
+
266
+ EAR packaging is slightly different from JAR/WAR packaging. It's main purpose is to package components together, and so it includes special methods for handling component inclusion that take care to update application.xml and the component's classpath.
267
+
268
+ EAR packages support four component types:
269
+
270
+ |_. Argument |_. Component |
271
+ | @:war@ | J2EE Web Application (WAR). |
272
+ | @:ejb@ | Enterprise Java Bean (JAR). |
273
+ | @:jar@ | J2EE Application Client (JAR). |
274
+ | @:lib@ | Shared library (JAR). |
275
+
276
+ This example shows two ways for adding components built by other projects:
277
+
278
+ {{{!ruby
279
+ package(:ear) << project('coolWebService').package(:war)
280
+ package(:ear).add project('commonLib') # By default, the JAR package
281
+ }}}
282
+
283
+ Adding a WAR package assumes it's a WAR component and treats it as such, but JAR packages can be any of three component types, so by default they are all treated as shared libraries. If you want to add an EJB or Application Client component, you need to say so explicitly, either passing @:type=>package@, or by passing the component type in the @:type@ option.
284
+
285
+ Here are three examples:
286
+
287
+ {{{!ruby
288
+ # Assumed to be a shared library.
289
+ package(:ear).add 'org.springframework:spring:jar:2.6'
290
+ # Component type mapped to package.
291
+ package(:ear).add :ejb=>project('beanery')
292
+ # Adding component with specific package type.
293
+ package(:ear).add project('client'), :type=>:jar
294
+ }}}
295
+
296
+ By default, WAR components are all added under the @/war@ path, and likewise, EJB components are added under the @/ejb@ path, shared libraries under @/lib@ and Application Client components under @/jar@.
297
+
298
+ If you want to place components in different locations you can do so using the @:path@ option, or by specifying a different mapping between component types and their destination directory. The following two examples are equivalent:
299
+
300
+ {{{!ruby
301
+ # Specify once per component.
302
+ package(:ear).add project('coolWebService').package(:war), :path=>'coolServices'
303
+ # Configure once and apply to all added components.
304
+ package(:ear).dirs[:war] = 'coolServices'
305
+ package(:ear) << project('coolWebService').package(:war)
306
+ }}}
307
+
308
+ EAR packages include an @application.xml@ file in the @META-INF@ directory that describes the application and its components. This file is created for you during packaging, by referencing all the components added to the EAR. There are a couple of things you will typically want to change.
309
+
310
+ * *display-name* -- The application's display name defaults to the project's identifier. You can change that by setting the @display_name@ attribute.
311
+
312
+ * *context-root* -- WAR components specify a context root, based on the package identifier, for example, "cool-web-1.0.war" will have the context root "cool-web". To specify a different context root, add the WAR package with the @context_root@ option.
313
+
314
+ Again, by example:
315
+
316
+ {{{!ruby
317
+ package(:ear).display_name = 'MyCoolWebService'
318
+ package(:ear).add project('coolWebService').package(:war), :context-root=>'coolness'
319
+ }}}
320
+
321
+ If you need to disable the context root (e.g. for Portlets), set @context_root@ to @false@.
322
+
323
+
324
+ h2. Packaging Tars and GZipped Tars
325
+
326
+ Everything you know about working with ZIP files translates to Tar files, the two tasks are identical in more respect, so here we'll just go over the differences.
327
+
328
+ {{{!ruby
329
+ package(:tar).include _('target/docs'), 'README'
330
+ package(:tgz).include _('target/docs'), 'README'
331
+ }}}
332
+
333
+ The first line creates a Tar archive with the extension @.tar@, the second creates a GZipped Tar archive with the extension @.tgz@.
334
+
335
+ In addition to packaging that includes the archive in the list of installed/released files, you can use the method @tar@ to create a @TarTask@. This task is similar to @ZipTask@, and introduces the @gzip@ attribute, which you can use to tell it whether to create a regular file, or GZip it. By default the attribute it set to true (GZip) if the file name ends with either @.gz@ or @.tgz@.
336
+
337
+
338
+ h2. Installing and Uploading
339
+
340
+ You can bring in the artifacts you need from remote repositories and install them in the local repositories. Other projects have the same expectation, that your packages be their artifacts.
341
+
342
+ So let's create these packages and install them in the local repository where other projects can access them:
343
+
344
+ {{{!sh
345
+ $ buildr install
346
+ }}}
347
+
348
+ If you changes your mind you can always:
349
+
350
+ {{{!sh
351
+ $ buildr uninstall
352
+ }}}
353
+
354
+ That works between projects you build on the same machine. Now let's share these artifacts with other developers through a remote repository:
355
+
356
+ {{{!sh
357
+ $ buildr upload
358
+ }}}
359
+
360
+ Of course, you'll need to tell Buildr about the release server:
361
+
362
+ {{{!ruby
363
+ repositories.release_to = 'sftp://john:secret@release/usr/share/repo'
364
+ }}}
365
+
366
+ This example uses the SFTP protocol. In addition, you can use the HTTP protocol -- Buildr supports HTTP and HTTPS, Basic Authentication and uploads using PUT -- or point to a directory on your file system.
367
+
368
+ The URL in this example contains the release server ("release"), path to repository ("user/share/repo") and username/password for access. The way SFTP works, you specify the path on the release server, and give the user permissions to create directories and files inside the repository. The file system path is different from the path you use to download these artifacts through an HTTP server, and starts at the root, not the user's home directory.
369
+
370
+ Of course, you'll want to specify the release server URL in the Buildfile, but leave the username/password settings private in your local @buildr.rb@ file. Let's break up the release server settings:
371
+
372
+ {{{!ruby
373
+ # build.rb, loaded first
374
+ repositories.release_to[:username] = 'john'
375
+ repositories.release_to[:password] = 'secret'
376
+
377
+ # Buildfile, loaded next
378
+ repositories.release_to[:url] = 'sftp://release/usr/share/repo'
379
+ }}}
380
+
381
+ The @upload@ task takes care of uploading all the packages created by your project, along with their associated POM files and MD5/SHA1 signatures (Buildr creates these for you).
382
+
383
+ If you need to upload other files, you can always extend the @upload@ task and use @repositories.release_to@ in combination with @URI.upload@. You can also extend it to upload to different servers, for example, to publish the documentation and test coverage reports to your site:
384
+
385
+ {{{!ruby
386
+ # We'll let some other task decide how to create 'docs'
387
+ task 'deploy'=>'docs' do
388
+ uri = URI("sftp://#{username}:#{password}@var/www/docs")
389
+ uri.upload file('docs')
390
+ end
391
+ }}}
392
+
393
+
394
+ h2. Packaging Sources and JavaDocs
395
+
396
+ IDEs can take advantage of source packages to help you debug and trace through compiled code. We'll start with a simple example:
397
+
398
+ {{{!ruby
399
+ package :sources
400
+ }}}
401
+
402
+ This one creates a ZIP package with the classifier "sources" that will contain all the source directories in that project, typically @src/main/java@, but also other sources generated from Apt, JavaCC, XMLBeans and friends.
403
+
404
+ You can also generate a ZIP package with the classifier "javadoc" that contains the JavaDoc documentation for the project. It uses the same set of documentation files generated by the project's @javadoc@ task, so you can use it in combination with the @javadoc@ method. For example:
405
+
406
+ {{{!ruby
407
+ package :javadoc
408
+ javadoc :windowtitle=>'Buggy but Works'
409
+ }}}
410
+
411
+ By default Buildr picks the project's description for the window title.
412
+
413
+ You can also tell Buildr to automatically create sources and JavaDoc packages in all the sub-projects that have any source files to package or document. Just add either or both of these methods in the top-level project:
414
+
415
+ {{{!ruby
416
+ package_with_sources
417
+ package_with_javadoc
418
+ }}}
419
+
420
+ You can also tell it to be selective using the @:only@ and @:except@ options.
421
+ For example:
422
+
423
+ {{{!ruby
424
+ package_with_javadoc :except=>'la-web'
425
+ }}}
426
+
427
+ We packaged the code, but will it actually work? Let's see "what the tests say":testing.html.