mguymon-buildr 1.4.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- metadata +600 -0
@@ -0,0 +1,618 @@
|
|
1
|
+
---
|
2
|
+
layout: default
|
3
|
+
title: Packaging
|
4
|
+
---
|
5
|
+
|
6
|
+
For our next trick, we're going to try and create an artifact ourselves. We're going to start with:
|
7
|
+
|
8
|
+
{% highlight ruby %}
|
9
|
+
package :jar
|
10
|
+
{% endhighlight %}
|
11
|
+
|
12
|
+
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:
|
13
|
+
|
14
|
+
{% highlight ruby %}
|
15
|
+
package :war
|
16
|
+
{% endhighlight %}
|
17
|
+
|
18
|
+
The easy case is always easy, but sometimes we have more complicated use cases which we'll address through the rest of this section.
|
19
|
+
|
20
|
+
Now let's run the build, test cases and create these packages:
|
21
|
+
|
22
|
+
{% highlight sh %}
|
23
|
+
$ buildr package
|
24
|
+
{% endhighlight %}
|
25
|
+
|
26
|
+
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.
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
|
31
|
+
h2(#referencing). Specifying And Referencing Packages
|
32
|
+
|
33
|
+
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:
|
34
|
+
|
35
|
+
{% highlight ruby %}
|
36
|
+
package :jar
|
37
|
+
package :type=>:jar
|
38
|
+
{% endhighlight %}
|
39
|
+
|
40
|
+
If you do not specify a package type, Buildr will attempt to infer one.
|
41
|
+
|
42
|
+
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.
|
43
|
+
|
44
|
+
To package a particular file, use the @:file@ argument, for example:
|
45
|
+
|
46
|
+
{% highlight ruby %}
|
47
|
+
package :zip, :file=>_('target/interesting.zip')
|
48
|
+
{% endhighlight %}
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
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.
|
53
|
+
|
54
|
+
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":#install_upload).
|
55
|
+
|
56
|
+
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:
|
57
|
+
|
58
|
+
{% highlight ruby %}
|
59
|
+
define 'killer-app', :version=>'1.0' do
|
60
|
+
# Generates silly-1.0.jar
|
61
|
+
package :jar, :id=>'silly'
|
62
|
+
|
63
|
+
# Generates killer-app-la-web-1.x.war
|
64
|
+
project 'la-web' do
|
65
|
+
package :war, :version=>'1.x'
|
66
|
+
end
|
67
|
+
|
68
|
+
# Generates killer-app-the-api-1.0-sources.zip
|
69
|
+
project 'teh-api' do
|
70
|
+
package :zip, :classifier=>'sources'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
{% endhighlight %}
|
74
|
+
|
75
|
+
The file name is determined from the identifier, version number, classifier and extension associated with that packaging type.
|
76
|
+
|
77
|
+
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.
|
78
|
+
|
79
|
+
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.
|
80
|
+
|
81
|
+
You can use the @packages@ method to obtain a list of all packages defined in the project, for example:
|
82
|
+
|
83
|
+
{% highlight ruby %}
|
84
|
+
project('killer-app:teh-impl').packages.first
|
85
|
+
project('killer-app:teh-impl').packages.select { |pkg| pkg.type == :zip }
|
86
|
+
{% endhighlight %}
|
87
|
+
|
88
|
+
|
89
|
+
h2(#zip). Packaging ZIPs
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
93
|
+
Let's start by including additional files in the ZIP package. We're going to include the @target/docs@ directory and @README@ file:
|
94
|
+
|
95
|
+
{% highlight ruby %}
|
96
|
+
package(:zip).include _('target/docs'), 'README'
|
97
|
+
{% endhighlight %}
|
98
|
+
|
99
|
+
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.
|
100
|
+
|
101
|
+
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:
|
102
|
+
|
103
|
+
{% highlight ruby %}
|
104
|
+
package(:zip).include(_('target/docs')).exclude('*.draft', '*.raw')
|
105
|
+
{% endhighlight %}
|
106
|
+
|
107
|
+
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:
|
108
|
+
|
109
|
+
{% highlight ruby %}
|
110
|
+
package(:zip).include _('target/docs'), :path=>"#{id}-#{version}"
|
111
|
+
{% endhighlight %}
|
112
|
+
|
113
|
+
If you need to use the @:path@ option repeatedly, consider using the @tap@ method instead. For example:
|
114
|
+
|
115
|
+
{% highlight ruby %}
|
116
|
+
package(:zip).path("#{id}-#{version}").tap do |path|
|
117
|
+
path.include _('target/docs')
|
118
|
+
path.include _('README')
|
119
|
+
end
|
120
|
+
{% endhighlight %}
|
121
|
+
|
122
|
+
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.
|
123
|
+
|
124
|
+
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.
|
125
|
+
|
126
|
+
If you need to include a file or directory under a different name, use the @:as@ option. For example:
|
127
|
+
|
128
|
+
{% highlight ruby %}
|
129
|
+
package(:zip).include(_('corporate-logo-350x240.png'), :as=>'logo.png')
|
130
|
+
{% endhighlight %}
|
131
|
+
|
132
|
+
You can also use @:as=>'.'@ to include all files from the given directory. For example:
|
133
|
+
|
134
|
+
{% highlight ruby %}
|
135
|
+
package(:zip).include _('target/docs/*')
|
136
|
+
package(:zip).include _('target/docs'), :as=>'.'
|
137
|
+
{% endhighlight %}
|
138
|
+
|
139
|
+
These two perform identically. They both include all the files from the @target/docs@ directory, but not the directory itself, and they are both lazy, meaning that the files can be created later and they will still get packaged into the zip package.
|
140
|
+
|
141
|
+
For example, when you use @package :jar@, under the hood it specifies to include all the files from @target/classes@ with @:as=>'.'@. Even though this happens during project definition and nothing has been compiled yet (and in fact @target/classes@ may not even exist yet), the .class files generated during compilation are still packaged in the .jar file, as expected.
|
142
|
+
|
143
|
+
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.
|
144
|
+
|
145
|
+
You can also merge two ZIP files together, expanding the content of one ZIP into the other. For example:
|
146
|
+
|
147
|
+
{% highlight ruby %}
|
148
|
+
package(:zip).merge _('part1.zip'), _('part2.zip')
|
149
|
+
{% endhighlight %}
|
150
|
+
|
151
|
+
If you need to be more selective, you can apply the include/exclude pattern to the expanded ZIP. For example:
|
152
|
+
|
153
|
+
{% highlight ruby %}
|
154
|
+
# Everything but the libs
|
155
|
+
package(:zip).merge(_('bigbad.war')).exclude('libs/**/*')
|
156
|
+
{% endhighlight %}
|
157
|
+
|
158
|
+
|
159
|
+
h2(#jar). Packaging JARs
|
160
|
+
|
161
|
+
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.
|
162
|
+
|
163
|
+
You can tell the JAR package to include a particular Manifest file:
|
164
|
+
|
165
|
+
{% highlight ruby %}
|
166
|
+
package(:jar).with :manifest=>_('src/main/MANIFEST.MF')
|
167
|
+
{% endhighlight %}
|
168
|
+
|
169
|
+
Or generate a manifest from a hash:
|
170
|
+
|
171
|
+
{% highlight ruby %}
|
172
|
+
package(:jar).with :manifest=>{ 'Copyright'=>'Acme Inc (C) 2007' }
|
173
|
+
{% endhighlight %}
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
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.
|
178
|
+
|
179
|
+
For example, we can get the same result by specifying this at the top project:
|
180
|
+
|
181
|
+
{% highlight ruby %}
|
182
|
+
manifest['Copyright'] = 'Acme Inc (C) 2007'
|
183
|
+
{% endhighlight %}
|
184
|
+
|
185
|
+
If you need to mix-in the project's manifest with values that only one package uses, you can do so easily:
|
186
|
+
|
187
|
+
{% highlight ruby %}
|
188
|
+
package(:jar).with :manifest=>manifest.merge('Main-Class'=>'com.acme.Main')
|
189
|
+
{% endhighlight %}
|
190
|
+
|
191
|
+
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:
|
192
|
+
|
193
|
+
{% highlight ruby %}
|
194
|
+
meta_inf << file('DISCLAIMER') << file('NOTICE')
|
195
|
+
{% endhighlight %}
|
196
|
+
|
197
|
+
If you have a @LICENSE@ file, it's already included in the @meta_inf@ list of files.
|
198
|
+
|
199
|
+
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:
|
200
|
+
|
201
|
+
{% highlight ruby %}
|
202
|
+
package(:jar).clean.include( only_these_files )
|
203
|
+
{% endhighlight %}
|
204
|
+
|
205
|
+
|
206
|
+
h2(#war). Packaging WARs
|
207
|
+
|
208
|
+
Pretty much everything you know about JARs works the same way for WARs, so let's just look at the differences.
|
209
|
+
|
210
|
+
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.
|
211
|
+
|
212
|
+
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:
|
213
|
+
|
214
|
+
{% highlight ruby %}
|
215
|
+
package(:war).with :classes=>_('target/additional')
|
216
|
+
{% endhighlight %}
|
217
|
+
|
218
|
+
If you want to include a different set of libraries other than the default:
|
219
|
+
|
220
|
+
{% highlight ruby %}
|
221
|
+
package(:war).with :libs=>MYSQL_JDBC
|
222
|
+
{% endhighlight %}
|
223
|
+
|
224
|
+
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@.
|
225
|
+
|
226
|
+
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:
|
227
|
+
|
228
|
+
{% highlight ruby %}
|
229
|
+
# Add an artifact to the existing set:
|
230
|
+
package(:war).libs += artifacts(MYSQL_JDBC)
|
231
|
+
# Remove an artifact from the existing set:
|
232
|
+
package(:war).libs -= artifacts(LOG4J)
|
233
|
+
# List all the artifacts:
|
234
|
+
puts 'Artifacts included in WAR package:'
|
235
|
+
puts package(:war).libs.map(&:to_spec)
|
236
|
+
{% endhighlight %}
|
237
|
+
|
238
|
+
|
239
|
+
h2(#aar). Packaging AARs
|
240
|
+
|
241
|
+
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.
|
242
|
+
|
243
|
+
{% highlight ruby %}
|
244
|
+
package(:aar).with(:libs=>'log4j:log4j:jar:1.1')
|
245
|
+
package(:aar).with(:services_xml=>_('target/services.xml'),
|
246
|
+
:wsdls=>_('target/*.wsdl'))
|
247
|
+
{% endhighlight %}
|
248
|
+
|
249
|
+
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.
|
250
|
+
|
251
|
+
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.
|
252
|
+
|
253
|
+
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.
|
254
|
+
|
255
|
+
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:
|
256
|
+
|
257
|
+
{% highlight ruby %}
|
258
|
+
# Host name depends on environment.
|
259
|
+
host = ENV['ENV'] == 'test' ? 'test.host' : 'ws.example.com'
|
260
|
+
filter.from(_('src/main/axis2')).into(_(:target)).
|
261
|
+
include('services.xml', '==*==.wsdl').using('http_port'=>'8080',
|
262
|
+
'http_host'=>host)
|
263
|
+
package(:aar).wsdls.clear
|
264
|
+
package(:aar).with(:services_xml=>_('target/services.xml'),
|
265
|
+
:wsdls=>_('target/==*==.wsdl'))
|
266
|
+
{% endhighlight %}
|
267
|
+
|
268
|
+
|
269
|
+
h2(#ear). Packaging EARs
|
270
|
+
|
271
|
+
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.
|
272
|
+
|
273
|
+
EAR packages support four component types:
|
274
|
+
|
275
|
+
|_. Argument |_. Component |
|
276
|
+
| @:war@ | J2EE Web Application (WAR). |
|
277
|
+
| @:ejb@ | Enterprise Java Bean (JAR). |
|
278
|
+
| @:jar@ | J2EE Application Client (JAR). |
|
279
|
+
| @:lib@ | Shared library (JAR). |
|
280
|
+
|
281
|
+
This example shows two ways for adding components built by other projects:
|
282
|
+
|
283
|
+
{% highlight ruby %}
|
284
|
+
package(:ear) << project('coolWebService').package(:war)
|
285
|
+
package(:ear).add project('commonLib') # By default, the JAR package
|
286
|
+
{% endhighlight %}
|
287
|
+
|
288
|
+
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.
|
289
|
+
|
290
|
+
Here are three examples:
|
291
|
+
|
292
|
+
{% highlight ruby %}
|
293
|
+
# Assumed to be a shared library.
|
294
|
+
package(:ear).add 'org.springframework:spring:jar:2.6'
|
295
|
+
# Component type mapped to package.
|
296
|
+
package(:ear).add :ejb=>project('beanery')
|
297
|
+
# Adding component with specific package type.
|
298
|
+
package(:ear).add project('client'), :type=>:jar
|
299
|
+
{% endhighlight %}
|
300
|
+
|
301
|
+
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@.
|
302
|
+
|
303
|
+
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:
|
304
|
+
|
305
|
+
{% highlight ruby %}
|
306
|
+
# Specify once per component.
|
307
|
+
package(:ear).add project('coolWebService').package(:war), :path=>'coolServices'
|
308
|
+
# Configure once and apply to all added components.
|
309
|
+
package(:ear).dirs[:war] = 'coolServices'
|
310
|
+
package(:ear) << project('coolWebService').package(:war)
|
311
|
+
{% endhighlight %}
|
312
|
+
|
313
|
+
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.
|
314
|
+
|
315
|
+
* *display-name* -- The application's display name defaults to the project's identifier. You can change that by setting the @display_name@ attribute.
|
316
|
+
|
317
|
+
* *description* -- The application's description defaults to the project's comment. You can change that by setting the @description@ attribute.
|
318
|
+
|
319
|
+
* *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.
|
320
|
+
|
321
|
+
Again, by example:
|
322
|
+
|
323
|
+
{% highlight ruby %}
|
324
|
+
package(:ear).display_name = 'MyCoolWebService'
|
325
|
+
package(:ear).description = 'MyCoolWebService: Making coolness kool again'
|
326
|
+
package(:ear).add project('coolWebService').package(:war), :context_root=>'coolness'
|
327
|
+
{% endhighlight %}
|
328
|
+
|
329
|
+
If you need to disable the context root (e.g. for Portlets), set @context_root@ to @false@.
|
330
|
+
|
331
|
+
It is also possible to add @security-role@ tags to the @application.xml@ file by appending a hash with @:id@, @:description@ and @:name@ to the @security_role@ array, like so:
|
332
|
+
|
333
|
+
{% highlight ruby %}
|
334
|
+
package(:ear).security_roles << {:id=>'SecurityRole_123',
|
335
|
+
:description=>'Read only user', :name=>'coolUser'}
|
336
|
+
package(:ear).security_roles << {:id=>'SecurityRole_456',
|
337
|
+
:description=>'Super user', :name=>'superCoolUser'}
|
338
|
+
{% endhighlight %}
|
339
|
+
|
340
|
+
h2(#bundle). Packaging OSGi Bundles
|
341
|
+
|
342
|
+
OSGi bundles are jar files with additional metadata stored in the manifest. Buildr uses an external tool "Bnd":http://www.aqute.biz/Code/Bnd to create the package. Directives and properties can be explicitly passed to the build tool and buildr will provide reasonable defaults for properties that can be derived from the project model. Please see the bnd tool for documentation on the available properties.
|
343
|
+
|
344
|
+
The bundle packaging format is included as an addon so the build file must explicitly require the addon using using <code>require "buildr/bnd"</code> and must add a remote repository from which the bnd can be downloaded. A typical project that uses the bundle packaging addon may look something like;
|
345
|
+
|
346
|
+
{% highlight ruby %}
|
347
|
+
require "buildr/bnd"
|
348
|
+
|
349
|
+
repositories.remote << Buildr::Bnd.remote_repository
|
350
|
+
|
351
|
+
define 'myProject' do
|
352
|
+
...
|
353
|
+
package(:bundle).tap do |bnd|
|
354
|
+
bnd['Import-Package'] = "*;resolution:=optional"
|
355
|
+
bnd['Export-Package'] = "*;version=#{version}"
|
356
|
+
end
|
357
|
+
...
|
358
|
+
end
|
359
|
+
{% endhighlight %}
|
360
|
+
|
361
|
+
The @[]@ method on the bundle package is used to provide directives to the bnd tool that are not inherited by sub-projects while the standard 'manifest' setting is used to define properties that inherited by sub-projects.
|
362
|
+
|
363
|
+
h3. Defaults
|
364
|
+
|
365
|
+
The addon sets the following bnd parameters;
|
366
|
+
|
367
|
+
* <tt>"Bundle-Version"</tt> defaults to the project version.
|
368
|
+
* <tt>"Bundle-SymbolicName"</tt> defaults to the concatenation of the project group and project id, replacing ':' characters with '.'.
|
369
|
+
* <tt>"Bundle-Name"</tt> defaults to the project description if present else the project name
|
370
|
+
* <tt>"Bundle-Description"</tt> defaults to the project description.
|
371
|
+
* <tt>"-classpath"</tt> is set to the compile target directory and any compile time dependencies.
|
372
|
+
* <tt>"Include-Resource"</tt> defaults to the dir project.resources.target if it exists.
|
373
|
+
|
374
|
+
h3. Parameters
|
375
|
+
|
376
|
+
h4. classpath_element
|
377
|
+
|
378
|
+
The user can also specify additional elements that are added to the classpath using the 'classpath_element' method. If the parameter to this element is a task, artifact, artifact namespace etc. then it will be resolved prior to invoking bnd.
|
379
|
+
|
380
|
+
{% highlight ruby %}
|
381
|
+
...
|
382
|
+
define 'foo' do
|
383
|
+
...
|
384
|
+
package(:bundle).tap do |bnd|
|
385
|
+
# This dependency will be added to classpath
|
386
|
+
bnd.classpath_element 'someOtherExistingFile.zip'
|
387
|
+
# All of these dependencies will be invoked and added to classpath
|
388
|
+
bnd.classpath_element artifact('com.sun.messaging.mq:imq:jar:4.4')
|
389
|
+
bnd.classpath_element project('bar') # Adds all the packages
|
390
|
+
bnd.classpath_element 'org.apache.ant:ant:jar:1.8.0'
|
391
|
+
bnd.classpath_element file('myLocalFile.jar')
|
392
|
+
...
|
393
|
+
end
|
394
|
+
|
395
|
+
project 'bar' do
|
396
|
+
...
|
397
|
+
end
|
398
|
+
end
|
399
|
+
{% endhighlight %}
|
400
|
+
|
401
|
+
h4. classpath
|
402
|
+
|
403
|
+
The user can specify the complete classpath using the 'classpath' method. The classpath should be an array of elements. If the element is a task, artifact, artifact namespace etc. then it will be resolved prior to invoking bnd.
|
404
|
+
|
405
|
+
{% highlight ruby %}
|
406
|
+
...
|
407
|
+
define 'foo' do
|
408
|
+
...
|
409
|
+
package(:bundle).tap do |bnd|
|
410
|
+
bnd.classpath [ project.compile.target,
|
411
|
+
'someOtherExistingFile.zip',
|
412
|
+
artifact('com.sun.messaging.mq:imq:jar:4.4'),
|
413
|
+
project('bar'),
|
414
|
+
'org.apache.ant:ant:jar:1.8.0',
|
415
|
+
file('myLocalFile.jar') ]
|
416
|
+
...
|
417
|
+
end
|
418
|
+
|
419
|
+
project 'bar' do
|
420
|
+
...
|
421
|
+
end
|
422
|
+
end
|
423
|
+
{% endhighlight %}
|
424
|
+
|
425
|
+
h3. Examples
|
426
|
+
|
427
|
+
h4. Including non-class resources in a bundle
|
428
|
+
|
429
|
+
Bnd can be used to include non-class resources in a bundle. The following example includes all resources in 'src/etc' into the bundle.
|
430
|
+
|
431
|
+
{% highlight ruby %}
|
432
|
+
define 'myproject' do
|
433
|
+
...
|
434
|
+
package(:bundle).tap do |bnd|
|
435
|
+
bnd['Include-Resource'] = project._('src/etc') + '/'
|
436
|
+
...
|
437
|
+
end
|
438
|
+
end
|
439
|
+
{% endhighlight %}
|
440
|
+
|
441
|
+
h4. Using bnd to wrap an existing jar
|
442
|
+
|
443
|
+
Bnd can be used to wrap an existing jar as an OSGi bundle. The following example wraps the OpenMQ JMS provider as an OSGi bundle.
|
444
|
+
|
445
|
+
{% highlight ruby %}
|
446
|
+
...
|
447
|
+
# Add repository for OpenMQ
|
448
|
+
repositories.remote << 'http://download.java.net/maven/2'
|
449
|
+
|
450
|
+
desc 'OSGi bundle for OpenMQ JMS provider client library'
|
451
|
+
define 'com.sun.messaging.mq.imq' do
|
452
|
+
project.version = '4.4'
|
453
|
+
project.group = 'iris'
|
454
|
+
package(:bundle).tap do |bnd|
|
455
|
+
bnd['Import-Package'] = "*;resolution:=optional"
|
456
|
+
bnd['Export-Package'] = "com.sun.messaging.*;version=#{version}"
|
457
|
+
bnd.classpath_element 'com.sun.messaging.mq:imq:jar:4.4'
|
458
|
+
end
|
459
|
+
end
|
460
|
+
{% endhighlight %}
|
461
|
+
|
462
|
+
h4. Create an OSGi bundle with an Activator
|
463
|
+
|
464
|
+
The following example presents a basic buildfile for building an OSGi bundle with an activator.
|
465
|
+
|
466
|
+
{% highlight ruby %}
|
467
|
+
...
|
468
|
+
# repository for OSGi core bundle
|
469
|
+
repositories.remote << 'https://repository.apache.org/content/repositories/releases'
|
470
|
+
|
471
|
+
desc 'Hello World bundle'
|
472
|
+
define 'helloworld' do
|
473
|
+
project.version = '1.0'
|
474
|
+
project.group = 'org.example'
|
475
|
+
compile.with 'org.apache.felix:org.osgi.core:jar:1.4.0'
|
476
|
+
package(:bundle).tap do |bnd|
|
477
|
+
bnd['Export-Package'] = "org.example.helloworld.api.*;version=#{version}"
|
478
|
+
bnd['Bundle-Activator'] = "org.example.helloworld.Activator"
|
479
|
+
end
|
480
|
+
end
|
481
|
+
{% endhighlight %}
|
482
|
+
|
483
|
+
h4. Inheriting parameters for bnd tool
|
484
|
+
|
485
|
+
The following example shows how you can use 'manifest' to define a bnd parameter that is inherited by all child sub-projects. The "Bundle-License" defined in the top level project is passed to the bnd tool when generating both the 'fe' and 'fi' sub-projects but the 'fo' sub-project overrides this parameter with a local value.
|
486
|
+
|
487
|
+
{% highlight ruby %}
|
488
|
+
...
|
489
|
+
define 'myproject' do
|
490
|
+
manifest['Bundle-License'] = "http://www.apache.org/licenses/LICENSE-2.0"
|
491
|
+
...
|
492
|
+
define 'fe' do
|
493
|
+
...
|
494
|
+
package(:bundle).tap do |bnd|
|
495
|
+
...
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
define 'fi' do
|
500
|
+
...
|
501
|
+
package(:bundle).tap do |bnd|
|
502
|
+
...
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
define 'fo' do
|
507
|
+
...
|
508
|
+
package(:bundle).tap do |bnd|
|
509
|
+
bnd['Bundle-License'] = "http://www.apache.org/licenses/LICENSE-1.1"
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
{% endhighlight %}
|
514
|
+
|
515
|
+
h2(#tar). Packaging Tars and GZipped Tars
|
516
|
+
|
517
|
+
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.
|
518
|
+
|
519
|
+
{% highlight ruby %}
|
520
|
+
package(:tar).include _('target/docs'), 'README'
|
521
|
+
package(:tgz).include _('target/docs'), 'README'
|
522
|
+
{% endhighlight %}
|
523
|
+
|
524
|
+
The first line creates a Tar archive with the extension @.tar@, the second creates a GZipped Tar archive with the extension @.tgz@.
|
525
|
+
|
526
|
+
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@.
|
527
|
+
|
528
|
+
|
529
|
+
h2(#install_upload). Installing and Uploading
|
530
|
+
|
531
|
+
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.
|
532
|
+
|
533
|
+
So let's create these packages and install them in the local repository where other projects can access them:
|
534
|
+
|
535
|
+
{% highlight sh %}
|
536
|
+
$ buildr install
|
537
|
+
{% endhighlight %}
|
538
|
+
|
539
|
+
If you changes your mind you can always:
|
540
|
+
|
541
|
+
{% highlight sh %}
|
542
|
+
$ buildr uninstall
|
543
|
+
{% endhighlight %}
|
544
|
+
|
545
|
+
That works between projects you build on the same machine. Now let's share these artifacts with other developers through a remote repository:
|
546
|
+
|
547
|
+
{% highlight sh %}
|
548
|
+
$ buildr upload
|
549
|
+
{% endhighlight %}
|
550
|
+
|
551
|
+
Of course, you'll need to tell Buildr about the release server:
|
552
|
+
|
553
|
+
{% highlight ruby %}
|
554
|
+
repositories.release_to = 'sftp://john:secret@release/usr/share/repo'
|
555
|
+
{% endhighlight %}
|
556
|
+
|
557
|
+
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.
|
558
|
+
|
559
|
+
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.
|
560
|
+
|
561
|
+
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:
|
562
|
+
|
563
|
+
{% highlight ruby %}
|
564
|
+
# build.rb, loaded first
|
565
|
+
repositories.release_to[:username] = 'john'
|
566
|
+
repositories.release_to[:password] = 'secret'
|
567
|
+
|
568
|
+
# Buildfile, loaded next
|
569
|
+
repositories.release_to[:url] = 'sftp://release/usr/share/repo'
|
570
|
+
{% endhighlight %}
|
571
|
+
|
572
|
+
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).
|
573
|
+
|
574
|
+
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:
|
575
|
+
|
576
|
+
{% highlight ruby %}
|
577
|
+
# We'll let some other task decide how to create 'docs'
|
578
|
+
task 'upload'=>'docs' do
|
579
|
+
uri = URI("sftp://#{username}:#{password}@var/www/docs")
|
580
|
+
uri.upload file('docs')
|
581
|
+
end
|
582
|
+
{% endhighlight %}
|
583
|
+
|
584
|
+
|
585
|
+
h2(#source_javadoc). Packaging Sources and JavaDocs
|
586
|
+
|
587
|
+
IDEs can take advantage of source packages to help you debug and trace through compiled code. We'll start with a simple example:
|
588
|
+
|
589
|
+
{% highlight ruby %}
|
590
|
+
package :sources
|
591
|
+
{% endhighlight %}
|
592
|
+
|
593
|
+
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.
|
594
|
+
|
595
|
+
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 @doc@ task, so you can use it in combination with the @doc@ method. For example:
|
596
|
+
|
597
|
+
{% highlight ruby %}
|
598
|
+
package :javadoc
|
599
|
+
doc :windowtitle=>'Buggy but Works'
|
600
|
+
{% endhighlight %}
|
601
|
+
|
602
|
+
By default Buildr picks the project's description for the window title.
|
603
|
+
|
604
|
+
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:
|
605
|
+
|
606
|
+
{% highlight ruby %}
|
607
|
+
package_with_sources
|
608
|
+
package_with_javadoc
|
609
|
+
{% endhighlight %}
|
610
|
+
|
611
|
+
You can also tell it to be selective using the @:only@ and @:except@ options.
|
612
|
+
For example:
|
613
|
+
|
614
|
+
{% highlight ruby %}
|
615
|
+
package_with_javadoc :except=>'la-web'
|
616
|
+
{% endhighlight %}
|
617
|
+
|
618
|
+
We packaged the code, but will it actually work? Let's see "what the tests say":testing.html.
|