mguymon-buildr 1.4.5-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,178 @@
|
|
|
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
|
+
module Buildr
|
|
18
|
+
class POM
|
|
19
|
+
|
|
20
|
+
POM_TO_SPEC_MAP = { :group=>"groupId", :id=>"artifactId", :type=>"type",
|
|
21
|
+
:version=>"version", :classifier=>"classifier", :scope=>"scope" }
|
|
22
|
+
SCOPES_TRANSITIVE = [nil, "compile", "runtime"]
|
|
23
|
+
SCOPES_WE_USE = SCOPES_TRANSITIVE + ["provided"]
|
|
24
|
+
|
|
25
|
+
# POM project as Hash (using XmlSimple).
|
|
26
|
+
attr_reader :project
|
|
27
|
+
# Parent POM if referenced by this POM.
|
|
28
|
+
attr_reader :parent
|
|
29
|
+
|
|
30
|
+
class << self
|
|
31
|
+
|
|
32
|
+
# :call-seq:
|
|
33
|
+
# POM.load(arg)
|
|
34
|
+
#
|
|
35
|
+
# Load new POM object form various kind of sources such as artifact, hash representing spec, filename, XML.
|
|
36
|
+
def load(source)
|
|
37
|
+
case source
|
|
38
|
+
when Hash
|
|
39
|
+
load(Buildr.artifact(source).pom)
|
|
40
|
+
when Artifact
|
|
41
|
+
pom = source.pom
|
|
42
|
+
pom.invoke
|
|
43
|
+
load(pom.to_s)
|
|
44
|
+
when Rake::FileTask
|
|
45
|
+
source.invoke
|
|
46
|
+
load(source.to_s)
|
|
47
|
+
when String
|
|
48
|
+
filename = File.expand_path(source)
|
|
49
|
+
unless pom = cache[filename]
|
|
50
|
+
trace "Loading m2 pom file from #{filename}"
|
|
51
|
+
begin
|
|
52
|
+
pom = POM.new(IO.read(filename))
|
|
53
|
+
rescue REXML::ParseException => e
|
|
54
|
+
fail "Could not parse #{filename}, #{e.continued_exception}"
|
|
55
|
+
end
|
|
56
|
+
cache[filename] = pom
|
|
57
|
+
end
|
|
58
|
+
pom
|
|
59
|
+
else
|
|
60
|
+
raise ArgumentError, "Expecting Hash spec, Artifact, file name or file task"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def cache()
|
|
67
|
+
@cache ||= {}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def initialize(xml) #:nodoc:
|
|
73
|
+
@project = XmlSimple.xml_in(xml)
|
|
74
|
+
@parent = POM.load(pom_to_hash(project["parent"].first).merge(:type=>'pom')) if project['parent']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# :call-seq:
|
|
78
|
+
# dependencies(scopes?) => artifacts
|
|
79
|
+
#
|
|
80
|
+
# Returns list of required dependencies as specified by the POM. You can specify which scopes
|
|
81
|
+
# to use (e.g. "compile", "runtime"); use +nil+ for dependencies with unspecified scope.
|
|
82
|
+
# The default scopes are +nil+, "compile" and "runtime" (aka SCOPES_WE_USE).
|
|
83
|
+
def dependencies(scopes = SCOPES_WE_USE)
|
|
84
|
+
#try to cache dependencies also
|
|
85
|
+
@depends_for_scopes ||= {}
|
|
86
|
+
unless depends = @depends_for_scopes[scopes]
|
|
87
|
+
declared = project["dependencies"].first["dependency"] rescue nil
|
|
88
|
+
depends = (declared || []).reject { |dep| value_of(dep["optional"]) =~ /true/ }.
|
|
89
|
+
map { |dep|
|
|
90
|
+
spec = pom_to_hash(dep, properties)
|
|
91
|
+
apply = managed(spec)
|
|
92
|
+
spec = apply.merge(spec) if apply
|
|
93
|
+
|
|
94
|
+
#calculate transitive dependencies
|
|
95
|
+
if scopes.include?(spec[:scope])
|
|
96
|
+
spec.delete(:scope)
|
|
97
|
+
|
|
98
|
+
exclusions = dep["exclusions"]["exclusion"] rescue nil
|
|
99
|
+
transitive_deps = POM.load(spec).dependencies(SCOPES_TRANSITIVE)
|
|
100
|
+
transitive_deps = transitive_deps.reject{|dep|
|
|
101
|
+
exclusions.find {|ex| dep.index("#{dep['groupdId'].first}:#{dep['artifactId'].first}:") == 0}
|
|
102
|
+
} if exclusions
|
|
103
|
+
|
|
104
|
+
[Artifact.to_spec(spec)] + transitive_deps
|
|
105
|
+
end
|
|
106
|
+
}.flatten.compact #.uniq_by{|spec| art = spec.split(':'); "#{art[0]}:#{art[1]}"}
|
|
107
|
+
|
|
108
|
+
@depends_for_scopes[scopes] = depends
|
|
109
|
+
end
|
|
110
|
+
depends
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# :call-seq:
|
|
114
|
+
# properties() => hash
|
|
115
|
+
#
|
|
116
|
+
# Returns properties available to this POM as hash. Includes explicit properties and pom.xxx/project.xxx
|
|
117
|
+
# properties for groupId, artifactId, version and packaging.
|
|
118
|
+
def properties()
|
|
119
|
+
@properties ||= begin
|
|
120
|
+
pom = ["groupId", "artifactId", "version", "packaging"].inject({}) { |hash, key|
|
|
121
|
+
value = project[key] || (parent ? parent.project[key] : nil)
|
|
122
|
+
hash[key] = hash["pom.#{key}"] = hash["project.#{key}"] = value_of(value) if value
|
|
123
|
+
hash
|
|
124
|
+
}
|
|
125
|
+
props = project["properties"].first rescue {}
|
|
126
|
+
props = props.inject({}) { |mapped, pair| mapped[pair.first] = value_of(pair.last, pom) ; mapped }
|
|
127
|
+
(parent ? parent.properties.merge(props) : props).merge(pom)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# :call-seq:
|
|
132
|
+
# managed() => hash
|
|
133
|
+
# managed(hash) => hash
|
|
134
|
+
#
|
|
135
|
+
# The first form returns all the managed dependencies specified by this POM in dependencyManagement.
|
|
136
|
+
# The second form uses a single spec hash and expands it from the current/parent POM. Used to determine
|
|
137
|
+
# the version number if specified in dependencyManagement instead of dependencies.
|
|
138
|
+
def managed(spec = nil)
|
|
139
|
+
if spec
|
|
140
|
+
managed.detect { |dep| [:group, :id, :type, :classifier].all? { |key| spec[key] == dep[key] } } ||
|
|
141
|
+
(parent ? parent.managed(spec) : nil)
|
|
142
|
+
else
|
|
143
|
+
@managed ||= begin
|
|
144
|
+
managed = project["dependencyManagement"].first["dependencies"].first["dependency"] rescue nil
|
|
145
|
+
managed ? managed.map { |dep| pom_to_hash(dep, properties) } : []
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
private
|
|
151
|
+
|
|
152
|
+
# :call-seq:
|
|
153
|
+
# value_of(element) => string
|
|
154
|
+
# value_of(element, true) => string
|
|
155
|
+
#
|
|
156
|
+
# Returns the normalized text value of an element from its XmlSimple value. The second form performs
|
|
157
|
+
# property substitution.
|
|
158
|
+
def value_of(element, substitute = nil)
|
|
159
|
+
value = element.to_a.join.strip
|
|
160
|
+
substitute ? value.gsub(/\$\{([^}]+)\}/) { |key| substitute[$1] } : value
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# :call-seq:
|
|
164
|
+
# pom_to_hash(element) => hash
|
|
165
|
+
# pom_to_hash(element, true) => hash
|
|
166
|
+
#
|
|
167
|
+
# Return the spec hash from an XmlSimple POM referencing element (e.g. project, parent, dependency).
|
|
168
|
+
# The second form performs property substitution.
|
|
169
|
+
def pom_to_hash(element, substitute = nil)
|
|
170
|
+
hash = POM_TO_SPEC_MAP.inject({}) { |spec, pair|
|
|
171
|
+
spec[pair.first] = value_of(element[pair.last], substitute) if element[pair.last]
|
|
172
|
+
spec
|
|
173
|
+
}
|
|
174
|
+
{ :type=>"jar" }.merge(hash)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
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 'rjb'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Equivalent to Java system properties. For example:
|
|
21
|
+
# ENV_JAVA['java.version']
|
|
22
|
+
# ENV_JAVA['java.class.version']
|
|
23
|
+
ENV_JAVA = {}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows
|
|
27
|
+
# you to access Java classes and create Java objects.
|
|
28
|
+
#
|
|
29
|
+
# Java classes are accessed as static methods on the Java module, for example:
|
|
30
|
+
# str = Java.java.lang.String.new('hai!')
|
|
31
|
+
# str.toUpperCase
|
|
32
|
+
# => 'HAI!'
|
|
33
|
+
# Java.java.lang.String.isInstance(str)
|
|
34
|
+
# => true
|
|
35
|
+
# Java.com.sun.tools.javac.Main.compile(args)
|
|
36
|
+
#
|
|
37
|
+
# The classpath attribute allows Buildr to add JARs and directories to the classpath,
|
|
38
|
+
# for example, we use it to load Ant and various Ant tasks, code generators, test
|
|
39
|
+
# frameworks, and so forth.
|
|
40
|
+
#
|
|
41
|
+
# When using an artifact specification, Buildr will automatically download and
|
|
42
|
+
# install the artifact before adding it to the classpath.
|
|
43
|
+
#
|
|
44
|
+
# For example, Ant is loaded as follows:
|
|
45
|
+
# Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
|
46
|
+
#
|
|
47
|
+
# Artifacts can only be downloaded after the Buildfile has loaded, giving it
|
|
48
|
+
# a chance to specify which remote repositories to use, so adding to classpath
|
|
49
|
+
# does not by itself load any libraries. You must call Java.load before accessing
|
|
50
|
+
# any Java classes to give Buildr a chance to load the libraries specified in the
|
|
51
|
+
# classpath.
|
|
52
|
+
#
|
|
53
|
+
# When building an extension, make sure to follow these rules:
|
|
54
|
+
# 1. Add to the classpath when the extension is loaded (i.e. in module or class
|
|
55
|
+
# definition), so the first call to Java.load anywhere in the code will include
|
|
56
|
+
# the libraries you specify.
|
|
57
|
+
# 2. Call Java.load once before accessing any Java classes, allowing Buildr to
|
|
58
|
+
# set up the classpath.
|
|
59
|
+
# 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
|
|
60
|
+
# with a partial classpath, or before all remote repositories are listed.
|
|
61
|
+
# 4. Check on a clean build with empty local repository.
|
|
62
|
+
module Java
|
|
63
|
+
|
|
64
|
+
module Package #:nodoc:
|
|
65
|
+
|
|
66
|
+
def method_missing(sym, *args, &block)
|
|
67
|
+
raise ArgumentError, 'No arguments expected' unless args.empty?
|
|
68
|
+
name = "#{@name}.#{sym}"
|
|
69
|
+
return ::Rjb.import(name) if sym.to_s =~ /^[[:upper:]]/
|
|
70
|
+
::Java.send :__package__, name
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# On OS X we know where the default JDK is. We can try to guess for other OS.
|
|
76
|
+
# We set JAVA_HOME early so we can use it without calling Java.load first.
|
|
77
|
+
ENV['JAVA_HOME'] ||= '/System/Library/Frameworks/JavaVM.framework/Home' if Config::CONFIG['host_os'] =~ /darwin/i
|
|
78
|
+
|
|
79
|
+
class << self
|
|
80
|
+
|
|
81
|
+
# Returns the classpath, an array listing directories, JAR files and
|
|
82
|
+
# artifacts. Use when loading the extension to add any additional
|
|
83
|
+
# libraries used by that extension.
|
|
84
|
+
#
|
|
85
|
+
# For example, Ant is loaded as follows:
|
|
86
|
+
# Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
|
87
|
+
def classpath
|
|
88
|
+
@classpath ||= []
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Most platforms requires tools.jar to be on the classpath, tools.jar contains the
|
|
92
|
+
# Java compiler (OS X and AIX are two exceptions we know about, may be more).
|
|
93
|
+
# Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
|
|
94
|
+
# but maybe the JRE. Return nil if not found.
|
|
95
|
+
def tools_jar #:nodoc:
|
|
96
|
+
@tools_jar ||= begin
|
|
97
|
+
home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
|
|
98
|
+
['lib/tools.jar', '../lib/tools.jar'].map { |path| File.expand_path(path, home) }.
|
|
99
|
+
find { |path| File.exist?(path) }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Loads the JVM and all the libraries listed on the classpath. Call this
|
|
104
|
+
# method before accessing any Java class, but only call it from methods
|
|
105
|
+
# used in the build, giving the Buildfile a chance to load all extensions
|
|
106
|
+
# that append to the classpath and specify which remote repositories to use.
|
|
107
|
+
def load
|
|
108
|
+
return self if @loaded
|
|
109
|
+
classpath << tools_jar if tools_jar
|
|
110
|
+
|
|
111
|
+
classpath.map! { |path| Proc === path ? path.call : path }
|
|
112
|
+
cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
|
|
113
|
+
java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
|
|
114
|
+
::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts
|
|
115
|
+
|
|
116
|
+
props = ::Rjb.import('java.lang.System').getProperties
|
|
117
|
+
enum = props.propertyNames
|
|
118
|
+
while enum.hasMoreElements
|
|
119
|
+
name = enum.nextElement.toString
|
|
120
|
+
ENV_JAVA[name] = props.getProperty(name)
|
|
121
|
+
end
|
|
122
|
+
@loaded = true
|
|
123
|
+
self
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def method_missing(sym, *args, &block) #:nodoc:
|
|
127
|
+
raise ArgumentError, 'No arguments expected' unless args.empty?
|
|
128
|
+
Java.load # need to load RJB's classpath now!
|
|
129
|
+
name = sym.to_s
|
|
130
|
+
return ::Rjb.import(name) if name =~ /^[[:upper:]]/
|
|
131
|
+
__package__ name
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
def __package__(name) #:nodoc:
|
|
137
|
+
Module.new.tap do |m|
|
|
138
|
+
m.extend Package
|
|
139
|
+
m.instance_variable_set :@name, name
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class Array
|
|
149
|
+
# Converts a Ruby array into a typed Java array, argument specifies the element type.
|
|
150
|
+
# This is necessary for JRuby and causes no harm on RJB.
|
|
151
|
+
def to_java(cls)
|
|
152
|
+
map { |item| cls.new(item) }
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
# necessary to require YAML even if it is mentioned by autoload as it fails on some platforms.
|
|
17
|
+
require 'yaml'
|
|
18
|
+
require 'fileutils'
|
|
19
|
+
require 'rspec/core/formatters/base_formatter'
|
|
20
|
+
|
|
21
|
+
module Buildr #:nodoc:
|
|
22
|
+
module TestFramework
|
|
23
|
+
|
|
24
|
+
# A class used by buildr for jruby based frameworks, so that buildr can know
|
|
25
|
+
# which tests succeeded/failed.
|
|
26
|
+
class TestResult
|
|
27
|
+
|
|
28
|
+
class Error < ::Exception
|
|
29
|
+
attr_reader :message, :backtrace
|
|
30
|
+
def initialize(message, backtrace)
|
|
31
|
+
@message = message
|
|
32
|
+
@backtrace = backtrace
|
|
33
|
+
set_backtrace backtrace
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.dump_yaml(file, e)
|
|
37
|
+
FileUtils.mkdir_p File.dirname(file)
|
|
38
|
+
File.open(file, 'w') { |f| f.puts(YAML.dump(Error.new(e.message, e.backtrace))) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.guard(file)
|
|
42
|
+
begin
|
|
43
|
+
yield
|
|
44
|
+
rescue => e
|
|
45
|
+
dump_yaml(file, e)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
attr_accessor :failed, :succeeded
|
|
51
|
+
|
|
52
|
+
def initialize
|
|
53
|
+
@failed, @succeeded = [], []
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# An Rspec formatter used by buildr
|
|
57
|
+
class YamlFormatter < ::RSpec::Core::Formatters::BaseFormatter
|
|
58
|
+
attr_reader :result
|
|
59
|
+
|
|
60
|
+
def initialize(output)
|
|
61
|
+
super(output)
|
|
62
|
+
@result = Hash.new
|
|
63
|
+
@result[:succeeded] = []
|
|
64
|
+
@result[:failed] = []
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def example_passed(example)
|
|
68
|
+
super(example)
|
|
69
|
+
result.succeeded << example_name(example)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def example_pending(example)
|
|
73
|
+
super(example)
|
|
74
|
+
result.succeeded << example_name(example)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def example_failed(example)
|
|
78
|
+
super(example)
|
|
79
|
+
result.failed << example_name(example)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def start(example_count)
|
|
83
|
+
super(example_count)
|
|
84
|
+
@result = TestResult.new
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def close
|
|
88
|
+
super
|
|
89
|
+
result.succeeded = result.succeeded - result.failed
|
|
90
|
+
output.puts YAML.dump(result)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
def example_name(example)
|
|
95
|
+
example.file_path
|
|
96
|
+
end
|
|
97
|
+
end # YamlFormatter
|
|
98
|
+
|
|
99
|
+
end # TestResult
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with this
|
|
3
|
+
# work for additional information regarding copyright ownership. The ASF
|
|
4
|
+
# licenses this file to you under the Apache License, Version 2.0 (the
|
|
5
|
+
# "License"); you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations under
|
|
14
|
+
# the License.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
require 'buildr/core/build'
|
|
18
|
+
require 'buildr/core/compile'
|
|
19
|
+
require 'buildr/java/ant'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
module Buildr
|
|
23
|
+
|
|
24
|
+
class TestFramework::Java < TestFramework::Base
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
|
|
28
|
+
def applies_to?(project) #:nodoc:
|
|
29
|
+
project.test.compile.language == :java || project.test.compile.language == :groovy
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def dependencies
|
|
33
|
+
unless @dependencies
|
|
34
|
+
super
|
|
35
|
+
# Add buildr utility classes (e.g. JavaTestFilter)
|
|
36
|
+
@dependencies |= [ File.join(File.dirname(__FILE__)) ]
|
|
37
|
+
end
|
|
38
|
+
@dependencies
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Add buildr utilities (JavaTestFilter) to classpath
|
|
45
|
+
Java.classpath << lambda { dependencies }
|
|
46
|
+
|
|
47
|
+
# :call-seq:
|
|
48
|
+
# filter_classes(dependencies, criteria)
|
|
49
|
+
#
|
|
50
|
+
# Return a list of classnames that match the given criteria.
|
|
51
|
+
# The criteria parameter is a hash that must contain at least one of:
|
|
52
|
+
#
|
|
53
|
+
# * :class_names -- List of patterns to match against class name
|
|
54
|
+
# * :interfaces -- List of java interfaces or java classes
|
|
55
|
+
# * :class_annotations -- List of annotations on class level
|
|
56
|
+
# * :method_annotations -- List of annotations on method level
|
|
57
|
+
# * :fields -- List of java field names
|
|
58
|
+
#
|
|
59
|
+
def filter_classes(dependencies, criteria = {})
|
|
60
|
+
return [] unless task.compile.target
|
|
61
|
+
target = task.compile.target.to_s
|
|
62
|
+
candidates = Dir["#{target}/**/*.class"].
|
|
63
|
+
map { |file| Util.relative_path(file, target).ext('').gsub(File::SEPARATOR, '.') }.
|
|
64
|
+
reject { |name| name =~ /\$./ }
|
|
65
|
+
result = []
|
|
66
|
+
if criteria[:class_names]
|
|
67
|
+
result.concat candidates.select { |name| criteria[:class_names].flatten.any? { |pat| pat === name } }
|
|
68
|
+
end
|
|
69
|
+
begin
|
|
70
|
+
Java.load
|
|
71
|
+
filter = Java.org.apache.buildr.JavaTestFilter.new(dependencies.to_java(Java.java.lang.String))
|
|
72
|
+
if criteria[:interfaces]
|
|
73
|
+
filter.add_interfaces(criteria[:interfaces].to_java(Java.java.lang.String))
|
|
74
|
+
end
|
|
75
|
+
if criteria[:class_annotations]
|
|
76
|
+
filter.add_class_annotations(criteria[:class_annotations].to_java(Java.java.lang.String))
|
|
77
|
+
end
|
|
78
|
+
if criteria[:method_annotations]
|
|
79
|
+
filter.add_method_annotations(criteria[:method_annotations].to_java(Java.java.lang.String))
|
|
80
|
+
end
|
|
81
|
+
if criteria[:fields]
|
|
82
|
+
filter.add_fields(criteria[:fields].to_java(Java.java.lang.String))
|
|
83
|
+
end
|
|
84
|
+
result.concat filter.filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
|
|
85
|
+
rescue =>ex
|
|
86
|
+
info "#{ex.class}: #{ex.message}"
|
|
87
|
+
raise
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# JMock is available when using JUnit and TestNG, JBehave.
|
|
95
|
+
module JMock
|
|
96
|
+
|
|
97
|
+
VERSION = '2.5.1'
|
|
98
|
+
|
|
99
|
+
class << self
|
|
100
|
+
def version
|
|
101
|
+
Buildr.settings.build['jmock'] || VERSION
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def dependencies
|
|
105
|
+
two_or_later = version[0,1].to_i >= 2
|
|
106
|
+
group = two_or_later ? "org.jmock" : "jmock"
|
|
107
|
+
|
|
108
|
+
@dependencies ||= ["#{group}:jmock:jar:#{version}"]
|
|
109
|
+
if two_or_later
|
|
110
|
+
@dependencies << "org.jmock:jmock-junit#{Buildr::JUnit.version.to_s[0,1]}:jar:#{version}"
|
|
111
|
+
@dependencies << "org.hamcrest:hamcrest-core:jar:1.1"
|
|
112
|
+
@dependencies << "org.hamcrest:hamcrest-library:jar:1.1"
|
|
113
|
+
end
|
|
114
|
+
@dependencies
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private
|
|
118
|
+
def const_missing(const)
|
|
119
|
+
return super unless const == :REQUIRES # TODO: remove in 1.5
|
|
120
|
+
Buildr.application.deprecated "Please use JMock.dependencies/.version instead of JMock::REQUIRES/VERSION"
|
|
121
|
+
dependencies
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# JUnit test framework, the default test framework for Java tests.
|
|
128
|
+
#
|
|
129
|
+
# Support the following options:
|
|
130
|
+
# * :fork -- If true/:once (default), fork for each test class. If :each, fork for each individual
|
|
131
|
+
# test case. If false, run all tests in the same VM (fast, but dangerous).
|
|
132
|
+
# * :clonevm -- If true clone the VM each time it is forked.
|
|
133
|
+
# * :properties -- Hash of system properties available to the test case.
|
|
134
|
+
# * :environment -- Hash of environment variables available to the test case.
|
|
135
|
+
# * :java_args -- Arguments passed as is to the JVM.
|
|
136
|
+
class JUnit < TestFramework::Java
|
|
137
|
+
|
|
138
|
+
# Used by the junit:report task. Access through JUnit#report if you want to set various
|
|
139
|
+
# options for that task, for example:
|
|
140
|
+
# JUnit.report.frames = false
|
|
141
|
+
class Report
|
|
142
|
+
|
|
143
|
+
# Parameters passed to the Ant JUnitReport task.
|
|
144
|
+
attr_reader :params
|
|
145
|
+
# True (default) to produce a report using frames, false to produce a single-page report.
|
|
146
|
+
attr_accessor :frames
|
|
147
|
+
# Directory for the report style (defaults to using the internal style).
|
|
148
|
+
attr_accessor :style_dir
|
|
149
|
+
# Target directory for generated report.
|
|
150
|
+
attr_accessor :target
|
|
151
|
+
|
|
152
|
+
def initialize
|
|
153
|
+
@params = {}
|
|
154
|
+
@frames = true
|
|
155
|
+
@target = 'reports/junit'
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# :call-seq:
|
|
159
|
+
# generate(projects, target?)
|
|
160
|
+
#
|
|
161
|
+
# Generates a JUnit report for these projects (must run JUnit tests first) into the
|
|
162
|
+
# target directory. You can specify a target, or let it pick the default one from the
|
|
163
|
+
# target attribute.
|
|
164
|
+
def generate(projects, target = @target.to_s)
|
|
165
|
+
html_in = File.join(target, 'html')
|
|
166
|
+
rm_rf html_in ; mkpath html_in
|
|
167
|
+
|
|
168
|
+
Buildr.ant('junit-report') do |ant|
|
|
169
|
+
ant.taskdef :name=>'junitreport', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
|
|
170
|
+
:classpath=>Buildr.artifacts(JUnit.ant_taskdef).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
|
171
|
+
ant.junitreport :todir=>target do
|
|
172
|
+
projects.select { |project| project.test.framework == :junit }.
|
|
173
|
+
map { |project| project.test.report_to.to_s }.select { |path| File.exist?(path) }.
|
|
174
|
+
each { |path| ant.fileset(:dir=>path) { ant.include :name=>'TEST-*.xml' } }
|
|
175
|
+
options = { :format=>frames ? 'frames' : 'noframes' }
|
|
176
|
+
options[:styledir] = style_dir if style_dir
|
|
177
|
+
ant.report options.merge(:todir=>html_in) do
|
|
178
|
+
params.each { |key, value| ant.param :name=>key, :expression=>value }
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# JUnit version number.
|
|
187
|
+
VERSION = '4.7'
|
|
188
|
+
|
|
189
|
+
class << self
|
|
190
|
+
# :call-seq:
|
|
191
|
+
# report()
|
|
192
|
+
#
|
|
193
|
+
# Returns the Report object used by the junit:report task. You can use this object to set
|
|
194
|
+
# various options that affect your report, for example:
|
|
195
|
+
# JUnit.report.frames = false
|
|
196
|
+
# JUnit.report.params['title'] = 'My App'
|
|
197
|
+
def report
|
|
198
|
+
@report ||= Report.new
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def version
|
|
202
|
+
Buildr.settings.build['junit'] || VERSION
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def dependencies
|
|
206
|
+
@dependencies ||= ["junit:junit:jar:#{version}"]+ JMock.dependencies
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def ant_taskdef #:nodoc:
|
|
210
|
+
"org.apache.ant:ant-junit:jar:#{Ant.version}"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
private
|
|
214
|
+
def const_missing(const)
|
|
215
|
+
return super unless const == :REQUIRES # TODO: remove in 1.5
|
|
216
|
+
Buildr.application.deprecated "Please use JUnit.dependencies/.version instead of JUnit::REQUIRES/VERSION"
|
|
217
|
+
dependencies
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def tests(dependencies) #:nodoc:
|
|
222
|
+
if (self.class.version.to_s[0,1].to_i < 4)
|
|
223
|
+
filter_classes(dependencies, :interfaces => %w{junit.framework.TestCase})
|
|
224
|
+
else
|
|
225
|
+
filter_classes(dependencies,
|
|
226
|
+
:interfaces => %w{junit.framework.TestCase},
|
|
227
|
+
:class_annotations => %w{org.junit.runner.RunWith},
|
|
228
|
+
:method_annotations => %w{org.junit.Test})
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def run(tests, dependencies) #:nodoc:
|
|
234
|
+
# Use Ant to execute the Junit tasks, gives us performance and reporting.
|
|
235
|
+
Buildr.ant('junit') do |ant|
|
|
236
|
+
case options[:fork]
|
|
237
|
+
when false
|
|
238
|
+
forking = {}
|
|
239
|
+
when :each
|
|
240
|
+
forking = { :fork=>true, :forkmode=>'perTest' }
|
|
241
|
+
when true, :once
|
|
242
|
+
forking = { :fork=>true, :forkmode=>'once' }
|
|
243
|
+
else
|
|
244
|
+
fail 'Option fork must be :once, :each or false.'
|
|
245
|
+
end
|
|
246
|
+
mkpath task.report_to.to_s
|
|
247
|
+
|
|
248
|
+
taskdef = Buildr.artifact(JUnit.ant_taskdef)
|
|
249
|
+
taskdef.invoke
|
|
250
|
+
ant.taskdef :name=>'junit', :classname=>'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask', :classpath=>taskdef.to_s
|
|
251
|
+
|
|
252
|
+
ant.junit forking.merge(:clonevm=>options[:clonevm] || false, :dir=>task.send(:project).path_to) do
|
|
253
|
+
ant.classpath :path=>dependencies.join(File::PATH_SEPARATOR)
|
|
254
|
+
(options[:properties] || []).each { |key, value| ant.sysproperty :key=>key, :value=>value }
|
|
255
|
+
(options[:environment] || []).each { |key, value| ant.env :key=>key, :value=>value }
|
|
256
|
+
Array(options[:java_args]).each { |value| ant.jvmarg :value=>value }
|
|
257
|
+
ant.formatter :type=>'plain'
|
|
258
|
+
ant.formatter :type=>'plain', :usefile=>false # log test
|
|
259
|
+
ant.formatter :type=>'xml'
|
|
260
|
+
ant.batchtest :todir=>task.report_to.to_s, :failureproperty=>'failed' do
|
|
261
|
+
ant.fileset :dir=>task.compile.target.to_s do
|
|
262
|
+
tests.each { |test| ant.include :name=>File.join(*test.split('.')).ext('class') }
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
return tests unless ant.project.getProperty('failed')
|
|
267
|
+
end
|
|
268
|
+
# But Ant doesn't tell us what went kaput, so we'll have to parse the test files.
|
|
269
|
+
tests.inject([]) do |passed, test|
|
|
270
|
+
report_file = File.join(task.report_to.to_s, "TEST-#{test}.txt")
|
|
271
|
+
if File.exist?(report_file)
|
|
272
|
+
report = File.read(report_file)
|
|
273
|
+
# The second line (if exists) is the status line and we scan it for its values.
|
|
274
|
+
status = (report.split("\n")[1] || '').scan(/(run|failures|errors):\s*(\d+)/i).
|
|
275
|
+
inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] = pair[1].to_i ; hash }
|
|
276
|
+
passed << test if status[:failures] == 0 && status[:errors] == 0
|
|
277
|
+
end
|
|
278
|
+
passed
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
namespace 'junit' do
|
|
283
|
+
desc "Generate JUnit tests report in #{report.target}"
|
|
284
|
+
task('report') do |task|
|
|
285
|
+
report.generate Project.projects
|
|
286
|
+
info "Generated JUnit tests report in #{report.target}"
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
task('clean') { rm_rf report.target.to_s }
|
|
291
|
+
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# TestNG test framework. To use in your project:
|
|
296
|
+
# test.using :testng
|
|
297
|
+
#
|
|
298
|
+
# Support the following options:
|
|
299
|
+
# * :properties -- Hash of properties passed to the test suite.
|
|
300
|
+
# * :java_args -- Arguments passed to the JVM.
|
|
301
|
+
class TestNG < TestFramework::Java
|
|
302
|
+
|
|
303
|
+
VERSION = '5.10'
|
|
304
|
+
|
|
305
|
+
class << self
|
|
306
|
+
def version
|
|
307
|
+
Buildr.settings.build['testng'] || VERSION
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def dependencies
|
|
311
|
+
["org.testng:testng:jar:jdk15:#{version}"]+ JMock.dependencies
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
private
|
|
315
|
+
def const_missing(const)
|
|
316
|
+
return super unless const == :REQUIRES # TODO: remove in 1.5
|
|
317
|
+
Buildr.application.deprecated "Please use TestNG.dependencies/.version instead of TestNG::REQUIRES/VERSION"
|
|
318
|
+
dependencies
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def tests(dependencies) #:nodoc:
|
|
323
|
+
filter_classes(dependencies,
|
|
324
|
+
:class_annotations => %w{org.testng.annotations.Test},
|
|
325
|
+
:method_annotations => %w{org.testng.annotations.Test})
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def run(tests, dependencies) #:nodoc:
|
|
329
|
+
cmd_args = ['-log', '2', '-sourcedir', task.compile.sources.join(';'), '-suitename', task.project.id ]
|
|
330
|
+
cmd_args << '-d' << task.report_to.to_s
|
|
331
|
+
# run all tests in the same suite
|
|
332
|
+
cmd_args << '-testclass' << tests
|
|
333
|
+
|
|
334
|
+
cmd_options = { :properties=>options[:properties], :java_args=>options[:java_args],
|
|
335
|
+
:classpath=>dependencies, :name => "TestNG in #{task.send(:project).name}" }
|
|
336
|
+
|
|
337
|
+
tmp = nil
|
|
338
|
+
begin
|
|
339
|
+
tmp = Tempfile.open("testNG")
|
|
340
|
+
tmp.write cmd_args.join("\n")
|
|
341
|
+
tmp.close
|
|
342
|
+
Java::Commands.java ['org.testng.TestNG', "@#{tmp.path}"], cmd_options
|
|
343
|
+
return tests
|
|
344
|
+
rescue
|
|
345
|
+
# testng-failed.xml contains the list of failed tests *only*
|
|
346
|
+
report = File.read(File.join(task.report_to.to_s, 'testng-failed.xml'))
|
|
347
|
+
failed = report.scan(/<class name="(.*?)">/im).flatten
|
|
348
|
+
error "TestNG regexp returned unexpected failed tests #{failed.inspect}" unless (failed - tests).empty?
|
|
349
|
+
# return the list of passed tests
|
|
350
|
+
return tests - failed
|
|
351
|
+
ensure
|
|
352
|
+
tmp.close unless tmp.nil?
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
end # Buildr
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
Buildr::TestFramework << Buildr::JUnit
|
|
362
|
+
Buildr::TestFramework << Buildr::TestNG
|