buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,174 @@
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
+ pom = POM.new(IO.read(filename))
52
+ cache[filename] = pom
53
+ end
54
+ pom
55
+ else
56
+ raise ArgumentError, "Expecting Hash spec, Artifact, file name or file task"
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def cache()
63
+ @cache ||= {}
64
+ end
65
+
66
+ end
67
+
68
+ def initialize(xml) #:nodoc:
69
+ @project = XmlSimple.xml_in(xml)
70
+ @parent = POM.load(pom_to_hash(project["parent"].first).merge(:type=>'pom')) if project['parent']
71
+ end
72
+
73
+ # :call-seq:
74
+ # dependencies(scopes?) => artifacts
75
+ #
76
+ # Returns list of required dependencies as specified by the POM. You can specify which scopes
77
+ # to use (e.g. "compile", "runtime"); use +nil+ for dependencies with unspecified scope.
78
+ # The default scopes are +nil+, "compile" and "runtime" (aka SCOPES_WE_USE).
79
+ def dependencies(scopes = SCOPES_WE_USE)
80
+ #try to cache dependencies also
81
+ @depends_for_scopes ||= {}
82
+ unless depends = @depends_for_scopes[scopes]
83
+ declared = project["dependencies"].first["dependency"] rescue nil
84
+ depends = (declared || []).reject { |dep| value_of(dep["optional"]) =~ /true/ }.
85
+ map { |dep|
86
+ spec = pom_to_hash(dep, properties)
87
+ apply = managed(spec)
88
+ spec = apply.merge(spec) if apply
89
+
90
+ #calculate transitive dependencies
91
+ if scopes.include?(spec[:scope])
92
+ spec.delete(:scope)
93
+
94
+ exclusions = dep["exclusions"]["exclusion"] rescue nil
95
+ transitive_deps = POM.load(spec).dependencies(SCOPES_TRANSITIVE)
96
+ transitive_deps = transitive_deps.reject{|dep|
97
+ exclusions.find {|ex| dep.index("#{dep['groupdId'].first}:#{dep['artifactId'].first}:") == 0}
98
+ } if exclusions
99
+
100
+ [Artifact.to_spec(spec)] + transitive_deps
101
+ end
102
+ }.flatten.compact #.uniq_by{|spec| art = spec.split(':'); "#{art[0]}:#{art[1]}"}
103
+
104
+ @depends_for_scopes[scopes] = depends
105
+ end
106
+ depends
107
+ end
108
+
109
+ # :call-seq:
110
+ # properties() => hash
111
+ #
112
+ # Returns properties available to this POM as hash. Includes explicit properties and pom.xxx/project.xxx
113
+ # properties for groupId, artifactId, version and packaging.
114
+ def properties()
115
+ @properties ||= begin
116
+ pom = ["groupId", "artifactId", "version", "packaging"].inject({}) { |hash, key|
117
+ value = project[key] || (parent ? parent.project[key] : nil)
118
+ hash["pom.#{key}"] = hash["project.#{key}"] = value_of(value) if value
119
+ hash
120
+ }
121
+ props = project["properties"].first rescue {}
122
+ props = props.inject({}) { |mapped, pair| mapped[pair.first] = value_of(pair.last, pom) ; mapped }
123
+ (parent ? parent.properties.merge(props) : props).merge(pom)
124
+ end
125
+ end
126
+
127
+ # :call-seq:
128
+ # managed() => hash
129
+ # managed(hash) => hash
130
+ #
131
+ # The first form returns all the managed dependencies specified by this POM in dependencyManagement.
132
+ # The second form uses a single spec hash and expands it from the current/parent POM. Used to determine
133
+ # the version number if specified in dependencyManagement instead of dependencies.
134
+ def managed(spec = nil)
135
+ if spec
136
+ managed.detect { |dep| [:group, :id, :type, :classifier].all? { |key| spec[key] == dep[key] } } ||
137
+ (parent ? parent.managed(spec) : nil)
138
+ else
139
+ @managed ||= begin
140
+ managed = project["dependencyManagement"].first["dependencies"].first["dependency"] rescue nil
141
+ managed ? managed.map { |dep| pom_to_hash(dep, properties) } : []
142
+ end
143
+ end
144
+ end
145
+
146
+ private
147
+
148
+ # :call-seq:
149
+ # value_of(element) => string
150
+ # value_of(element, true) => string
151
+ #
152
+ # Returns the normalized text value of an element from its XmlSimple value. The second form performs
153
+ # property substitution.
154
+ def value_of(element, substitute = nil)
155
+ value = element.to_a.join.strip
156
+ substitute ? value.gsub(/\$\{([^}]+)\}/) { |key| substitute[$1] } : value
157
+ end
158
+
159
+ # :call-seq:
160
+ # pom_to_hash(element) => hash
161
+ # pom_to_hash(element, true) => hash
162
+ #
163
+ # Return the spec hash from an XmlSimple POM referencing element (e.g. project, parent, dependency).
164
+ # The second form performs property substitution.
165
+ def pom_to_hash(element, substitute = nil)
166
+ hash = POM_TO_SPEC_MAP.inject({}) { |spec, pair|
167
+ spec[pair.first] = value_of(element[pair.last], substitute) if element[pair.last]
168
+ spec
169
+ }
170
+ { :type=>"jar" }.merge(hash)
171
+ end
172
+
173
+ end
174
+ end
@@ -0,0 +1,155 @@
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
+ name = sym.to_s
129
+ return ::Rjb.import(name) if name =~ /^[[:upper:]]/
130
+ __package__ name
131
+ end
132
+
133
+ private
134
+
135
+ def __package__(name) #:nodoc:
136
+ const = name.split('.').map { |part| part.gsub(/^./) { |char| char.upcase } }.join
137
+ return const_get(const) if constants.include?(const) || constants.include?(const.to_sym)
138
+ package = Module.new
139
+ package.extend Package
140
+ package.instance_variable_set :@name, name
141
+ const_set(const, package)
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+
148
+
149
+ class Array
150
+ # Converts a Ruby array into a typed Java array, argument specifies the element type.
151
+ # This is necessary for JRuby and causes no harm on RJB.
152
+ def to_java(cls)
153
+ map { |item| cls.new(item) }
154
+ end
155
+ end
@@ -0,0 +1,353 @@
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
+ require 'fileutils'
17
+ module Buildr #:nodoc:
18
+ module TestFramework
19
+
20
+ # A class used by buildr for jruby based frameworks, so that buildr can know
21
+ # which tests succeeded/failed.
22
+ class TestResult
23
+
24
+ class Error < ::Exception
25
+ attr_reader :message, :backtrace
26
+ def initialize(message, backtrace)
27
+ @message = message
28
+ @backtrace = backtrace
29
+ set_backtrace backtrace
30
+ end
31
+
32
+ def self.dump_yaml(file, e)
33
+ FileUtils.mkdir_p File.dirname(file)
34
+ File.open(file, 'w') { |f| f.puts(YAML.dump(Error.new(e.message, e.backtrace))) }
35
+ end
36
+
37
+ def self.guard(file)
38
+ begin
39
+ yield
40
+ rescue => e
41
+ dump_yaml(file, e)
42
+ end
43
+ end
44
+ end
45
+
46
+ attr_accessor :failed, :succeeded
47
+
48
+ def initialize
49
+ @failed, @succeeded = [], []
50
+ end
51
+
52
+ # An Rspec formatter used by buildr
53
+ class YamlFormatter
54
+ attr_reader :result
55
+
56
+ attr_accessor :example_group, :options, :where
57
+
58
+ def initialize(options, where)
59
+ @options = options
60
+ @where = where
61
+ @result = Hash.new
62
+ @result[:succeeded] = []
63
+ @result[:failed] = []
64
+ end
65
+
66
+ %w[ example_started
67
+ start_dump dump_failure dump_summary dump_pending ].each do |meth|
68
+ module_eval "def #{meth}(*args); end"
69
+ end
70
+
71
+ def example_group_started(example_group)
72
+ @example_group = example_group
73
+ end
74
+
75
+ def example_passed(example)
76
+ result.succeeded << example_group.location.gsub(/:\d+$/, '')
77
+ end
78
+
79
+ def example_pending(example, counter, failure)
80
+ result.succeeded << example_group.location.gsub(/:\d+$/, '')
81
+ end
82
+
83
+ def example_failed(example, counter, failure)
84
+ result.failed << example_group.location.gsub(/:\d+$/, '')
85
+ end
86
+
87
+ def start(example_count)
88
+ @result = TestResult.new
89
+ end
90
+
91
+ def close
92
+ result.succeeded = result.succeeded - result.failed
93
+ FileUtils.mkdir_p File.dirname(where)
94
+ File.open(where, 'w') { |f| f.puts YAML.dump(result) }
95
+ end
96
+ end # YamlFormatter
97
+
98
+ # Rspec formatter used for JtestR
99
+ # (JtestR provides its own version of rspec)
100
+ class JtestRYamlFormatter
101
+ attr_reader :result
102
+
103
+ attr_accessor :example_group, :options, :where
104
+
105
+ def initialize(options, where)
106
+ @options = options
107
+ @where = where
108
+ @result = Hash.new
109
+ @result[:succeeded] = []
110
+ @result[:failed] = []
111
+ end
112
+
113
+ %w[ example_started
114
+ start_dump dump_failure dump_summary dump_pending ].each do |meth|
115
+ module_eval "def #{meth}(*args); end"
116
+ end
117
+
118
+ def add_example_group(example_group)
119
+ @example_group = example_group
120
+ end
121
+
122
+ def example_passed(example)
123
+ end
124
+
125
+ def example_pending(example, counter, failure)
126
+ end
127
+
128
+ def example_failed(example, counter, failure)
129
+ if example_group.respond_to?(:spec_path)
130
+ result.failed << example_group.spec_path.gsub(/:\d+$/, '')
131
+ else
132
+ path = path_from_bt(failure.exception.backtrace)
133
+ result.failed << path if path
134
+ end
135
+ end
136
+
137
+ def start(example_count)
138
+ @result = TestResult.new
139
+ end
140
+
141
+ def path_from_bt(ary)
142
+ files = options.files
143
+ test = nil
144
+ ary.find do |bt|
145
+ bt = bt.split(':').first.strip
146
+ test = bt if files.include?(bt)
147
+ end
148
+ test
149
+ end
150
+
151
+ def close
152
+ files = options.files
153
+ result.succeeded = files - result.failed
154
+
155
+ FileUtils.mkdir_p File.dirname(where)
156
+ File.open(where, 'w') { |f| f.puts YAML.dump(result) }
157
+ end
158
+ end # JtestRYamlFormatter
159
+
160
+ # A JtestR ResultHandler
161
+ # Using this handler we can use RSpec formatters, like html/ci_reporter with JtestR
162
+ # Created for YamlFormatter
163
+ class RSpecResultHandler
164
+
165
+ # Workaround for http://jira.codehaus.org/browse/JTESTR-68
166
+ module TestNGResultHandlerMixin
167
+ def onTestSuccess(test_result)
168
+ @result_handler.succeed_single(test_result.name)
169
+ end
170
+ end
171
+
172
+ class BacktraceTweaker
173
+ attr_reader :ignore_patterns
174
+ def initialize
175
+ @ignore_patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.dup
176
+ # ignore jruby/jtestr backtrace
177
+ ignore_patterns << /org\.jruby\.javasupport\.JavaMethod\./
178
+ ignore_patterns << /jtestr.*\.jar!/i << /runner\.rb/
179
+ end
180
+
181
+ def clean_up_double_slashes(line)
182
+ line.gsub!('//','/')
183
+ end
184
+
185
+ def tweak_backtrace(error)
186
+ return if error.backtrace.nil?
187
+ error.backtrace.collect! do |line|
188
+ clean_up_double_slashes(line)
189
+ ignore_patterns.each do |ignore|
190
+ if line =~ ignore
191
+ line = nil
192
+ break
193
+ end
194
+ end
195
+ line
196
+ end
197
+ error.backtrace.compact!
198
+ end
199
+ end
200
+
201
+ class << self
202
+ # an rspec reporter used to proxy events to rspec formatters
203
+ attr_reader :reporter
204
+
205
+ def init(argv = [], out = STDOUT, err = STDERR)
206
+ ::JtestR::TestNGResultHandler.module_eval { include TestNGResultHandlerMixin }
207
+ rspec_parser = ::Spec::Runner::OptionParser.new(err, out)
208
+ rspec_parser.order!(argv)
209
+ rspec_parser.options.backtrace_tweaker = BacktraceTweaker.new
210
+ @reporter = Spec::Runner::Reporter.new(rspec_parser.options)
211
+ end
212
+
213
+ def before
214
+ reporter.start(reporter.options.files.size)
215
+ end
216
+
217
+ def after
218
+ reporter.end
219
+ reporter.dump
220
+ end
221
+ end
222
+
223
+ module ExampleMethods
224
+ attr_accessor :name, :description, :__full_description
225
+ end
226
+
227
+ def reporter
228
+ self.class.reporter
229
+ end
230
+
231
+ attr_accessor :example_group, :current_example, :current_failure
232
+
233
+ def initialize(name, desc, *args)
234
+ self.example_group = ::Spec::Example::ExampleGroup.new(desc)
235
+ example_group.extend ExampleMethods
236
+ example_group.name = name.to_s
237
+ if example_group.name[/Spec/]
238
+ example_group.description = desc.to_s
239
+ else
240
+ example_group.description = name.to_s
241
+ end
242
+ reporter.add_example_group(example_group)
243
+ end
244
+
245
+ def starting
246
+ end
247
+
248
+ def ending
249
+ end
250
+
251
+ def add_fault(fault)
252
+ self.current_failure = fault
253
+ end
254
+
255
+ def add_pending(pending)
256
+ end
257
+
258
+ def starting_single(name = nil)
259
+ self.current_failure = nil
260
+ self.current_example = Object.new
261
+ current_example.extend ::Spec::Example::ExampleMethods
262
+ current_example.extend ExampleMethods
263
+ name = name.to_s
264
+ name[/\((pen?ding|error|failure|success)\)?$/]
265
+ name = $`
266
+ current_example.description = name
267
+ if example_group.name[/Spec/]
268
+ current_example.__full_description = "#{example_group.description} #{name}"
269
+ else
270
+ current_example.__full_description = "#{example_group.name}: #{name}"
271
+ end
272
+ reporter.example_started(current_example)
273
+ #puts "STARTED #{name} #{current_example.__full_description}"
274
+ end
275
+
276
+ def succeed_single(name = nil)
277
+ #puts "SUCC SINGLE #{name}"
278
+ reporter.example_finished(current_example, nil)
279
+ end
280
+
281
+ def fail_single(name = nil)
282
+ #puts "FAIL SINGLE #{name}"
283
+ reporter.example_finished(current_example, current_error)
284
+ end
285
+
286
+ def error_single(name = nil)
287
+ #puts "ERR SINGLE #{name}"
288
+ reporter.example_finished(current_example, current_error)
289
+ end
290
+
291
+ def pending_single(name = nil)
292
+ #puts "PEND SINGLE #{name}"
293
+ error = ::Spec::Example::ExamplePendingError.new(name)
294
+ reporter.example_finished(current_example, error)
295
+ end
296
+
297
+ private
298
+ def current_error(fault = current_failure)
299
+ case fault
300
+ when nil
301
+ nil
302
+ when Test::Unit::Failure
303
+ Error.new(fault.message, fault.location)
304
+ when Test::Unit::Error
305
+ if fault.exception.is_a?(NativeException)
306
+ exception = fault.exception.cause
307
+ bt = exception.stack_trace.to_a
308
+ else
309
+ exception = fault.exception
310
+ bt = exception.backtrace
311
+ end
312
+ Error.new(exception.message, bt)
313
+ when Expectations::Results::Error
314
+ fault.exception
315
+ when Spec::Runner::Reporter::Failure
316
+ ex = fault.exception
317
+ fault.example.instance_variable_get(:@_implementation).to_s =~ /@(.+:\d+)/
318
+ Error.new(ex.message, [$1.to_s] + ex.backtrace)
319
+ when Expectations::Results
320
+ file = fault.file
321
+ line = fault.line
322
+ Error.new(fault.message, ["#{fault.file}:#{fault.line}"])
323
+ else
324
+ if fault.respond_to?(:test_header)
325
+ fault.test_header[/\((.+)\)/]
326
+ test_cls, test_meth = $1.to_s, $`.to_s
327
+ exception = fault.exception
328
+ (class << exception; self; end).module_eval do
329
+ define_method(:backtrace) do
330
+ (["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
331
+ end
332
+ end
333
+ exception
334
+ elsif fault.respond_to?(:method)
335
+ test_cls, test_meth = fault.method.test_class.name, fault.method.method_name
336
+ exception = fault.throwable
337
+ (class << exception; self; end).module_eval do
338
+ define_method(:backtrace) do
339
+ (["#{test_cls}:in `#{test_meth}'"] + stackTrace).map { |s| s.to_s }
340
+ end
341
+ end
342
+ exception
343
+ else
344
+ raise "Cannot handle fault #{fault.class}: #{fault.inspect}"
345
+ end
346
+ end
347
+ end
348
+
349
+ end # RSpecResultHandler
350
+
351
+ end # TestResult
352
+ end
353
+ end