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,210 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ # 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
+ puts "Running #{name}" if verbose
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
+ system(*cmd_args).tap do |ok|
54
+ block.call ok, $?
55
+ end
56
+ end
57
+ end
58
+
59
+ # :call-seq:
60
+ # apt(*files, options)
61
+ #
62
+ # Runs Apt with the specified arguments.
63
+ #
64
+ # The last argument may be a Hash with additional options:
65
+ # * :compile -- If true, compile source files to class files.
66
+ # * :source -- Specifies source compatibility with a given JVM release.
67
+ # * :output -- Directory where to place the generated source files, or the
68
+ # generated class files when compiling.
69
+ # * :classpath -- One or more file names, tasks or artifact specifications.
70
+ # These are all expanded into artifacts, and all tasks are invoked.
71
+ def apt(*args)
72
+ options = Hash === args.last ? args.pop : {}
73
+ rake_check_options options, :compile, :source, :output, :classpath
74
+
75
+ files = args.flatten.map(&:to_s).
76
+ collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
77
+ cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
78
+ if options[:compile]
79
+ cmd_args << '-d' << options[:output].to_s
80
+ else
81
+ cmd_args << '-nocompile' << '-s' << options[:output].to_s
82
+ end
83
+ cmd_args << '-source' << options[:source] if options[:source]
84
+ classpath = classpath_from(options)
85
+ tools = File.expand_path('lib/tools.jar', ENV['JAVA_HOME']) if ENV['JAVA_HOME']
86
+ classpath << tools if tools && File.exist?(tools)
87
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
88
+ cmd_args += files
89
+ unless Buildr.application.options.dryrun
90
+ puts 'Running apt' if verbose
91
+ puts (['apt'] + cmd_args).join(' ') if Buildr.application.options.trace
92
+ Java.load
93
+ Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
94
+ fail 'Failed to process annotations, see errors above'
95
+ end
96
+ end
97
+
98
+ # :call-seq:
99
+ # javac(*files, options)
100
+ #
101
+ # Runs Javac with the specified arguments.
102
+ #
103
+ # The last argument may be a Hash with additional options:
104
+ # * :output -- Target directory for all compiled class files.
105
+ # * :classpath -- One or more file names, tasks or artifact specifications.
106
+ # These are all expanded into artifacts, and all tasks are invoked.
107
+ # * :sourcepath -- Additional source paths to use.
108
+ # * :javac_args -- Any additional arguments to pass (e.g. -extdirs, -encoding)
109
+ # * :name -- Shows this name, otherwise shows the working directory.
110
+ def javac(*args)
111
+ options = Hash === args.last ? args.pop : {}
112
+ rake_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
113
+
114
+ files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
115
+ collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
116
+ name = options[:name] || Dir.pwd
117
+
118
+ cmd_args = []
119
+ classpath = classpath_from(options)
120
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
121
+ cmd_args << '-sourcepath' << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
122
+ cmd_args << '-d' << options[:output].to_s if options[:output]
123
+ cmd_args += options[:javac_args].flatten if options[:javac_args]
124
+ cmd_args += files
125
+ unless Buildr.application.options.dryrun
126
+ puts "Compiling #{files.size} source files in #{name}" if verbose
127
+ puts (['javac'] + cmd_args).join(' ') if Buildr.application.options.trace
128
+ Java.load
129
+ Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
130
+ fail 'Failed to compile, see errors above'
131
+ end
132
+ end
133
+
134
+ # :call-seq:
135
+ # javadoc(*files, options)
136
+ #
137
+ # Runs Javadocs with the specified files and options.
138
+ #
139
+ # This method accepts the following special options:
140
+ # * :output -- The output directory
141
+ # * :classpath -- Array of classpath dependencies.
142
+ # * :sourcepath -- Array of sourcepaths (paths or tasks).
143
+ # * :name -- Shows this name, otherwise shows the working directory.
144
+ #
145
+ # All other options are passed to Javadoc as following:
146
+ # * true -- As is, for example, :author=>true becomes -author
147
+ # * false -- Prefixed, for example, :index=>false becomes -noindex
148
+ # * string -- Option with value, for example, :windowtitle=>'My project' becomes -windowtitle "My project"
149
+ # * array -- Option with set of values separated by spaces.
150
+ def javadoc(*args)
151
+ options = Hash === args.last ? args.pop : {}
152
+
153
+ cmd_args = [ '-d', options[:output], Buildr.application.options.trace ? '-verbose' : '-quiet' ]
154
+ options.reject { |key, value| [:output, :name, :sourcepath, :classpath].include?(key) }.
155
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
156
+ each do |key, value|
157
+ case value
158
+ when true, nil
159
+ cmd_args << "-#{key}"
160
+ when false
161
+ cmd_args << "-no#{key}"
162
+ when Hash
163
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
164
+ else
165
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
166
+ end
167
+ end
168
+ [:sourcepath, :classpath].each do |option|
169
+ options[option].to_a.flatten.tap do |paths|
170
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
171
+ end
172
+ end
173
+ cmd_args += args.flatten.uniq
174
+ name = options[:name] || Dir.pwd
175
+ unless Buildr.application.options.dryrun
176
+ puts "Generating Javadoc for #{name}" if verbose
177
+ puts (['javadoc'] + cmd_args).join(' ') if Buildr.application.options.trace
178
+ Java.load
179
+ Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
180
+ fail 'Failed to generate Javadocs, see errors above'
181
+ end
182
+ end
183
+
184
+ protected
185
+
186
+ # :call-seq:
187
+ # path_to_bin(cmd?) => path
188
+ #
189
+ # Returns the path to the specified Java command (with no argument to java itself).
190
+ def path_to_bin(name = nil)
191
+ home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
192
+ File.expand_path(File.join(home, 'bin', name.to_s))
193
+ end
194
+
195
+ # :call-seq:
196
+ # classpath_from(options) => files
197
+ #
198
+ # Extracts the classpath from the options, expands it by calling artifacts, invokes
199
+ # each of the artifacts and returns an array of paths.
200
+ def classpath_from(options)
201
+ Buildr.artifacts(options[:classpath] || []).map(&:to_s).
202
+ map { |t| task(t).invoke; File.expand_path(t) }
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
@@ -0,0 +1,432 @@
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 = File.expand_path('lib/tools.jar', ENV['JAVA_HOME']) if ENV['JAVA_HOME']
58
+ dependencies << tools if tools && File.exist?(tools)
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
+ puts (['javac'] + cmd_args).join(' ') if Buildr.application.options.trace
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
+
94
+ # Scalac compiler:
95
+ # compile.using(:scalac)
96
+ # Used by default if .scala files are found in the src/main/scala directory (or src/test/scala)
97
+ # and sets the target directory to target/classes (or target/test/classes).
98
+ #
99
+ # Accepts the following options:
100
+ # * :warnings -- Generate warnings if true (opposite of -nowarn).
101
+ # * :deprecation -- Output source locations where deprecated APIs are used.
102
+ # * :optimise -- Generates faster bytecode by applying optimisations to the program.
103
+ # * :source -- Source compatibility with specified release.
104
+ # * :target -- Class file compatibility with specified release.
105
+ # * :debug -- Generate debugging info.
106
+ # * :other -- Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types
107
+ class Scalac < Base
108
+ class << self
109
+ def scala_home
110
+ @home ||= ENV['SCALA_HOME']
111
+ end
112
+
113
+ def dependencies
114
+ [ 'scala-library.jar', 'scala-compiler.jar'].map { |jar| File.expand_path("lib/#{jar}", scala_home) }
115
+ end
116
+
117
+ def use_fsc
118
+ ENV["USE_FSC"] =~ /^(yes|on|true)$/i
119
+ end
120
+ end
121
+
122
+ OPTIONS = [:warnings, :deprecation, :optimise, :source, :target, :debug, :other]
123
+ Java.classpath << dependencies unless Scalac.use_fsc
124
+
125
+ specify :language=>:scala, :target=>'classes', :target_ext=>'class', :packaging=>:jar
126
+
127
+ def initialize(project, options) #:nodoc:
128
+ super
129
+ options[:debug] = Buildr.options.debug if options[:debug].nil?
130
+ options[:warnings] = verbose if options[:warnings].nil?
131
+ options[:deprecation] ||= false
132
+ options[:optimise] ||= false
133
+ end
134
+
135
+ def compile(sources, target, dependencies) #:nodoc:
136
+ check_options options, OPTIONS
137
+
138
+ cmd_args = []
139
+ cmd_args << '-classpath' << (dependencies + Scalac.dependencies).join(File::PATH_SEPARATOR)
140
+ source_paths = sources.select { |source| File.directory?(source) }
141
+ cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
142
+ cmd_args << '-d' << File.expand_path(target)
143
+ cmd_args += scalac_args
144
+ cmd_args += files_from_sources(sources)
145
+
146
+ unless Buildr.application.options.dryrun
147
+ Scalac.scala_home or fail 'Are we forgetting something? SCALA_HOME not set.'
148
+ puts (['scalac'] + cmd_args).join(' ') if Buildr.application.options.trace
149
+ if Scalac.use_fsc
150
+ system(([File.expand_path('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or
151
+ fail 'Failed to compile, see errors above'
152
+ else
153
+ Java.load
154
+ Java.scala.tools.nsc.Main.process(cmd_args.to_java(Java.java.lang.String))
155
+ fail 'Failed to compile, see errors above' if Java.scala.tools.nsc.Main.reporter.hasErrors
156
+ end
157
+ end
158
+ end
159
+
160
+ private
161
+
162
+ # Returns Scalac command line arguments from the set of options.
163
+ def scalac_args #:nodoc:
164
+ args = []
165
+ args << "-nowarn" unless options[:warnings]
166
+ args << "-verbose" if Buildr.application.options.trace
167
+ args << "-g" if options[:debug]
168
+ args << "-deprecation" if options[:deprecation]
169
+ args << "-optimise" if options[:optimise]
170
+ args << "-source" << options[:source].to_s if options[:source]
171
+ args << "-target:jvm-" + options[:target].to_s if options[:target]
172
+ args + Array(options[:other])
173
+ end
174
+
175
+ end
176
+ end
177
+
178
+
179
+ # Methods added to Project for creating JavaDoc documentation.
180
+ module Javadoc
181
+
182
+ # A convenient task for creating Javadocs from the project's compile task. Minimizes all
183
+ # the hard work to calling #from and #using.
184
+ #
185
+ # For example:
186
+ # javadoc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')
187
+ # Or, short and sweet:
188
+ # desc 'My App'
189
+ # define 'myapp' do
190
+ # . . .
191
+ # javadoc projects('myapp:foo', 'myapp:bar')
192
+ # end
193
+ class JavadocTask < Rake::Task
194
+
195
+ def initialize(*args) #:nodoc:
196
+ super
197
+ @options = {}
198
+ @classpath = []
199
+ @sourcepath = []
200
+ @files = FileList[]
201
+ enhance do |task|
202
+ rm_rf target.to_s, :verbose=>false
203
+ generate source_files, File.expand_path(target.to_s), options.merge(:classpath=>classpath, :sourcepath=>sourcepath)
204
+ touch target.to_s, :verbose=>false
205
+ end
206
+ end
207
+
208
+ # The target directory for the generated Javadoc files.
209
+ attr_reader :target
210
+
211
+ # :call-seq:
212
+ # into(path) => self
213
+ #
214
+ # Sets the target directory and returns self. This will also set the Javadoc task
215
+ # as a prerequisite to a file task on the target directory.
216
+ #
217
+ # For example:
218
+ # package :zip, :classifier=>'docs', :include=>javadoc.target
219
+ def into(path)
220
+ @target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
221
+ self
222
+ end
223
+
224
+ # :call-seq:
225
+ # include(*files) => self
226
+ #
227
+ # Includes additional source files and directories when generating the documentation
228
+ # and returns self. When specifying a directory, includes all .java files in that directory.
229
+ def include(*files)
230
+ @files.include *files.flatten.compact
231
+ self
232
+ end
233
+
234
+ # :call-seq:
235
+ # exclude(*files) => self
236
+ #
237
+ # Excludes source files and directories from generating the documentation.
238
+ def exclude(*files)
239
+ @files.exclude *files
240
+ self
241
+ end
242
+
243
+ # Classpath dependencies.
244
+ attr_accessor :classpath
245
+
246
+ # :call-seq:
247
+ # with(*artifacts) => self
248
+ #
249
+ # Adds files and artifacts as classpath dependencies, and returns self.
250
+ def with(*specs)
251
+ @classpath |= Buildr.artifacts(specs.flatten).uniq
252
+ self
253
+ end
254
+
255
+ # Additional sourcepaths that are not part of the documented files.
256
+ attr_accessor :sourcepath
257
+
258
+ # Returns the Javadoc options.
259
+ attr_reader :options
260
+
261
+ # :call-seq:
262
+ # using(options) => self
263
+ #
264
+ # Sets the Javadoc options from a hash and returns self.
265
+ #
266
+ # For example:
267
+ # javadoc.using :windowtitle=>'My application'
268
+ def using(*args)
269
+ args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
270
+ args.each { |key| @options[key.to_sym] = true }
271
+ self
272
+ end
273
+
274
+ # :call-seq:
275
+ # from(*sources) => self
276
+ #
277
+ # Includes files, directories and projects in the Javadoc documentation and returns self.
278
+ #
279
+ # You can call this method with Java source files and directories containing Java source files
280
+ # to include these files in the Javadoc documentation, similar to #include. You can also call
281
+ # this method with projects. When called with a project, it includes all the source files compiled
282
+ # by that project and classpath dependencies used when compiling.
283
+ #
284
+ # For example:
285
+ # javadoc.from projects('myapp:foo', 'myapp:bar')
286
+ def from(*sources)
287
+ sources.flatten.each do |source|
288
+ case source
289
+ when Project
290
+ self.enhance source.prerequisites
291
+ self.include source.compile.sources
292
+ self.with source.compile.dependencies
293
+ when Rake::Task, String
294
+ self.include source
295
+ else
296
+ fail "Don't know how to generate Javadocs from #{source || 'nil'}"
297
+ end
298
+ end
299
+ self
300
+ end
301
+
302
+ def prerequisites() #:nodoc:
303
+ super + @files + classpath + sourcepath
304
+ end
305
+
306
+ def source_files() #:nodoc:
307
+ @source_files ||= @files.map(&:to_s).
308
+ map { |file| File.directory?(file) ? FileList[File.join(file, "**/*.java")] : file }.
309
+ flatten.reject { |file| @files.exclude?(file) }
310
+ end
311
+
312
+ def needed?() #:nodoc:
313
+ return false if source_files.empty?
314
+ return true unless File.exist?(target.to_s)
315
+ source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
316
+ end
317
+
318
+ private
319
+
320
+ def generate(sources, target, options = {})
321
+ cmd_args = [ '-d', target, Buildr.application.options.trace ? '-verbose' : '-quiet' ]
322
+ options.reject { |key, value| [:sourcepath, :classpath].include?(key) }.
323
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
324
+ each do |key, value|
325
+ case value
326
+ when true, nil
327
+ cmd_args << "-#{key}"
328
+ when false
329
+ cmd_args << "-no#{key}"
330
+ when Hash
331
+ value.each { |k,v| cmd_args << "-#{key}" << k.to_s << v.to_s }
332
+ else
333
+ cmd_args += Array(value).map { |item| ["-#{key}", item.to_s] }.flatten
334
+ end
335
+ end
336
+ [:sourcepath, :classpath].each do |option|
337
+ Array(options[option]).flatten.tap do |paths|
338
+ cmd_args << "-#{option}" << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
339
+ end
340
+ end
341
+ cmd_args += sources.flatten.uniq
342
+ unless Buildr.application.options.dryrun
343
+ puts "Generating Javadoc for #{name}" if verbose
344
+ puts (['javadoc'] + cmd_args).join(' ') if Buildr.application.options.trace
345
+ Java.load
346
+ Java.com.sun.tools.javadoc.Main.execute(cmd_args.to_java(Java.java.lang.String)) == 0 or
347
+ fail 'Failed to generate Javadocs, see errors above'
348
+ end
349
+ end
350
+
351
+ end
352
+
353
+
354
+ include Extension
355
+
356
+ first_time do
357
+ desc 'Create the Javadocs for this project'
358
+ Project.local_task('javadoc')
359
+ end
360
+
361
+ before_define do |project|
362
+ JavadocTask.define_task('javadoc').tap do |javadoc|
363
+ javadoc.into project.path_to(:target, :javadoc)
364
+ javadoc.using :windowtitle=>project.comment || project.name
365
+ end
366
+ end
367
+
368
+ after_define do |project|
369
+ project.javadoc.from project
370
+ end
371
+
372
+ # :call-seq:
373
+ # javadoc(*sources) => JavadocTask
374
+ #
375
+ # This method returns the project's Javadoc task. It also accepts a list of source files,
376
+ # directories and projects to include when generating the Javadocs.
377
+ #
378
+ # By default the Javadoc task uses all the source directories from compile.sources and generates
379
+ # Javadocs in the target/javadoc directory. This method accepts sources and adds them by calling
380
+ # JavadocsTask#from.
381
+ #
382
+ # For example, if you want to generate Javadocs for a given project that includes all source files
383
+ # in two of its sub-projects:
384
+ # javadoc projects('myapp:foo', 'myapp:bar').using(:windowtitle=>'Docs for foo and bar')
385
+ def javadoc(*sources, &block)
386
+ task('javadoc').from(*sources).enhance &block
387
+ end
388
+
389
+ end
390
+
391
+
392
+ # Methods added to Project to support the Java Annotation Processor.
393
+ module Apt
394
+
395
+ # :call-seq:
396
+ # apt(*sources) => task
397
+ #
398
+ # Returns a task that will use Java#apt to generate source files in target/generated/apt,
399
+ # from all the source directories passed as arguments. Uses the compile.sources list if
400
+ # on arguments supplied.
401
+ #
402
+ # For example:
403
+ #
404
+ def apt(*sources)
405
+ sources = compile.sources if sources.empty?
406
+ file(path_to(:target, 'generated/apt')=>sources) do |task|
407
+ cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
408
+ cmd_args << '-nocompile' << '-s' << task.name
409
+ cmd_args << '-source' << compile.options.source if compile.options.source
410
+ classpath = Buildr.artifacts(compile.dependencies).map(&:to_s).each { |t| task(t).invoke }
411
+ cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
412
+ cmd_args += (sources.map(&:to_s) - [task.name]).
413
+ map { |file| File.directory?(file) ? FileList["#{file}/**/*.java"] : file }.flatten
414
+ unless Buildr.application.options.dryrun
415
+ puts 'Running apt' if verbose
416
+ puts (['apt'] + cmd_args).join(' ') if Buildr.application.options.trace
417
+ Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
418
+ fail 'Failed to process annotations, see errors above'
419
+ end
420
+ end
421
+ end
422
+
423
+ end
424
+
425
+ end
426
+
427
+ Buildr::Compiler << Buildr::Compiler::Javac
428
+ Buildr::Compiler << Buildr::Compiler::Scalac
429
+ class Buildr::Project
430
+ include Buildr::Javadoc
431
+ include Buildr::Apt
432
+ end