buildr 1.2.10 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +566 -268
- data/DISCLAIMER +7 -1
- data/KEYS +151 -0
- data/NOTICE +23 -8
- data/README +122 -22
- data/Rakefile +49 -229
- data/{lib → addon}/buildr/antlr.rb +23 -10
- data/addon/buildr/cobertura.rb +232 -0
- data/{lib → addon}/buildr/hibernate.rb +20 -4
- data/{lib → addon}/buildr/javacc.rb +27 -12
- data/addon/buildr/jdepend.rb +60 -0
- data/{lib → addon}/buildr/jetty.rb +34 -18
- data/addon/buildr/nailgun.rb +892 -0
- data/{lib → addon}/buildr/openjpa.rb +23 -6
- 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/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
- data/{lib → addon}/buildr/xmlbeans.rb +39 -14
- data/bin/buildr +21 -7
- data/buildr.gemspec +50 -0
- data/doc/css/default.css +225 -0
- data/doc/css/print.css +95 -0
- data/doc/css/syntax.css +43 -0
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/pages/artifacts.textile +317 -0
- data/doc/pages/building.textile +501 -0
- data/doc/pages/contributing.textile +178 -0
- data/doc/pages/download.textile +25 -0
- data/doc/pages/extending.textile +229 -0
- data/doc/pages/getting_started.textile +337 -0
- data/doc/pages/index.textile +63 -0
- data/doc/pages/mailing_lists.textile +17 -0
- data/doc/pages/more_stuff.textile +367 -0
- data/doc/pages/packaging.textile +592 -0
- data/doc/pages/projects.textile +449 -0
- data/doc/pages/recipes.textile +127 -0
- data/doc/pages/settings_profiles.textile +339 -0
- data/doc/pages/testing.textile +475 -0
- data/doc/pages/troubleshooting.textile +121 -0
- data/doc/pages/whats_new.textile +389 -0
- data/doc/print.haml +52 -0
- data/doc/print.toc.yaml +28 -0
- data/doc/scripts/buildr-git.rb +411 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +64 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/site.haml +55 -0
- data/doc/site.toc.yaml +44 -0
- data/lib/buildr.rb +28 -45
- data/lib/buildr/core.rb +27 -0
- data/lib/buildr/core/application.rb +373 -0
- data/lib/buildr/core/application_cli.rb +134 -0
- data/lib/{core → buildr/core}/build.rb +91 -77
- data/lib/{core → buildr/core}/checks.rb +116 -95
- data/lib/buildr/core/common.rb +155 -0
- data/lib/buildr/core/compile.rb +594 -0
- data/lib/buildr/core/environment.rb +120 -0
- data/lib/buildr/core/filter.rb +258 -0
- data/lib/{core → buildr/core}/generate.rb +22 -5
- data/lib/buildr/core/help.rb +118 -0
- data/lib/buildr/core/progressbar.rb +156 -0
- data/lib/{core → buildr/core}/project.rb +468 -213
- data/lib/buildr/core/test.rb +690 -0
- data/lib/{core → buildr/core}/transports.rb +107 -127
- data/lib/buildr/core/util.rb +235 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/{java → buildr/ide}/eclipse.rb +86 -60
- data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
- data/lib/buildr/ide/idea.rb +194 -0
- data/lib/buildr/ide/idea7x.ipr.template +290 -0
- data/lib/buildr/ide/idea7x.rb +210 -0
- data/lib/buildr/java.rb +26 -0
- data/lib/buildr/java/ant.rb +71 -0
- data/lib/buildr/java/bdd_frameworks.rb +267 -0
- data/lib/buildr/java/commands.rb +210 -0
- data/lib/buildr/java/compilers.rb +432 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/groovyc.rb +137 -0
- data/lib/buildr/java/jruby.rb +99 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
- data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
- data/lib/buildr/java/packaging.rb +706 -0
- data/lib/{java → buildr/java}/pom.rb +20 -4
- data/lib/buildr/java/rjb.rb +142 -0
- data/lib/buildr/java/test_frameworks.rb +290 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +21 -0
- data/lib/{java → buildr/packaging}/artifact.rb +170 -179
- data/lib/buildr/packaging/artifact_namespace.rb +957 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +102 -0
- data/lib/buildr/packaging/package.rb +233 -0
- data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
- data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
- data/rakelib/apache.rake +126 -0
- data/rakelib/changelog.rake +56 -0
- data/rakelib/doc.rake +103 -0
- data/rakelib/package.rake +44 -0
- data/rakelib/release.rake +53 -0
- data/rakelib/rspec.rake +81 -0
- data/rakelib/rubyforge.rake +45 -0
- data/rakelib/scm.rake +49 -0
- data/rakelib/setup.rake +59 -0
- data/rakelib/stage.rake +45 -0
- data/spec/application_spec.rb +316 -0
- data/spec/archive_spec.rb +494 -0
- data/spec/artifact_namespace_spec.rb +635 -0
- data/spec/artifact_spec.rb +738 -0
- data/spec/build_spec.rb +193 -0
- data/spec/checks_spec.rb +537 -0
- data/spec/common_spec.rb +579 -0
- data/spec/compile_spec.rb +561 -0
- data/spec/groovy_compilers_spec.rb +239 -0
- data/spec/java_bdd_frameworks_spec.rb +238 -0
- data/spec/java_compilers_spec.rb +446 -0
- data/spec/java_packaging_spec.rb +1042 -0
- data/spec/java_test_frameworks_spec.rb +414 -0
- data/spec/packaging_helper.rb +63 -0
- data/spec/packaging_spec.rb +589 -0
- data/spec/project_spec.rb +739 -0
- data/spec/sandbox.rb +116 -0
- data/spec/scala_compilers_spec.rb +239 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helpers.rb +283 -0
- data/spec/test_spec.rb +871 -0
- data/spec/transport_spec.rb +300 -0
- data/spec/version_requirement_spec.rb +115 -0
- metadata +188 -77
- data/lib/buildr/cobertura.rb +0 -89
- data/lib/buildr/jdepend.rb +0 -40
- data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
- data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
- data/lib/buildr/jetty/JettyWrapper.class +0 -0
- data/lib/buildr/scala.rb +0 -368
- data/lib/core/application.rb +0 -188
- data/lib/core/common.rb +0 -562
- data/lib/core/help.rb +0 -72
- data/lib/core/rake_ext.rb +0 -81
- data/lib/java/ant.rb +0 -71
- data/lib/java/compile.rb +0 -589
- data/lib/java/idea.rb +0 -159
- data/lib/java/java.rb +0 -432
- data/lib/java/packaging.rb +0 -581
- data/lib/java/test.rb +0 -795
- data/lib/tasks/concat.rb +0 -35
@@ -1,5 +1,21 @@
|
|
1
|
-
|
2
|
-
|
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 'xmlsimple'
|
18
|
+
require 'buildr/packaging'
|
3
19
|
|
4
20
|
|
5
21
|
module Buildr
|
@@ -35,7 +51,7 @@ module Buildr
|
|
35
51
|
when String
|
36
52
|
filename = File.expand_path(source)
|
37
53
|
unless pom = cache[filename]
|
38
|
-
puts "Loading m2 pom file from #{filename}" if
|
54
|
+
puts "Loading m2 pom file from #{filename}" if Buildr.application.options.trace
|
39
55
|
pom = POM.new(IO.read(filename))
|
40
56
|
cache[filename] = pom
|
41
57
|
end
|
@@ -87,7 +103,7 @@ module Buildr
|
|
87
103
|
|
88
104
|
[Artifact.to_spec(spec)] + transitive_deps
|
89
105
|
end
|
90
|
-
}.flatten.compact
|
106
|
+
}.flatten.compact #.uniq_by{|spec| art = spec.split(':'); "#{art[0]}:#{art[1]}"}
|
91
107
|
|
92
108
|
@depends_for_scopes[scopes] = depends
|
93
109
|
end
|
@@ -0,0 +1,142 @@
|
|
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
|
+
class << self
|
76
|
+
|
77
|
+
# Returns the classpath, an array listing directories, JAR files and
|
78
|
+
# artifacts. Use when loading the extension to add any additional
|
79
|
+
# libraries used by that extension.
|
80
|
+
#
|
81
|
+
# For example, Ant is loaded as follows:
|
82
|
+
# Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
83
|
+
def classpath
|
84
|
+
@classpath ||= []
|
85
|
+
end
|
86
|
+
|
87
|
+
# Loads the JVM and all the libraries listed on the classpath. Call this
|
88
|
+
# method before accessing any Java class, but only call it from methods
|
89
|
+
# used in the build, giving the Buildfile a chance to load all extensions
|
90
|
+
# that append to the classpath and specify which remote repositories to use.
|
91
|
+
def load
|
92
|
+
return self if @loaded
|
93
|
+
unless RUBY_PLATFORM =~ /darwin/i
|
94
|
+
home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
|
95
|
+
tools = File.expand_path('lib/tools.jar', home)
|
96
|
+
raise "I need tools.jar to compile, can't find it in #{home}/lib" unless File.exist?(tools)
|
97
|
+
classpath << tools
|
98
|
+
end
|
99
|
+
cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
|
100
|
+
java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
|
101
|
+
::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts
|
102
|
+
|
103
|
+
props = ::Rjb.import('java.lang.System').getProperties
|
104
|
+
enum = props.propertyNames
|
105
|
+
while enum.hasMoreElements
|
106
|
+
name = enum.nextElement.toString
|
107
|
+
ENV_JAVA[name] = props.getProperty(name)
|
108
|
+
end
|
109
|
+
@loaded = true
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def method_missing(sym, *args, &block) #:nodoc:
|
114
|
+
raise ArgumentError, 'No arguments expected' unless args.empty?
|
115
|
+
name = sym.to_s
|
116
|
+
return ::Rjb.import(name) if name =~ /^[[:upper:]]/
|
117
|
+
__package__ name
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def __package__(name) #:nodoc:
|
123
|
+
const = name.split('.').map { |part| part.gsub(/^./) { |char| char.upcase } }.join
|
124
|
+
return const_get(const) if const_defined?(const)
|
125
|
+
package = Module.new
|
126
|
+
package.extend Package
|
127
|
+
package.instance_variable_set :@name, name
|
128
|
+
const_set(const, package)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
class Array
|
137
|
+
# Converts a Ruby array into a typed Java array, argument specifies the element type.
|
138
|
+
# This is necessary for JRuby and causes no harm on RJB.
|
139
|
+
def to_java(cls)
|
140
|
+
map { |item| cls.new(item) }
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,290 @@
|
|
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
|
+
module Buildr
|
22
|
+
|
23
|
+
class TestFramework
|
24
|
+
module JavaTest
|
25
|
+
|
26
|
+
# Add buildr utilities (JavaTestFilter) to classpath
|
27
|
+
Java.classpath << File.join(File.dirname(__FILE__))
|
28
|
+
|
29
|
+
def self.included(mod)
|
30
|
+
super
|
31
|
+
mod.extend ClassMethods
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
# :call-seq:
|
36
|
+
# filter_classes(dependencies, criteria)
|
37
|
+
#
|
38
|
+
# Return a list of classnames that match the given criteria.
|
39
|
+
# The criteria parameter is a hash that must contain at least one of:
|
40
|
+
#
|
41
|
+
# * :class_names -- List of patterns to match against class name
|
42
|
+
# * :interfaces -- List of java interfaces or java classes
|
43
|
+
# * :class_annotations -- List of annotations on class level
|
44
|
+
# * :method_annotations -- List of annotations on method level
|
45
|
+
#
|
46
|
+
def filter_classes(dependencies, criteria = {})
|
47
|
+
return [] unless task.compile.target
|
48
|
+
target = task.compile.target.to_s
|
49
|
+
candidates = Dir["#{target}/**/*.class"].
|
50
|
+
map { |file| Util.relative_path(file, target).ext('').gsub(File::SEPARATOR, '.') }.
|
51
|
+
reject { |name| name =~ /\$/ }
|
52
|
+
result = []
|
53
|
+
if criteria[:class_names]
|
54
|
+
result.concat candidates.select { |name| criteria[:class_names].flatten.any? { |pat| pat === name } }
|
55
|
+
end
|
56
|
+
begin
|
57
|
+
Java.load
|
58
|
+
filter = Java.org.apache.buildr.JavaTestFilter.new(dependencies.to_java(Java.java.lang.String))
|
59
|
+
if criteria[:interfaces]
|
60
|
+
filter.add_interfaces(criteria[:interfaces].to_java(Java.java.lang.String))
|
61
|
+
end
|
62
|
+
if criteria[:class_annotations]
|
63
|
+
filter.add_class_annotations(criteria[:class_annotations].to_java(Java.java.lang.String))
|
64
|
+
end
|
65
|
+
if criteria[:method_annotations]
|
66
|
+
filter.add_method_annotations(criteria[:method_annotations].to_java(Java.java.lang.String))
|
67
|
+
end
|
68
|
+
result.concat filter.filter(candidates.to_java(Java.java.lang.String)).map(&:to_s)
|
69
|
+
rescue =>ex
|
70
|
+
puts "#{ex.class}: #{ex.message}" if verbose
|
71
|
+
raise
|
72
|
+
end
|
73
|
+
result.uniq
|
74
|
+
end
|
75
|
+
|
76
|
+
module ClassMethods
|
77
|
+
def applies_to?(project) #:nodoc:
|
78
|
+
project.test.compile.language == :java
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# JMock is available when using JUnit and TestNG, JBehave.
|
86
|
+
module JMock
|
87
|
+
# JMock version.
|
88
|
+
VERSION = '1.2.0' unless const_defined?('VERSION')
|
89
|
+
# JMock specification.
|
90
|
+
REQUIRES = ["jmock:jmock:jar:#{VERSION}"]
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# JUnit test framework, the default test framework for Java tests.
|
95
|
+
#
|
96
|
+
# Support the following options:
|
97
|
+
# * :fork -- If true/:once (default), fork for each test class. If :each, fork for each individual
|
98
|
+
# test case. If false, run all tests in the same VM (fast, but dangerous).
|
99
|
+
# * :clonevm -- If true clone the VM each time it is forked.
|
100
|
+
# * :properties -- Hash of system properties available to the test case.
|
101
|
+
# * :environment -- Hash of environment variables available to the test case.
|
102
|
+
# * :java_args -- Arguments passed as is to the JVM.
|
103
|
+
class JUnit < TestFramework::Base
|
104
|
+
|
105
|
+
# Used by the junit:report task. Access through JUnit#report if you want to set various
|
106
|
+
# options for that task, for example:
|
107
|
+
# JUnit.report.frames = false
|
108
|
+
class Report
|
109
|
+
|
110
|
+
# Ant-Trax required for running the JUnitReport task.
|
111
|
+
Java.classpath << "org.apache.ant:ant-trax:jar:#{Ant::VERSION}"
|
112
|
+
|
113
|
+
# Parameters passed to the Ant JUnitReport task.
|
114
|
+
attr_reader :params
|
115
|
+
# True (default) to produce a report using frames, false to produce a single-page report.
|
116
|
+
attr_accessor :frames
|
117
|
+
# Directory for the report style (defaults to using the internal style).
|
118
|
+
attr_accessor :style_dir
|
119
|
+
# Target directory for generated report.
|
120
|
+
attr_accessor :target
|
121
|
+
|
122
|
+
def initialize
|
123
|
+
@params = {}
|
124
|
+
@frames = true
|
125
|
+
@target = 'reports/junit'
|
126
|
+
end
|
127
|
+
|
128
|
+
# :call-seq:
|
129
|
+
# generate(projects, target?)
|
130
|
+
#
|
131
|
+
# Generates a JUnit report for these projects (must run JUnit tests first) into the
|
132
|
+
# target directory. You can specify a target, or let it pick the default one from the
|
133
|
+
# target attribute.
|
134
|
+
def generate(projects, target = @target.to_s)
|
135
|
+
html_in = File.join(target, 'html')
|
136
|
+
rm_rf html_in ; mkpath html_in
|
137
|
+
|
138
|
+
Buildr.ant('junit-report') do |ant|
|
139
|
+
ant.junitreport :todir=>target do
|
140
|
+
projects.select { |project| project.test.framework == :junit }.
|
141
|
+
map { |project| project.test.report_to.to_s }.select { |path| File.exist?(path) }.
|
142
|
+
each { |path| ant.fileset(:dir=>path) { ant.include :name=>'TEST-*.xml' } }
|
143
|
+
options = { :format=>frames ? 'frames' : 'noframes' }
|
144
|
+
options[:styledir] = style_dir if style_dir
|
145
|
+
ant.report options.merge(:todir=>html_in) do
|
146
|
+
params.each { |key, value| ant.param :name=>key, :expression=>value }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
class << self
|
155
|
+
|
156
|
+
# :call-seq:
|
157
|
+
# report()
|
158
|
+
#
|
159
|
+
# Returns the Report object used by the junit:report task. You can use this object to set
|
160
|
+
# various options that affect your report, for example:
|
161
|
+
# JUnit.report.frames = false
|
162
|
+
# JUnit.report.params['title'] = 'My App'
|
163
|
+
def report
|
164
|
+
@report ||= Report.new
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
# JUnit version number.
|
170
|
+
VERSION = '4.3.1' unless const_defined?('VERSION')
|
171
|
+
|
172
|
+
REQUIRES = ["junit:junit:jar:#{VERSION}"] + JMock::REQUIRES
|
173
|
+
|
174
|
+
# Ant-JUnit requires for JUnit and JUnit reports tasks.
|
175
|
+
Java.classpath << "org.apache.ant:ant-junit:jar:#{Ant::VERSION}"
|
176
|
+
|
177
|
+
include TestFramework::JavaTest
|
178
|
+
|
179
|
+
def tests(dependencies) #:nodoc:
|
180
|
+
filter_classes(dependencies,
|
181
|
+
:interfaces => %w{junit.framework.TestCase},
|
182
|
+
:class_annotations => %w{org.junit.runner.RunWith},
|
183
|
+
:method_annotations => %w{org.junit.Test})
|
184
|
+
end
|
185
|
+
|
186
|
+
def run(tests, dependencies) #:nodoc:
|
187
|
+
# Use Ant to execute the Junit tasks, gives us performance and reporting.
|
188
|
+
Buildr.ant('junit') do |ant|
|
189
|
+
case options[:fork]
|
190
|
+
when false
|
191
|
+
forking = {}
|
192
|
+
when :each
|
193
|
+
forking = { :fork=>true, :forkmode=>'perTest' }
|
194
|
+
when true, :once
|
195
|
+
forking = { :fork=>true, :forkmode=>'once' }
|
196
|
+
else
|
197
|
+
fail 'Option fork must be :once, :each or false.'
|
198
|
+
end
|
199
|
+
mkpath task.report_to.to_s
|
200
|
+
ant.junit forking.merge(:clonevm=>options[:clonevm] || false, :dir=>task.send(:project).path_to) do
|
201
|
+
ant.classpath :path=>dependencies.join(File::PATH_SEPARATOR)
|
202
|
+
(options[:properties] || []).each { |key, value| ant.sysproperty :key=>key, :value=>value }
|
203
|
+
(options[:environment] || []).each { |key, value| ant.env :key=>key, :value=>value }
|
204
|
+
ant.formatter :type=>'plain'
|
205
|
+
ant.formatter :type=>'plain', :usefile=>false # log test
|
206
|
+
ant.formatter :type=>'xml'
|
207
|
+
ant.batchtest :todir=>task.report_to.to_s, :failureproperty=>'failed' do
|
208
|
+
ant.fileset :dir=>task.compile.target.to_s do
|
209
|
+
tests.each { |test| ant.include :name=>File.join(*test.split('.')).ext('class') }
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
return tests unless ant.project.getProperty('failed')
|
214
|
+
end
|
215
|
+
# But Ant doesn't tell us what went kaput, so we'll have to parse the test files.
|
216
|
+
tests.inject([]) do |passed, test|
|
217
|
+
report_file = File.join(task.report_to.to_s, "TEST-#{test}.txt")
|
218
|
+
if File.exist?(report_file)
|
219
|
+
report = File.read(report_file)
|
220
|
+
# The second line (if exists) is the status line and we scan it for its values.
|
221
|
+
status = (report.split("\n")[1] || '').scan(/(run|failures|errors):\s*(\d+)/i).
|
222
|
+
inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] = pair[1].to_i ; hash }
|
223
|
+
passed << test if status[:failures] == 0 && status[:errors] == 0
|
224
|
+
end
|
225
|
+
passed
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
namespace 'junit' do
|
230
|
+
desc "Generate JUnit tests report in #{report.target}"
|
231
|
+
task('report') do |task|
|
232
|
+
report.generate Project.projects
|
233
|
+
puts "Generated JUnit tests report in #{report.target}" if verbose
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
task('clean') { rm_rf report.target.to_s }
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# TestNG test framework. To use in your project:
|
243
|
+
# test.using :testng
|
244
|
+
#
|
245
|
+
# Support the following options:
|
246
|
+
# * :properties -- Hash of properties passed to the test suite.
|
247
|
+
# * :java_args -- Arguments passed to the JVM.
|
248
|
+
class TestNG < TestFramework::Base
|
249
|
+
|
250
|
+
# TestNG version number.
|
251
|
+
VERSION = '5.5' unless const_defined?('VERSION')
|
252
|
+
# TestNG specification.
|
253
|
+
REQUIRES = ["org.testng:testng:jar:jdk15:#{VERSION}"] + JMock::REQUIRES
|
254
|
+
|
255
|
+
include TestFramework::JavaTest
|
256
|
+
|
257
|
+
def tests(dependencies) #:nodoc:
|
258
|
+
filter_classes(dependencies,
|
259
|
+
:class_annotations => %w{org.testng.annotations.Test},
|
260
|
+
:method_annotations => %w{org.testng.annotations.Test})
|
261
|
+
end
|
262
|
+
|
263
|
+
def run(tests, dependencies) #:nodoc:
|
264
|
+
cmd_args = [ 'org.testng.TestNG', '-sourcedir', task.compile.sources.join(';'), '-suitename', task.send(:project).name ]
|
265
|
+
cmd_args << '-d' << task.report_to.to_s
|
266
|
+
cmd_options = { :properties=>options[:properties], :java_args=>options[:java_args],
|
267
|
+
:classpath=>dependencies }
|
268
|
+
tests.inject([]) do |passed, test|
|
269
|
+
begin
|
270
|
+
Java::Commands.java cmd_args, '-testclass', test, cmd_options.merge(:name=>test)
|
271
|
+
passed << test
|
272
|
+
rescue
|
273
|
+
passed
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
Buildr::TestFramework << Buildr::JUnit
|
284
|
+
Buildr::TestFramework << Buildr::TestNG
|
285
|
+
|
286
|
+
# Backward compatibility crap.
|
287
|
+
Buildr::JUnit::JUNIT_REQUIRES = Buildr::JUnit::REQUIRES
|
288
|
+
Buildr::TestNG::TestNG_REQUIRES = Buildr::TestNG::REQUIRES
|
289
|
+
Java::JUnit = Buildr::JUnit
|
290
|
+
Java::TestNG = Buildr::TestNG
|