mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,121 @@
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 File.expand_path(File.join(File.dirname(__FILE__), 'test_coverage_helper'))
18
+ Sandbox.require_optional_extension 'buildr/java/emma'
19
+ artifacts(Buildr::Emma::dependencies).map(&:invoke)
20
+
21
+
22
+ describe Buildr::Emma do
23
+ include TestCoverageHelper
24
+
25
+ before do
26
+ # Reloading the extension because the sandbox removes all its actions
27
+ Buildr.module_eval { remove_const :Emma }
28
+ load File.expand_path('../lib/buildr/java/emma.rb')
29
+ @tool_module = Buildr::Emma
30
+ end
31
+
32
+ it_should_behave_like 'test coverage tool'
33
+
34
+ describe 'project-specific' do
35
+ describe 'metadata file' do
36
+ it 'should have a default value' do
37
+ define('foo').emma.metadata_file.should point_to_path('reports/emma/coverage.em')
38
+ end
39
+
40
+ it 'should be overridable' do
41
+ define('foo') { emma.metadata_file = path_to('target/metadata.emma') }
42
+ project('foo').emma.metadata_file.should point_to_path('target/metadata.emma')
43
+ end
44
+
45
+ it 'should be created during instrumentation' do
46
+ write 'src/main/java/Foo.java', 'public class Foo {}'
47
+ define('foo')
48
+ task('foo:emma:instrument').invoke
49
+ file(project('foo').emma.metadata_file).should exist
50
+ end
51
+ end
52
+
53
+ describe 'coverage file' do
54
+ it 'should have a default value' do
55
+ define('foo').emma.coverage_file.should point_to_path('reports/emma/coverage.ec')
56
+ end
57
+
58
+ it 'should be overridable' do
59
+ define('foo') { emma.coverage_file = path_to('target/coverage.emma') }
60
+ project('foo').emma.coverage_file.should point_to_path('target/coverage.emma')
61
+ end
62
+
63
+ it 'should be created during test' do
64
+ write 'src/main/java/Foo.java', 'public class Foo {}'
65
+ write_test :for=>'Foo', :in=>'src/test/java'
66
+ define('foo')
67
+ task('foo:test').invoke
68
+ file(project('foo').emma.coverage_file).should exist
69
+ end
70
+ end
71
+
72
+ describe 'instrumentation' do
73
+ before do
74
+ ['Foo', 'Bar'].each { |cls| write File.join('src/main/java', "#{cls}.java"), "public class #{cls} {}" }
75
+ end
76
+
77
+ it 'should instrument only included classes' do
78
+ define('foo') { emma.include 'Foo' }
79
+ task("foo:emma:instrument").invoke
80
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Foo.class'] }
81
+ end
82
+
83
+ it 'should not instrument excluded classes' do
84
+ define('foo') { emma.exclude 'Foo' }
85
+ task("foo:emma:instrument").invoke
86
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Bar.class'] }
87
+ end
88
+
89
+ it 'should instrument classes that are included but not excluded' do
90
+ write 'src/main/java/Baz.java', 'public class Baz {}'
91
+ define('foo') { emma.include('Ba*').exclude('*ar') }
92
+ task("foo:emma:instrument").invoke
93
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Baz.class'] }
94
+ end
95
+ end
96
+
97
+ describe 'reports' do
98
+ before do
99
+ write 'src/main/java/Foo.java', 'public class Foo {}'
100
+ write_test :for=>'Foo', :in=>'src/test/java'
101
+ end
102
+
103
+ describe 'in html' do
104
+ it 'should inform the user if no coverage data' do
105
+ rm 'src/test/java/FooTest.java'
106
+ define('foo')
107
+ lambda { task('foo:emma:html').invoke }.
108
+ should show_info(/No test coverage report for foo. Missing: #{project('foo').emma.coverage_file}/)
109
+ end
110
+ end
111
+
112
+ describe 'in xml' do
113
+ it 'should have an xml file' do
114
+ define('foo')
115
+ task('foo:emma:xml').invoke
116
+ file(File.join(project('foo').emma.report_dir, 'coverage.xml')).should exist
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,56 @@
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 File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+ COMPILERS = Buildr::Compiler.compilers.dup
20
+ COMPILERS_WITHOUT_JAVAC = COMPILERS.dup
21
+ COMPILERS_WITHOUT_JAVAC.delete Buildr::Compiler::Javac
22
+
23
+ describe Buildr::Compiler::ExternalJavac do
24
+
25
+ before(:all) do
26
+ Buildr::Compiler.send :compilers=, COMPILERS_WITHOUT_JAVAC
27
+ end
28
+
29
+ describe "should compile a Java project just in the same way javac does" do
30
+ javac_spec = File.read(File.join(File.dirname(__FILE__), "compiler_spec.rb"))
31
+ javac_spec = javac_spec.match(Regexp.escape("require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))\n")).post_match
32
+ javac_spec.gsub!("javac", "externaljavac")
33
+ javac_spec.gsub!("--trace=externaljavac", "--trace=javac")
34
+ javac_spec.gsub!("trace_categories = [:externaljavac]", "trace_categories = [:javac]")
35
+ eval(javac_spec)
36
+ end
37
+
38
+ it "should accept a :jvm option as JAVA_HOME" do
39
+ write 'src/main/java/Foo.java', 'public class Foo {}'
40
+ define "foo" do
41
+ compile.using(:externaljavac).options.jvm = "somepath"
42
+ end
43
+ begin
44
+ trace true #We set it true to grab the trace statement with the jvm path in it!
45
+ lambda {lambda {project("foo").compile.invoke}.should raise_error(RuntimeError, /Failed to compile, see errors above/)}.should show(/somepath\/bin\/javac .*/)
46
+ end
47
+ trace false
48
+ end
49
+
50
+ after :all do
51
+ Buildr::Compiler.send :compilers=, COMPILERS
52
+ end
53
+
54
+ end
55
+
56
+
@@ -0,0 +1,132 @@
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 File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+
19
+
20
+ unless RUBY_PLATFORM =~ /java/
21
+ describe ENV, 'JAVA_HOME on OS X' do
22
+ before do
23
+ @old_home, ENV['JAVA_HOME'] = ENV['JAVA_HOME'], nil
24
+ @old_env_java = Object.module_eval { remove_const :ENV_JAVA }
25
+ Config::CONFIG.should_receive(:[]).with('host_os').and_return('darwin0.9')
26
+ end
27
+
28
+ it 'should point to default JVM' do
29
+ load File.expand_path('../lib/buildr/java/rjb.rb')
30
+ ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.framework/Home'
31
+ end
32
+
33
+ it 'should use value of environment variable if specified' do
34
+ ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.specified'
35
+ load File.expand_path('../lib/buildr/java/rjb.rb')
36
+ ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.specified'
37
+ end
38
+
39
+ after do
40
+ ENV['JAVA_HOME'] = @old_home
41
+ ENV_JAVA.replace @old_env_java
42
+ end
43
+ end
44
+ else
45
+ describe 'JRuby environment' do
46
+ it 'should enforce a minimum version of jruby' do
47
+ check =File.read(File.expand_path('../lib/buildr/java/jruby.rb')).match(/JRUBY_MIN_VERSION.*\n.*JRUBY_MIN_VERSION\n/).to_s
48
+ check.sub!('JRUBY_VERSION', "'0.0.0'")
49
+ lambda { eval(check) }.should raise_error(/JRuby must be at least at version /)
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ describe 'Java.tools_jar' do
56
+ before do
57
+ @old_home = ENV['JAVA_HOME']
58
+ end
59
+
60
+ describe 'when JAVA_HOME points to a JDK' do
61
+ before do
62
+ Java.instance_eval { @tools_jar = nil }
63
+ write 'jdk/lib/tools.jar'
64
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
65
+ end
66
+
67
+ it 'should return the path to tools.jar' do
68
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
69
+ end
70
+ end
71
+
72
+ describe 'when JAVA_HOME points to a JRE inside a JDK' do
73
+ before do
74
+ Java.instance_eval { @tools_jar = nil }
75
+ write 'jdk/lib/tools.jar'
76
+ ENV['JAVA_HOME'] = File.expand_path('jdk/jre')
77
+ end
78
+
79
+ it 'should return the path to tools.jar' do
80
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
81
+ end
82
+ end
83
+
84
+ describe 'when there is no tools.jar' do
85
+ before do
86
+ Java.instance_eval { @tools_jar = nil }
87
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
88
+ end
89
+
90
+ it 'should return nil' do
91
+ Java.tools_jar.should be_nil
92
+ end
93
+ end
94
+
95
+ after do
96
+ ENV['JAVA_HOME'] = @old_home
97
+ end
98
+ end
99
+
100
+ describe 'Java#java' do
101
+ before do
102
+ @old_home = ENV['JAVA_HOME']
103
+ end
104
+
105
+ describe 'when JAVA_HOME points to an invalid JRE/JDK installation' do
106
+ before do
107
+ write 'jdk'
108
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
109
+ end
110
+
111
+ it 'should fail with an error message mentioning JAVA_HOME' do
112
+ begin
113
+ Java.java ['-version']
114
+ fail 'Java.java did not fail with JAVA_HOME pointing to invalid JRE/JDK installation'
115
+ rescue => error
116
+ error.message.to_s.should match(/JAVA_HOME/)
117
+ end
118
+ end
119
+ end
120
+
121
+ after do
122
+ ENV['JAVA_HOME'] = @old_home
123
+ end
124
+ end
125
+
126
+
127
+ describe Java::JavaWrapper do
128
+ it 'should be removed in version 1.5 since it was deprecated in version 1.3' do
129
+ Buildr::VERSION.should < '1.5'
130
+ lambda { Java::JavaWrapper }.should_not raise_error
131
+ end
132
+ end
@@ -0,0 +1,1266 @@
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 File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
18
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'packaging', 'packaging_helper'))
19
+
20
+
21
+ describe Project, '#manifest' do
22
+ it 'should include user name' do
23
+ ENV['USER'] = 'MysteriousJoe'
24
+ define('foo').manifest['Build-By'].should eql('MysteriousJoe')
25
+ end
26
+
27
+ it 'should include JDK version' do
28
+ define('foo').manifest['Build-Jdk'].should =~ /^1\.\d+\.\w+$/
29
+ end
30
+
31
+ it 'should include project comment' do
32
+ desc 'My Project'
33
+ define('foo').manifest['Implementation-Title'].should eql('My Project')
34
+ end
35
+
36
+ it 'should include project name if no comment' do
37
+ define('foo').manifest['Implementation-Title'].should eql('foo')
38
+ end
39
+
40
+ it 'should include project version' do
41
+ define('foo', :version=>'2.1').manifest['Implementation-Version'].should eql('2.1')
42
+ end
43
+
44
+ it 'should not include project version unless specified' do
45
+ define('foo').manifest['Implementation-Version'].should be_nil
46
+ end
47
+
48
+ it 'should inherit from parent project' do
49
+ define('foo', :version=>'2.1') { define 'bar' }
50
+ project('foo:bar').manifest['Implementation-Version'].should eql('2.1')
51
+ end
52
+
53
+ end
54
+
55
+
56
+ shared_examples_for 'package with manifest' do
57
+ before do
58
+ @long_line = 'No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE).'
59
+ end
60
+
61
+ def package_with_manifest(manifest = nil)
62
+ packaging = @packaging
63
+ @project = define('foo', :version=>'1.2') do
64
+ package packaging
65
+ package(packaging).with(:manifest=>manifest) unless manifest.nil?
66
+ end
67
+ end
68
+
69
+ def inspect_manifest(package = nil)
70
+ package ||= project('foo').package(@packaging)
71
+ package.invoke
72
+ yield Buildr::Packaging::Java::Manifest.from_zip(package)
73
+ end
74
+
75
+ it 'should include default header when no options specified' do
76
+ ENV['USER'] = 'MysteriousJoe'
77
+ package_with_manifest # Nothing for default.
78
+ inspect_manifest do |manifest|
79
+ manifest.sections.size.should be(1)
80
+ manifest.main.should == {
81
+ 'Manifest-Version' =>'1.0',
82
+ 'Created-By' =>'Buildr',
83
+ 'Implementation-Title' =>@project.name,
84
+ 'Implementation-Version' =>'1.2',
85
+ 'Build-Jdk' =>ENV_JAVA['java.version'],
86
+ 'Build-By' =>'MysteriousJoe'
87
+ }
88
+ end
89
+ end
90
+
91
+ it 'should not exist when manifest=false' do
92
+ package_with_manifest false
93
+ @project.package(@packaging).invoke
94
+ Zip::ZipFile.open(@project.package(@packaging).to_s) do |zip|
95
+ zip.file.exist?('META-INF/MANIFEST.MF').should be_false
96
+ end
97
+ end
98
+
99
+ it 'should generate a new manifest for a file that does not have one' do
100
+ Zip::ZipOutputStream.open 'tmp.zip' do |zip|
101
+ zip.put_next_entry 'empty.txt'
102
+ end
103
+ begin
104
+ manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
105
+ manifest.each do |key, val|
106
+ Buildr::Packaging::Java::Manifest::STANDARD_HEADER.should include(key)
107
+ end
108
+ ensure
109
+ rm 'tmp.zip'
110
+ end
111
+ end
112
+
113
+ it 'should map manifest from hash' do
114
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
115
+ inspect_manifest do |manifest|
116
+ manifest.sections.size.should be(1)
117
+ manifest.main['Manifest-Version'].should eql('1.0')
118
+ manifest.main['Created-By'].should eql('Buildr')
119
+ manifest.main['Foo'].should eql('1')
120
+ manifest.main['bar'].should eql('Bar')
121
+ end
122
+ end
123
+
124
+ it 'should close the temporary file used for packaging the MANIFEST.MF file' do
125
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
126
+ package = project('foo').package(@packaging)
127
+ package.invoke
128
+ module AccessManifestTMP
129
+ attr_reader :manifest_tmp
130
+ end
131
+ (package.dup.extend(AccessManifestTMP).manifest_tmp.closed?).should be_true
132
+ end
133
+
134
+ it 'should end hash manifest with EOL' do
135
+ package_with_manifest 'Foo'=>1, :bar=>'Bar'
136
+ package = project('foo').package(@packaging)
137
+ package.invoke
138
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF').should =~ /#{Buildr::Packaging::Java::Manifest::LINE_SEPARATOR}$/ }
139
+ end
140
+
141
+ it 'should break hash manifest lines longer than 72 characters using continuations' do
142
+ package_with_manifest 'foo'=>@long_line
143
+ package = project('foo').package(@packaging)
144
+ inspect_manifest do |manifest|
145
+ manifest.main['foo'].should == @long_line
146
+ end
147
+ end
148
+
149
+ it 'should map manifest from array' do
150
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
151
+ inspect_manifest do |manifest|
152
+ manifest.sections.size.should be(2)
153
+ manifest.main['Manifest-Version'].should eql('1.0')
154
+ manifest.main['foo'].should eql('first')
155
+ manifest.sections.last['bar'].should eql('second')
156
+ end
157
+ end
158
+
159
+ it 'should end array manifest with EOL' do
160
+ package_with_manifest [ { :foo=>'first' }, { :bar=>'second' } ]
161
+ package = project('foo').package(@packaging)
162
+ package.invoke
163
+ Zip::ZipFile.open(package.to_s) { |zip| zip.file.read('META-INF/MANIFEST.MF')[-1].should == ?\n }
164
+ end
165
+
166
+ it 'should break array manifest lines longer than 72 characters using continuations' do
167
+ package_with_manifest ['foo'=>@long_line]
168
+ package = project('foo').package(@packaging)
169
+ inspect_manifest do |manifest|
170
+ manifest.main['foo'].should == @long_line
171
+ end
172
+ end
173
+
174
+ it 'should put Name: at beginning of section' do
175
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
176
+ package = project('foo').package(@packaging)
177
+ package.invoke
178
+ inspect_manifest do |manifest|
179
+ manifest.sections[1]["Name"].should == "first"
180
+ end
181
+ end
182
+
183
+ it 'should create manifest from proc' do
184
+ package_with_manifest lambda { 'Meta: data' }
185
+ inspect_manifest do |manifest|
186
+ manifest.sections.size.should be(1)
187
+ manifest.main['Manifest-Version'].should eql('1.0')
188
+ manifest.main['Meta'].should eql('data')
189
+ end
190
+ end
191
+
192
+ it 'should create manifest from file' do
193
+ write 'MANIFEST.MF', 'Meta: data'
194
+ package_with_manifest 'MANIFEST.MF'
195
+ inspect_manifest do |manifest|
196
+ manifest.sections.size.should be(1)
197
+ manifest.main['Meta'].should eql('data')
198
+ end
199
+ end
200
+
201
+ it 'should give 644 permissions to the manifest' do
202
+ package_with_manifest [ {}, { 'Name'=>'first', :Foo=>'first', :bar=>'second' } ]
203
+ package ||= project('foo').package(@packaging)
204
+ package.invoke
205
+ Zip::ZipFile.open(package.to_s) do |zip|
206
+ permissions = format("%o", zip.file.stat('META-INF/MANIFEST.MF').mode)
207
+ permissions.should match /644$/
208
+ end
209
+ end
210
+
211
+ it 'should not add manifest version twice' do
212
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
213
+ package_with_manifest 'MANIFEST.MF'
214
+ package ||= project('foo').package(@packaging)
215
+ package.invoke
216
+ Zip::ZipFile.open(package.to_s) do |zip|
217
+ zip.read('META-INF/MANIFEST.MF').scan(/(Manifest-Version)/m).size.should == 1
218
+ end
219
+ end
220
+
221
+ it 'should give precedence to version specified in manifest file' do
222
+ write 'MANIFEST.MF', 'Manifest-Version: 1.9'
223
+ package_with_manifest 'MANIFEST.MF'
224
+ inspect_manifest do |manifest|
225
+ manifest.main['Manifest-Version'].should == '1.9'
226
+ end
227
+ end
228
+
229
+ it 'should create manifest from task' do
230
+ file 'MANIFEST.MF' do |task|
231
+ write task.to_s, 'Meta: data'
232
+ end
233
+ package_with_manifest 'MANIFEST.MF'
234
+ inspect_manifest do |manifest|
235
+ manifest.sections.size.should be(1)
236
+ manifest.main['Manifest-Version'].should eql('1.0')
237
+ manifest.main['Meta'].should eql('data')
238
+ end
239
+ end
240
+
241
+ it 'should respond to with() and accept manifest' do
242
+ write 'DISCLAIMER'
243
+ mkpath 'target/classes'
244
+ packaging = @packaging
245
+ define('foo', :version=>'1.0') { package(packaging).with :manifest=>{'Foo'=>'data'} }
246
+ inspect_manifest { |manifest| manifest.main['Foo'].should eql('data') }
247
+ end
248
+
249
+ it 'should include META-INF directory' do
250
+ packaging = @packaging
251
+ package = define('foo', :version=>'1.0') { package(packaging) }.packages.first
252
+ package.invoke
253
+ Zip::ZipFile.open(package.to_s) do |zip|
254
+ zip.entries.map(&:to_s).should include('META-INF/')
255
+ end
256
+ end
257
+
258
+ it 'should inherit manifest from parent project' do
259
+ packaging = @packaging
260
+ package = nil
261
+ define('foo', :version => '1.0') do
262
+ manifest['Foo'] = '1'
263
+ package(packaging)
264
+ define('bar', :version => '1.0') do
265
+ manifest['bar'] = 'Bar'
266
+ package(:jar)
267
+ package = packages.first
268
+ end
269
+ end
270
+ inspect_manifest(package) do |manifest|
271
+ manifest.sections.size.should be(1)
272
+ manifest.main['Manifest-Version'].should eql('1.0')
273
+ manifest.main['Created-By'].should eql('Buildr')
274
+ manifest.main['Foo'].should eql('1')
275
+ manifest.main['bar'].should eql('Bar')
276
+ end
277
+ end
278
+
279
+ it 'should not modify manifest of parent project' do
280
+ packaging = @packaging
281
+ define('foo', :version => '1.0') do
282
+ manifest['Foo'] = '1'
283
+ package(packaging)
284
+ define('bar', :version => '1.0') do
285
+ manifest['bar'] = 'Bar'
286
+ package(:jar)
287
+ end
288
+ define('baz', :version => '1.0') do
289
+ manifest['baz'] = 'Baz'
290
+ package(:jar)
291
+ end
292
+ end
293
+ inspect_manifest(project('foo').packages.first) do |manifest|
294
+ manifest.sections.size.should be(1)
295
+ manifest.main['Manifest-Version'].should eql('1.0')
296
+ manifest.main['Created-By'].should eql('Buildr')
297
+ manifest.main['Foo'].should eql('1')
298
+ manifest.main['bar'].should be_nil
299
+ manifest.main['baz'].should be_nil
300
+ end
301
+ inspect_manifest(project('foo:bar').packages.first) do |manifest|
302
+ manifest.sections.size.should be(1)
303
+ manifest.main['Manifest-Version'].should eql('1.0')
304
+ manifest.main['Created-By'].should eql('Buildr')
305
+ manifest.main['Foo'].should eql('1')
306
+ manifest.main['bar'].should eql('Bar')
307
+ manifest.main['baz'].should be_nil
308
+ end
309
+ inspect_manifest(project('foo:baz').packages.first) do |manifest|
310
+ manifest.sections.size.should be(1)
311
+ manifest.main['Manifest-Version'].should eql('1.0')
312
+ manifest.main['Created-By'].should eql('Buildr')
313
+ manifest.main['Foo'].should eql('1')
314
+ manifest.main['baz'].should eql('Baz')
315
+ manifest.main['bar'].should be_nil
316
+ end
317
+ end
318
+ end
319
+
320
+
321
+ describe Project, '#meta_inf' do
322
+ it 'should by an array' do
323
+ define('foo').meta_inf.should be_kind_of(Array)
324
+ end
325
+
326
+ it 'should include LICENSE file if found' do
327
+ write 'LICENSE'
328
+ define('foo').meta_inf.first.should point_to_path('LICENSE')
329
+ end
330
+
331
+ it 'should be empty unless LICENSE exists' do
332
+ define('foo').meta_inf.should be_empty
333
+ end
334
+
335
+ it 'should inherit from parent project' do
336
+ write 'LICENSE'
337
+ define('foo') { define 'bar' }
338
+ project('foo:bar').meta_inf.first.should point_to_path('LICENSE')
339
+ end
340
+
341
+ it 'should expect LICENSE file parent project' do
342
+ write 'bar/LICENSE'
343
+ define('foo') { define 'bar' }
344
+ project('foo:bar').meta_inf.should be_empty
345
+ end
346
+ end
347
+
348
+
349
+ shared_examples_for 'package with meta_inf' do
350
+
351
+ def package_with_meta_inf(meta_inf = nil)
352
+ packaging = @packaging
353
+ @project = Buildr.define('foo', :version=>'1.2') do
354
+ package packaging
355
+ package(packaging).with(:meta_inf=>meta_inf) if meta_inf
356
+ end
357
+ end
358
+
359
+ def inspect_meta_inf
360
+ package = project('foo').package(@packaging)
361
+ package.invoke
362
+ assumed = Array(@meta_inf_ignore)
363
+ Zip::ZipFile.open(package.to_s) do |zip|
364
+ entries = zip.entries.map(&:name).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
365
+ assumed.each { |f| entries.should include(f) }
366
+ yield entries - assumed if block_given?
367
+ end
368
+ end
369
+
370
+ it 'should default to LICENSE file' do
371
+ write 'LICENSE'
372
+ package_with_meta_inf
373
+ inspect_meta_inf { |files| files.should eql(['LICENSE']) }
374
+ end
375
+
376
+ it 'should be empty if no LICENSE file' do
377
+ package_with_meta_inf
378
+ inspect_meta_inf { |files| files.should be_empty }
379
+ end
380
+
381
+ it 'should include file specified by :meta_inf option' do
382
+ write 'README'
383
+ package_with_meta_inf 'README'
384
+ inspect_meta_inf { |files| files.should eql(['README']) }
385
+ end
386
+
387
+ it 'should include files specified by :meta_inf option' do
388
+ files = ['README', 'DISCLAIMER'].each { |file| write file }
389
+ package_with_meta_inf files
390
+ inspect_meta_inf { |files| files.should eql(files) }
391
+ end
392
+
393
+ it 'should include file task specified by :meta_inf option' do
394
+ file('README') { |task| write task.to_s }
395
+ package_with_meta_inf file('README')
396
+ inspect_meta_inf { |files| files.should eql(['README']) }
397
+ end
398
+
399
+ it 'should include file tasks specified by :meta_inf option' do
400
+ files = ['README', 'DISCLAIMER'].each { |file| file(file) { |task| write task.to_s } }
401
+ package_with_meta_inf files.map { |f| file(f) }
402
+ inspect_meta_inf { |files| files.should eql(files) }
403
+ end
404
+
405
+ it 'should complain if cannot find file' do
406
+ package_with_meta_inf 'README'
407
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /README/)
408
+ end
409
+
410
+ it 'should complain if cannot build task' do
411
+ file('README') { fail 'Failed' }
412
+ package_with_meta_inf 'README'
413
+ lambda { inspect_meta_inf }.should raise_error(RuntimeError, /Failed/)
414
+ end
415
+
416
+ it 'should respond to with() and accept manifest and meta_inf' do
417
+ write 'DISCLAIMER'
418
+ mkpath 'target/classes'
419
+ packaging = @packaging
420
+ define('foo', :version=>'1.0') { package(packaging).with :meta_inf=>'DISCLAIMER' }
421
+ inspect_meta_inf { |files| files.should eql(['DISCLAIMER']) }
422
+ end
423
+ end
424
+
425
+
426
+ describe Packaging, 'jar' do
427
+ it_should_behave_like 'packaging'
428
+ before { @packaging = :jar }
429
+ it_should_behave_like 'package with manifest'
430
+ it_should_behave_like 'package with meta_inf'
431
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
432
+
433
+ it 'should place the manifest as the first entry of the file' do
434
+ write 'src/main/java/Test.java', 'class Test {}'
435
+ define('foo', :version=>'1.0') { package(:jar) }
436
+ project('foo').package(:jar).invoke
437
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
438
+ entries_to_s = jar.entries.map(&:to_s).delete_if {|entry| entry[-1,1] == "/"}
439
+ # Sometimes META-INF/ is counted as first entry, which is fair game.
440
+ (entries_to_s.first == 'META-INF/MANIFEST.MF' || entries_to_s[1] == 'META-INF/MANIFEST.MF').should be_true
441
+ end
442
+ end
443
+
444
+ it 'should use files from compile directory if nothing included' do
445
+ write 'src/main/java/Test.java', 'class Test {}'
446
+ define('foo', :version=>'1.0') { package(:jar) }
447
+ project('foo').package(:jar).invoke
448
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
449
+ jar.entries.map(&:to_s).sort.should include('META-INF/MANIFEST.MF', 'Test.class')
450
+ end
451
+ end
452
+
453
+ it 'should use files from resources directory if nothing included' do
454
+ write 'src/main/resources/test/important.properties'
455
+ define('foo', :version=>'1.0') { package(:jar) }
456
+ project('foo').package(:jar).invoke
457
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
458
+ jar.entries.map(&:to_s).sort.should include('test/important.properties')
459
+ end
460
+ end
461
+
462
+ it 'should include class directories' do
463
+ write 'src/main/java/code/Test.java', 'package code ; class Test {}'
464
+ define('foo', :version=>'1.0') { package(:jar) }
465
+ project('foo').package(:jar).invoke
466
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
467
+ jar.entries.map(&:to_s).sort.should include('code/')
468
+ end
469
+ end
470
+
471
+ it 'should include resource files starting with dot' do
472
+ write 'src/main/resources/test/.config'
473
+ define('foo', :version=>'1.0') { package(:jar) }
474
+ project('foo').package(:jar).invoke
475
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
476
+ jar.entries.map(&:to_s).sort.should include('test/.config')
477
+ end
478
+ end
479
+
480
+ it 'should include empty resource directories' do
481
+ mkpath 'src/main/resources/empty'
482
+ define('foo', :version=>'1.0') { package(:jar) }
483
+ project('foo').package(:jar).invoke
484
+ Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
485
+ jar.entries.map(&:to_s).sort.should include('empty/')
486
+ end
487
+ end
488
+
489
+ it 'should raise error when calling with() with nil value' do
490
+ lambda {
491
+ define('foo', :version=>'1.0') { package(:jar).with(nil) }
492
+ }.should raise_error
493
+ end
494
+
495
+ it 'should exclude resources when ordered to do so' do
496
+ write 'src/main/resources/foo.xml', ''
497
+ foo = define('foo', :version => '1.0') { package(:jar).exclude('foo.xml')}
498
+ foo.package(:jar).invoke
499
+ Zip::ZipFile.open(foo.package(:jar).to_s) do |jar|
500
+ jar.entries.map(&:to_s).sort.should_not include('foo.xml')
501
+ end
502
+ end
503
+
504
+ end
505
+
506
+
507
+ describe Packaging, 'war' do
508
+ it_should_behave_like 'packaging'
509
+ before { @packaging = :war }
510
+ it_should_behave_like 'package with manifest'
511
+ it_should_behave_like 'package with meta_inf'
512
+ before { @meta_inf_ignore = 'MANIFEST.MF' }
513
+
514
+ def make_jars
515
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
516
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
517
+ end
518
+
519
+ def inspect_war
520
+ project('foo').package(:war).invoke
521
+ Zip::ZipFile.open(project('foo').package(:war).to_s) do |war|
522
+ yield war.entries.map(&:to_s).sort
523
+ end
524
+ end
525
+
526
+ it 'should use files from webapp directory if nothing included' do
527
+ write 'src/main/webapp/test.html'
528
+ define('foo', :version=>'1.0') { package(:war) }
529
+ inspect_war { |files| files.should include('test.html') }
530
+ end
531
+
532
+ it 'should accept files from :classes option' do
533
+ write 'src/main/java/Test.java', 'class Test {}'
534
+ write 'classes/test'
535
+ define('foo', :version=>'1.0') { package(:war).with(:classes=>'classes') }
536
+ inspect_war { |files| files.should include('WEB-INF/classes/test') }
537
+ end
538
+
539
+ it 'should use files from compile directory if nothing included' do
540
+ write 'src/main/java/Test.java', 'class Test {}'
541
+ define('foo', :version=>'1.0') { package(:war) }
542
+ inspect_war { |files| files.should include('WEB-INF/classes/Test.class') }
543
+ end
544
+
545
+ it 'should ignore compile directory if no source files to compile' do
546
+ define('foo', :version=>'1.0') { package(:war) }
547
+ inspect_war { |files| files.should_not include('target/classes') }
548
+ end
549
+
550
+ it 'should include only specified classes directories' do
551
+ write 'src/main/java'
552
+ define('foo', :version=>'1.0') { package(:war).with :classes=>_('additional') }
553
+ project('foo').package(:war).classes.should_not include(project('foo').file('target/classes'))
554
+ project('foo').package(:war).classes.should include(project('foo').file('additional'))
555
+ end
556
+
557
+ it 'should use files from resources directory if nothing included' do
558
+ write 'src/main/resources/test/important.properties'
559
+ define('foo', :version=>'1.0') { package(:war) }
560
+ inspect_war { |files| files.should include('WEB-INF/classes/test/important.properties') }
561
+ end
562
+
563
+ it 'should include empty resource directories' do
564
+ mkpath 'src/main/resources/empty'
565
+ define('foo', :version=>'1.0') { package(:war) }
566
+ inspect_war { |files| files.should include('WEB-INF/classes/empty/') }
567
+ end
568
+
569
+ it 'should accept file from :libs option' do
570
+ write 'lib/foo.jar'
571
+ define('foo', :version=>'1.0') { package(:war).libs << 'lib/foo.jar' }
572
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/foo.jar') }
573
+ end
574
+
575
+
576
+ it 'should accept artifacts from :libs option' do
577
+ make_jars
578
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>'group:id:jar:1.0') }
579
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
580
+ end
581
+
582
+ it 'should accept artifacts from :libs option' do
583
+ make_jars
584
+ define('foo', :version=>'1.0') { package(:war).with(:libs=>['group:id:jar:1.0', 'group:id:jar:2.0']) }
585
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
586
+ end
587
+
588
+ it 'should use artifacts from compile classpath if no libs specified' do
589
+ make_jars
590
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war) }
591
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar', 'WEB-INF/lib/id-2.0.jar') }
592
+ end
593
+
594
+ it 'should use artifacts from compile classpath if no libs specified, leaving the user specify which to exclude as files' do
595
+ make_jars
596
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).path('WEB-INF/lib').exclude('id-2.0.jar') }
597
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
598
+ end
599
+
600
+ it 'should use artifacts from compile classpath if no libs specified, leaving the user specify which to exclude as files with glob expressions' do
601
+ make_jars
602
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).path('WEB-INF/lib').exclude('**/id-2.0.jar') }
603
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
604
+ end
605
+
606
+ it 'should exclude files regardless of the path where they are included, using wildcards' do
607
+ make_jars
608
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).exclude('**/id-2.0.jar') }
609
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
610
+ end
611
+
612
+ it 'should exclude files regardless of the path where they are included, specifying target path entirely' do
613
+ make_jars
614
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:war).exclude('WEB-INF/lib/id-2.0.jar') }
615
+ inspect_war { |files| files.should include('META-INF/MANIFEST.MF', 'WEB-INF/lib/id-1.0.jar') }
616
+ end
617
+
618
+ it 'should exclude files regardless of the path where they are included for war files' do
619
+ write 'src/main/java/com/example/included/Test.java', 'package com.example.included; class Test {}'
620
+ write 'src/main/java/com/example/excluded/Test.java', 'package com.example.excluded; class Test {}'
621
+ define('foo', :version=>'1.0') do
622
+ package(:war).enhance do |war|
623
+ war.exclude('WEB-INF/classes/com/example/excluded/**.class')
624
+ end
625
+ end
626
+ inspect_war do |files|
627
+ files.should include('WEB-INF/classes/com/example/included/Test.class')
628
+ files.should_not include('WEB-INF/classes/com/example/excluded/Test.class')
629
+ end
630
+ end
631
+
632
+ it 'should include only specified libraries' do
633
+ define 'foo', :version=>'1.0' do
634
+ compile.with 'group:id:jar:1.0'
635
+ package(:war).with :libs=>'additional:id:jar:1.0'
636
+ end
637
+ project('foo').package(:war).libs.should_not include(artifact('group:id:jar:1.0'))
638
+ project('foo').package(:war).libs.should include(artifact('additional:id:jar:1.0'))
639
+ end
640
+
641
+ end
642
+
643
+
644
+ describe Packaging, 'aar' do
645
+ it_should_behave_like 'packaging'
646
+ before { @packaging = :aar }
647
+ it_should_behave_like 'package with manifest'
648
+ it_should_behave_like 'package with meta_inf'
649
+ before do
650
+ write 'src/main/axis2/services.xml'
651
+ @meta_inf_ignore = ['MANIFEST.MF', 'services.xml']
652
+ end
653
+
654
+ def make_jars
655
+ artifact('group:id:jar:1.0') { |t| write t.to_s }
656
+ artifact('group:id:jar:2.0') { |t| write t.to_s }
657
+ end
658
+
659
+ def inspect_aar
660
+ project('foo').package(:aar).invoke
661
+ Zip::ZipFile.open(project('foo').package(:aar).to_s) do |aar|
662
+ yield aar.entries.map(&:to_s).sort
663
+ end
664
+ end
665
+
666
+ it 'should automatically include services.xml and any *.wsdl files under src/main/axis2' do
667
+ write 'src/main/axis2/my-service.wsdl'
668
+ define('foo', :version=>'1.0') { package(:aar) }
669
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'META-INF/services.xml', 'META-INF/my-service.wsdl') }
670
+ end
671
+
672
+ it 'should accept files from :include option' do
673
+ write 'test'
674
+ define('foo', :version=>'1.0') { package(:aar).include 'test' }
675
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'test') }
676
+ end
677
+
678
+ it 'should use files from compile directory if nothing included' do
679
+ write 'src/main/java/Test.java', 'class Test {}'
680
+ define('foo', :version=>'1.0') { package(:aar) }
681
+ inspect_aar { |files| files.should include('Test.class') }
682
+ end
683
+
684
+ it 'should use files from resources directory if nothing included' do
685
+ write 'src/main/resources/test/important.properties'
686
+ define('foo', :version=>'1.0') { package(:aar) }
687
+ inspect_aar { |files| files.should include('test/important.properties') }
688
+ end
689
+
690
+ it 'should include empty resource directories' do
691
+ mkpath 'src/main/resources/empty'
692
+ define('foo', :version=>'1.0') { package(:aar) }
693
+ inspect_aar { |files| files.should include('empty/') }
694
+ end
695
+
696
+ it 'should accept file from :libs option' do
697
+ make_jars
698
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>'group:id:jar:1.0' }
699
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar') }
700
+ end
701
+
702
+ it 'should accept file from :libs option' do
703
+ make_jars
704
+ define('foo', :version=>'1.0') { package(:aar).with :libs=>['group:id:jar:1.0', 'group:id:jar:2.0'] }
705
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF', 'lib/id-1.0.jar', 'lib/id-2.0.jar') }
706
+ end
707
+
708
+ it 'should NOT use artifacts from compile classpath if no libs specified' do
709
+ make_jars
710
+ define('foo', :version=>'1.0') { compile.with 'group:id:jar:1.0', 'group:id:jar:2.0' ; package(:aar) }
711
+ inspect_aar { |files| files.should include('META-INF/MANIFEST.MF') }
712
+ end
713
+
714
+ it 'should return all libraries from libs attribute' do
715
+ define 'foo', :version=>'1.0' do
716
+ compile.with 'group:id:jar:1.0'
717
+ package(:aar).with :libs=>'additional:id:jar:1.0'
718
+ end
719
+ project('foo').package(:aar).libs.should_not include(artifact('group:id:jar:1.0'))
720
+ project('foo').package(:aar).libs.should include(artifact('additional:id:jar:1.0'))
721
+ end
722
+
723
+ end
724
+
725
+
726
+ describe Packaging, 'ear' do
727
+ it_should_behave_like 'packaging'
728
+ before { @packaging = :ear }
729
+ it_should_behave_like 'package with manifest'
730
+ it_should_behave_like 'package with meta_inf'
731
+ before { @meta_inf_ignore = ['MANIFEST.MF', 'application.xml'] }
732
+
733
+ def inspect_ear
734
+ project('foo').package(:ear).invoke
735
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
736
+ yield ear.entries.map(&:to_s).sort
737
+ end
738
+ end
739
+
740
+ def inspect_application_xml
741
+ project('foo').package(:ear).invoke
742
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
743
+ yield REXML::Document.new(ear.read('META-INF/application.xml')).root
744
+ end
745
+ end
746
+
747
+ def inspect_classpath(package)
748
+ project('foo').package(:ear).invoke
749
+ Zip::ZipFile.open(project('foo').package(:ear).to_s) do |ear|
750
+ File.open('tmp.zip', 'wb') do |tmp|
751
+ tmp.write ear.file.read(package)
752
+ end
753
+ manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
754
+ yield manifest.main['Class-Path'].split(' ')
755
+ end
756
+ end
757
+
758
+ it 'should set display name from project id' do
759
+ define 'foo', :version=>'1.0' do
760
+ package(:ear).display_name.should eql('foo')
761
+ define 'bar' do
762
+ package(:ear).display_name.should eql('foo-bar')
763
+ end
764
+ end
765
+ end
766
+
767
+ it 'should set display name in application.xml' do
768
+ define 'foo', :version=>'1.0' do
769
+ package(:ear)
770
+ end
771
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'foo' }
772
+ end
773
+
774
+ it 'should accept different display name' do
775
+ define 'foo', :version=>'1.0' do
776
+ package(:ear).display_name = 'bar'
777
+ end
778
+ inspect_application_xml { |xml| xml.get_text('/application/display-name').should == 'bar' }
779
+ end
780
+
781
+ it 'should set description in application.xml to project comment if not specified' do
782
+ desc "MyDescription"
783
+ define 'foo', :version=>'1.0' do
784
+ package(:ear)
785
+ end
786
+ inspect_application_xml { |xml| xml.get_text('/application/description').should == 'MyDescription' }
787
+ end
788
+
789
+ it 'should not set description in application.xml if not specified and no project comment' do
790
+ define 'foo', :version=>'1.0' do
791
+ package(:ear)
792
+ end
793
+ inspect_application_xml { |xml| xml.get_text('/application/description').should be_nil }
794
+ end
795
+
796
+ it 'should set description in application.xml if specified' do
797
+ define 'foo', :version=>'1.0' do
798
+ package(:ear).description = "MyDescription"
799
+ end
800
+ inspect_application_xml { |xml| xml.get_text('/application/description').should == 'MyDescription' }
801
+ end
802
+
803
+ it 'should add security-roles to application.xml if given' do
804
+ define 'foo', :version=>'1.0' do
805
+ package(:ear).security_roles << {:id=>'sr1',
806
+ :description=>'System Administrator', :name=>'systemadministrator'}
807
+ end
808
+ inspect_application_xml do |xml|
809
+ xml.get_text("/application/security-role[@id='sr1']/description").to_s.should eql('System Administrator')
810
+ xml.get_text("/application/security-role[@id='sr1']/role-name").to_s.should eql('systemadministrator')
811
+ end
812
+ end
813
+
814
+ it 'should map WARs to /war directory' do
815
+ define 'foo', :version=>'1.0' do
816
+ package(:ear) << package(:war)
817
+ end
818
+ inspect_ear { |files| files.should include('war/foo-1.0.war') }
819
+ end
820
+
821
+ it 'should map EJBs to /ejb directory' do
822
+ define 'foo', :version=>'1.0' do
823
+ package(:ear).add :ejb=>package(:jar)
824
+ end
825
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
826
+ end
827
+
828
+ it 'should not modify original artifact for its components' do
829
+ define 'one', :version => '1.0' do
830
+ write 'src/main/resources/one.txt', '1'
831
+ package(:jar)
832
+ end
833
+
834
+ define 'two', :version => '1.0' do
835
+ write 'src/main/resources/two.txt', '2'
836
+ package(:jar)
837
+ end
838
+
839
+ define 'foo', :version => '1.0' do
840
+ package(:ear).add project(:one).package(:jar)
841
+ package(:ear).add :ejb => project(:two).package(:jar)
842
+ end
843
+
844
+ inspect_ear { |files| files.should include('lib/one-1.0.jar', 'ejb/two-1.0.jar') }
845
+
846
+ Buildr::Packaging::Java::Manifest.from_zip(project('one').package(:jar)).main['Class-Path'].should be_nil
847
+ Buildr::Packaging::Java::Manifest.from_zip(project('two').package(:jar)).main['Class-Path'].should be_nil
848
+
849
+ inspect_classpath 'ejb/two-1.0.jar' do |classpath|
850
+ classpath.should include('../lib/one-1.0.jar')
851
+ end
852
+ end
853
+
854
+ it 'should map JARs to /lib directory' do
855
+ define 'foo', :version=>'1.0' do
856
+ package(:ear) << package(:jar)
857
+ end
858
+ inspect_ear { |files| files.should include('lib/foo-1.0.jar') }
859
+ end
860
+
861
+ it 'should accept component type with :type option' do
862
+ define 'foo', :version=>'1.0' do
863
+ package(:ear).add package(:jar), :type=>:ejb
864
+ end
865
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
866
+ end
867
+
868
+ it 'should accept component and its type as type=>artifact' do
869
+ define 'foo', :version=>'1.0' do
870
+ package(:ear).add :ejb=>package(:jar)
871
+ end
872
+ inspect_ear { |files| files.should include('ejb/foo-1.0.jar') }
873
+ end
874
+
875
+ it 'should map typed JARs to /jar directory' do
876
+ define 'foo', :version=>'1.0' do
877
+ package(:ear).add :jar=>package(:jar)
878
+ end
879
+ inspect_ear { |files| files.should include('jar/foo-1.0.jar') }
880
+ end
881
+
882
+ it 'should add multiple components at a time using the type=>component style' do
883
+ define 'bar', :version => '1.5' do
884
+ package(:war) # must be added as a webapp
885
+ package(:jar) # must be added as a shared lib
886
+ package(:zip) # this one should be excluded
887
+ end
888
+ define 'baz', :version => '1.5' do
889
+ package(:jar, :id => 'one')
890
+ package(:jar, :id => 'two')
891
+ end
892
+ define 'foo', :version => '1.0' do
893
+ package(:ear).add :lib => project('baz'),
894
+ :war => project('bar').package(:war),
895
+ :ejb => project('bar').package(:jar)
896
+ end
897
+ inspect_ear do |files|
898
+ files.should include(*%w{ lib/one-1.5.jar lib/two-1.5.jar war/bar-1.5.war ejb/bar-1.5.jar })
899
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
900
+ end
901
+ end
902
+
903
+ it 'should add all EAR supported packages when given a project argument' do
904
+ define 'bar', :version => '1.5' do
905
+ package(:war) # must be added as a webapp
906
+ package(:jar) # must be added as a shared lib
907
+ package(:zip) # this one should be excluded
908
+ end
909
+ define 'baz', :version => '1.5' do
910
+ package(:war)
911
+ package(:jar)
912
+ end
913
+ define 'foo', :version => '1.0' do
914
+ package(:ear).add projects(:bar, :baz)
915
+ end
916
+ inspect_ear do |files|
917
+ files.should include('war/bar-1.5.war', 'lib/bar-1.5.jar', 'lib/baz-1.5.jar', 'war/baz-1.5.war')
918
+ files.should_not satisfy { files.any? { |f| f =~ /\.zip$/ } }
919
+ end
920
+ end
921
+
922
+ it 'should complain about unknown component type' do
923
+ define 'foo', :version=>'1.0' do
924
+ lambda { package(:ear).add package(:zip) }.should raise_error(RuntimeError, /ear component/i)
925
+ end
926
+ end
927
+
928
+ it 'should allow unknown component types with explicit type' do
929
+ define 'foo', :version=>'1.0' do
930
+ package(:ear).add :lib=>package(:zip)
931
+ end
932
+ inspect_ear { |files| files.should include('lib/foo-1.0.zip') }
933
+ end
934
+
935
+ it 'should accept alternative directory name' do
936
+ define 'foo', :version=>'1.0' do
937
+ package(:ear).add package(:jar), :path=>'trash'
938
+ end
939
+ inspect_ear { |files| files.should include('trash/foo-1.0.jar') }
940
+ end
941
+
942
+ it 'should accept customization of directory map' do
943
+ define 'foo', :version=>'1.0' do
944
+ package(:ear).dirs[:jar] = 'jarred'
945
+ package(:ear).add :jar=>package(:jar)
946
+ end
947
+ inspect_ear { |files| files.should include('jarred/foo-1.0.jar') }
948
+ end
949
+
950
+ it 'should accept customization of directory map with nil paths in application.xml' do
951
+ define 'foo', :version=>'1.0' do
952
+ package(:ear).dirs[:war] = nil
953
+ package(:ear).add :war=>package(:war)
954
+ package(:ear).add package(:jar)
955
+ end
956
+ inspect_ear { |files| files.should include('foo-1.0.war') }
957
+ inspect_application_xml do |xml|
958
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('foo-1.0.war')
959
+ end
960
+ end
961
+
962
+ it 'should accept customization of directory map with nil paths in the classpath' do
963
+ define 'foo', :version=>'1.0' do
964
+ package(:ear).dirs[:lib] = nil
965
+ package(:ear).add :war=>package(:war)
966
+ package(:ear) << package(:jar)
967
+ end
968
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
969
+ classpath.should include('../foo-1.0.jar')
970
+ end
971
+ end
972
+
973
+ it 'should list WAR components in application.xml' do
974
+ define 'foo', :version=>'1.0' do
975
+ package(:ear) << package(:war) << package(:war, :id=>'bar')
976
+ end
977
+ inspect_application_xml do |xml|
978
+ xml.get_elements("/application/module[@id='foo'][web]").should_not be_empty
979
+ xml.get_elements("/application/module[@id='bar'][web]").should_not be_empty
980
+ end
981
+ end
982
+
983
+ it 'should specify web-uri for WAR components in application.xml' do
984
+ define 'foo', :version=>'1.0' do
985
+ package(:ear) << package(:war)
986
+ package(:ear).add package(:war, :id=>'bar'), :path=>'ws'
987
+ end
988
+ inspect_application_xml do |xml|
989
+ xml.get_text("/application/module[@id='foo']/web/web-uri").to_s.should eql('war/foo-1.0.war')
990
+ xml.get_text("/application/module[@id='bar']/web/web-uri").to_s.should eql('ws/bar-1.0.war')
991
+ end
992
+ end
993
+
994
+ it 'should specify context-root for WAR components in application.xml' do
995
+ define 'foo', :version=>'1.0' do
996
+ package(:ear) << package(:war)
997
+ package(:ear).add package(:war, :id=>'bar')
998
+ end
999
+ inspect_application_xml do |xml|
1000
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/foo')
1001
+ xml.get_text("/application/module[@id='bar']/web/context-root").to_s.should eql('/bar')
1002
+ end
1003
+ end
1004
+
1005
+ it 'should accept context-root for WAR components in application.xml' do
1006
+ define 'foo', :version=>'1.0' do
1007
+ package(:ear).add package(:war), :context_root=>'rooted'
1008
+ end
1009
+ inspect_application_xml do |xml|
1010
+ xml.get_text("/application/module[@id='foo']/web/context-root").to_s.should eql('/rooted')
1011
+ end
1012
+ end
1013
+
1014
+ it 'should allow disabling the context root' do
1015
+ define 'foo', :version=>'1.0' do
1016
+ package(:ear).add package(:war), :context_root=>false
1017
+ end
1018
+ inspect_application_xml do |xml|
1019
+ xml.get_elements("/application/module[@id='foo']/web/context-root").should be_empty
1020
+ end
1021
+ end
1022
+
1023
+ it 'should list EJB components in application.xml' do
1024
+ define 'foo', :version=>'1.0' do
1025
+ package(:ear).add :ejb=>package(:jar)
1026
+ package(:ear).add :ejb=>package(:jar, :id=>'bar')
1027
+ end
1028
+ inspect_application_xml do |xml|
1029
+ xml.get_text("/application/module[@id='foo']/ejb").to_s.should eql('ejb/foo-1.0.jar')
1030
+ xml.get_text("/application/module[@id='bar']/ejb").to_s.should eql('ejb/bar-1.0.jar')
1031
+ end
1032
+ end
1033
+
1034
+ it 'should list JAR components in application.xml' do
1035
+ define 'foo', :version=>'1.0' do
1036
+ package(:ear) << { :jar=>package(:jar) } << { :jar=>package(:jar, :id=>'bar') }
1037
+ end
1038
+ inspect_application_xml do |xml|
1039
+ jars = xml.get_elements('/application/jar').map(&:texts).map(&:join)
1040
+ jars.should include('jar/foo-1.0.jar', 'jar/bar-1.0.jar')
1041
+ end
1042
+ end
1043
+
1044
+ it 'should update WAR component classpath to include libraries' do
1045
+ define 'foo', :version=>'1.0' do
1046
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
1047
+ package(:ear).add package(:war)
1048
+ end
1049
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
1050
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
1051
+ end
1052
+ end
1053
+
1054
+ it 'should update WAR component classpath but skip internal libraries' do
1055
+ define 'foo', :version=>'1.0' do
1056
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
1057
+ package(:war).with(:libs=>package(:jar, :id=>'lib1'))
1058
+ package(:ear).add package(:war)
1059
+ end
1060
+ inspect_classpath 'war/foo-1.0.war' do |classpath|
1061
+ classpath.should_not include('../lib/lib1-1.0.jar')
1062
+ classpath.should include('../lib/lib2-1.0.jar')
1063
+ end
1064
+ end
1065
+
1066
+ it 'should update EJB component classpath to include libraries' do
1067
+ define 'foo', :version=>'1.0' do
1068
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
1069
+ package(:ear).add :ejb=>package(:jar, :id=>'foo')
1070
+ end
1071
+ inspect_classpath 'ejb/foo-1.0.jar' do |classpath|
1072
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
1073
+ end
1074
+ end
1075
+
1076
+ it 'should update JAR component classpath to include libraries' do
1077
+ define 'foo', :version=>'1.0' do
1078
+ package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
1079
+ package(:ear).add :jar=>package(:jar, :id=>'foo')
1080
+ end
1081
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
1082
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
1083
+ end
1084
+ end
1085
+
1086
+ it 'should deal with very long classpaths' do
1087
+ define 'foo', :version=>'1.0' do
1088
+ 20.times { |i| package(:ear) << package(:jar, :id=>"lib#{i}") }
1089
+ package(:ear).add :jar=>package(:jar, :id=>'foo')
1090
+ end
1091
+ inspect_classpath 'jar/foo-1.0.jar' do |classpath|
1092
+ classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
1093
+ end
1094
+ end
1095
+
1096
+
1097
+ it 'should generate relative classpaths for top level EJB' do
1098
+ define 'foo', :version => '1.0' do
1099
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
1100
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
1101
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
1102
+ package(:ear).add :ejb => package(:jar, :id => 'ejb1'), :path => '.'
1103
+ end
1104
+ inspect_classpath 'ejb1-1.0.jar' do |classpath|
1105
+ classpath.should include(*%w{ one-1.0.jar dos/two-1.0.jar tres/three-1.0.jar })
1106
+ end
1107
+ end
1108
+
1109
+ it 'should generate relative classpaths for second level EJB' do
1110
+ define 'foo', :version => '1.0' do
1111
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
1112
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
1113
+ package(:ear).add package(:jar, :id => 'three'), :path => 'tres'
1114
+ package(:ear).add :ejb => package(:jar, :id => 'ejb2'), :path => 'dos'
1115
+ end
1116
+ inspect_classpath 'dos/ejb2-1.0.jar' do |classpath|
1117
+ classpath.should include(*%w{ ../one-1.0.jar two-1.0.jar ../tres/three-1.0.jar })
1118
+ end
1119
+ end
1120
+
1121
+ it 'should generate relative classpaths for nested EJB' do
1122
+ define 'foo', :version => '1.0' do
1123
+ package(:ear).add package(:jar, :id => 'one'), :path => '.'
1124
+ package(:ear).add package(:jar, :id => 'two'), :path => 'dos'
1125
+ package(:ear).add package(:jar, :id => 'three'), :path => 'dos/tres'
1126
+ package(:ear).add package(:jar, :id => 'four'), :path => 'dos/cuatro'
1127
+ package(:ear).add :ejb => package(:jar, :id => 'ejb4'), :path => 'dos/cuatro'
1128
+ end
1129
+ inspect_classpath 'dos/cuatro/ejb4-1.0.jar' do |classpath|
1130
+ classpath.should include(*%w{ ../../one-1.0.jar ../two-1.0.jar ../tres/three-1.0.jar four-1.0.jar })
1131
+ end
1132
+ end
1133
+
1134
+ end
1135
+
1136
+
1137
+ describe Packaging, 'sources' do
1138
+ it_should_behave_like 'packaging'
1139
+ before { @packaging, @package_type = :sources, :jar }
1140
+
1141
+ it 'should create package of type :jar and classifier \'sources\'' do
1142
+ define 'foo', :version=>'1.0' do
1143
+ package(:sources).type.should eql(:jar)
1144
+ package(:sources).classifier.should eql('sources')
1145
+ package(:sources).name.should match(/foo-1.0-sources.jar$/)
1146
+ end
1147
+ end
1148
+
1149
+ it 'should contain source and resource files' do
1150
+ write 'src/main/java/Source.java'
1151
+ write 'src/main/resources/foo.properties', 'foo=bar'
1152
+ define('foo', :version=>'1.0') { package(:sources) }
1153
+ project('foo').task('package').invoke
1154
+ project('foo').packages.first.should contain('Source.java')
1155
+ project('foo').packages.first.should contain('foo.properties')
1156
+ end
1157
+
1158
+ it 'should create sources jar if resources exists (but not sources)' do
1159
+ write 'src/main/resources/foo.properties', 'foo=bar'
1160
+ define('foo', :version=>'1.0') { package(:sources) }
1161
+ project('foo').package(:sources).invoke
1162
+ project('foo').packages.first.should contain('foo.properties')
1163
+ end
1164
+
1165
+ it 'should be a ZipTask' do
1166
+ define 'foo', :version=>'1.0' do
1167
+ package(:sources).should be_kind_of(ZipTask)
1168
+ end
1169
+ end
1170
+ end
1171
+
1172
+ describe Packaging, 'javadoc' do
1173
+ it_should_behave_like 'packaging'
1174
+ before { @packaging, @package_type = :javadoc, :jar }
1175
+
1176
+ it 'should create package of type :zip and classifier \'javadoc\'' do
1177
+ define 'foo', :version=>'1.0' do
1178
+ package(:javadoc).type.should eql(:jar)
1179
+ package(:javadoc).classifier.should eql('javadoc')
1180
+ package(:javadoc).name.pathmap('%f').should eql('foo-1.0-javadoc.jar')
1181
+ end
1182
+ end
1183
+
1184
+ it 'should contain Javadocs' do
1185
+ write 'src/main/java/Source.java', 'public class Source {}'
1186
+ define('foo', :version=>'1.0') { package(:javadoc) }
1187
+ project('foo').task('package').invoke
1188
+ project('foo').packages.first.should contain('Source.html', 'index.html')
1189
+ end
1190
+
1191
+ it 'should use project description in window title' do
1192
+ write 'src/main/java/Source.java', 'public class Source {}'
1193
+ desc 'My Project'
1194
+ define('foo', :version=>'1.0') { package(:javadoc) }
1195
+ project('foo').task('package').invoke
1196
+ project('foo').packages.first.entry('index.html').should contain('My Project')
1197
+ end
1198
+
1199
+ it 'should be a ZipTask' do
1200
+ define 'foo', :version=>'1.0' do
1201
+ package(:javadoc).should be_kind_of(ZipTask)
1202
+ end
1203
+ end
1204
+ end
1205
+
1206
+ shared_examples_for 'package_with_' do
1207
+
1208
+ def prepare(options = {})
1209
+ packager = "package_with_#{@packaging}"
1210
+ write 'src/main/java/Source.java'
1211
+ write 'baz/src/main/java/Source.java'
1212
+ define 'foo', :version=>'1.0' do
1213
+ send packager, options
1214
+ define 'bar' ; define 'baz'
1215
+ end
1216
+ end
1217
+
1218
+ def applied_to
1219
+ projects.select { |project| project.packages.first }.map(&:name)
1220
+ end
1221
+
1222
+ it 'should create package of the right packaging with classifier' do
1223
+ prepare
1224
+ project('foo').packages.first.to_s.should =~ /foo-1.0-#{@packaging}.#{@ext}/
1225
+ end
1226
+
1227
+ it 'should create package for projects that have source files' do
1228
+ prepare
1229
+ applied_to.should include('foo', 'foo:baz')
1230
+ end
1231
+
1232
+ it 'should not create package for projects that have no source files' do
1233
+ prepare
1234
+ applied_to.should_not include('foo:bar')
1235
+ end
1236
+
1237
+ it 'should limit to projects specified by :only' do
1238
+ prepare :only=>'baz'
1239
+ applied_to.should eql(['foo:baz'])
1240
+ end
1241
+
1242
+ it 'should limit to projects specified by :only array' do
1243
+ prepare :only=>['baz']
1244
+ applied_to.should eql(['foo:baz'])
1245
+ end
1246
+
1247
+ it 'should ignore project specified by :except' do
1248
+ prepare :except=>'baz'
1249
+ applied_to.should eql(['foo'])
1250
+ end
1251
+
1252
+ it 'should ignore projects specified by :except array' do
1253
+ prepare :except=>['baz']
1254
+ applied_to.should eql(['foo'])
1255
+ end
1256
+ end
1257
+
1258
+ describe 'package_with_sources' do
1259
+ it_should_behave_like 'package_with_'
1260
+ before { @packaging, @ext = :sources, 'jar' }
1261
+ end
1262
+
1263
+ describe 'package_with_javadoc' do
1264
+ it_should_behave_like 'package_with_'
1265
+ before { @packaging, @ext = :javadoc, 'jar' }
1266
+ end