mguymon-buildr 1.4.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- metadata +600 -0
@@ -0,0 +1,73 @@
|
|
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
|
+
module Buildr
|
17
|
+
module Compiler
|
18
|
+
class ExternalJavac< Buildr::Compiler::Javac
|
19
|
+
|
20
|
+
OPTIONS = [:jvm, :warnings, :debug, :deprecation, :source, :target, :lint, :other]
|
21
|
+
|
22
|
+
specify :language=>:java, :sources => 'java', :source_ext => 'java',
|
23
|
+
:target=>'classes', :target_ext=>'class', :packaging=>:jar
|
24
|
+
|
25
|
+
|
26
|
+
def compile(sources, target, dependencies) #:nodoc:
|
27
|
+
check_options options, OPTIONS
|
28
|
+
cmd_args = []
|
29
|
+
# tools.jar contains the Java compiler.
|
30
|
+
dependencies << Java.tools_jar if Java.tools_jar
|
31
|
+
cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
|
32
|
+
source_paths = sources.select { |source| File.directory?(source) }
|
33
|
+
cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
|
34
|
+
cmd_args << '-d' << File.expand_path(target)
|
35
|
+
cmd_args += externaljavac_args
|
36
|
+
Tempfile.open("external") {|tmp|
|
37
|
+
tmp.write files_from_sources(sources).join(' ')
|
38
|
+
cmd_args << "@#{tmp.path}"
|
39
|
+
}
|
40
|
+
unless Buildr.application.options.dryrun
|
41
|
+
javac_path = File.join(options[:jvm] || ENV['JAVA_HOME'], "bin", "javac")
|
42
|
+
final_args = cmd_args.insert(0, javac_path).push('2>&1').join(' ')
|
43
|
+
trace(final_args)
|
44
|
+
info %x[#{final_args}]
|
45
|
+
fail 'Failed to compile, see errors above' unless $?.success?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# See arg list here: http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm
|
52
|
+
def externaljavac_args #:nodoc:
|
53
|
+
args = []
|
54
|
+
args << '-nowarn' unless options[:warnings]
|
55
|
+
args << '-verbose' if trace?(:javac)
|
56
|
+
args << '-g' if options[:debug]
|
57
|
+
args << '-deprecation' if options[:deprecation]
|
58
|
+
args << '-source' << options[:source].to_s if options[:source]
|
59
|
+
args << '-target' << options[:target].to_s if options[:target]
|
60
|
+
case options[:lint]
|
61
|
+
when Array then args << "-Xlint:#{options[:lint].join(',')}"
|
62
|
+
when String then args << "-Xlint:#{options[:lint]}"
|
63
|
+
when true then args << '-Xlint'
|
64
|
+
end
|
65
|
+
args + Array(options[:other])
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Buildr::Compiler.compilers << Buildr::Compiler::ExternalJavac
|
@@ -0,0 +1,122 @@
|
|
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 'java'
|
18
|
+
require 'jruby'
|
19
|
+
|
20
|
+
|
21
|
+
# Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows
|
22
|
+
# you to access Java classes and create Java objects.
|
23
|
+
#
|
24
|
+
# Java classes are accessed as static methods on the Java module, for example:
|
25
|
+
# str = Java.java.lang.String.new('hai!')
|
26
|
+
# str.toUpperCase
|
27
|
+
# => 'HAI!'
|
28
|
+
# Java.java.lang.String.isInstance(str)
|
29
|
+
# => true
|
30
|
+
# Java.com.sun.tools.javac.Main.compile(args)
|
31
|
+
#
|
32
|
+
# The classpath attribute allows Buildr to add JARs and directories to the classpath,
|
33
|
+
# for example, we use it to load Ant and various Ant tasks, code generators, test
|
34
|
+
# frameworks, and so forth.
|
35
|
+
#
|
36
|
+
# When using an artifact specification, Buildr will automatically download and
|
37
|
+
# install the artifact before adding it to the classpath.
|
38
|
+
#
|
39
|
+
# For example, Ant is loaded as follows:
|
40
|
+
# Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
41
|
+
#
|
42
|
+
# Artifacts can only be downloaded after the Buildfile has loaded, giving it
|
43
|
+
# a chance to specify which remote repositories to use, so adding to classpath
|
44
|
+
# does not by itself load any libraries. You must call Java.load before accessing
|
45
|
+
# any Java classes to give Buildr a chance to load the libraries specified in the
|
46
|
+
# classpath.
|
47
|
+
#
|
48
|
+
# When building an extension, make sure to follow these rules:
|
49
|
+
# 1. Add to the classpath when the extension is loaded (i.e. in module or class
|
50
|
+
# definition), so the first call to Java.load anywhere in the code will include
|
51
|
+
# the libraries you specify.
|
52
|
+
# 2. Call Java.load once before accessing any Java classes, allowing Buildr to
|
53
|
+
# set up the classpath.
|
54
|
+
# 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
|
55
|
+
# with a partial classpath, or before all remote repositories are listed.
|
56
|
+
# 4. Check on a clean build with empty local repository.
|
57
|
+
module Java
|
58
|
+
|
59
|
+
# Since we already have a JVM loaded, we can use it to guess where JAVA_HOME is.
|
60
|
+
# We set JAVA_HOME early so we can use it without calling Java.load first.
|
61
|
+
ENV['JAVA_HOME'] ||= java.lang.System.getProperty("java.home")
|
62
|
+
|
63
|
+
# This version is the minimal version Buildr will support.
|
64
|
+
# Any older version of JRuby will raise an exception.
|
65
|
+
JRUBY_MIN_VERSION = '1.5.1'
|
66
|
+
raise "JRuby must be at least at version #{JRUBY_MIN_VERSION}" unless JRUBY_VERSION >= JRUBY_MIN_VERSION
|
67
|
+
|
68
|
+
class << self
|
69
|
+
|
70
|
+
# Returns the classpath, an array listing directories, JAR files and
|
71
|
+
# artifacts. Use when loading the extension to add any additional
|
72
|
+
# libraries used by that extension.
|
73
|
+
#
|
74
|
+
# For example, Ant is loaded as follows:
|
75
|
+
# Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
76
|
+
def classpath
|
77
|
+
@classpath ||= []
|
78
|
+
end
|
79
|
+
|
80
|
+
# Most platforms requires tools.jar to be on the classpath, tools.jar contains the
|
81
|
+
# Java compiler (OS X and AIX are two exceptions we know about, may be more).
|
82
|
+
# Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
|
83
|
+
# but maybe the JRE. Return nil if not found.
|
84
|
+
def tools_jar #:nodoc:
|
85
|
+
@tools_jar ||= ['lib/tools.jar', '../lib/tools.jar'].map { |path| File.expand_path(path, ENV['JAVA_HOME']) }.
|
86
|
+
find { |path| File.exist?(path) }
|
87
|
+
end
|
88
|
+
|
89
|
+
# Loads the JVM and all the libraries listed on the classpath. Call this
|
90
|
+
# method before accessing any Java class, but only call it from methods
|
91
|
+
# used in the build, giving the Buildfile a chance to load all extensions
|
92
|
+
# that append to the classpath and specify which remote repositories to use.
|
93
|
+
def load
|
94
|
+
return self if @loaded
|
95
|
+
|
96
|
+
# Adding jars to the jruby's $CLASSPATH should be the correct thing, however it
|
97
|
+
# seems like some tools require their jars on system class loader (javadoc, junit, etc)
|
98
|
+
# cp.each { |path| $CLASSPATH << path }
|
99
|
+
|
100
|
+
# Use system ClassLoader to add classpath
|
101
|
+
sysloader = java.lang.ClassLoader.getSystemClassLoader
|
102
|
+
add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
|
103
|
+
getDeclaredMethod('addURL', [java.net.URL.java_class].to_java(java.lang.Class))
|
104
|
+
add_url_method.setAccessible(true)
|
105
|
+
add_path = lambda { |path| add_url_method.invoke(sysloader, [java.io.File.new(path).toURI.toURL].to_java(java.net.URL)) }
|
106
|
+
|
107
|
+
# Most platforms requires tools.jar to be on the classpath.
|
108
|
+
add_path[tools_jar] if tools_jar
|
109
|
+
|
110
|
+
classpath.map! { |path| Proc === path ? path.call : path }
|
111
|
+
Buildr.artifacts(classpath).map(&:to_s).each do |path|
|
112
|
+
file(path).invoke
|
113
|
+
add_path[path]
|
114
|
+
end
|
115
|
+
|
116
|
+
@loaded = true
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,295 @@
|
|
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
|
+
|
20
|
+
module Buildr #:nodoc:
|
21
|
+
|
22
|
+
module JtestR
|
23
|
+
|
24
|
+
# An Rspec formatter used by JtestR
|
25
|
+
class YamlFormatter
|
26
|
+
attr_reader :result
|
27
|
+
|
28
|
+
attr_accessor :example_group, :options, :where
|
29
|
+
|
30
|
+
def initialize(options, where)
|
31
|
+
@options = options
|
32
|
+
@where = where
|
33
|
+
end
|
34
|
+
|
35
|
+
%w[ example_started
|
36
|
+
start_dump dump_failure dump_summary dump_pending ].each do |meth|
|
37
|
+
module_eval "def #{meth}(*args); end"
|
38
|
+
end
|
39
|
+
|
40
|
+
def example_group_started(example_group)
|
41
|
+
@example_group = example_group
|
42
|
+
end
|
43
|
+
|
44
|
+
def example_passed(example)
|
45
|
+
result.succeeded << example_name(example)
|
46
|
+
end
|
47
|
+
|
48
|
+
def example_pending(example, counter)
|
49
|
+
result.succeeded << example_name(example)
|
50
|
+
end
|
51
|
+
|
52
|
+
def example_failed(example, counter, failure)
|
53
|
+
result.failed << example_name(example)
|
54
|
+
end
|
55
|
+
|
56
|
+
def start(example_count)
|
57
|
+
@result = Buildr::TestFramework::TestResult.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def close
|
61
|
+
result.succeeded = result.succeeded - result.failed
|
62
|
+
FileUtils.mkdir_p File.dirname(where)
|
63
|
+
File.open(where, 'w') { |f| f.puts YAML.dump(result) }
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def example_name(example)
|
68
|
+
if Spec::Example::ExampleProxy === example
|
69
|
+
example_group.location.gsub(/:\d+$/, '')
|
70
|
+
else
|
71
|
+
example.name.gsub(/(.+)(\..+\(\))/, '\1')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end # YamlFormatter
|
75
|
+
|
76
|
+
# A JtestR ResultHandler
|
77
|
+
# Using this handler we can use RSpec formatters, like html/ci_reporter with JtestR
|
78
|
+
# Created for JTestrYamlFormatter
|
79
|
+
class ResultHandler
|
80
|
+
|
81
|
+
# Workaround for http://jira.codehaus.org/browse/JTESTR-68
|
82
|
+
module TestNGResultHandlerMixin
|
83
|
+
def onTestSuccess(test_result)
|
84
|
+
@result_handler.succeed_single(test_result.name)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class BacktraceTweaker
|
89
|
+
attr_reader :ignore_patterns
|
90
|
+
def initialize
|
91
|
+
@ignore_patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.dup
|
92
|
+
# ignore jruby/jtestr backtrace
|
93
|
+
ignore_patterns << /org\.jruby\.javasupport\.JavaMethod\./
|
94
|
+
ignore_patterns << /jtestr.*\.jar!/i << /runner\.rb/
|
95
|
+
end
|
96
|
+
|
97
|
+
def clean_up_double_slashes(line)
|
98
|
+
line.gsub!('//','/')
|
99
|
+
end
|
100
|
+
|
101
|
+
def tweak_backtrace(error)
|
102
|
+
return if error.backtrace.nil?
|
103
|
+
error.backtrace.collect! do |line|
|
104
|
+
clean_up_double_slashes(line)
|
105
|
+
ignore_patterns.each do |ignore|
|
106
|
+
if line =~ ignore
|
107
|
+
line = nil
|
108
|
+
break
|
109
|
+
end
|
110
|
+
end
|
111
|
+
line
|
112
|
+
end
|
113
|
+
error.backtrace.compact!
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class << self
|
118
|
+
# an rspec reporter used to proxy events to rspec formatters
|
119
|
+
attr_reader :reporter
|
120
|
+
attr_accessor :test_files
|
121
|
+
|
122
|
+
def init(argv = [], out = STDOUT, err = STDERR)
|
123
|
+
::JtestR::TestNGResultHandler.module_eval { include TestNGResultHandlerMixin }
|
124
|
+
rspec_parser = ::Spec::Runner::OptionParser.new(err, out)
|
125
|
+
rspec_parser.order!(argv)
|
126
|
+
rspec_parser.options.backtrace_tweaker = BacktraceTweaker.new
|
127
|
+
@reporter = Spec::Runner::Reporter.new(rspec_parser.options)
|
128
|
+
end
|
129
|
+
|
130
|
+
def before
|
131
|
+
reporter.start(reporter.options.files.size)
|
132
|
+
end
|
133
|
+
|
134
|
+
def after
|
135
|
+
reporter.end
|
136
|
+
reporter.dump
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
module ExampleMethods
|
142
|
+
attr_accessor :name, :description, :__full_description, :location
|
143
|
+
end
|
144
|
+
|
145
|
+
def reporter
|
146
|
+
self.class.reporter
|
147
|
+
end
|
148
|
+
|
149
|
+
attr_accessor :example_group, :current_example, :current_failure
|
150
|
+
|
151
|
+
def initialize(name, desc, *args)
|
152
|
+
self.example_group = ::Spec::Example::ExampleGroup.new(desc)
|
153
|
+
example_group.extend ExampleMethods
|
154
|
+
example_group.name = name.to_s
|
155
|
+
if example_group.name[/Spec/]
|
156
|
+
example_group.description = desc.to_s
|
157
|
+
else
|
158
|
+
example_group.description = name.to_s
|
159
|
+
end
|
160
|
+
reporter.example_group_started(example_group)
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def starting
|
165
|
+
end
|
166
|
+
|
167
|
+
def ending
|
168
|
+
end
|
169
|
+
|
170
|
+
def add_fault(fault)
|
171
|
+
self.current_failure = fault
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_pending(pending)
|
175
|
+
end
|
176
|
+
|
177
|
+
def starting_single(name = nil)
|
178
|
+
self.current_failure = nil
|
179
|
+
self.current_example = Object.new
|
180
|
+
current_example.extend ::Spec::Example::ExampleMethods
|
181
|
+
current_example.extend ExampleMethods
|
182
|
+
name = name.to_s
|
183
|
+
current_example.location = name.to_s
|
184
|
+
current_example.name = name.gsub(/(.*)\((.+)\)/, '\2')
|
185
|
+
current_example.description = name
|
186
|
+
if example_group.name[/Spec/]
|
187
|
+
current_example.__full_description = "#{example_group.description} #{name}"
|
188
|
+
else
|
189
|
+
current_example.__full_description = "#{example_group.name}: #{name}"
|
190
|
+
end
|
191
|
+
reporter.example_started(current_example)
|
192
|
+
end
|
193
|
+
|
194
|
+
def succeed_single(name = nil)
|
195
|
+
reporter.example_finished(current_example, nil)
|
196
|
+
end
|
197
|
+
|
198
|
+
def fail_single(name = nil)
|
199
|
+
current_example.name = current_name
|
200
|
+
reporter.example_finished(current_example, current_error)
|
201
|
+
end
|
202
|
+
|
203
|
+
def error_single(name = nil)
|
204
|
+
current_example.name = current_name
|
205
|
+
reporter.example_finished(current_example, current_error)
|
206
|
+
end
|
207
|
+
|
208
|
+
def pending_single(name = nil)
|
209
|
+
error = ::Spec::Example::ExamplePendingError.new(name)
|
210
|
+
reporter.example_finished(current_example, error)
|
211
|
+
end
|
212
|
+
|
213
|
+
private
|
214
|
+
def detect_file(trace)
|
215
|
+
# find first matching test file in stacktrace
|
216
|
+
file = nil
|
217
|
+
first_pos = nil
|
218
|
+
ResultHandler.test_files.each do |f|
|
219
|
+
pos = trace.index(f)
|
220
|
+
if pos && (first_pos.nil? || pos < first_pos)
|
221
|
+
file = f
|
222
|
+
first_pos = pos
|
223
|
+
end
|
224
|
+
end
|
225
|
+
file || fail("JTestR::ResultHandler.detect_file failed: #{trace}")
|
226
|
+
end
|
227
|
+
|
228
|
+
def current_name(example = current_example, fault = current_failure)
|
229
|
+
return example.name unless fault
|
230
|
+
case fault
|
231
|
+
when Test::Unit::Error
|
232
|
+
detect_file(fault.long_display)
|
233
|
+
when Test::Unit::Failure
|
234
|
+
detect_file(fault.location.to_s)
|
235
|
+
when Spec::Runner::Reporter::Failure
|
236
|
+
detect_file(fault.exception.backtrace.to_s)
|
237
|
+
else
|
238
|
+
example.name
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def current_error(fault = current_failure)
|
243
|
+
case fault
|
244
|
+
when nil
|
245
|
+
nil
|
246
|
+
when Test::Unit::Failure
|
247
|
+
Buildr::TestFramework::TestResult::Error.new(fault.message, fault.location)
|
248
|
+
when Test::Unit::Error
|
249
|
+
if fault.exception.is_a?(NativeException)
|
250
|
+
exception = fault.exception.cause
|
251
|
+
bt = exception.stack_trace.to_a
|
252
|
+
else
|
253
|
+
exception = fault.exception
|
254
|
+
bt = exception.backtrace
|
255
|
+
end
|
256
|
+
Buildr::TestFramework::TestResult::Error.new(exception.message, bt)
|
257
|
+
when Expectations::Results::Error
|
258
|
+
fault.exception
|
259
|
+
when Spec::Runner::Reporter::Failure
|
260
|
+
ex = fault.exception
|
261
|
+
Buildr::TestFramework::TestResult::Error.new(ex.message, ex.backtrace)
|
262
|
+
when Expectations::Results
|
263
|
+
file = fault.file
|
264
|
+
line = fault.line
|
265
|
+
Buildr::TestFramework::TestResult::Error.new(fault.message, ["#{fault.file}:#{fault.line}"])
|
266
|
+
else
|
267
|
+
if fault.respond_to?(:test_header)
|
268
|
+
fault.test_header[/\((.+)\)/]
|
269
|
+
test_cls, test_meth = $1.to_s, $`.to_s
|
270
|
+
exception = fault.exception
|
271
|
+
(class << exception; self; end).module_eval do
|
272
|
+
define_method(:backtrace) do
|
273
|
+
(["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
|
274
|
+
end
|
275
|
+
end
|
276
|
+
exception
|
277
|
+
elsif fault.respond_to?(:method)
|
278
|
+
test_cls, test_meth = fault.method.test_class.name, fault.method.method_name
|
279
|
+
exception = fault.throwable
|
280
|
+
(class << exception; self; end).module_eval do
|
281
|
+
define_method(:backtrace) do
|
282
|
+
(["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
|
283
|
+
end
|
284
|
+
end
|
285
|
+
exception
|
286
|
+
else
|
287
|
+
raise "Cannot handle fault #{fault.class}: #{fault.inspect}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
end # ResultHandler
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|