buildr 1.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/CHANGELOG +780 -0
  2. data/DISCLAIMER +7 -0
  3. data/KEYS +151 -0
  4. data/LICENSE +176 -0
  5. data/NOTICE +31 -0
  6. data/README +173 -0
  7. data/Rakefile +63 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +232 -0
  10. data/addon/buildr/hibernate.rb +142 -0
  11. data/addon/buildr/javacc.rb +85 -0
  12. data/addon/buildr/jdepend.rb +60 -0
  13. data/addon/buildr/jetty.rb +248 -0
  14. data/addon/buildr/nailgun.rb +892 -0
  15. data/addon/buildr/openjpa.rb +90 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  18. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  19. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  20. data/addon/buildr/xmlbeans.rb +93 -0
  21. data/bin/buildr +21 -0
  22. data/buildr.gemspec +50 -0
  23. data/doc/css/default.css +225 -0
  24. data/doc/css/print.css +95 -0
  25. data/doc/css/syntax.css +43 -0
  26. data/doc/images/apache-incubator-logo.png +0 -0
  27. data/doc/images/buildr-hires.png +0 -0
  28. data/doc/images/buildr.png +0 -0
  29. data/doc/images/note.png +0 -0
  30. data/doc/images/tip.png +0 -0
  31. data/doc/images/zbuildr.tif +0 -0
  32. data/doc/pages/artifacts.textile +317 -0
  33. data/doc/pages/building.textile +501 -0
  34. data/doc/pages/contributing.textile +178 -0
  35. data/doc/pages/download.textile +25 -0
  36. data/doc/pages/extending.textile +229 -0
  37. data/doc/pages/getting_started.textile +337 -0
  38. data/doc/pages/index.textile +63 -0
  39. data/doc/pages/mailing_lists.textile +17 -0
  40. data/doc/pages/more_stuff.textile +367 -0
  41. data/doc/pages/packaging.textile +592 -0
  42. data/doc/pages/projects.textile +449 -0
  43. data/doc/pages/recipes.textile +127 -0
  44. data/doc/pages/settings_profiles.textile +339 -0
  45. data/doc/pages/testing.textile +475 -0
  46. data/doc/pages/troubleshooting.textile +121 -0
  47. data/doc/pages/whats_new.textile +389 -0
  48. data/doc/print.haml +52 -0
  49. data/doc/print.toc.yaml +28 -0
  50. data/doc/scripts/buildr-git.rb +411 -0
  51. data/doc/scripts/install-jruby.sh +44 -0
  52. data/doc/scripts/install-linux.sh +64 -0
  53. data/doc/scripts/install-osx.sh +52 -0
  54. data/doc/site.haml +55 -0
  55. data/doc/site.toc.yaml +44 -0
  56. data/lib/buildr.rb +47 -0
  57. data/lib/buildr/core.rb +27 -0
  58. data/lib/buildr/core/application.rb +373 -0
  59. data/lib/buildr/core/application_cli.rb +134 -0
  60. data/lib/buildr/core/build.rb +262 -0
  61. data/lib/buildr/core/checks.rb +382 -0
  62. data/lib/buildr/core/common.rb +155 -0
  63. data/lib/buildr/core/compile.rb +594 -0
  64. data/lib/buildr/core/environment.rb +120 -0
  65. data/lib/buildr/core/filter.rb +258 -0
  66. data/lib/buildr/core/generate.rb +195 -0
  67. data/lib/buildr/core/help.rb +118 -0
  68. data/lib/buildr/core/progressbar.rb +156 -0
  69. data/lib/buildr/core/project.rb +890 -0
  70. data/lib/buildr/core/test.rb +690 -0
  71. data/lib/buildr/core/transports.rb +486 -0
  72. data/lib/buildr/core/util.rb +235 -0
  73. data/lib/buildr/ide.rb +19 -0
  74. data/lib/buildr/ide/eclipse.rb +181 -0
  75. data/lib/buildr/ide/idea.ipr.template +300 -0
  76. data/lib/buildr/ide/idea.rb +194 -0
  77. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  78. data/lib/buildr/ide/idea7x.rb +210 -0
  79. data/lib/buildr/java.rb +26 -0
  80. data/lib/buildr/java/ant.rb +71 -0
  81. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  82. data/lib/buildr/java/commands.rb +210 -0
  83. data/lib/buildr/java/compilers.rb +432 -0
  84. data/lib/buildr/java/deprecated.rb +141 -0
  85. data/lib/buildr/java/groovyc.rb +137 -0
  86. data/lib/buildr/java/jruby.rb +99 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  89. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  91. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  92. data/lib/buildr/java/packaging.rb +706 -0
  93. data/lib/buildr/java/pom.rb +178 -0
  94. data/lib/buildr/java/rjb.rb +142 -0
  95. data/lib/buildr/java/test_frameworks.rb +290 -0
  96. data/lib/buildr/java/version_requirement.rb +172 -0
  97. data/lib/buildr/packaging.rb +21 -0
  98. data/lib/buildr/packaging/artifact.rb +729 -0
  99. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  100. data/lib/buildr/packaging/artifact_search.rb +140 -0
  101. data/lib/buildr/packaging/gems.rb +102 -0
  102. data/lib/buildr/packaging/package.rb +233 -0
  103. data/lib/buildr/packaging/tar.rb +104 -0
  104. data/lib/buildr/packaging/zip.rb +719 -0
  105. data/rakelib/apache.rake +126 -0
  106. data/rakelib/changelog.rake +56 -0
  107. data/rakelib/doc.rake +103 -0
  108. data/rakelib/package.rake +44 -0
  109. data/rakelib/release.rake +53 -0
  110. data/rakelib/rspec.rake +81 -0
  111. data/rakelib/rubyforge.rake +45 -0
  112. data/rakelib/scm.rake +49 -0
  113. data/rakelib/setup.rake +59 -0
  114. data/rakelib/stage.rake +45 -0
  115. data/spec/application_spec.rb +316 -0
  116. data/spec/archive_spec.rb +494 -0
  117. data/spec/artifact_namespace_spec.rb +635 -0
  118. data/spec/artifact_spec.rb +738 -0
  119. data/spec/build_spec.rb +193 -0
  120. data/spec/checks_spec.rb +537 -0
  121. data/spec/common_spec.rb +579 -0
  122. data/spec/compile_spec.rb +561 -0
  123. data/spec/groovy_compilers_spec.rb +239 -0
  124. data/spec/java_bdd_frameworks_spec.rb +238 -0
  125. data/spec/java_compilers_spec.rb +446 -0
  126. data/spec/java_packaging_spec.rb +1042 -0
  127. data/spec/java_test_frameworks_spec.rb +414 -0
  128. data/spec/packaging_helper.rb +63 -0
  129. data/spec/packaging_spec.rb +589 -0
  130. data/spec/project_spec.rb +739 -0
  131. data/spec/sandbox.rb +116 -0
  132. data/spec/scala_compilers_spec.rb +239 -0
  133. data/spec/spec.opts +6 -0
  134. data/spec/spec_helpers.rb +283 -0
  135. data/spec/test_spec.rb +871 -0
  136. data/spec/transport_spec.rb +300 -0
  137. data/spec/version_requirement_spec.rb +115 -0
  138. metadata +324 -0
@@ -0,0 +1,63 @@
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 'rake/gempackagetask'
18
+
19
+
20
+ def spec(platform = nil)
21
+ @specs ||= {}
22
+ platform ||= RUBY_PLATFORM =~ /java/ ? 'java' : 'ruby'
23
+ @specs[platform] ||= begin
24
+ spec = Gem::Specification.load(File.join(File.dirname(__FILE__), 'buildr.gemspec'))
25
+ spec.platform = platform
26
+ if platform =~ /java/
27
+ spec.add_dependency 'ci_reporter', '~> 1.5'
28
+ else
29
+ spec.add_dependency 'rjb', '~>1.1'
30
+ end
31
+ spec
32
+ end
33
+ end
34
+
35
+
36
+ desc 'Compile Java libraries used by Buildr'
37
+ task 'compile' do
38
+ puts 'Compiling Java libraries ...'
39
+ sh Config::CONFIG['ruby_install_name'], '-Ilib', '-Iaddon', 'bin/buildr', 'compile'
40
+ puts 'OK'
41
+ end
42
+ file Rake::GemPackageTask.new(spec).package_dir=>'compile'
43
+ file Rake::GemPackageTask.new(spec).package_dir_path=>'compile'
44
+
45
+ # We also need the other package (JRuby if building on Ruby, and vice versa)
46
+ Rake::GemPackageTask.new spec(RUBY_PLATFORM =~ /java/ ? 'ruby' : 'java') do |task|
47
+ # Block necessary otherwise doesn't do full job.
48
+ end
49
+
50
+
51
+ ENV['incubating'] = 'true'
52
+ ENV['staging'] = "people.apache.org:~/public_html/#{spec.name}/#{spec.version}"
53
+
54
+ task 'apache:license'=>spec.files
55
+ task('apache:license').prerequisites.exclude('doc/css/syntax.css')
56
+
57
+ task 'spec:check' do
58
+ print 'Checking that we have JRuby, Scala and Groovy available ... '
59
+ fail 'Full testing requires JRuby!' unless which('jruby')
60
+ fail 'Full testing requires Scala!' unless which('scala')
61
+ fail 'Full testing requires Groovy!' unless which('groovy')
62
+ puts 'OK'
63
+ end
@@ -0,0 +1,65 @@
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/java'
18
+
19
+
20
+ module Buildr
21
+ # Provides ANTLR grammar generation tasks. Require explicitly using <code>require "buildr/antlr"</code>.
22
+ module ANTLR
23
+ REQUIRES = [ "org.antlr:antlr:jar:3.0", "antlr:antlr:jar:2.7.7", "org.antlr:stringtemplate:jar:3.0" ]
24
+
25
+ Java.classpath << REQUIRES
26
+
27
+ class << self
28
+ def antlr(*args)
29
+ options = Hash === args.last ? args.pop : {}
30
+ rake_check_options options, :output, :token
31
+
32
+ args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.g"] : f }.flatten
33
+ args = ["-o", options[:output]] + args if options[:output]
34
+ if options[:token]
35
+ # antlr expects the token directory to exist when it starts
36
+ mkdir_p options[:token]
37
+ args = ["-lib", options[:token]] + args
38
+ end
39
+ Java.load
40
+ #Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
41
+ Java.org.antlr.Tool.new(args.to_java(Java.java.lang.String)).process
42
+ end
43
+ end
44
+
45
+ def antlr(*args)
46
+ if Hash === args.last
47
+ options = args.pop
48
+ in_package = options[:in_package].split(".")
49
+ token = options[:token].split(".") if options[:token]
50
+ else
51
+ in_package = []; token = nil
52
+ end
53
+ file(path_to(:target, :generated, :antlr)=>args.flatten) do |task|
54
+ args = {:output=>File.join(task.name, in_package)}
55
+ args.merge!({:token=>File.join(task.name, token)}) if token
56
+ ANTLR.antlr task.prerequisites, args
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ class Project
63
+ include ANTLR
64
+ end
65
+ end
@@ -0,0 +1,232 @@
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/java'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Provides the <code>cobertura:html</code> and <code>cobertura:xml</code> tasks.
23
+ # Require explicitly using <code>require "buildr/cobertura"</code>.
24
+ #
25
+ # You can generate cobertura reports for a single project
26
+ # using the project name as prefix:
27
+ #
28
+ # project_name:cobertura:html
29
+ #
30
+ # You can also specify which classes to include/exclude from instrumentation by
31
+ # passing a class name regexp to the <code>cobertura.include</code> or
32
+ # <code>cobertura.exclude</code> methods.
33
+ #
34
+ # define 'someModule' do
35
+ # cobertura.include 'some.package.*'
36
+ # cobertura.include /some.(foo|bar).*/
37
+ # cobertura.exclude 'some.foo.util.SimpleUtil'
38
+ # cobertura.exclude /*.Const(ants)?/i
39
+ # end
40
+ module Cobertura
41
+
42
+ class << self
43
+
44
+ REQUIRES = ["net.sourceforge.cobertura:cobertura:jar:1.9", "log4j:log4j:jar:1.2.9",
45
+ "asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"]
46
+
47
+ def requires()
48
+ @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
49
+ end
50
+
51
+ def report_to(file = nil)
52
+ File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
53
+ end
54
+
55
+ def data_file()
56
+ File.expand_path("reports/cobertura.ser")
57
+ end
58
+
59
+ end
60
+
61
+ class CoberturaConfig # :nodoc:
62
+
63
+ def initialize(project)
64
+ @project = project
65
+ end
66
+
67
+ attr_reader :project
68
+ private :project
69
+
70
+ attr_writer :data_file, :instrumented_dir, :report_dir
71
+
72
+ def data_file
73
+ @data_file ||= project.path_to(:reports, 'cobertura.ser')
74
+ end
75
+
76
+ def instrumented_dir
77
+ @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
78
+ end
79
+
80
+ def report_dir
81
+ @report_dir ||= project.path_to(:reports, :cobertura)
82
+ end
83
+
84
+ def report_to(file = nil)
85
+ File.expand_path(File.join(*[report_dir, file.to_s].compact))
86
+ end
87
+
88
+ # :call-seq:
89
+ # project.cobertura.include(*classPatterns)
90
+ #
91
+ def include(*classPatterns)
92
+ includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
93
+ self
94
+ end
95
+
96
+ def includes
97
+ @includeClasses ||= []
98
+ end
99
+
100
+ # :call-seq:
101
+ # project.cobertura.exclude(*classPatterns)
102
+ #
103
+ def exclude(*classPatterns)
104
+ excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
105
+ self
106
+ end
107
+
108
+ def excludes
109
+ @excludeClasses ||= []
110
+ end
111
+
112
+ def sources
113
+ project.compile.sources
114
+ end
115
+ end
116
+
117
+ module CoberturaExtension # :nodoc:
118
+ include Buildr::Extension
119
+
120
+ def cobertura
121
+ @cobertura_config ||= CoberturaConfig.new(self)
122
+ end
123
+
124
+ after_define do |project|
125
+ cobertura = project.cobertura
126
+
127
+ namespace 'cobertura' do
128
+ # Instrumented bytecode goes in a different directory. This task creates before running the test
129
+ # cases and monitors for changes in the generate bytecode.
130
+ instrumented = project.file(cobertura.instrumented_dir => file(project.compile.target)) do |task|
131
+ mkdir_p task.to_s, :verbose => false
132
+ unless project.compile.sources.empty?
133
+ puts "Instrumenting classes with cobertura data file #{cobertura.data_file}"
134
+ Buildr.ant "cobertura" do |ant|
135
+ ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
136
+ ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
137
+ includes, excludes = cobertura.includes, cobertura.excludes
138
+
139
+ classes_dir = project.compile.target.to_s
140
+ if includes.empty? && excludes.empty?
141
+ ant.fileset :dir => classes_dir do
142
+ ant.include :name => "**/*.class"
143
+ end
144
+ else
145
+ includes = [//] if includes.empty?
146
+ Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
147
+ cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
148
+ if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
149
+ ant.fileset :file => cls
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ touch task.to_s, :verbose=>false
157
+ end
158
+
159
+ task 'instrument' => instrumented
160
+ [:xml, :html].each do |format|
161
+ task format => ['instrument', 'test'] do
162
+ puts "Creating test coverage reports in #{cobertura.report_to(format)}"
163
+ Buildr.ant "cobertura" do |ant|
164
+ ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
165
+ ant.send "cobertura-report", :format=>format,
166
+ :destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
167
+ cobertura.sources.flatten.each do |src|
168
+ ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ end
176
+
177
+ # We now have two target directories with bytecode. It would make sense to remove compile.target
178
+ # and add instrumented instead, but apparently Cobertura only creates some of the classes, so
179
+ # we need both directories and instrumented must come first.
180
+ project.test.dependencies.unshift cobertura.instrumented_dir
181
+ project.test.with Cobertura.requires
182
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
183
+
184
+ project.clean do
185
+ rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir], :verbose=>false
186
+ end
187
+
188
+ end
189
+
190
+ end
191
+
192
+ class Buildr::Project
193
+ include CoberturaExtension
194
+ end
195
+
196
+ namespace "cobertura" do
197
+
198
+ task "instrument" do
199
+ Buildr.projects.each do |project|
200
+ project.cobertura.data_file = data_file
201
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
202
+ project.task('cobertura:instrument').invoke
203
+ end
204
+ end
205
+
206
+ [:xml, :html].each do |format|
207
+ report_target = report_to(format)
208
+ desc "Run the test cases and produce code coverage reports in #{report_target}"
209
+ task format => ["instrument", "test"] do
210
+ puts "Creating test coverage reports in #{report_target}"
211
+ Buildr.ant "cobertura" do |ant|
212
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
213
+ ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
214
+ Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
215
+ ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+
222
+ task "clean" do
223
+ rm_rf [report_to, data_file], :verbose=>false
224
+ end
225
+ end
226
+
227
+ task "clean" do
228
+ task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
229
+ end
230
+
231
+ end
232
+ end
@@ -0,0 +1,142 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/java'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Provides Hibernate Doclet and schema export tasks. Require explicitly using <code>require "buildr/hibernate"</code>.
23
+ module Hibernate
24
+
25
+ REQUIRES = Buildr.struct(
26
+ :collections => "commons-collections:commons-collections:jar:3.1",
27
+ :logging => "commons-logging:commons-logging:jar:1.0.3",
28
+ :dom4j => "dom4j:dom4j:jar:1.6.1",
29
+ :hibernate => "org.hibernate:hibernate:jar:3.1.2",
30
+ :xdoclet => Buildr.group("xdoclet", "xdoclet-xdoclet-module", "xdoclet-hibernate-module",
31
+ # :under=>"xdoclet", :version=>"1.2.3") + ["xdoclet:xjavadoc:jar:1.1-j5"]
32
+ :under=>"xdoclet", :version=>"1.2.3") + ["xdoclet:xjavadoc:jar:1.1"]
33
+ )
34
+
35
+ class << self
36
+ include Buildr::Ant
37
+
38
+ # :call-seq:
39
+ # doclet(options) => AntProject
40
+ #
41
+ # Uses XDoclet to generate HBM files form annotated source files.
42
+ # Options include:
43
+ # * :sources -- Directory (or directories) containing source files.
44
+ # * :target -- The target directory.
45
+ # * :excludetags -- Tags to exclude (see HibernateDocletTask)
46
+ #
47
+ # For example:
48
+ # doclet :sources=>compile.sources, :target=>compile.target, :excludedtags=>"@version,@author,@todo"
49
+ def doclet(options)
50
+ options[:sources].each { |src| file(src).invoke }
51
+ ant "hibernatedoclet" do |ant|
52
+ ant.taskdef :name=>"hibernatedoclet", :classname=>"xdoclet.modules.hibernate.HibernateDocletTask", :classpath=>requires
53
+ ant.hibernatedoclet :destdir=>options[:target].to_s, :excludedtags=>options[:excludedtags], :force=>"true" do
54
+ ant.hibernate :version=>"3.0"
55
+ options[:sources].map(&:to_s).each do |source|
56
+ ant.fileset :dir=>source.to_s, :includes=>"**/*.java"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ # :call-seq:
63
+ # schemaexport(properties) { ... } => AntProject
64
+ #
65
+ # Runs the Hibernate SchemaExportTask with the specified properties. For example:
66
+ # Buildr::Hibernate.schemaexport(:properties=>properties.to_s, :quiet=>"yes", :text=>"yes", :delimiter=>";",
67
+ # :drop=>"no", :create=>"yes", :output=>target) do
68
+ # fileset :dir=>source.to_s, :includes=>"**/*.hbm.xml"
69
+ # end
70
+ def schemaexport(options = nil)
71
+ ant "schemaexport" do |ant|
72
+ ant.taskdef :name=>"schemaexport", :classname=>"org.hibernate.tool.hbm2ddl.SchemaExportTask", :classpath=>requires
73
+ ant.schemaexport(options) { yield ant if block_given? } if options
74
+ end
75
+ end
76
+
77
+ protected
78
+
79
+ # This will download all the required artifacts before returning a classpath, and we want to do this only once.
80
+ def requires()
81
+ @requires ||= Buildr.artifacts(REQUIRES.to_a).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
82
+ end
83
+
84
+ end
85
+
86
+ # :call-seq:
87
+ # hibernate_doclet(options?) => task
88
+ #
89
+ # Runs the hibernate doclet on the source files and creates HBM files in the target directory.
90
+ # By default runs on all source files, but you can limit it to a given package using the :package
91
+ # options. You can also pass other options to the doclet task.
92
+ #
93
+ # For example:
94
+ # resources hibernate_doclet(:package=>"org.apache.ode.store.hib", :excludedtags=>"@version,@author,@todo")
95
+ def hibernate_doclet(options = {})
96
+ if options[:package]
97
+ depends = compile.sources.map { |src| FileList[File.join(src.to_s, options[:package].gsub(".", "/"), "*.java")] }.flatten
98
+ else
99
+ depends = compile.sources.map { |src| FileList[File.join(src.to_s, "**/*.java")] }.flatten
100
+ end
101
+ file("target/hbm.timestamp"=>depends) do |task|
102
+ Hibernate.doclet({ :sources=>compile.sources, :target=>compile.target }.merge(options))
103
+ write task.name
104
+ end
105
+ end
106
+
107
+ # :call-seq:
108
+ # hibernate_schemaexport(path) => task
109
+ # hibernate_schemaexport(path) { |task, ant| .. } => task
110
+ #
111
+ # Returns an new file task with an accessor (ant) to an AntProject that defines the schemaexport task.
112
+ # If called with a block, the task will yield to the block passing both itself and the Ant project.
113
+ #
114
+ # See #schemaexport.
115
+ #
116
+ # For example:
117
+ # hibernate_schemaexport "derby.sql" do |task, ant|
118
+ # ant.schemaexport :properties=>"derby.properties", :output=>task.name,
119
+ # :delimiter=>";", :drop=>"no", :create=>"yes" do
120
+ # fileset(:dir=>compile.sources.first) { include :name=>"**/*.hbm.xml" } }
121
+ # end
122
+ # end
123
+ def hibernate_schemaexport(args, &block)
124
+ path, arg_names, deps = Rake.application.resolve_args([args])
125
+ unless Rake::Task.task_defined?(path)
126
+ class << file(path) ; attr_accessor :ant ; end
127
+ file(path).enhance { |task| task.ant = Hibernate.schemaexport }
128
+ end
129
+ if block
130
+ file(path).enhance(deps) { |task| block.call task, task.ant }
131
+ else
132
+ file(path).enhance deps
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ class Project
139
+ include Hibernate
140
+ end
141
+
142
+ end