assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,210 @@
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/project'
18
+ require 'buildr/packaging'
19
+ require 'stringio'
20
+ require 'rexml/document'
21
+
22
+ module Buildr
23
+ module Idea7x #:nodoc:
24
+
25
+ include Extension
26
+
27
+ CLASSIFIER = "-7x"
28
+ IML_SUFFIX = CLASSIFIER + ".iml"
29
+ IPR_TEMPLATE = "idea7x.ipr.template"
30
+ MODULE_DIR = "$MODULE_DIR$"
31
+ FILE_PATH_PREFIX = "file://"
32
+ MODULE_DIR_URL = FILE_PATH_PREFIX + MODULE_DIR
33
+ PROJECT_DIR = "$PROJECT_DIR$"
34
+ PROJECT_DIR_URL = FILE_PATH_PREFIX + PROJECT_DIR
35
+
36
+ first_time do
37
+ # Global task "idea" generates artifacts for all projects.
38
+ desc "Generate Idea 7.x artifacts for all projects"
39
+ Project.local_task "idea7x"=>"artifacts"
40
+ end
41
+
42
+ before_define do |project|
43
+ project.recursive_task("idea7x")
44
+ end
45
+
46
+ after_define do |project|
47
+ idea7x = project.task("idea7x")
48
+
49
+ # We need paths relative to the top project's base directory.
50
+ root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir }; f[p] }[project]
51
+
52
+ # Find a path relative to the project's root directory.
53
+ relative = lambda { |path| Util.relative_path(File.expand_path(path.to_s), project.path_to) }
54
+
55
+ m2repo = Buildr::Repositories.instance.local
56
+ excludes = [ '**/.svn/', '**/CVS/' ].join('|')
57
+
58
+ # Only for projects that are packageable.
59
+ task_name = project.path_to("#{project.name.gsub(':', '-')}#{IML_SUFFIX}")
60
+ idea7x.enhance [ file(task_name) ]
61
+
62
+ # The only thing we need to look for is a change in the Buildfile.
63
+ file(task_name=>Buildr.application.buildfile) do |task|
64
+ # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
65
+ deps = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s ]
66
+
67
+ # Convert classpath elements into applicable Project objects
68
+ deps.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
69
+
70
+ # project_libs: artifacts created by other projects
71
+ project_libs, others = deps.partition { |path| path.is_a?(Project) }
72
+
73
+ # Separate artifacts from Maven2 repository
74
+ m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
75
+
76
+ # Project type is going to be the first package type
77
+ if package = project.packages.first
78
+ info "Writing #{task.name}"
79
+ File.open(task.name, "w") do |file|
80
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
81
+ xml.module(:version=>"4", :relativePaths=>"true", :type=>"JAVA_MODULE") do
82
+ xml.component(:name=>"NewModuleRootManager", "inherit-compiler-output"=>"false") do
83
+
84
+ Buildr::Idea7x.generate_compile_output(project, xml, relative)
85
+
86
+ Buildr::Idea7x.generate_content(project, xml, relative)
87
+
88
+ Buildr::Idea7x.generate_order_entries(project_libs, xml)
89
+
90
+ ext_libs = m2_libs.map { |path| "jar://#{path.to_s.sub(m2repo, "$M2_REPO$")}!/" }
91
+ ext_libs << "#{MODULE_DIR_URL}/#{relative[project.test.resources.target.to_s]}" if project.test.resources.target
92
+ ext_libs << "#{MODULE_DIR_URL}/#{relative[project.resources.target.to_s]}" if project.resources.target
93
+
94
+ Buildr::Idea7x.generate_module_libs(xml, ext_libs)
95
+ xml.orderEntryProperties
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ # Root project aggregates all the subprojects.
103
+ if project.parent == nil
104
+ Buildr::Idea7x.generate_ipr(project, idea7x, Buildr.application.buildfile)
105
+ end
106
+
107
+ end # after_define
108
+
109
+ class << self
110
+
111
+ def generate_order_entries(project_libs, xml)
112
+ xml.orderEntry :type=>"sourceFolder", :forTests=>"false"
113
+ xml.orderEntry :type=>"inheritedJdk"
114
+
115
+ # Classpath elements from other projects
116
+ project_libs.map(&:id).sort.uniq.each do |project_id|
117
+ xml.orderEntry :type=>'module', "module-name"=>"#{project_id}#{CLASSIFIER}"
118
+ end
119
+ end
120
+
121
+ def generate_compile_output(project, xml, relative)
122
+ xml.output(:url=>"#{MODULE_DIR_URL}/#{relative[project.compile.target.to_s]}") if project.compile.target
123
+ xml.tag!("output-test", :url=>"#{MODULE_DIR_URL}/#{relative[project.test.compile.target.to_s]}") if project.test.compile.target
124
+ xml.tag!("exclude-output")
125
+ end
126
+
127
+ def generate_content(project, xml, relative)
128
+ xml.content(:url=>"#{MODULE_DIR_URL}") do
129
+ unless project.compile.sources.empty?
130
+ srcs = project.compile.sources.map { |src| relative[src.to_s] }
131
+ srcs.sort.uniq.each do |path|
132
+ xml.sourceFolder :url=>"#{MODULE_DIR_URL}/#{path}", :isTestSource=>"false"
133
+ end
134
+ end
135
+ unless project.test.compile.sources.empty?
136
+ test_sources = project.test.compile.sources.map { |src| relative[src.to_s] }
137
+ test_sources.each do |paths|
138
+ paths.sort.uniq.each do |path|
139
+ xml.sourceFolder :url=>"#{MODULE_DIR_URL}/#{path}", :isTestSource=>"true"
140
+ end
141
+ end
142
+ end
143
+ [project.resources=>false, project.test.resources=>true].each do |resources, test|
144
+ resources.each do |path|
145
+ path[0].sources.each do |srcpath|
146
+ xml.sourceFolder :url=>"#{FILE_PATH_PREFIX}#{srcpath}", :isTestSource=>path[1].to_s
147
+ end
148
+ end
149
+ end
150
+ xml.excludeFolder :url=>"#{MODULE_DIR_URL}/#{relative[project.resources.target.to_s]}" if project.resources.target
151
+ xml.excludeFolder :url=>"#{MODULE_DIR_URL}/#{relative[project.test.resources.target.to_s]}" if project.test.resources.target
152
+ end
153
+ end
154
+
155
+ def generate_module_libs(xml, ext_libs)
156
+ ext_libs.each do |path|
157
+ xml.orderEntry :type=>"module-library" do
158
+ xml.library do
159
+ xml.CLASSES do
160
+ xml.root :url=> path
161
+ end
162
+ xml.JAVADOC
163
+ xml.SOURCES
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ def generate_ipr(project, idea7x, sources)
170
+ task_name = project.path_to("#{project.name.gsub(':', '-')}-7x.ipr")
171
+ idea7x.enhance [ file(task_name) ]
172
+ file(task_name=>sources) do |task|
173
+ info "Writing #{task.name}"
174
+
175
+ # Generating just the little stanza that chanages from one project to another
176
+ partial = StringIO.new
177
+ xml = Builder::XmlMarkup.new(:target=>partial, :indent=>2)
178
+ xml.component(:name=>"ProjectModuleManager") do
179
+ xml.modules do
180
+ project.projects.each do |subp|
181
+ module_name = subp.name.gsub(":", "-")
182
+ module_path = subp.name.split(":"); module_path.shift
183
+ module_path = module_path.join(File::SEPARATOR)
184
+ path = "#{module_path}/#{module_name}#{IML_SUFFIX}"
185
+ xml.module :fileurl=>"#{PROJECT_DIR_URL}/#{path}", :filepath=>"#{PROJECT_DIR}/#{path}"
186
+ end
187
+ if package = project.packages.first
188
+ xml.module :fileurl=>"#{PROJECT_DIR_URL}/#{project.name}#{IML_SUFFIX}", :filepath=>"#{PROJECT_DIR}/#{project.name}#{IML_SUFFIX}"
189
+ end
190
+ end
191
+ end
192
+
193
+ # Loading the whole fairly constant crap
194
+ template_xml = REXML::Document.new(File.open(File.join(File.dirname(__FILE__), IPR_TEMPLATE)))
195
+ include_xml = REXML::Document.new(partial.string)
196
+ template_xml.root.add_element(include_xml.root)
197
+ File.open task.name, 'w' do |file|
198
+ template_xml.write file
199
+ end
200
+ end
201
+ end
202
+
203
+ end
204
+
205
+ end # module Idea7x
206
+ end # module Buildr
207
+
208
+ class Buildr::Project
209
+ include Buildr::Idea7x
210
+ end
@@ -0,0 +1,23 @@
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 RUBY_PLATFORM == 'java' ? 'buildr/java/jruby' : 'buildr/java/rjb'
18
+ require 'buildr/java/compiler'
19
+ require 'buildr/java/tests'
20
+ require 'buildr/java/bdd'
21
+ require 'buildr/java/packaging'
22
+ require 'buildr/java/commands'
23
+ require 'buildr/java/deprecated'
@@ -0,0 +1,92 @@
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 'antwrap'
18
+ require 'buildr/core/project'
19
+ require 'buildr/core/help'
20
+
21
+
22
+ module Buildr
23
+ module Ant
24
+
25
+ # Which version of Ant we're using by default.
26
+ VERSION = '1.7.1'
27
+
28
+ class << self
29
+ # Current version of Ant being used.
30
+ def version
31
+ Buildr.settings.build['ant'] || VERSION
32
+ end
33
+
34
+ # Ant classpath dependencies.
35
+ def dependencies
36
+ # Ant-Trax required for running the JUnitReport task, and there's no other place
37
+ # to put it but the root classpath.
38
+ @dependencies ||= ["org.apache.ant:ant:jar:#{version}", "org.apache.ant:ant-launcher:jar:#{version}",
39
+ "org.apache.ant:ant-trax:jar:#{version}"]
40
+ end
41
+
42
+ private
43
+ def const_missing(const)
44
+ return super unless const == :REQUIRES # TODO: remove in 1.5
45
+ Buildr.application.deprecated "Please use Ant.dependencies/.version instead of Ant::REQUIRES/VERSION"
46
+ dependencies
47
+ end
48
+ end
49
+
50
+
51
+ Java.classpath << lambda { Ant.dependencies }
52
+
53
+ # :call-seq:
54
+ # ant(name) { |AntProject| ... } => AntProject
55
+ #
56
+ # Creates a new AntProject with the specified name, yield to the block for defining various
57
+ # Ant tasks, and executes each task as it's defined.
58
+ #
59
+ # For example:
60
+ # ant("hibernatedoclet') do |doclet|
61
+ # doclet.taskdef :name=>'hibernatedoclet',
62
+ # :classname=>'xdoclet.modules.hibernate.HibernateDocletTask', :classpath=>DOCLET
63
+ # doclet.hibernatedoclet :destdir=>dest_dir, :force=>'true' do
64
+ # hibernate :version=>'3.0'
65
+ # fileset :dir=>source, :includes=>'**/*.java'
66
+ # end
67
+ # end
68
+ def ant(name, &block)
69
+ options = { :name=>name, :basedir=>Dir.pwd, :declarative=>true }
70
+ options.merge!(:logger=> Logger.new(STDOUT), :loglevel=> Logger::DEBUG) if Buildr.application.options.trace
71
+ Java.load
72
+ Antwrap::AntProject.new(options).tap do |project|
73
+ # Set Ant logging level to debug (--trace), info (default) or error only (--quiet).
74
+ project.project.getBuildListeners().get(0).
75
+ setMessageOutputLevel((Buildr.application.options.trace && 4) || (verbose && 2) || 0)
76
+ yield project if block_given?
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ include Ant
83
+ class Project
84
+ include Ant
85
+ end
86
+
87
+ Buildr.help do
88
+ Java.load
89
+ "\nUsing Java #{ENV_JAVA['java.version']}, Ant #{Ant.version}."
90
+ end
91
+
92
+ end
@@ -0,0 +1,449 @@
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 'buildr/java/tests'
17
+ require 'buildr/java/test_result'
18
+
19
+ module Buildr
20
+
21
+ # Mixin for test frameworks using src/spec/{lang}
22
+ class TestFramework::JavaBDD < TestFramework::Java #:nodoc:
23
+
24
+ class << self
25
+ attr_reader :lang, :bdd_dir
26
+ end
27
+ attr_accessor :lang, :bdd_dir
28
+
29
+ def initialize(task, options)
30
+ self.bdd_dir = self.class.bdd_dir
31
+ project = task.project
32
+ project.task('test:compile').tap do |comp|
33
+ comp.send :associate_with, project, bdd_dir
34
+ self.lang = comp.language || self.class.lang
35
+ end
36
+ project.task('test:resources').tap do |res|
37
+ res.send :associate_with, project, bdd_dir
38
+ res.filter.clear
39
+ project.path_to(:source, bdd_dir, :resources).tap { |dir| res.from dir if File.exist?(dir) }
40
+ end
41
+ super
42
+ end
43
+
44
+ end
45
+
46
+ module TestFramework::JRubyBased
47
+ extend self
48
+
49
+ VERSION = '1.1.3'
50
+
51
+ class << self
52
+ def version
53
+ Buildr.settings.build['jruby'] || VERSION
54
+ end
55
+
56
+ def jruby_artifact
57
+ "org.jruby:jruby-complete:jar:#{version}"
58
+ end
59
+
60
+ def dependencies
61
+ [jruby_artifact]
62
+ end
63
+
64
+ def included(mod)
65
+ mod.extend ClassMethods
66
+ super
67
+ end
68
+ end
69
+
70
+ module ClassMethods
71
+ def dependencies
72
+ deps = super
73
+ unless RUBY_PLATFORM[/java/] && TestFramework::JRubyBased.jruby_installed?
74
+ deps |= TestFramework::JRubyBased.dependencies
75
+ end
76
+ deps
77
+ end
78
+ end
79
+
80
+ def run(tests, dependencies)
81
+ maybe_install_jruby
82
+ dependencies |= [task.compile.target.to_s]
83
+
84
+ spec_dir = task.project.path_to(:source, :spec, :ruby)
85
+ report_dir = task.report_to.to_s
86
+ FileUtils.rm_rf report_dir
87
+ FileUtils.mkdir_p report_dir
88
+ ENV['CI_REPORTS'] = report_dir
89
+
90
+ runner = runner_config
91
+ runner.content = runner_content(binding)
92
+
93
+ Buildr.write(runner.file, runner.content)
94
+ FileUtils.rm_f runner.result
95
+
96
+ if RUBY_PLATFORM[/java/] && !options.fork
97
+ runtime = new_runtime
98
+ runtime.getObject.java.lang.System.getProperties().putAll(options[:properties] || {})
99
+ runtime.getLoadService.require runner.file
100
+ else
101
+ cmd_options = task.options.only(:properties, :java_args)
102
+ cmd_options.update(:classpath => dependencies, :project => task.project)
103
+ jruby runner.file, tests, cmd_options
104
+ end
105
+
106
+ result = YAML.load(File.read(runner.result))
107
+ if Exception === result
108
+ raise [result.message, result.backtrace].flatten.join("\n")
109
+ end
110
+ result.succeeded
111
+ end
112
+
113
+ def jruby_home
114
+ @jruby_home ||= RUBY_PLATFORM =~ /java/ ? Config::CONFIG['prefix'] :
115
+ ( ENV['JRUBY_HOME'] || File.expand_path('~/.jruby') )
116
+ end
117
+
118
+ def jruby_installed?
119
+ !Dir.glob(File.join(jruby_home, 'lib', 'jruby*.jar')).empty?
120
+ end
121
+
122
+ protected
123
+ def maybe_install_jruby
124
+ unless jruby_installed?
125
+ jruby_artifact = Buildr.artifact(TestFramework::JRubyBased.jruby_artifact)
126
+ msg = "JRUBY_HOME is not correctly set or points to an invalid JRuby installation: #{jruby_home}"
127
+ say msg
128
+ say ''
129
+ say "You need to install JRuby version #{jruby_artifact.version} using your system package manager."
130
+ say 'Or you can just execute the following command: '
131
+ say ''
132
+ say " java -jar #{jruby_artifact} -S extract '#{jruby_home}'"
133
+ say ''
134
+ if agree('Do you want me to execute it for you? [y/N]', false)
135
+ jruby_artifact.invoke
136
+ Java::Commands.java('-jar', jruby_artifact.to_s, '-S', 'extract', jruby_home)
137
+ end
138
+
139
+ fail msg unless jruby_installed?
140
+ end
141
+ end
142
+
143
+ def jruby(*args)
144
+ java_args = ['org.jruby.Main', *args]
145
+ java_args << {} unless Hash === args.last
146
+ cmd_options = java_args.last
147
+ project = cmd_options.delete(:project)
148
+ cmd_options[:classpath] ||= []
149
+ Dir.glob(File.join(jruby_home, 'lib', '*.jar')) { |jar| cmd_options[:classpath] << jar }
150
+ cmd_options[:java_args] ||= []
151
+ cmd_options[:java_args] << '-Xmx512m' unless cmd_options[:java_args].detect {|a| a =~ /^-Xmx/}
152
+ cmd_options[:properties] ||= {}
153
+ cmd_options[:properties]['jruby.home'] = jruby_home
154
+ Java::Commands.java(*java_args)
155
+ end
156
+
157
+ def new_runtime(cfg = {})
158
+ config = Java.org.jruby.RubyInstanceConfig.new
159
+ cfg.each_pair do |name, value|
160
+ config.send("#{name}=", value)
161
+ end
162
+ yield config if block_given?
163
+ Java.org.jruby.Ruby.newInstance config
164
+ end
165
+
166
+ def jruby_gem
167
+ %{
168
+ require 'jruby'
169
+ def JRuby.gem(name, version = '>0', *args)
170
+ require 'rbconfig'
171
+ jruby_home = Config::CONFIG['prefix']
172
+ expected_version = '#{TestFramework::JRubyBased.version}'
173
+ unless JRUBY_VERSION >= expected_version
174
+ fail "Expected JRuby version \#{expected_version} installed at \#{jruby_home} but got \#{JRUBY_VERSION}"
175
+ end
176
+ require 'rubygems'
177
+ begin
178
+ Kernel.gem name, version
179
+ rescue LoadError, Gem::LoadError => e
180
+ require 'rubygems/gem_runner'
181
+ Gem.manage_gems
182
+ args = ['install', name, '--version', version] + args
183
+ Gem::GemRunner.new.run(args)
184
+ Kernel.gem name, version
185
+ end
186
+ end
187
+ }
188
+ end
189
+
190
+ def runner_config(runner = OpenStruct.new)
191
+ [:requires, :gems, :output, :format].each do |key|
192
+ runner.send("#{key}=", options[key])
193
+ end
194
+ runner.html_report ||= File.join(task.report_to.to_s, 'report.html')
195
+ runner.result ||= task.project.path_to(:target, :spec, 'result.yaml')
196
+ runner.file ||= task.project.path_to(:target, :spec, 'runner.rb')
197
+ runner.requires ||= []
198
+ runner.requires.unshift File.join(File.dirname(__FILE__), 'test_result')
199
+ runner.gems ||= {}
200
+ runner.rspec ||= ['--format', 'progress', '--format', "html:#{runner.html_report}"]
201
+ runner.format.each { |format| runner.rspec << '--format' << format } if runner.format
202
+ runner.rspec.push '--format', "Buildr::TestFramework::TestResult::YamlFormatter:#{runner.result}"
203
+ runner
204
+ end
205
+
206
+ end
207
+
208
+ # <a href="http://rspec.info">RSpec</a> is the defacto BDD framework for ruby.
209
+ # To test your project with RSpec use:
210
+ # test.using :rspec
211
+ #
212
+ #
213
+ # Support the following options:
214
+ # * :gems -- A hash of gems to install before running the tests.
215
+ # The keys of this hash are the gem name, the value must be the required version.
216
+ # * :requires -- A list of ruby files to require before running the specs
217
+ # Mainly used if an rspec format needs to require some file.
218
+ # * :format -- A list of valid Rspec --format option values. (defaults to 'progress')
219
+ # * :output -- File path to output dump. @false@ to supress output
220
+ # * :fork -- Create a new JavaVM to run the tests on
221
+ # * :properties -- Hash of properties passed to the test suite.
222
+ # * :java_args -- Arguments passed to the JVM.
223
+ class RSpec < TestFramework::JavaBDD
224
+ @lang = :ruby
225
+ @bdd_dir = :spec
226
+
227
+ include TestFramework::JRubyBased
228
+
229
+ TESTS_PATTERN = [ /_spec.rb$/ ]
230
+ OPTIONS = [:properties, :java_args]
231
+
232
+ def self.applies_to?(project) #:nodoc:
233
+ !Dir[project.path_to(:source, bdd_dir, lang, '**/*_spec.rb')].empty?
234
+ end
235
+
236
+ def tests(dependencies) #:nodoc:
237
+ Dir[task.project.path_to(:source, bdd_dir, lang, '**/*_spec.rb')].
238
+ select do |name|
239
+ selector = ENV['SPEC']
240
+ selector.nil? || Regexp.new(selector) === name
241
+ end
242
+ end
243
+
244
+ def runner_config
245
+ runner = super
246
+ runner.gems.update 'rspec' => '>0'
247
+ runner.requires.unshift 'spec'
248
+ runner
249
+ end
250
+
251
+ def runner_content(binding)
252
+ runner_erb = %q{
253
+ <%= jruby_gem %>
254
+ <%= dependencies.inspect %>.each { |dep| $CLASSPATH << dep }
255
+ <%= runner.gems.inspect %>.each { |ary| JRuby.gem(*ary.flatten) }
256
+ <%= runner.requires.inspect %>.each { |rb| Kernel.require rb }
257
+ <% if runner.output == false %>
258
+ output = StringIO.new
259
+ <% elsif runner.output.kind_of?(String) %>
260
+ output = File.open(<%= result.output.inspect %>, 'w')
261
+ <% else %>
262
+ output = STDOUT
263
+ <% end %>
264
+ parser = ::Spec::Runner::OptionParser.new(output, output)
265
+ argv = <%= runner.rspec.inspect %> || []
266
+ argv.push *<%= tests.inspect %>
267
+ parser.order!(argv)
268
+ $rspec_options = parser.options
269
+ Buildr::TestFramework::TestResult::Error.guard('<%= runner.file %>') do
270
+ ::Spec::Runner::CommandLine.run($rspec_options)
271
+ end
272
+ exit 0 # let buildr figure the result from the yaml file
273
+ }
274
+ Filter::Mapper.new(:erb, binding).transform(runner_erb)
275
+ end
276
+
277
+ end
278
+
279
+ # <a href="http://jtestr.codehaus.org/">JtestR</a> is a framework for BDD and TDD using JRuby and ruby tools.
280
+ # To test your project with JtestR use:
281
+ # test.using :jtestr
282
+ #
283
+ #
284
+ # Support the following options:
285
+ # * :config -- path to JtestR config file. defaults to @spec/ruby/jtestr_config.rb@
286
+ # * :gems -- A hash of gems to install before running the tests.
287
+ # The keys of this hash are the gem name, the value must be the required version.
288
+ # * :requires -- A list of ruby files to require before running the specs
289
+ # Mainly used if an rspec format needs to require some file.
290
+ # * :format -- A list of valid Rspec --format option values. (defaults to 'progress')
291
+ # * :output -- File path to output dump. @false@ to supress output
292
+ # * :fork -- Create a new JavaVM to run the tests on
293
+ # * :properties -- Hash of properties passed to the test suite.
294
+ # * :java_args -- Arguments passed to the JVM.
295
+ class JtestR < TestFramework::JavaBDD
296
+ @lang = :ruby
297
+ @bdd_dir = :spec
298
+
299
+ include TestFramework::JRubyBased
300
+
301
+ VERSION = '0.3.1'
302
+
303
+ # pattern for rspec stories
304
+ STORY_PATTERN = /_(steps|story)\.rb$/
305
+ # pattern for test_unit files
306
+ TESTUNIT_PATTERN = /(_test|Test)\.rb$|(tc|ts)[^\\\/]+\.rb$/
307
+ # pattern for test files using http://expectations.rubyforge.org/
308
+ EXPECT_PATTERN = /_expect\.rb$/
309
+
310
+ TESTS_PATTERN = [STORY_PATTERN, TESTUNIT_PATTERN, EXPECT_PATTERN] + RSpec::TESTS_PATTERN
311
+
312
+ class << self
313
+
314
+ def version
315
+ Buildr.settings.build['jtestr'] || VERSION
316
+ end
317
+
318
+ def dependencies
319
+ @dependencies ||= Array(super) + ["org.jtestr:jtestr:jar:#{version}"] +
320
+ JUnit.dependencies + TestNG.dependencies
321
+ end
322
+
323
+ def applies_to?(project) #:nodoc:
324
+ File.exist?(project.path_to(:source, bdd_dir, lang, 'jtestr_config.rb')) ||
325
+ Dir[project.path_to(:source, bdd_dir, lang, '**/*.rb')].any? { |f| TESTS_PATTERN.any? { |r| r === f } } ||
326
+ JUnit.applies_to?(project) || TestNG.applies_to?(project)
327
+ end
328
+
329
+ private
330
+ def const_missing(const)
331
+ return super unless const == :REQUIRES # TODO: remove in 1.5
332
+ Buildr.application.deprecated 'Please use JtestR.dependencies/.version instead of JtestR::REQUIRES/VERSION'
333
+ dependencies
334
+ end
335
+
336
+ end
337
+
338
+ def initialize(task, options) #:nodoc:
339
+ super
340
+ [:test, :spec].each do |usage|
341
+ java_tests = task.project.path_to(:source, usage, :java)
342
+ task.compile.from java_tests if File.directory?(java_tests)
343
+ resources = task.project.path_to(:source, usage, :resources)
344
+ task.resources.from resources if File.directory?(resources)
345
+ end
346
+ end
347
+
348
+ def user_config
349
+ options[:config] || task.project.path_to(:source, bdd_dir, lang, 'jtestr_config.rb')
350
+ end
351
+
352
+ def tests(dependencies) #:nodoc:
353
+ dependencies |= [task.compile.target.to_s]
354
+ types = { :story => STORY_PATTERN, :rspec => RSpec::TESTS_PATTERN,
355
+ :testunit => TESTUNIT_PATTERN, :expect => EXPECT_PATTERN }
356
+ tests = types.keys.inject({}) { |h, k| h[k] = []; h }
357
+ tests[:junit] = JUnit.new(task, {}).tests(dependencies)
358
+ tests[:testng] = TestNG.new(task, {}).tests(dependencies)
359
+ Dir[task.project.path_to(:source, bdd_dir, lang, '**/*.rb')].each do |rb|
360
+ type = types.find { |k, v| Array(v).any? { |r| r === rb } }
361
+ tests[type.first] << rb if type
362
+ end
363
+ @jtestr_tests = tests
364
+ tests.values.flatten
365
+ end
366
+
367
+ def runner_config
368
+ runner = super
369
+ # JtestR 0.3.1 comes with rspec 1.1.4 (and any other jtestr dependency) included,
370
+ # so the rspec version used depends on the jtestr jar.
371
+ runner.requires.unshift 'jtestr'
372
+ runner
373
+ end
374
+
375
+ def runner_content(binding)
376
+ runner_erb = File.join(File.dirname(__FILE__), 'jtestr_runner.rb.erb')
377
+ Filter::Mapper.new(:erb, binding).transform(File.read(runner_erb), runner_erb)
378
+ end
379
+
380
+ end
381
+
382
+
383
+ # JBehave is a Java BDD framework. To use in your project:
384
+ # test.using :jbehave
385
+ #
386
+ # This framework will search in your project for:
387
+ # src/spec/java/**/*Behaviour.java
388
+ #
389
+ # JMock libraries are included on runtime.
390
+ #
391
+ # Support the following options:
392
+ # * :properties -- Hash of properties to the test suite
393
+ # * :java_args -- Arguments passed to the JVM
394
+ class JBehave < TestFramework::JavaBDD
395
+ @lang = :java
396
+ @bdd_dir = :spec
397
+
398
+ VERSION = '1.0.1'
399
+ TESTS_PATTERN = [ /Behaviou?r$/ ] #:nodoc:
400
+
401
+ class << self
402
+ def version
403
+ Buildr.settings.build['jbehave'] || VERSION
404
+ end
405
+
406
+ def dependencies
407
+ @dependencies ||= ["org.jbehave:jbehave:jar:#{version}", 'cglib:cglib-full:jar:2.0.2'] +
408
+ JMock.dependencies + JUnit.dependencies
409
+ end
410
+
411
+ def applies_to?(project) #:nodoc:
412
+ %w{
413
+ **/*Behaviour.java **/*Behavior.java
414
+ }.any? { |glob| !Dir[project.path_to(:source, bdd_dir, lang, glob)].empty? }
415
+ end
416
+
417
+ private
418
+ def const_missing(const)
419
+ return super unless const == :REQUIRES # TODO: remove in 1.5
420
+ Buildr.application.deprecated 'Please use JBehave.dependencies/.version instead of JBehave::REQUIRES/VERSION'
421
+ dependencies
422
+ end
423
+ end
424
+
425
+ def tests(dependencies) #:nodoc:
426
+ filter_classes(dependencies, :class_names => TESTS_PATTERN,
427
+ :interfaces => %w{ org.jbehave.core.behaviour.Behaviours })
428
+ end
429
+
430
+ def run(tests, dependencies) #:nodoc:
431
+ cmd_args = ['org.jbehave.core.BehaviourRunner']
432
+ cmd_options = { :properties=>options[:properties], :java_args=>options[:java_args], :classpath=>dependencies }
433
+ tests.inject([]) do |passed, test|
434
+ begin
435
+ Java::Commands.java cmd_args, test, cmd_options
436
+ passed << test
437
+ rescue
438
+ passed
439
+ end
440
+ end
441
+ end
442
+
443
+ end
444
+
445
+ end
446
+
447
+ Buildr::TestFramework << Buildr::RSpec
448
+ Buildr::TestFramework << Buildr::JtestR
449
+ Buildr::TestFramework << Buildr::JBehave