mguymon-buildr 1.4.5-java

Sign up to get free protection for your applications and to get access to all the features.
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,54 @@
1
+ ---
2
+ layout: preface
3
+ ---
4
+
5
+ p(title). !images/zbuildr.png!
6
+
7
+ <ol class='toc'>
8
+ <li>"Quick Start":quick_start.html</li>
9
+ <li>"Installing and Running":installing.html</li>
10
+ <li>"Projects":projects.html</li>
11
+ <li>"Building":building.html</li>
12
+ <li>"Artifacts":artifacts.html</li>
13
+ <li>"Packaging":packaging.html</li>
14
+ <li>"Testing":testing.html</li>
15
+ <li>"Settings & Profiles":settings_profiles.html</li>
16
+ <li>"Languages":languages.html</li>
17
+ <li>"More Stuff":more_stuff.html</li>
18
+ <li>"Extending Buildr":extending.html</li>
19
+ <li>"Contributing":contributing.html</li>
20
+ </ol>
21
+
22
+
23
+ p(preface). !images/asf-logo.png!
24
+
25
+ Copyright 2007-2009 Apache Buildr
26
+
27
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
28
+
29
+ http://www.apache.org/licenses/LICENSE-2.0
30
+
31
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
32
+
33
+
34
+
35
+ <div class='preface quotes'>
36
+ "Daniel Spiewak":http://www.codecommit.com/blog:
37
+
38
+ bq. If you think about it, the question isn’t “Why use Buildr?”, it’s really “Why use anything else?” The advantages afforded by Buildr are so substantial, I really can’t see myself going with any other tool, at least not when I have a choice.
39
+
40
+ "Tristan Juricek":http://tristanhunt.com/:
41
+
42
+ bq. That’s still the strongest sell: it builds everything I need, and as I’ve needed more, I just got things working without a lot of fuss.
43
+
44
+ "Matthieu Riou":http://offthelip.org/:
45
+
46
+ bq. We used to rely on Ant, with a fairly extensive set of scripts. It worked but was expensive to maintain. The biggest mistake afterward was to migrate to Maven2. I could write pages of rants explaining all the problems we ran into and we still ended up with thousands of lines of XML.
47
+
48
+ "Martin Grotzke":http://www.javakaffee.de/blog/:
49
+
50
+ bq. The positive side effect for me as a java user is that I learn a little ruby, and that’s easy but lots of fun… :-)
51
+ </div>
52
+
53
+
54
+ p(preface).
@@ -0,0 +1,276 @@
1
+ ---
2
+ layout: default
3
+ title: Projects
4
+ ---
5
+
6
+
7
+ h2(#starting). Starting Out
8
+
9
+ In Java, most projects are built the same way: compile source code, run test cases, package the code, release it. Rinse, repeat.
10
+
11
+ Feed it a project definition, and Buildr will set up all these tasks for you. The only thing you need to do is specify the parts that are specific to your project, like the classpath dependencies, whether you're packaging a JAR or a WAR, etc.
12
+
13
+ The remainder of this guide deals with what it takes to build a project. But first, let's pick up a sample project to work with. We'll call it _killer-app_:
14
+
15
+ {% highlight ruby %}
16
+ require "buildr/openjpa"
17
+
18
+ include Buildr::OpenJPA
19
+
20
+ VERSION_NUMBER = '1.0'
21
+
22
+ AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
23
+ AXIOM = group('axiom-api', 'axiom-impl', 'axiom-dom',
24
+ :under=>'org.apache.ws.commons.axiom', :version=>'1.2.4')
25
+ AXIS_OF_WS = [AXIOM, AXIS2]
26
+ OPENJPA = ['org.apache.openjpa:openjpa:jar:1.2.0',
27
+ 'net.sourceforge.serp:serp:jar:1.12.0']
28
+
29
+ repositories.remote << 'http://www.ibiblio.org/maven2/'
30
+
31
+ desc 'Code. Build. ??? Profit!'
32
+ define 'killer-app' do
33
+
34
+ project.version = VERSION_NUMBER
35
+ project.group = 'acme'
36
+ manifest['Copyright'] = 'Acme Inc (C) 2007'
37
+ compile.options.target = '1.5'
38
+
39
+ desc 'Abstract classes and interfaces'
40
+ define 'teh-api' do
41
+ package :jar
42
+ end
43
+
44
+ desc 'All those implementation details'
45
+ define 'teh-impl' do
46
+ compile.with AXIS_OF_WS, OPENJPA
47
+ compile { open_jpa_enhance }
48
+ package :jar
49
+ end
50
+
51
+ desc 'What our users see'
52
+ define 'la-web' do
53
+ test.with AXIS_OF_WS
54
+ package(:war).with :libs=>projects('teh-api', 'teh-impl')
55
+ end
56
+
57
+ javadoc projects
58
+ package :javadoc
59
+
60
+ end
61
+ {% endhighlight %}
62
+
63
+ A project definition requires four pieces of information: the project name, group identifier, version number and base directory. The project name ... do we need to explain why its necessary? The group identifier and version number are used for packaging and deployment, we'll talk more about that in the "Packaging":packaging.html section. The base directory lets you find files inside the project.
64
+
65
+ Everything else depends on what that particular project is building. And it all goes inside the project definition block, the piece of code that comes between @define <name> .. do@ and @end@.
66
+
67
+
68
+ h2(#dir_structure). The Directory Structure
69
+
70
+ Buildr follows a convention we picked from years of working with Apache projects.
71
+
72
+ Java projects are laid out so the source files are in the @src/main/java@ directory and compile into the @target/classes@ directory. Resource files go in the @src/main/resources@ directory, and copied over to @target/resources@. Likewise, tests come from @src/test/java@ and @src/test/resources@, and end life in @target/test/classes@ and @target/test/resources@, respectively.
73
+
74
+ WAR packages pick up additional files from the aptly named @src/main/webapp@. And most stuff, including generated source files are parked under the @target@ directory. Test cases and such may generate reports in the, you guessed it, @reports@ directory.
75
+
76
+ Other languages will use different directories, but following the same general conventions. For example, Scala code compiles from the @src/main/scala@ directory, RSpec tests are found in the @src/test/rspec@ directory, and Flash will compile to @target/flash@. Throughout this document we will show examples using mostly Java, but you can imagine how this pattern applies to other languages.
77
+
78
+ When projects grow big, you split them into smaller projects by nesting projects inside each other. Each sub-project has a sub-directory under the parent project and follows the same internal directory structure. You can, of course, change all of that to suite your needs, but if you follow these conventions, Buildr will figure all the paths for you.
79
+
80
+ Going back to the example above, the directory structure will look something like this:
81
+
82
+ p=. !images/project-structure.png!
83
+
84
+ Notice the @buildfile@ at the top. That's your project build script, the one Buildr runs.
85
+
86
+ When you run the @buildr@ command, it picks up the @buildfile@ (which here we'll just call _Buildfile_) from the current directory, or if not there, from the closest parent directory. So you can run @buildr@ from any directory inside your project, and it will always pick up the same Buildfile. That also happens to be the base directory for the top project. If you have any sub-projects, Buildr assumes they reflect sub-directories under their parent.
87
+
88
+ And yes, you can have two top projects in the same Buildfile. For example, you can use that to have one project that groups all the application modules (JARs, WARs, etc) and another project that groups all the distribution packages (binary, sources, javadocs).
89
+
90
+ When you start with a new project you won't see the @target@ or @reports@ directories. Buildr creates these when it needs to. Just know that they're there.
91
+
92
+
93
+ h2(#naming). Naming And Finding Projects
94
+
95
+ Each project has a given name, the first argument you pass when calling @define@. The project name is just a string, but we advise to stay clear of colon (@:@) and slashes (@/@ and @\@), which could conflict with other task and file names. Also, avoid using common Buildr task names, don't pick @compile@, @build@ or any existing task name for your project name.
96
+
97
+ Since each project knows its parent project, child projects and siblings, you can reference them from within the project using just the given name. In other cases, you'll need to use the full name. The full name is just @parent:child@. So if you wanted to refer to _teh-impl_, you could do so with either @project('killer-app:teh-impl')@ or @project('killer-app').project('teh-impl')@.
98
+
99
+ The @project@ method is convenient when you have a dependency from one project to another, e.g. using the other project in the classpath, or accessing one of its source files. Call it with a project name and it will return that object or raise an error. You can also call it with no arguments and it will return the project itself. It's syntactic sugar that's useful when accessing project properties.
100
+
101
+ The @projects@ method takes a list of names and returns a list of projects. If you call it with no arguments on a project, it returns all its sub-projects. If you call it with no argument in any other context, it returns all the projects defined so far.
102
+
103
+ Let's illustrate this with a few examples:
104
+
105
+ {% highlight ruby %}
106
+ puts projects.inspect
107
+ => [project("killer-app"), project("killer-app:teh-api") ... ]
108
+
109
+ puts project('killer-app').projects.inspect
110
+ => [project("killer-app:teh-api"), project("killer-app:teh-impl") ... ]
111
+
112
+ puts project('teh-api')
113
+ => No such project teh-api
114
+
115
+ puts project('killer-app:teh-api').inspect
116
+ => project("killer-app:teh-api")
117
+
118
+ puts project('killer-app').project('teh-api').inspect
119
+ => project("killer-app:teh-api")
120
+ {% endhighlight %}
121
+
122
+ To see a list of all projects defined in your Buildfile run @buildr help:projects@.
123
+
124
+
125
+ h2(#tasks). Running Project Tasks
126
+
127
+ Most times, you run tasks like @build@ or @package@ that operate on the current project and recursively on its sub-projects. The "current project" is the one that uses the current working directory. So if you're in the @la-web/src@ directory looking at source files, _la-web_ is the current project. For example:
128
+
129
+ {% highlight sh %}
130
+ # build killer-app and all its sub-projects
131
+ $ buildr build
132
+
133
+ # switch to and test only teh-impl
134
+ $ cd teh-impl
135
+ $ buildr test
136
+
137
+ # switch to and package only la-web
138
+ $ cd ../la-web
139
+ $ buildr package
140
+ {% endhighlight %}
141
+
142
+ You can use the project's full name to invoke one of its tasks directly, and it doesn't matter which directory you're in. For example:
143
+
144
+ {% highlight sh %}
145
+ # build killer-app and all its sub-projects
146
+ $ buildr killer-app:build
147
+
148
+ # test only teh-impl
149
+ $ buildr killer-app:teh-impl:test
150
+
151
+ # package only la-web
152
+ $ buildr killer-app:la-web:package
153
+ {% endhighlight %}
154
+
155
+ Buildr provides the following tasks that you can run on the current project, or on a specific project by prefixing them with the project's full name:
156
+
157
+ {% highlight text %}
158
+ clean # Clean files generated during a build
159
+ compile # Compile all projects
160
+ build # Build the project
161
+ upload # Upload packages created by the project
162
+ install # Install packages created by the project
163
+ javadoc # Create the Javadocs for this project
164
+ package # Create packages
165
+ test # Run all test cases
166
+ uninstall # Remove previously installed packages
167
+ {% endhighlight %}
168
+
169
+ To see a list of all the tasks provided by Buildr run @buildr help:tasks@.
170
+
171
+
172
+ h2(#properties). Setting Project Properties
173
+
174
+ We mentioned the group identifier, version number and base directory. These are project properties. There are a few more properties we'll cover later on.
175
+
176
+ There are two ways to set project properties. You can pass them as a hash when you call @define@, or use accessors to set them on the project directly. For example:
177
+
178
+ {% highlight ruby %}
179
+ define 'silly', :version=>'1.0' do
180
+ project.group = 'acme'
181
+ end
182
+
183
+ puts project('silly').version
184
+ => 1.0
185
+ puts project('silly').group
186
+ => acme
187
+ {% endhighlight %}
188
+
189
+ Project properties are inherited. You can specify them once in the parent project, and they'll have the same value in all its sub-projects. In the example, we only specify the version number once, for use in all sub-projects.
190
+
191
+
192
+ h2(#paths). Resolving Paths
193
+
194
+ You can run @buildr@ from any directory in your project. To keep tasks consistent and happy, it switches over to the Buildfile directory and executes all the tasks from there, before returning back to your working directory. Your tasks can all rely on relative paths that start from the same directory as the Buildfile.
195
+
196
+ But in practice, you'll want to use the @path_to@ method. This method calculates a path relative to the project, a better way if you ever need to refactor your code, say turn a ad hoc task into a function you reuse.
197
+
198
+ The @path_to@ method takes an array of strings and concatenates them into a path. Absolute paths are returned as they are, relative paths are expanded relative to the project's base directory. Slashes, if you don't already know, work very well on both Windows, Linux and OS X. And as a shortcut, you can use @_@.
199
+
200
+ For example:
201
+
202
+ {% highlight ruby %}
203
+ # Relative to the current project
204
+ path_to('src', 'main', 'java')
205
+
206
+ # the same using symbols
207
+ path_to(:src, :main, :java)
208
+
209
+ # Exactly the same thing
210
+ _('src/main/java')
211
+
212
+ # Relative to the teh-impl project
213
+ project('teh-impl')._('src/main/java')
214
+ {% endhighlight %}
215
+
216
+
217
+ h2(#defining). Defining The Project
218
+
219
+ The project definition itself gives you a lot of pre-canned tasks to start with, but that's not enough to build a project. You need to specify what gets built and how, which dependencies to use, the packages you want to create and so forth. You can configure existing tasks, extend them to do additional work, and create new tasks. All that magic happens inside the project definition block.
220
+
221
+ Since the project definition executes each time you run Buildr, you don't want to perform any work directly inside the project definition block. Rather, you want to use it to specify how different build task work when you invoke them. Here's an example to illustrate the point:
222
+
223
+ {% highlight ruby %}
224
+ define 'silly' do
225
+ puts 'Running buildr'
226
+
227
+ build do
228
+ puts 'Building silly'
229
+ end
230
+ end
231
+ {% endhighlight %}
232
+
233
+ Each time you run Buildr, it will execute the project definition and print out "Running buildr". We also extend the @build@ task, and whenever we run it, it will print "Building silly". Incidentally, @build@ is the default task, so if you run Buildr with no arguments, it will print both messages while executing the build. If you run Buildr with a different task, say @clean@, it will only print the first message.
234
+
235
+ The @define@ method gathers the project definition, but does not execute it immediately. It executes the project definition the first time you reference that project, directly or indirectly, for example, by calling @project@ with that project's name, or calling @projects@ to return a list of all projects. Executing a project definition will also execute all its sub-projects' definitions. And, of course, all project definitions are executed once the Buildfile loads, so Buildr can determine how to execute each of the build tasks.
236
+
237
+ If this sounds a bit complex, don't worry. In reality, it does the right thing. A simple rule to remember is that each project definition is executed before you need it, lazy evaluation of sort. The reason we do that? So you can write projects that depend on each other without worrying about their order.
238
+
239
+ In our example, the _la-web_ project depends on packages created by the _teh-api_ and _teh-impl_ projects, the later requiring _teh-api_ to compile. That example is simple enough that we ended up specifying the projects in order of dependency. But you don't always want to do that. For large projects, you may want to group sub-projects by logical units, or sort them alphabetically for easier editing.
240
+
241
+ One project can reference another ahead of its definition. If Buildr detects a cyclic dependency, it will let you know.
242
+
243
+ In this example we define one project in terms of another, using the same dependencies, so we only need to specify them once:
244
+
245
+ {% highlight ruby %}
246
+ define 'bar' do
247
+ compile.with project('foo').compile.dependencies
248
+ end
249
+
250
+ define 'foo' do
251
+ compile.with ..lots of stuff..
252
+ end
253
+ {% endhighlight %}
254
+
255
+ One last thing to remember. Actually three, but they all go hand in hand.
256
+
257
+ *Self is project* Each of these project definition blocks executes in the context of that project, just as if it was a method defined on the project. So when you call the @compile@ method, you're essentially calling that method on the current project: @compile@, @self.compile@ and @project.compile@ are all the same.
258
+
259
+ *Blocks are closures* The project definition is also a closure, which can reference variables from enclosing scopes. You can use that, for example, to define constants, variables and even functions in your Buildfile, and reference them from your project definition. As you'll see later on, in the "Artifacts":artifacts.html section, it will save you a lot of work.
260
+
261
+ *Projects are namespaces* While executing the project definition, Buildr switches the namespace to the project name. If you define the task "do-this" inside the _teh-impl_ project, the actual task name is "killer-app:teh-impl:do-this". Likewise, the @compile@ task is actually "killer-app:teh-impl:compile".
262
+
263
+ From outside the project you can reference a task by its full name, either @task('foo:do')@ or @project('foo').task('do')@. If you need to reference a task defined outside the project from within the project, prefix it with "rake:", for example, @task('rake:globally-defined')@.
264
+
265
+
266
+ h2(#your_own_tasks). Writing Your Own Tasks
267
+
268
+ Of all the features Buildr provide, it doesn't have a task for making coffee. Yet. If you need to write your own tasks, you get all the power of Rake: you can use regular tasks, file tasks, task rules and even write your own custom task classes. Check out the "Rake documentation":http://docs.rubyrake.org/ for more information.
269
+
270
+ We mentioned projects as namespaces before. When you call @task@ on a project, it finds or defines the task using the project namespace. So given a project object, @task('do-this')@ will return it's "do-this" task. If you lookup the source code for the @compile@ method, you'll find that it's little more than a shortcut for @task('compile')@.
271
+
272
+ Another shortcut is the @file@ method. When you call @file@ on a project, Buildr uses the @path_to@ method to expand relative paths using the project's base directory. If you call @file('src')@ on _teh-impl_, it will return you a file task that points at the @teh-impl/src@ directory.
273
+
274
+ In the current implementation projects are also created as tasks, although you don't invoke these tasks directly. That's the reason for not using a project name that conflicts with an existing task name. If you do that, you'll find quick enough, as the task will execute each time you run Buildr.
275
+
276
+ So now that you know everything about projects and tasks, let's go and "build some code":building.html.
@@ -0,0 +1,210 @@
1
+ ---
2
+ layout: default
3
+ title: Quick Start
4
+ ---
5
+
6
+ This quick start guide is meant to be a _very_ simple introduction to Buildr and its most basic concepts. However, despite its basic level, we will still cover most of the concepts you will ever need to be productive with Buildr. We will leave out some important things (like "sub-projects":projects.html), and we will over-simplify some other concepts (such as "artifacts":artifacts.html). Nevertheless, most Buildr projects never need to go beyond the techniques contained within these pages.
7
+
8
+ *No knowledge of Ruby is assumed.* Buildr is designed to be a very intuitive, very easy-to-use tool. You can create buildfiles which describe incredibly intricate projects, write custom tasks which do things far beyond Ant, and still never need to pick up more than a smattering of Ruby syntax. With that said, if you do know Ruby, Buildr's DSL will seem very natural and welcoming. We do assume that you have already "downloaded and installed":installing.html Buildr and are ready to put the tool to good use.
9
+
10
+
11
+ h2(#first-project). Your First Project
12
+
13
+ Much like Maven, Buildr is oriented around projects and tasks. You define your project in a concise, declarative fashion and most common tasks (such as compilation and testing) will be made available to you "at no extra charge". Most of the project definition is contained within the _buildfile_ -- or _Buildfile_, if you're really in love with the Make convention -- a single file sitting at the root of your project. A project definition does not need to be any more complicated than the following:
14
+
15
+ {% highlight ruby %}
16
+ define 'killer-app'
17
+ {% endhighlight %}
18
+
19
+ h3. Compiling
20
+
21
+ Of course, this isn't really giving Buildr much information. What it can't learn from the buildfile, Buildr will figure out by inspecting your directory structure. Java sources are expected to exist within the @src/main/java/@ directory. If Buildr finds these sources, it will automatically configure the compilation to source that directory, depositing the results in the @target/classes/@ directory (all under the project directory of course). We can run this compilation using the following command:
22
+
23
+ {% highlight sh %}
24
+ $ buildr compile
25
+ {% endhighlight %}
26
+
27
+ Information about the classpath and dependencies is described "later on":#dependencies.
28
+
29
+ p(tip). By default, Buildr projects assume the Java language and the @src/main/java/@ source directory. You can also have projects in the Scala or Groovy language (both languages support joint compilation with Java). To use Scala, place your @.scala@ files in the @src/main/scala/@ directory and include the following invocation at the head of your buildfile: @require 'buildr/scala'@ Similarly, Groovy expects sources in the @src/main/groovy/@ directory and necessitates @require 'buildr/groovy'@ (see "languages":languages.html for more information).
30
+
31
+ The @compile@ task will also detect _any_ files which exist under the @src/main/resources/@ directory. These resources are copied verbatim to the @target/resources/@ directory as part of the compilation task. Buildr also performs some basic change detection to minimize compilation. If your source files haven't changed since the last compile, then they will not be recompiled.
32
+
33
+ h3. Packaging
34
+
35
+ At some point, we're going to want to wrap up our classes and produce a single JAR file for distribution. Buildr can certainly help us with this, but we are going to need to provide it with a little bit more information. Specifically, we need to say the type of package to produce (e.g. @:jar@, @:war@, etc) as well as the current version of our project. This information is placed within the buildfile:
36
+
37
+ {% highlight ruby %}
38
+ define 'killer-app' do
39
+ project.version = '0.1.0'
40
+ package :jar
41
+ end
42
+ {% endhighlight %}
43
+
44
+ The @project.version@ attribute can be any value you like. Even non-numeric versions are perfectly acceptable (e.g. @'ikj-0.3.1-E'@). This version -- coupled with the packaging information -- will be used to generate a JAR file: @killer-app-0.1.0.jar@. As would be expected, this file is placed within the @target/@ directory when the following command is run:
45
+
46
+ {% highlight sh %}
47
+ $ buildr package
48
+ {% endhighlight %}
49
+
50
+ The @package@ task depends upon the @compile@ task, so if a rebuild is necessary prior to the creation of the JAR, Buildr will see to it.
51
+
52
+ We can also chain tasks together in a single invocation. For example, we may want to clean all of the old compilation results prior to recompiling and generating a packaged result:
53
+
54
+ {% highlight sh %}
55
+ $ buildr clean package
56
+ {% endhighlight %}
57
+
58
+ The @clean@ task simply removes the @target/@ directory, effectively wiping out any compilation results like class files or resources.
59
+
60
+ h3. Directory Structure
61
+
62
+ As you may have noticed, Buildr does have some default notions about what a project should look like and how it should be organized. We think that these defaults are quite nice and make for a more navigable project. However, we do understand that not all projects are exactly alike. Buildr's "layouts":extending.html#layouts make it possible for any project to easily change these defaults. For example, this would allow you to easily migrate a project that had been based on a different directory structure, such as the @src/@ and @bin/@ convention often used by Ant.
63
+
64
+
65
+ h2(#dependencies). Dependencies
66
+
67
+ So far, we have seen how Buildr can automatically infer what amounts to dozens of lines of @build.xml@ contents, all based on a buildfile and a directory structure. However, the best is yet to come. Buildr also provides Maven-style dependency management (but without the long loading times!). In other words, you specify each dependent library using a string descriptor and Buildr figures out how to download and configure your classpath (the library descriptors are just a Ruby array, therefore they are separated by commas (@,@)). You must specify at least one remote repository so that Buildr knows from where to download these libraries. For example, we can configure our project to reference the "Apache Commons CLI":http://commons.apache.org/cli/ library and download libraries from the Ibiblio repository:
68
+
69
+ {% highlight ruby %}
70
+ repositories.remote << 'http://www.ibiblio.org/maven2'
71
+
72
+ define 'killer-app' do
73
+ project.version = '0.1.0'
74
+ compile.with 'commons-cli:commons-cli:jar:1.2'
75
+ package :jar
76
+ end
77
+ {% endhighlight %}
78
+
79
+ This sort of dependency declaration should look quite familiar if you are at all familiar with Maven. The general format for an artifact descriptor is _groupId:artifactId:packageType:version_. Any Maven artifacts included in this fashion will be retrieved from the "list of remote repositories":artifacts.html#repositories (in this case, Ibiblio) and installed in your local repository at @~/.m2/repository/@.
80
+
81
+ p(tip). You can search the global repository of artifacts at sites like "MvnBrowser":http://www.mvnbrowser.com. Simply enter the name of the library you are looking for, and the search should pull up the groupId, artifactId and a list of available versions.
82
+
83
+ Unfortunately, not all libraries are quite as simple as Commons CLI. Many libraries (such as Apache Wicket) have dependencies of their own. While we may be able to _compile_ against Apache Wicket without these extra libraries on our classpath, we cannot actually _run_ our application without its transitive dependencies. To avoid tracking down each of these dependencies and adding them manually, we can simply use the @transitive@ directive (this is how Maven behaves by default):
84
+
85
+ {% highlight ruby %}
86
+ repositories.remote << 'http://www.ibiblio.org/maven2'
87
+
88
+ define 'killer-app' do
89
+ project.version = '0.1.0'
90
+ compile.with transitive('org.apache.wicket:wicket:jar:1.4-rc6')
91
+ package :jar
92
+ end
93
+ {% endhighlight %}
94
+
95
+ The @compile.with@ property accepts a full array of comma-separated artifacts, making it possible to specify any number of dependencies as necessary. Of course, such a long list of verbose string descriptors could get very tiresome and messy. For this reason, it is conventional to assign each dependency to a constant (e.g. @WICKET@) which is declared just above the project in the buildfile and passed to @compile.with@ in a clean, easy-to-read style:
96
+
97
+ {% highlight ruby %}
98
+ repositories.remote << 'http://www.ibiblio.org/maven2'
99
+
100
+ WICKET = transitive('org.apache.wicket:wicket:jar:1.4-rc6')
101
+ SLF4J = 'org.slf4j:slf4j-jdk14:jar:1.5.8'
102
+
103
+ define 'killer-app' do
104
+ project.version = '0.1.0'
105
+ compile.with WICKET, SLF4J
106
+ package :jar
107
+ end
108
+ {% endhighlight %}
109
+
110
+ Unfortunate as it may seem, not all libraries are available in Maven repositories. While most of the major libraries (e.g. Hibernate, Spring, etc) are kept updated by intrepid volunteers, some of the more obscure frameworks are left out in the cold. An example of one such framework is "DBPool":http://www.snaq.net/java/DBPool, a very fast connection pool designed to integrate with JDBC. However, like most Java libraries, DBPool does provide a zip archive which contains the JAR file, as well as some documentation and perhaps a license or two.
111
+
112
+ Almost magically, we can instruct Buildr to get the DBPool artifact from this URL. Buildr will treat this download just like any other artifact, retrieving it when requried by the @compile@ task. However, unlike a normal Maven artifact, Buildr will do some extra processing once the download is complete. It will actually dig into the downloaded archive, detect and extract the JAR file, installing it into the local repository just like any other artifact:
113
+
114
+ {% highlight ruby %}
115
+ DBPOOL = 'net.snaq:dbpool:jar:4.8.3'
116
+ download artifact(DBPOOL) => 'http://www.snaq.net/java/DBPool/DBPool_v4.8.3.zip'
117
+
118
+ define 'killer-app' do
119
+ project.version '0.1.0'
120
+ compile.with DBPool
121
+ package :jar
122
+ end
123
+ {% endhighlight %}
124
+
125
+ This is one area where Buildr's dependency management vastly excedes Maven's. With Maven, you would have to install the DBPool dependency manually. Buildr's auto-magical download and extraction keeps the dependency definitions centralized within the buildfile, available to your entire team and automatically resolved as needed by the compilation tasks.
126
+
127
+
128
+ h2(#testing). Testing
129
+
130
+ Buildr supports auto-magical integration with a number of mainstream testing frameworks. For Java, this includes the ubiquitus JUnit4, as well as TestNG and a number of others. Scala supports Specs and ScalaTest, while Groovy supports EasyB. Configuration is as simple as placing your test sources in the appropriate directory. In the case of JUnit or TestNG, this would be @src/test/java/@. Once these tests are in place, we can run them using the @test@ task:
131
+
132
+ {% highlight sh %}
133
+ $ buildr test
134
+ {% endhighlight %}
135
+
136
+ When the @test@ task runs, it will ensure that your main sources are compiled, as well as the tests themselves. In the case of JUnit4, test classes are auto-detected based on which base class they extend (@TestCase@). These tests will be invoked using the special test classpath. This classpath includes all of the dependencies passed to @compile.with@ along with the dependencies required for testing. Thus, Buildr will actually go out and download JUnit 4.5 (if necessary) and place that JAR on the classpath in order to run your tests. It is also possible to add artifacts specifically required for testing. So, if your tests make use of the Commons Collections library, but your main sources do not, you can include that dependency only for the tests by using the @test.with@ property. This functions identically to @compile.with@:
137
+
138
+ {% highlight ruby %}
139
+ define 'killer-app' do
140
+ project.version = '0.1.0'
141
+ compile.with 'commons-cli:commons-cli:jar:1.2'
142
+ test.with 'commons-collections:commons-collections:jar:3.2'
143
+ package :jar
144
+ end
145
+ {% endhighlight %}
146
+
147
+ Of course, not everyone _likes_ JUnit4. As mentioned previously, Buildr supports a number of test frameworks. It is possible to use TestNG instead of JUnit4 by setting the @test.using@ property to @:testng@:
148
+
149
+ {% highlight ruby %}
150
+ define 'killer-app' do
151
+ project.version = '0.1.0'
152
+ compile.with 'commons-cli:commons-cli:jar:1.2'
153
+ test.with 'commons-collections:commons-collections:jar:3.2'
154
+ test.using :testng
155
+ package :jar
156
+ end
157
+ {% endhighlight %}
158
+
159
+ Note that only one test framework per-project may be used. This may seem like an obvious restriction given that both frameworks introduced so far have used the same directory, but other frameworks such as Specs and EasyB do not follow the same convention. In cases of ambiguity (for example, when tests are present in both @src/test/java/@ _and_ @src/spec/scala/@), only one test framework will be chosen, but this choice is not well-defined. When in doubt, explicitly specify the test framework with the @test.using@ property. This overrides Buildr's auto-detection and ensures sane behavior.
160
+
161
+ Other test frameworks are documented "here":testing.html and "here":languages.html.
162
+
163
+
164
+ h2(#custom-tasks). Custom Tasks
165
+
166
+ If there is one area in which Buildr excels, it is defining custom tasks. This is something which is notoriously difficult in both Ant and Maven, often requiring separate Java plugins and mountains of code simply to perform basic tasks. For example, let's imagine that we wanted to define a @run@ task which would compile and run our "killer-app" project. This is a simple matter of invoking the @java@ command against our main class:
167
+
168
+ {% highlight ruby %}
169
+ define 'killer-app' do
170
+ project.version = '0.1.0'
171
+ package :jar
172
+
173
+ task :run => :compile do
174
+ system 'java -cp target/classes org.apache.killer.Main'
175
+ end
176
+ end
177
+ {% endhighlight %}
178
+
179
+ This code defines a new task, @run@, which depends upon the @compile@ task. This task only performs a single operation: it invokes the @system@ method, passing the relevant command as a string. Note that the @system@ method documentation may be found "here":http://www.ruby-doc.org/core/classes/Kernel.html#M005971. Tasks use real Ruby (actually, the entire buildfile is real Ruby too), so if you are familiar with that language, then you should be right at home writing custom tasks in Buildr. We can invoke this task in the following way:
180
+
181
+ {% highlight sh %}
182
+ $ buildr killer-app:run
183
+ {% endhighlight %}
184
+
185
+ This works, but it's clumsy. The reason we had to give the "@killer-app:@" prefix is because we defined the @run@ task _within_ our project, rather than outside of the @define@ block. However, if we define @run@ outside of the project, then we don't really have access to the @compile@ task (which is project-specific). The solution here is a bit of magic known as @local_task@. This is how tasks like @compile@ and @test@, which are technically project-specific (think: instance methods) can be invoked without the fully-qualified project name:
186
+
187
+ {% highlight ruby %}
188
+ Project.local_task :run
189
+
190
+ define 'killer-app' do
191
+ project.version '0.1.0'
192
+
193
+ package :jar
194
+
195
+ task :run => :compile do
196
+ system 'java -cp target/classes org.apache.killer.Main'
197
+ end
198
+ end
199
+ {% endhighlight %}
200
+
201
+ Now, we can invoke @run@ exactly the way we want, with a minimum of wasted characters:
202
+
203
+ {% highlight sh %}
204
+ $ buildr run
205
+ {% endhighlight %}
206
+
207
+
208
+ h2(#summary). Summary
209
+
210
+ As long as this guide was, we have barely even scratched the surface of Buildr's true power. This was meant only to get you up and running as quickly as possible, exploiting some of Buildr's unique features to ease your build process. For more comprehensive documentation, start reading about "projects in Buildr":projects.html and work your way from there.