buildr 1.3.5-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +998 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +45 -0
- data/_buildr +29 -0
- data/_jbuildr +29 -0
- data/addon/buildr/antlr.rb +65 -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 +142 -0
- data/addon/buildr/javacc.rb +85 -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 +90 -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/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +65 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +88 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +211 -0
- data/doc/building.textile +244 -0
- data/doc/contributing.textile +252 -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 +79 -0
- data/doc/extending.textile +186 -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 +69 -0
- data/doc/installing.textile +266 -0
- data/doc/languages.textile +459 -0
- data/doc/mailing_lists.textile +25 -0
- data/doc/more_stuff.textile +457 -0
- data/doc/packaging.textile +430 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +271 -0
- data/doc/quick_start.textile +210 -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 +72 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +280 -0
- data/doc/testing.textile +222 -0
- data/etc/KEYS +151 -0
- data/lib/buildr.rb +36 -0
- data/lib/buildr/core.rb +35 -0
- data/lib/buildr/core/application.rb +656 -0
- data/lib/buildr/core/build.rb +452 -0
- data/lib/buildr/core/checks.rb +254 -0
- data/lib/buildr/core/common.rb +150 -0
- data/lib/buildr/core/compile.rb +608 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +362 -0
- data/lib/buildr/core/generate.rb +195 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +156 -0
- data/lib/buildr/core/project.rb +866 -0
- data/lib/buildr/core/shell.rb +198 -0
- data/lib/buildr/core/test.rb +723 -0
- data/lib/buildr/core/transports.rb +559 -0
- data/lib/buildr/core/util.rb +449 -0
- data/lib/buildr/groovy.rb +19 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +138 -0
- data/lib/buildr/groovy/shell.rb +48 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +334 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +68 -0
- data/lib/buildr/ide/eclipse/scala.rb +66 -0
- data/lib/buildr/ide/idea.ipr.template +300 -0
- data/lib/buildr/ide/idea.rb +190 -0
- data/lib/buildr/ide/idea7x.ipr.template +290 -0
- data/lib/buildr/ide/idea7x.rb +212 -0
- data/lib/buildr/java.rb +23 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +459 -0
- data/lib/buildr/java/cobertura.rb +274 -0
- data/lib/buildr/java/commands.rb +213 -0
- data/lib/buildr/java/compiler.rb +349 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/jruby.rb +117 -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 +137 -0
- data/lib/buildr/java/packaging.rb +716 -0
- data/lib/buildr/java/pom.rb +174 -0
- data/lib/buildr/java/rjb.rb +155 -0
- data/lib/buildr/java/test_result.rb +353 -0
- data/lib/buildr/java/tests.rb +333 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +24 -0
- data/lib/buildr/packaging/archive.rb +488 -0
- data/lib/buildr/packaging/artifact.rb +749 -0
- data/lib/buildr/packaging/artifact_namespace.rb +972 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +102 -0
- data/lib/buildr/packaging/package.rb +238 -0
- data/lib/buildr/packaging/tar.rb +186 -0
- data/lib/buildr/packaging/version_requirement.rb +172 -0
- data/lib/buildr/packaging/zip.rb +73 -0
- data/lib/buildr/packaging/ziptask.rb +316 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/scala.rb +25 -0
- data/lib/buildr/scala/bdd.rb +109 -0
- data/lib/buildr/scala/compiler.rb +195 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
- data/lib/buildr/scala/shell.rb +55 -0
- data/lib/buildr/scala/tests.rb +157 -0
- data/lib/buildr/shell.rb +180 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +92 -0
- data/rakelib/jekylltask.rb +120 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +149 -0
- data/rakelib/rspec.rake +73 -0
- data/rakelib/setup.rake +54 -0
- data/rakelib/stage.rake +213 -0
- data/rakelib/stage.rake~ +213 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/core/application_spec.rb +502 -0
- data/spec/core/build_spec.rb +677 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +670 -0
- data/spec/core/compile_spec.rb +583 -0
- data/spec/core/extension_spec.rb +93 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +762 -0
- data/spec/core/test_spec.rb +1098 -0
- data/spec/core/transport_spec.rb +537 -0
- data/spec/core/util_spec.rb +67 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +240 -0
- data/spec/ide/eclipse_spec.rb +501 -0
- data/spec/ide/idea7x_spec.rb +84 -0
- data/spec/java/ant_spec.rb +33 -0
- data/spec/java/bdd_spec.rb +382 -0
- data/spec/java/cobertura_spec.rb +85 -0
- data/spec/java/compiler_spec.rb +446 -0
- data/spec/java/emma_spec.rb +119 -0
- data/spec/java/java_spec.rb +124 -0
- data/spec/java/packaging_spec.rb +1134 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +493 -0
- data/spec/packaging/archive_spec.rb +527 -0
- data/spec/packaging/artifact_namespace_spec.rb +654 -0
- data/spec/packaging/artifact_spec.rb +795 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +684 -0
- data/spec/sandbox.rb +142 -0
- data/spec/scala/bdd_spec.rb +119 -0
- data/spec/scala/compiler_spec.rb +284 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +261 -0
- data/spec/spec_helpers.rb +340 -0
- data/spec/version_requirement_spec.rb +129 -0
- metadata +383 -0
@@ -0,0 +1,274 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
|
17
|
+
require 'buildr/java'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
|
22
|
+
# Provides the <code>cobertura:html</code>, <code>cobertura:xml</code> and <code>cobertura:check</code> tasks.
|
23
|
+
# Require explicitly using <code>require "buildr/cobertura"</code>.
|
24
|
+
#
|
25
|
+
# You can generate cobertura reports for a single project
|
26
|
+
# using the project name as prefix:
|
27
|
+
#
|
28
|
+
# project_name:cobertura:html
|
29
|
+
#
|
30
|
+
# You can also specify which classes to include/exclude from instrumentation by
|
31
|
+
# passing a class name regexp to the <code>cobertura.include</code> or
|
32
|
+
# <code>cobertura.exclude</code> methods.
|
33
|
+
#
|
34
|
+
# define 'someModule' do
|
35
|
+
# cobertura.include 'some.package.*'
|
36
|
+
# cobertura.include /some.(foo|bar).*/
|
37
|
+
# cobertura.exclude 'some.foo.util.SimpleUtil'
|
38
|
+
# cobertura.exclude /*.Const(ants)?/i
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
module Cobertura
|
42
|
+
|
43
|
+
VERSION = '1.9'
|
44
|
+
|
45
|
+
class << self
|
46
|
+
|
47
|
+
def version
|
48
|
+
Buildr.settings.build['cobertura'] || VERSION
|
49
|
+
end
|
50
|
+
|
51
|
+
def dependencies
|
52
|
+
@dependencies ||= [ "net.sourceforge.cobertura:cobertura:jar:#{version}", "log4j:log4j:jar:1.2.9",
|
53
|
+
"asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def report_to(file = nil)
|
57
|
+
File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
|
58
|
+
end
|
59
|
+
|
60
|
+
def data_file()
|
61
|
+
File.expand_path("reports/cobertura.ser")
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class CoberturaConfig # :nodoc:
|
67
|
+
|
68
|
+
def initialize(project)
|
69
|
+
@project = project
|
70
|
+
end
|
71
|
+
|
72
|
+
attr_reader :project
|
73
|
+
private :project
|
74
|
+
|
75
|
+
attr_writer :data_file, :instrumented_dir, :report_dir
|
76
|
+
|
77
|
+
def data_file
|
78
|
+
@data_file ||= project.path_to(:reports, 'cobertura.ser')
|
79
|
+
end
|
80
|
+
|
81
|
+
def instrumented_dir
|
82
|
+
@instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
|
83
|
+
end
|
84
|
+
|
85
|
+
def report_dir
|
86
|
+
@report_dir ||= project.path_to(:reports, :cobertura)
|
87
|
+
end
|
88
|
+
|
89
|
+
def report_to(file = nil)
|
90
|
+
File.expand_path(File.join(*[report_dir, file.to_s].compact))
|
91
|
+
end
|
92
|
+
|
93
|
+
# :call-seq:
|
94
|
+
# project.cobertura.include(*classPatterns)
|
95
|
+
#
|
96
|
+
def include(*classPatterns)
|
97
|
+
includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def includes
|
102
|
+
@includeClasses ||= []
|
103
|
+
end
|
104
|
+
|
105
|
+
# :call-seq:
|
106
|
+
# project.cobertura.exclude(*classPatterns)
|
107
|
+
#
|
108
|
+
def exclude(*classPatterns)
|
109
|
+
excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def excludes
|
114
|
+
@excludeClasses ||= []
|
115
|
+
end
|
116
|
+
|
117
|
+
def sources
|
118
|
+
project.compile.sources
|
119
|
+
end
|
120
|
+
|
121
|
+
def check
|
122
|
+
@check ||= CoberturaCheck.new
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class CoberturaCheck
|
127
|
+
attr_writer :branch_rate, :line_rate, :total_branch_rate, :total_line_rate, :package_line_rate, :package_branch_rate
|
128
|
+
attr_reader :branch_rate, :line_rate, :total_branch_rate, :total_line_rate, :package_line_rate, :package_branch_rate
|
129
|
+
end
|
130
|
+
|
131
|
+
module CoberturaExtension # :nodoc:
|
132
|
+
include Buildr::Extension
|
133
|
+
|
134
|
+
def cobertura
|
135
|
+
@cobertura_config ||= CoberturaConfig.new(self)
|
136
|
+
end
|
137
|
+
|
138
|
+
after_define do |project|
|
139
|
+
cobertura = project.cobertura
|
140
|
+
|
141
|
+
namespace 'cobertura' do
|
142
|
+
unless project.compile.target.nil?
|
143
|
+
# Instrumented bytecode goes in a different directory. This task creates before running the test
|
144
|
+
# cases and monitors for changes in the generate bytecode.
|
145
|
+
instrumented = project.file(cobertura.instrumented_dir => project.compile.target) do |task|
|
146
|
+
mkdir_p task.to_s
|
147
|
+
unless project.compile.sources.empty?
|
148
|
+
info "Instrumenting classes with cobertura data file #{cobertura.data_file}"
|
149
|
+
Buildr.ant "cobertura" do |ant|
|
150
|
+
ant.taskdef :resource=>"tasks.properties",
|
151
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
152
|
+
ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
|
153
|
+
includes, excludes = cobertura.includes, cobertura.excludes
|
154
|
+
|
155
|
+
classes_dir = project.compile.target.to_s
|
156
|
+
if includes.empty? && excludes.empty?
|
157
|
+
ant.fileset :dir => classes_dir do
|
158
|
+
ant.include :name => "**/*.class"
|
159
|
+
end
|
160
|
+
else
|
161
|
+
includes = [//] if includes.empty?
|
162
|
+
Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
|
163
|
+
cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
|
164
|
+
if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
|
165
|
+
ant.fileset :file => cls
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
touch task.to_s
|
173
|
+
end
|
174
|
+
|
175
|
+
task 'instrument' => instrumented
|
176
|
+
|
177
|
+
# We now have two target directories with bytecode. It would make sense to remove compile.target
|
178
|
+
# and add instrumented instead, but apparently Cobertura only creates some of the classes, so
|
179
|
+
# we need both directories and instrumented must come first.
|
180
|
+
project.test.dependencies.unshift cobertura.instrumented_dir
|
181
|
+
project.test.with Cobertura.dependencies
|
182
|
+
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
|
183
|
+
|
184
|
+
unless project.compile.sources.empty?
|
185
|
+
[:xml, :html].each do |format|
|
186
|
+
task format => ['instrument', 'test'] do
|
187
|
+
info "Creating test coverage reports in #{cobertura.report_to(format)}"
|
188
|
+
Buildr.ant "cobertura" do |ant|
|
189
|
+
ant.taskdef :resource=>"tasks.properties",
|
190
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
191
|
+
ant.send "cobertura-report", :format=>format,
|
192
|
+
:destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
|
193
|
+
cobertura.sources.flatten.each do |src|
|
194
|
+
ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
task :check => [:instrument, :test] do
|
203
|
+
Buildr.ant "cobertura" do |ant|
|
204
|
+
ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
|
205
|
+
|
206
|
+
params = { :datafile => Cobertura.data_file }
|
207
|
+
|
208
|
+
# oh so ugly...
|
209
|
+
params[:branchrate] = cobertura.check.branch_rate if cobertura.check.branch_rate
|
210
|
+
params[:linerate] = cobertura.check.line_rate if cobertura.check.line_rate
|
211
|
+
params[:totalbranchrate] = cobertura.check.total_branch_rate if cobertura.check.total_branch_rate
|
212
|
+
params[:totallinerate] = cobertura.check.total_line_rate if cobertura.check.total_line_rate
|
213
|
+
params[:packagebranchrate] = cobertura.check.package_branch_rate if cobertura.check.package_branch_rate
|
214
|
+
params[:packagelinerate] = cobertura.check.package_line_rate if cobertura.check.package_line_rate
|
215
|
+
|
216
|
+
ant.send("cobertura-check", params) do
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
project.clean do
|
225
|
+
rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir]
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
class Buildr::Project
|
233
|
+
include CoberturaExtension
|
234
|
+
end
|
235
|
+
|
236
|
+
namespace "cobertura" do
|
237
|
+
|
238
|
+
task "instrument" do
|
239
|
+
Buildr.projects.each do |project|
|
240
|
+
project.cobertura.data_file = data_file
|
241
|
+
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
|
242
|
+
instrument_task ="#{project.name}:cobertura:instrument"
|
243
|
+
task(instrument_task).invoke if Rake::Task.task_defined?(instrument_task)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
[:xml, :html].each do |format|
|
248
|
+
report_target = report_to(format)
|
249
|
+
desc "Run the test cases and produce code coverage reports in #{report_target}"
|
250
|
+
task format => ["instrument", "test"] do
|
251
|
+
info "Creating test coverage reports in #{report_target}"
|
252
|
+
Buildr.ant "cobertura" do |ant|
|
253
|
+
ant.taskdef :resource=>"tasks.properties",
|
254
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
255
|
+
ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
|
256
|
+
Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
|
257
|
+
ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
task "clean" do
|
265
|
+
rm_rf [report_to, data_file]
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
task "clean" do
|
270
|
+
task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
|
17
|
+
# Base module for all things Java.
|
18
|
+
module Java
|
19
|
+
|
20
|
+
# JDK commands: java, javac, javadoc, etc.
|
21
|
+
module Commands
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
# :call-seq:
|
26
|
+
# java(class, *args, options?)
|
27
|
+
#
|
28
|
+
# Runs Java with the specified arguments.
|
29
|
+
#
|
30
|
+
# The last argument may be a Hash with additional options:
|
31
|
+
# * :classpath -- One or more file names, tasks or artifact specifications.
|
32
|
+
# These are all expanded into artifacts, and all tasks are invoked.
|
33
|
+
# * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
|
34
|
+
# * :properties -- Hash of system properties (e.g. 'path'=>base_dir).
|
35
|
+
# * :name -- Shows this name, otherwise shows the first argument (the class name).
|
36
|
+
# * :verbose -- If true, prints the command and all its argument.
|
37
|
+
def java(*args, &block)
|
38
|
+
options = Hash === args.last ? args.pop : {}
|
39
|
+
options[:verbose] ||= Buildr.application.options.trace || false
|
40
|
+
rake_check_options options, :classpath, :java_args, :properties, :name, :verbose
|
41
|
+
|
42
|
+
name = options[:name] || "java #{args.first}"
|
43
|
+
cmd_args = [path_to_bin('java')]
|
44
|
+
classpath = classpath_from(options)
|
45
|
+
cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
46
|
+
options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
|
47
|
+
cmd_args += (options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
|
48
|
+
cmd_args += args.flatten.compact
|
49
|
+
unless Buildr.application.options.dryrun
|
50
|
+
info "Running #{name}"
|
51
|
+
block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
|
52
|
+
puts cmd_args.join(' ') if Buildr.application.options.trace
|
53
|
+
cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
|
54
|
+
sh(*cmd_args) do |ok, ps|
|
55
|
+
block.call ok, ps
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# :call-seq:
|
61
|
+
# apt(*files, options)
|
62
|
+
#
|
63
|
+
# Runs Apt with the specified arguments.
|
64
|
+
#
|
65
|
+
# The last argument may be a Hash with additional options:
|
66
|
+
# * :compile -- If true, compile source files to class files.
|
67
|
+
# * :source -- Specifies source compatibility with a given JVM release.
|
68
|
+
# * :output -- Directory where to place the generated source files, or the
|
69
|
+
# generated class files when compiling.
|
70
|
+
# * :classpath -- One or more file names, tasks or artifact specifications.
|
71
|
+
# These are all expanded into artifacts, and all tasks are invoked.
|
72
|
+
def apt(*args)
|
73
|
+
options = Hash === args.last ? args.pop : {}
|
74
|
+
rake_check_options options, :compile, :source, :output, :classpath
|
75
|
+
|
76
|
+
files = args.flatten.map(&:to_s).
|
77
|
+
collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
|
78
|
+
cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
|
79
|
+
if options[:compile]
|
80
|
+
cmd_args << '-d' << options[:output].to_s
|
81
|
+
else
|
82
|
+
cmd_args << '-nocompile' << '-s' << options[:output].to_s
|
83
|
+
end
|
84
|
+
cmd_args << '-source' << options[:source] if options[:source]
|
85
|
+
classpath = classpath_from(options)
|
86
|
+
tools = Java.tools_jar
|
87
|
+
classpath << tools if tools
|
88
|
+
cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
89
|
+
cmd_args += files
|
90
|
+
unless Buildr.application.options.dryrun
|
91
|
+
info 'Running apt'
|
92
|
+
trace (['apt'] + cmd_args).join(' ')
|
93
|
+
Java.load
|
94
|
+
Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
|
95
|
+
fail 'Failed to process annotations, see errors above'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# :call-seq:
|
100
|
+
# javac(*files, options)
|
101
|
+
#
|
102
|
+
# Runs Javac with the specified arguments.
|
103
|
+
#
|
104
|
+
# The last argument may be a Hash with additional options:
|
105
|
+
# * :output -- Target directory for all compiled class files.
|
106
|
+
# * :classpath -- One or more file names, tasks or artifact specifications.
|
107
|
+
# These are all expanded into artifacts, and all tasks are invoked.
|
108
|
+
# * :sourcepath -- Additional source paths to use.
|
109
|
+
# * :javac_args -- Any additional arguments to pass (e.g. -extdirs, -encoding)
|
110
|
+
# * :name -- Shows this name, otherwise shows the working directory.
|
111
|
+
def javac(*args)
|
112
|
+
options = Hash === args.last ? args.pop : {}
|
113
|
+
rake_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
|
114
|
+
|
115
|
+
files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
|
116
|
+
collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
|
117
|
+
name = options[:name] || Dir.pwd
|
118
|
+
|
119
|
+
cmd_args = []
|
120
|
+
classpath = classpath_from(options)
|
121
|
+
cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
|
122
|
+
cmd_args << '-sourcepath' << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
|
123
|
+
cmd_args << '-d' << options[:output].to_s if options[:output]
|
124
|
+
cmd_args += options[:javac_args].flatten if options[:javac_args]
|
125
|
+
cmd_args += files
|
126
|
+
unless Buildr.application.options.dryrun
|
127
|
+
info "Compiling #{files.size} source files in #{name}"
|
128
|
+
trace (['javac'] + cmd_args).join(' ')
|
129
|
+
Java.load
|
130
|
+
Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
|
131
|
+
fail 'Failed to compile, see errors above'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# :call-seq:
|
136
|
+
# javadoc(*files, options)
|
137
|
+
#
|
138
|
+
# Runs Javadocs with the specified files and options.
|
139
|
+
#
|
140
|
+
# This method accepts the following special options:
|
141
|
+
# * :output -- The output directory
|
142
|
+
# * :classpath -- Array of classpath dependencies.
|
143
|
+
# * :sourcepath -- Array of sourcepaths (paths or tasks).
|
144
|
+
# * :name -- Shows this name, otherwise shows the working directory.
|
145
|
+
#
|
146
|
+
# All other options are passed to Javadoc as following:
|
147
|
+
# * true -- As is, for example, :author=>true becomes -author
|
148
|
+
# * false -- Prefixed, for example, :index=>false becomes -noindex
|
149
|
+
# * string -- Option with value, for example, :windowtitle=>'My project' becomes -windowtitle "My project"
|
150
|
+
# * array -- Option with set of values separated by spaces.
|
151
|
+
def javadoc(*args)
|
152
|
+
options = Hash === args.last ? args.pop : {}
|
153
|
+
|
154
|
+
cmd_args = [ '-d', options[:output], Buildr.application.options.trace ? '-verbose' : '-quiet' ]
|
155
|
+
options.reject { |key, value| [:output, :name, :sourcepath, :classpath].include?(key) }.
|
156
|
+
each { |key, value| value.invoke if value.respond_to?(:invoke) }.
|
157
|
+
each do |key, value|
|
158
|
+
case value
|
159
|
+
when true, nil
|
160
|
+
cmd_args << "-#{key}"
|
161
|
+
when false
|
162
|
+
cmd_args << "-no#{key}"
|
163
|
+
when Hash
|
164
|
+
value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
|
165
|
+
else
|
166
|
+
cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
|
167
|
+
end
|
168
|
+
end
|
169
|
+
[:sourcepath, :classpath].each do |option|
|
170
|
+
options[option].to_a.flatten.tap do |paths|
|
171
|
+
cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
|
172
|
+
end
|
173
|
+
end
|
174
|
+
cmd_args += args.flatten.uniq
|
175
|
+
name = options[:name] || Dir.pwd
|
176
|
+
unless Buildr.application.options.dryrun
|
177
|
+
info "Generating Javadoc for #{name}"
|
178
|
+
trace (['javadoc'] + cmd_args).join(' ')
|
179
|
+
Java.load
|
180
|
+
Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
|
181
|
+
fail 'Failed to generate Javadocs, see errors above'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
protected
|
186
|
+
|
187
|
+
# :call-seq:
|
188
|
+
# path_to_bin(cmd?) => path
|
189
|
+
#
|
190
|
+
# Returns the path to the specified Java command (with no argument to java itself).
|
191
|
+
def path_to_bin(name = nil)
|
192
|
+
home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
|
193
|
+
bin = File.expand_path(File.join(home, 'bin'))
|
194
|
+
fail 'JAVA_HOME environment variable does not point to a valid JRE/JDK installation.' unless File.exist? bin
|
195
|
+
File.expand_path(File.join(bin, name.to_s))
|
196
|
+
end
|
197
|
+
|
198
|
+
# :call-seq:
|
199
|
+
# classpath_from(options) => files
|
200
|
+
#
|
201
|
+
# Extracts the classpath from the options, expands it by calling artifacts, invokes
|
202
|
+
# each of the artifacts and returns an array of paths.
|
203
|
+
def classpath_from(options)
|
204
|
+
Buildr.artifacts(options[:classpath] || []).map(&:to_s).
|
205
|
+
map { |t| task(t).invoke; File.expand_path(t) }
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|