assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,211 @@
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
+ # Base module for all things Java.
18
+ module Java
19
+
20
+ # JDK commands: java, javac, javadoc, etc.
21
+ module Commands
22
+
23
+ class << self
24
+
25
+ # :call-seq:
26
+ # java(class, *args, options?)
27
+ #
28
+ # Runs Java with the specified arguments.
29
+ #
30
+ # The last argument may be a Hash with additional options:
31
+ # * :classpath -- One or more file names, tasks or artifact specifications.
32
+ # These are all expanded into artifacts, and all tasks are invoked.
33
+ # * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
34
+ # * :properties -- Hash of system properties (e.g. 'path'=>base_dir).
35
+ # * :name -- Shows this name, otherwise shows the first argument (the class name).
36
+ # * :verbose -- If true, prints the command and all its argument.
37
+ def java(*args, &block)
38
+ options = Hash === args.last ? args.pop : {}
39
+ options[:verbose] ||= Buildr.application.options.trace || false
40
+ rake_check_options options, :classpath, :java_args, :properties, :name, :verbose
41
+
42
+ name = options[:name] || "java #{args.first}"
43
+ cmd_args = [path_to_bin('java')]
44
+ classpath = classpath_from(options)
45
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
46
+ options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
47
+ cmd_args += (options[:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
48
+ cmd_args += args.flatten.compact
49
+ unless Buildr.application.options.dryrun
50
+ info "Running #{name}"
51
+ block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
52
+ puts cmd_args.join(' ') if Buildr.application.options.trace
53
+ cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
54
+ system(*cmd_args).tap do |ok|
55
+ block.call ok, $?
56
+ end
57
+ end
58
+ end
59
+
60
+ # :call-seq:
61
+ # apt(*files, options)
62
+ #
63
+ # Runs Apt with the specified arguments.
64
+ #
65
+ # The last argument may be a Hash with additional options:
66
+ # * :compile -- If true, compile source files to class files.
67
+ # * :source -- Specifies source compatibility with a given JVM release.
68
+ # * :output -- Directory where to place the generated source files, or the
69
+ # generated class files when compiling.
70
+ # * :classpath -- One or more file names, tasks or artifact specifications.
71
+ # These are all expanded into artifacts, and all tasks are invoked.
72
+ def apt(*args)
73
+ options = Hash === args.last ? args.pop : {}
74
+ rake_check_options options, :compile, :source, :output, :classpath
75
+
76
+ files = args.flatten.map(&:to_s).
77
+ collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
78
+ cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
79
+ if options[:compile]
80
+ cmd_args << '-d' << options[:output].to_s
81
+ else
82
+ cmd_args << '-nocompile' << '-s' << options[:output].to_s
83
+ end
84
+ cmd_args << '-source' << options[:source] if options[:source]
85
+ classpath = classpath_from(options)
86
+ tools = Java.tools_jar
87
+ classpath << tools if tools
88
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
89
+ cmd_args += files
90
+ unless Buildr.application.options.dryrun
91
+ info 'Running apt'
92
+ trace (['apt'] + cmd_args).join(' ')
93
+ Java.load
94
+ Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
95
+ fail 'Failed to process annotations, see errors above'
96
+ end
97
+ end
98
+
99
+ # :call-seq:
100
+ # javac(*files, options)
101
+ #
102
+ # Runs Javac with the specified arguments.
103
+ #
104
+ # The last argument may be a Hash with additional options:
105
+ # * :output -- Target directory for all compiled class files.
106
+ # * :classpath -- One or more file names, tasks or artifact specifications.
107
+ # These are all expanded into artifacts, and all tasks are invoked.
108
+ # * :sourcepath -- Additional source paths to use.
109
+ # * :javac_args -- Any additional arguments to pass (e.g. -extdirs, -encoding)
110
+ # * :name -- Shows this name, otherwise shows the working directory.
111
+ def javac(*args)
112
+ options = Hash === args.last ? args.pop : {}
113
+ rake_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
114
+
115
+ files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
116
+ collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
117
+ name = options[:name] || Dir.pwd
118
+
119
+ cmd_args = []
120
+ classpath = classpath_from(options)
121
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
122
+ cmd_args << '-sourcepath' << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
123
+ cmd_args << '-d' << options[:output].to_s if options[:output]
124
+ cmd_args += options[:javac_args].flatten if options[:javac_args]
125
+ cmd_args += files
126
+ unless Buildr.application.options.dryrun
127
+ info "Compiling #{files.size} source files in #{name}"
128
+ trace (['javac'] + cmd_args).join(' ')
129
+ Java.load
130
+ Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
131
+ fail 'Failed to compile, see errors above'
132
+ end
133
+ end
134
+
135
+ # :call-seq:
136
+ # javadoc(*files, options)
137
+ #
138
+ # Runs Javadocs with the specified files and options.
139
+ #
140
+ # This method accepts the following special options:
141
+ # * :output -- The output directory
142
+ # * :classpath -- Array of classpath dependencies.
143
+ # * :sourcepath -- Array of sourcepaths (paths or tasks).
144
+ # * :name -- Shows this name, otherwise shows the working directory.
145
+ #
146
+ # All other options are passed to Javadoc as following:
147
+ # * true -- As is, for example, :author=>true becomes -author
148
+ # * false -- Prefixed, for example, :index=>false becomes -noindex
149
+ # * string -- Option with value, for example, :windowtitle=>'My project' becomes -windowtitle "My project"
150
+ # * array -- Option with set of values separated by spaces.
151
+ def javadoc(*args)
152
+ options = Hash === args.last ? args.pop : {}
153
+
154
+ cmd_args = [ '-d', options[:output], Buildr.application.options.trace ? '-verbose' : '-quiet' ]
155
+ options.reject { |key, value| [:output, :name, :sourcepath, :classpath].include?(key) }.
156
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
157
+ each do |key, value|
158
+ case value
159
+ when true, nil
160
+ cmd_args << "-#{key}"
161
+ when false
162
+ cmd_args << "-no#{key}"
163
+ when Hash
164
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
165
+ else
166
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
167
+ end
168
+ end
169
+ [:sourcepath, :classpath].each do |option|
170
+ options[option].to_a.flatten.tap do |paths|
171
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
172
+ end
173
+ end
174
+ cmd_args += args.flatten.uniq
175
+ name = options[:name] || Dir.pwd
176
+ unless Buildr.application.options.dryrun
177
+ info "Generating Javadoc for #{name}"
178
+ trace (['javadoc'] + cmd_args).join(' ')
179
+ Java.load
180
+ Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
181
+ fail 'Failed to generate Javadocs, see errors above'
182
+ end
183
+ end
184
+
185
+ protected
186
+
187
+ # :call-seq:
188
+ # path_to_bin(cmd?) => path
189
+ #
190
+ # Returns the path to the specified Java command (with no argument to java itself).
191
+ def path_to_bin(name = nil)
192
+ home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
193
+ File.expand_path(File.join(home, 'bin', name.to_s))
194
+ end
195
+
196
+ # :call-seq:
197
+ # classpath_from(options) => files
198
+ #
199
+ # Extracts the classpath from the options, expands it by calling artifacts, invokes
200
+ # each of the artifacts and returns an array of paths.
201
+ def classpath_from(options)
202
+ Buildr.artifacts(options[:classpath] || []).map(&:to_s).
203
+ map { |t| task(t).invoke; File.expand_path(t) }
204
+ end
205
+
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
@@ -0,0 +1,348 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/core/project'
18
+ require 'buildr/core/common'
19
+ require 'buildr/core/compile'
20
+ require 'buildr/packaging'
21
+
22
+
23
+ module Buildr
24
+ module Compiler
25
+
26
+ # Javac compiler:
27
+ # compile.using(:javac)
28
+ # Used by default if .java files are found in the src/main/java directory (or src/test/java)
29
+ # and sets the target directory to target/classes (or target/test/classes).
30
+ #
31
+ # Accepts the following options:
32
+ # * :warnings -- Issue warnings when compiling. True when running in verbose mode.
33
+ # * :debug -- Generates bytecode with debugging information. Set from the debug
34
+ # environment variable/global option.
35
+ # * :deprecation -- If true, shows deprecation messages. False by default.
36
+ # * :source -- Source code compatibility.
37
+ # * :target -- Bytecode compatibility.
38
+ # * :lint -- Lint option is one of true, false (default), name (e.g. 'cast') or array.
39
+ # * :other -- Array of options passed to the compiler (e.g. '-implicit:none')
40
+ class Javac < Base
41
+
42
+ OPTIONS = [:warnings, :debug, :deprecation, :source, :target, :lint, :other]
43
+
44
+ specify :language=>:java, :target=>'classes', :target_ext=>'class', :packaging=>:jar
45
+
46
+ def initialize(project, options) #:nodoc:
47
+ super
48
+ options[:debug] = Buildr.options.debug if options[:debug].nil?
49
+ options[:warnings] = verbose if options[:warnings].nil?
50
+ options[:deprecation] ||= false
51
+ options[:lint] ||= false
52
+ end
53
+
54
+ def compile(sources, target, dependencies) #:nodoc:
55
+ check_options options, OPTIONS
56
+ cmd_args = []
57
+ # tools.jar contains the Java compiler.
58
+ dependencies << Java.tools_jar if Java.tools_jar
59
+ cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
60
+ source_paths = sources.select { |source| File.directory?(source) }
61
+ cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
62
+ cmd_args << '-d' << File.expand_path(target)
63
+ cmd_args += javac_args
64
+ cmd_args += files_from_sources(sources)
65
+ unless Buildr.application.options.dryrun
66
+ trace((['javac'] + cmd_args).join(' '))
67
+ Java.load
68
+ Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
69
+ fail 'Failed to compile, see errors above'
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def javac_args #:nodoc:
76
+ args = []
77
+ args << '-nowarn' unless options[:warnings]
78
+ args << '-verbose' if Buildr.application.options.trace
79
+ args << '-g' if options[:debug]
80
+ args << '-deprecation' if options[:deprecation]
81
+ args << '-source' << options[:source].to_s if options[:source]
82
+ args << '-target' << options[:target].to_s if options[:target]
83
+ case options[:lint]
84
+ when Array then args << "-Xlint:#{options[:lint].join(',')}"
85
+ when String then args << "-Xlint:#{options[:lint]}"
86
+ when true then args << '-Xlint'
87
+ end
88
+ args + Array(options[:other])
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+
96
+ # Methods added to Project for creating JavaDoc documentation.
97
+ module Javadoc
98
+
99
+ # A convenient task for creating Javadocs from the project's compile task. Minimizes all
100
+ # the hard work to calling #from and #using.
101
+ #
102
+ # For example:
103
+ # javadoc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')
104
+ # Or, short and sweet:
105
+ # desc 'My App'
106
+ # define 'myapp' do
107
+ # . . .
108
+ # javadoc projects('myapp:foo', 'myapp:bar')
109
+ # end
110
+ class JavadocTask < Rake::Task
111
+
112
+ def initialize(*args) #:nodoc:
113
+ super
114
+ @options = {}
115
+ @classpath = []
116
+ @sourcepath = []
117
+ @files = FileList[]
118
+ enhance do |task|
119
+ rm_rf target.to_s, :verbose=>false
120
+ generate source_files, File.expand_path(target.to_s), options.merge(:classpath=>classpath, :sourcepath=>sourcepath)
121
+ touch target.to_s, :verbose=>false
122
+ end
123
+ end
124
+
125
+ # The target directory for the generated Javadoc files.
126
+ attr_reader :target
127
+
128
+ # :call-seq:
129
+ # into(path) => self
130
+ #
131
+ # Sets the target directory and returns self. This will also set the Javadoc task
132
+ # as a prerequisite to a file task on the target directory.
133
+ #
134
+ # For example:
135
+ # package :zip, :classifier=>'docs', :include=>javadoc.target
136
+ def into(path)
137
+ @target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
138
+ self
139
+ end
140
+
141
+ # :call-seq:
142
+ # include(*files) => self
143
+ #
144
+ # Includes additional source files and directories when generating the documentation
145
+ # and returns self. When specifying a directory, includes all .java files in that directory.
146
+ def include(*files)
147
+ @files.include *files.flatten.compact
148
+ self
149
+ end
150
+
151
+ # :call-seq:
152
+ # exclude(*files) => self
153
+ #
154
+ # Excludes source files and directories from generating the documentation.
155
+ def exclude(*files)
156
+ @files.exclude *files
157
+ self
158
+ end
159
+
160
+ # Classpath dependencies.
161
+ attr_accessor :classpath
162
+
163
+ # :call-seq:
164
+ # with(*artifacts) => self
165
+ #
166
+ # Adds files and artifacts as classpath dependencies, and returns self.
167
+ def with(*specs)
168
+ @classpath |= Buildr.artifacts(specs.flatten).uniq
169
+ self
170
+ end
171
+
172
+ # Additional sourcepaths that are not part of the documented files.
173
+ attr_accessor :sourcepath
174
+
175
+ # Returns the Javadoc options.
176
+ attr_reader :options
177
+
178
+ # :call-seq:
179
+ # using(options) => self
180
+ #
181
+ # Sets the Javadoc options from a hash and returns self.
182
+ #
183
+ # For example:
184
+ # javadoc.using :windowtitle=>'My application'
185
+ def using(*args)
186
+ args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
187
+ args.each { |key| @options[key.to_sym] = true }
188
+ self
189
+ end
190
+
191
+ # :call-seq:
192
+ # from(*sources) => self
193
+ #
194
+ # Includes files, directories and projects in the Javadoc documentation and returns self.
195
+ #
196
+ # You can call this method with Java source files and directories containing Java source files
197
+ # to include these files in the Javadoc documentation, similar to #include. You can also call
198
+ # this method with projects. When called with a project, it includes all the source files compiled
199
+ # by that project and classpath dependencies used when compiling.
200
+ #
201
+ # For example:
202
+ # javadoc.from projects('myapp:foo', 'myapp:bar')
203
+ def from(*sources)
204
+ sources.flatten.each do |source|
205
+ case source
206
+ when Project
207
+ self.enhance source.prerequisites
208
+ self.include source.compile.sources
209
+ self.with source.compile.dependencies
210
+ when Rake::Task, String
211
+ self.include source
212
+ else
213
+ fail "Don't know how to generate Javadocs from #{source || 'nil'}"
214
+ end
215
+ end
216
+ self
217
+ end
218
+
219
+ def prerequisites() #:nodoc:
220
+ super + @files + classpath + sourcepath
221
+ end
222
+
223
+ def source_files() #:nodoc:
224
+ @source_files ||= @files.map(&:to_s).
225
+ map { |file| File.directory?(file) ? FileList[File.join(file, "**/*.java")] : file }.
226
+ flatten.reject { |file| @files.exclude?(file) }
227
+ end
228
+
229
+ def needed?() #:nodoc:
230
+ return false if source_files.empty?
231
+ return true unless File.exist?(target.to_s)
232
+ source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
233
+ end
234
+
235
+ private
236
+
237
+ def generate(sources, target, options = {})
238
+ cmd_args = [ '-d', target, Buildr.application.options.trace ? '-verbose' : '-quiet' ]
239
+ options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
240
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
241
+ each do |key, value|
242
+ case value
243
+ when true, nil
244
+ cmd_args << "-#{key}"
245
+ when false
246
+ cmd_args << "-no#{key}"
247
+ when Hash
248
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
249
+ else
250
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
251
+ end
252
+ end
253
+ [:sourcepath, :classpath].each do |option|
254
+ Array(options[option]).flatten.tap do |paths|
255
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
256
+ end
257
+ end
258
+ cmd_args += sources.flatten.uniq
259
+ unless Buildr.application.options.dryrun
260
+ info "Generating Javadoc for #{name}"
261
+ trace (['javadoc'] + cmd_args).join(' ')
262
+ Java.load
263
+ Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
264
+ fail 'Failed to generate Javadocs, see errors above'
265
+ end
266
+ end
267
+
268
+ end
269
+
270
+
271
+ include Extension
272
+
273
+ first_time do
274
+ desc 'Create the Javadocs for this project'
275
+ Project.local_task('javadoc')
276
+ end
277
+
278
+ before_define do |project|
279
+ JavadocTask.define_task('javadoc').tap do |javadoc|
280
+ javadoc.into project.path_to(:target, :javadoc)
281
+ javadoc.using :windowtitle=>project.comment || project.name
282
+ end
283
+ end
284
+
285
+ after_define do |project|
286
+ project.javadoc.from project
287
+ end
288
+
289
+ # :call-seq:
290
+ # javadoc(*sources) => JavadocTask
291
+ #
292
+ # This method returns the project's Javadoc task. It also accepts a list of source files,
293
+ # directories and projects to include when generating the Javadocs.
294
+ #
295
+ # By default the Javadoc task uses all the source directories from compile.sources and generates
296
+ # Javadocs in the target/javadoc directory. This method accepts sources and adds them by calling
297
+ # JavadocsTask#from.
298
+ #
299
+ # For example, if you want to generate Javadocs for a given project that includes all source files
300
+ # in two of its sub-projects:
301
+ # javadoc projects('myapp:foo', 'myapp:bar').using(:windowtitle=>'Docs for foo and bar')
302
+ def javadoc(*sources, &block)
303
+ task('javadoc').from(*sources).enhance &block
304
+ end
305
+
306
+ end
307
+
308
+
309
+ # Methods added to Project to support the Java Annotation Processor.
310
+ module Apt
311
+
312
+ # :call-seq:
313
+ # apt(*sources) => task
314
+ #
315
+ # Returns a task that will use Java#apt to generate source files in target/generated/apt,
316
+ # from all the source directories passed as arguments. Uses the compile.sources list if
317
+ # on arguments supplied.
318
+ #
319
+ # For example:
320
+ #
321
+ def apt(*sources)
322
+ sources = compile.sources if sources.empty?
323
+ file(path_to(:target, 'generated/apt')=>sources) do |task|
324
+ cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
325
+ cmd_args << '-nocompile' << '-s' << task.name
326
+ cmd_args << '-source' << compile.options.source if compile.options.source
327
+ classpath = Buildr.artifacts(compile.dependencies).map(&:to_s).each { |t| task(t).invoke }
328
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
329
+ cmd_args += (sources.map(&:to_s) - [task.name]).
330
+ map { |file| File.directory?(file) ? FileList["#{file}/**/*.java"] : file }.flatten
331
+ unless Buildr.application.options.dryrun
332
+ info 'Running apt'
333
+ trace (['apt'] + cmd_args).join(' ')
334
+ Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
335
+ fail 'Failed to process annotations, see errors above'
336
+ end
337
+ end
338
+ end
339
+
340
+ end
341
+
342
+ end
343
+
344
+ Buildr::Compiler << Buildr::Compiler::Javac
345
+ class Buildr::Project
346
+ include Buildr::Javadoc
347
+ include Buildr::Apt
348
+ end