mguymon-buildr 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- metadata +649 -0
@@ -0,0 +1,622 @@
|
|
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/common'
|
18
|
+
require 'find'
|
19
|
+
|
20
|
+
|
21
|
+
module Buildr
|
22
|
+
|
23
|
+
# The underlying compiler used by CompileTask.
|
24
|
+
# To add a new compiler, extend Compiler::Base and add your compiler using:
|
25
|
+
# Buildr::Compiler.add MyCompiler
|
26
|
+
module Compiler
|
27
|
+
|
28
|
+
class << self
|
29
|
+
|
30
|
+
# Returns true if the specified compiler exists.
|
31
|
+
def has?(name)
|
32
|
+
compilers.any? { |compiler| compiler.to_sym == name.to_sym }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Select a compiler by its name.
|
36
|
+
def select(name)
|
37
|
+
compilers.detect { |compiler| compiler.to_sym == name.to_sym }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Adds a compiler to the list of supported compiler.
|
41
|
+
#
|
42
|
+
# For example:
|
43
|
+
# Buildr::Compiler << Buildr::Javac
|
44
|
+
def add(compiler)
|
45
|
+
@compilers ||= []
|
46
|
+
@compilers |= [compiler]
|
47
|
+
end
|
48
|
+
alias :<< :add
|
49
|
+
|
50
|
+
# Returns a list of available compilers.
|
51
|
+
def compilers
|
52
|
+
@compilers ||= []
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Only used by our specs.
|
58
|
+
def compilers=(compilers)
|
59
|
+
@compilers = compilers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Base class for all compilers, with common functionality. Extend and over-ride as you see fit
|
64
|
+
# (see Javac as an example).
|
65
|
+
class Base #:nodoc:
|
66
|
+
|
67
|
+
class << self
|
68
|
+
|
69
|
+
# The compiler's identifier (e.g. :javac). Inferred from the class name.
|
70
|
+
def to_sym
|
71
|
+
@symbol ||= name.split('::').last.downcase.to_sym
|
72
|
+
end
|
73
|
+
|
74
|
+
# The compiled language (e.g. :java).
|
75
|
+
attr_reader :language
|
76
|
+
# Source directories to use if none were specified (e.g. 'java'). Defaults to #language.
|
77
|
+
attr_reader :sources
|
78
|
+
# Extension for source files (e.g. 'java'). Defaults to language.
|
79
|
+
attr_reader :source_ext
|
80
|
+
# The target path (e.g. 'classes')
|
81
|
+
attr_reader :target
|
82
|
+
# Extension for target files (e.g. 'class').
|
83
|
+
attr_reader :target_ext
|
84
|
+
# The default packaging type (e.g. :jar).
|
85
|
+
attr_reader :packaging
|
86
|
+
|
87
|
+
# Returns true if this compiler applies to any source code found in the listed source
|
88
|
+
# directories. For example, Javac returns true if any of the source directories contains
|
89
|
+
# a .java file. The default implementation looks to see if there are any files in the
|
90
|
+
# specified path with the extension #source_ext.
|
91
|
+
def applies_to?(project, task)
|
92
|
+
paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
|
93
|
+
paths.flatten!
|
94
|
+
ext_glob = Array(source_ext).join(',')
|
95
|
+
|
96
|
+
paths.each { |path|
|
97
|
+
Find.find(path) {|found|
|
98
|
+
if (!File.directory?(found)) && found.match(/.*\.#{Array(source_ext).join('|')}/)
|
99
|
+
return true
|
100
|
+
end
|
101
|
+
} if File.exist? path
|
102
|
+
}
|
103
|
+
false
|
104
|
+
end
|
105
|
+
|
106
|
+
# Implementations can use this method to specify various compiler attributes.
|
107
|
+
# For example:
|
108
|
+
# specify :language=>:java, :target=>'classes', :target_ext=>'class', :packaging=>:jar
|
109
|
+
def specify(attrs)
|
110
|
+
attrs[:sources] ||= attrs[:language].to_s
|
111
|
+
attrs[:source_ext] ||= attrs[:language].to_s
|
112
|
+
attrs.each { |name, value| instance_variable_set("@#{name}", value) }
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns additional dependencies required by this language. For example, since the
|
116
|
+
# test framework picks on these, you can use the JUnit framework with Scala.
|
117
|
+
# Defaults to obtaining a list of artifact specifications from the REQUIRES constant.
|
118
|
+
def dependencies
|
119
|
+
[]
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
# Construct a new compiler with the specified options. Note that options may
|
125
|
+
# change before the compiler is run.
|
126
|
+
def initialize(project, options)
|
127
|
+
@project = project
|
128
|
+
@options = options
|
129
|
+
end
|
130
|
+
|
131
|
+
# Options for this compiler.
|
132
|
+
attr_reader :options
|
133
|
+
|
134
|
+
# Determines if the compiler needs to run by checking if the target files exist,
|
135
|
+
# and if any source files or dependencies are newer than corresponding target files.
|
136
|
+
def needed?(sources, target, dependencies)
|
137
|
+
map = compile_map(sources, target)
|
138
|
+
return false if map.empty?
|
139
|
+
return true unless File.exist?(target.to_s)
|
140
|
+
source_files_not_yet_compiled = map.select { |source, target| !File.exist?(target) }.to_a
|
141
|
+
trace "Compile needed because source file #{source_files_not_yet_compiled[0][0]} has no corresponding #{source_files_not_yet_compiled[0][1]}" unless source_files_not_yet_compiled.empty?
|
142
|
+
return true if map.any? { |source, target| !File.exist?(target) || File.stat(source).mtime > File.stat(target).mtime }
|
143
|
+
oldest = map.map { |source, target| File.stat(target).mtime }.min
|
144
|
+
return dependencies.any? { |path| file(path).timestamp > oldest }
|
145
|
+
end
|
146
|
+
|
147
|
+
# Compile all files lists in sources (files and directories) into target using the
|
148
|
+
# specified dependencies.
|
149
|
+
def compile(sources, target, dependencies)
|
150
|
+
raise 'Not implemented'
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns additional dependencies required by this language. For example, since the
|
154
|
+
# test framework picks on these, you can use the JUnit framework with Scala.
|
155
|
+
def dependencies
|
156
|
+
self.class.dependencies
|
157
|
+
end
|
158
|
+
|
159
|
+
protected
|
160
|
+
|
161
|
+
# Use this to complain about CompileTask options not supported by this compiler.
|
162
|
+
#
|
163
|
+
# For example:
|
164
|
+
# def compile(files, task)
|
165
|
+
# check_options task, OPTIONS
|
166
|
+
# . . .
|
167
|
+
# end
|
168
|
+
def check_options(options, *supported)
|
169
|
+
unsupported = options.to_hash.keys - supported.flatten
|
170
|
+
raise ArgumentError, "No such option: #{unsupported.join(' ')}" unless unsupported.empty?
|
171
|
+
end
|
172
|
+
|
173
|
+
# Expands a list of source directories/files into a list of files that have the #source_ext extension.
|
174
|
+
def files_from_sources(sources)
|
175
|
+
ext_glob = Array(self.class.source_ext).join(',')
|
176
|
+
sources.flatten.map { |source| File.directory?(source) ? FileList["#{source}/**/*.{#{ext_glob}}"] : source }.
|
177
|
+
flatten.reject { |file| File.directory?(file) }.map { |file| File.expand_path(file) }.uniq
|
178
|
+
end
|
179
|
+
|
180
|
+
# The compile map is a hash that associates source files with target files based
|
181
|
+
# on a list of source directories and target directory. The compile task uses this
|
182
|
+
# to determine if there are source files to compile, and which source files to compile.
|
183
|
+
# The default method maps all files in the source directories with #source_ext into
|
184
|
+
# paths in the target directory with #target_ext (e.g. 'source/foo.java'=>'target/foo.class').
|
185
|
+
def compile_map(sources, target)
|
186
|
+
target_ext = self.class.target_ext
|
187
|
+
ext_glob = Array(self.class.source_ext).join(',')
|
188
|
+
sources.flatten.map{|f| File.expand_path(f)}.inject({}) do |map, source|
|
189
|
+
if File.directory?(source)
|
190
|
+
FileList["#{source}/**/*.{#{ext_glob}}"].reject { |file| File.directory?(file) }.
|
191
|
+
each { |file| map[file] = File.join(target, Util.relative_path(file, source).ext(target_ext)) }
|
192
|
+
else
|
193
|
+
# try to extract package name from .java or .scala files
|
194
|
+
if ['.java', '.scala', '.groovy'].include? File.extname(source)
|
195
|
+
package = findFirst(source, /^\s*package\s+(\S+)\s*;?\s*$/)
|
196
|
+
map[source] = package ? File.join(target, package[1].gsub('.', '/'), File.basename(source).ext(target_ext)) : target
|
197
|
+
elsif
|
198
|
+
map[source] = target
|
199
|
+
end
|
200
|
+
end
|
201
|
+
map
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
def findFirst(file, pattern)
|
208
|
+
match = nil
|
209
|
+
File.open(file, "r") do |infile|
|
210
|
+
while (line = infile.gets)
|
211
|
+
match = line.match(pattern)
|
212
|
+
break if match
|
213
|
+
end
|
214
|
+
end
|
215
|
+
match
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
# Compile task.
|
223
|
+
#
|
224
|
+
# Attempts to determine which compiler to use based on the project layout, for example,
|
225
|
+
# uses the Javac compiler if it finds any .java files in src/main/java. You can also
|
226
|
+
# select the compiler explicitly:
|
227
|
+
# compile.using(:scalac)
|
228
|
+
#
|
229
|
+
# Accepts multiple source directories that are invoked as prerequisites before compilation.
|
230
|
+
# You can pass a task as a source directory:
|
231
|
+
# compile.from(apt)
|
232
|
+
#
|
233
|
+
# Likewise, dependencies are invoked before compiling. All dependencies are evaluated as
|
234
|
+
# #artifacts, so you can pass artifact specifications and even projects:
|
235
|
+
# compile.with('module1.jar', 'log4j:log4j:jar:1.0', project('foo'))
|
236
|
+
#
|
237
|
+
# Creates a file task for the target directory, so executing that task as a dependency will
|
238
|
+
# execute the compile task first.
|
239
|
+
#
|
240
|
+
# Compiler options are inherited form a parent task, e.g. the foo:bar:compile task inherits
|
241
|
+
# its options from the foo:compile task. Even if foo is an empty project that does not compile
|
242
|
+
# any classes itself, you can use it to set compile options for all its sub-projects.
|
243
|
+
#
|
244
|
+
# Normally, the project will take care of setting the source and target directory, and you
|
245
|
+
# only need to set options and dependencies. See Project#compile.
|
246
|
+
class CompileTask < Rake::Task
|
247
|
+
|
248
|
+
def initialize(*args) #:nodoc:
|
249
|
+
super
|
250
|
+
parent_task = Project.parent_task(name)
|
251
|
+
inherit = lambda { |hash, key| parent_task.options[key] } if parent_task.respond_to?(:options)
|
252
|
+
@options = OpenObject.new &inherit
|
253
|
+
@sources = FileList[]
|
254
|
+
@dependencies = FileList[]
|
255
|
+
|
256
|
+
enhance do |task|
|
257
|
+
unless sources.empty?
|
258
|
+
raise 'No compiler selected and can\'t determine which compiler to use' unless compiler
|
259
|
+
raise 'No target directory specified' unless target
|
260
|
+
mkpath target.to_s
|
261
|
+
info "Compiling #{task.name.gsub(/:[^:]*$/, '')} into #{target.to_s}"
|
262
|
+
@compiler.compile(sources.map(&:to_s), target.to_s, dependencies.map(&:to_s))
|
263
|
+
# By touching the target we let other tasks know we did something,
|
264
|
+
# and also prevent recompiling again for dependencies.
|
265
|
+
touch target.to_s
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
# Source directories.
|
271
|
+
attr_accessor :sources
|
272
|
+
|
273
|
+
# :call-seq:
|
274
|
+
# from(*sources) => self
|
275
|
+
#
|
276
|
+
# Adds source directories and files to compile, and returns self.
|
277
|
+
#
|
278
|
+
# For example:
|
279
|
+
# compile.from('src/java').into('classes').with('module1.jar')
|
280
|
+
def from(*sources)
|
281
|
+
@sources |= sources.flatten
|
282
|
+
guess_compiler if @compiler.nil? && sources.flatten.any? { |source| File.exist?(source.to_s) }
|
283
|
+
self
|
284
|
+
end
|
285
|
+
|
286
|
+
# *Deprecated*: Use dependencies instead.
|
287
|
+
def classpath
|
288
|
+
Buildr.application.deprecated 'Use dependencies instead.'
|
289
|
+
dependencies
|
290
|
+
end
|
291
|
+
|
292
|
+
# *Deprecated*: Use dependencies= instead.
|
293
|
+
def classpath=(artifacts)
|
294
|
+
Buildr.application.deprecated 'Use dependencies= instead.'
|
295
|
+
self.dependencies = artifacts
|
296
|
+
end
|
297
|
+
|
298
|
+
# Compilation dependencies.
|
299
|
+
attr_accessor :dependencies
|
300
|
+
|
301
|
+
# :call-seq:
|
302
|
+
# with(*artifacts) => self
|
303
|
+
#
|
304
|
+
# Adds files and artifacts as dependencies, and returns self.
|
305
|
+
#
|
306
|
+
# Calls #artifacts on the arguments, so you can pass artifact specifications,
|
307
|
+
# tasks, projects, etc. Use this rather than setting the dependencies array directly.
|
308
|
+
#
|
309
|
+
# For example:
|
310
|
+
# compile.with('module1.jar', 'log4j:log4j:jar:1.0', project('foo'))
|
311
|
+
def with(*specs)
|
312
|
+
@dependencies |= Buildr.artifacts(specs.flatten).uniq
|
313
|
+
self
|
314
|
+
end
|
315
|
+
|
316
|
+
# The target directory for the compiled code.
|
317
|
+
attr_reader :target
|
318
|
+
|
319
|
+
# :call-seq:
|
320
|
+
# into(path) => self
|
321
|
+
#
|
322
|
+
# Sets the target directory and returns self. This will also set the compile task
|
323
|
+
# as a prerequisite to a file task on the target directory.
|
324
|
+
#
|
325
|
+
# For example:
|
326
|
+
# compile(src_dir).into(target_dir).with(artifacts)
|
327
|
+
# Both compile.invoke and file(target_dir).invoke will compile the source files.
|
328
|
+
def into(path)
|
329
|
+
@target = file(path.to_s).enhance([self]) unless @target.to_s == path.to_s
|
330
|
+
self
|
331
|
+
end
|
332
|
+
|
333
|
+
# Returns the compiler options.
|
334
|
+
attr_reader :options
|
335
|
+
|
336
|
+
# :call-seq:
|
337
|
+
# using(options) => self
|
338
|
+
#
|
339
|
+
# Sets the compiler options from a hash and returns self. Can also be used to
|
340
|
+
# select the compiler.
|
341
|
+
#
|
342
|
+
# For example:
|
343
|
+
# compile.using(:warnings=>true, :source=>'1.5')
|
344
|
+
# compile.using(:scala)
|
345
|
+
def using(*args)
|
346
|
+
args.pop.each { |key, value| options.send "#{key}=", value } if Hash === args.last
|
347
|
+
self.compiler = args.pop until args.empty?
|
348
|
+
self
|
349
|
+
end
|
350
|
+
|
351
|
+
# Returns the compiler if known. The compiler is either automatically selected
|
352
|
+
# based on existing source directories (e.g. src/main/java), or by requesting
|
353
|
+
# a specific compiler (see #using).
|
354
|
+
def compiler
|
355
|
+
guess_compiler unless @compiler
|
356
|
+
@compiler && @compiler.class.to_sym
|
357
|
+
end
|
358
|
+
|
359
|
+
# Returns the compiled language, if known. See also #compiler.
|
360
|
+
def language
|
361
|
+
compiler && @compiler.class.language
|
362
|
+
end
|
363
|
+
|
364
|
+
# Returns the default packaging type for this compiler, if known.
|
365
|
+
def packaging
|
366
|
+
compiler && @compiler.class.packaging
|
367
|
+
end
|
368
|
+
|
369
|
+
def timestamp #:nodoc:
|
370
|
+
# If we compiled successfully, then the target directory reflects that.
|
371
|
+
# If we didn't, see needed?
|
372
|
+
target ? target.timestamp : Rake::EARLY
|
373
|
+
end
|
374
|
+
|
375
|
+
# The project this task belongs to.
|
376
|
+
attr_reader :project
|
377
|
+
|
378
|
+
# The usage, one of :main or :test.
|
379
|
+
attr_reader :usage
|
380
|
+
|
381
|
+
protected
|
382
|
+
|
383
|
+
# Selects which compiler to use.
|
384
|
+
def compiler=(name) #:nodoc:
|
385
|
+
cls = Compiler.select(name) or raise ArgumentError, "No #{name} compiler available. Did you install it?"
|
386
|
+
return self if cls === @compiler
|
387
|
+
@compiler = cls.new(project, options)
|
388
|
+
from Array(cls.sources).map { |path| project.path_to(:source, usage, path) }.
|
389
|
+
select { |path| File.exist?(path) } if sources.empty?
|
390
|
+
into project.path_to(:target, usage, cls.target) unless target
|
391
|
+
with Array(@compiler.dependencies)
|
392
|
+
self
|
393
|
+
end
|
394
|
+
|
395
|
+
# Associates this task with project and particular usage (:main, :test).
|
396
|
+
def associate_with(project, usage) #:nodoc:
|
397
|
+
@project, @usage = project, usage
|
398
|
+
guess_compiler
|
399
|
+
end
|
400
|
+
|
401
|
+
# Try to guess if we have a compiler to match source files.
|
402
|
+
def guess_compiler #:nodoc:
|
403
|
+
candidate = Compiler.compilers.detect { |cls| cls.applies_to?(project, self) }
|
404
|
+
self.compiler = candidate if candidate
|
405
|
+
end
|
406
|
+
|
407
|
+
private
|
408
|
+
|
409
|
+
def needed? #:nodoc:
|
410
|
+
return false if sources.empty?
|
411
|
+
# Fail during invoke.
|
412
|
+
return true unless @compiler && target
|
413
|
+
return @compiler.needed?(sources.map(&:to_s), target.to_s, dependencies.map(&:to_s))
|
414
|
+
end
|
415
|
+
|
416
|
+
def invoke_prerequisites(args, chain) #:nodoc:
|
417
|
+
@sources = Array(@sources).map(&:to_s).uniq
|
418
|
+
@dependencies = FileList[@dependencies.uniq]
|
419
|
+
@prerequisites |= @dependencies + @sources
|
420
|
+
super
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
# The resources task is executed by the compile task to copy resource files over
|
427
|
+
# to the target directory. You can enhance this task in the normal way, but mostly
|
428
|
+
# you will use the task's filter.
|
429
|
+
#
|
430
|
+
# For example:
|
431
|
+
# resources.filter.using 'Copyright'=>'Acme Inc, 2007'
|
432
|
+
class ResourcesTask < Rake::Task
|
433
|
+
|
434
|
+
# Returns the filter used to copy resources over. See Buildr::Filter.
|
435
|
+
attr_reader :filter
|
436
|
+
|
437
|
+
def initialize(*args) #:nodoc:
|
438
|
+
super
|
439
|
+
@filter = Buildr::Filter.new
|
440
|
+
@filter.using Buildr.settings.profile['filter'] if Hash === Buildr.settings.profile['filter']
|
441
|
+
enhance do
|
442
|
+
target.invoke if target
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
# :call-seq:
|
447
|
+
# include(*files) => self
|
448
|
+
#
|
449
|
+
# Includes the specified files in the filter and returns self.
|
450
|
+
def include(*files)
|
451
|
+
filter.include *files
|
452
|
+
self
|
453
|
+
end
|
454
|
+
|
455
|
+
# :call-seq:
|
456
|
+
# exclude(*files) => self
|
457
|
+
#
|
458
|
+
# Excludes the specified files in the filter and returns self.
|
459
|
+
def exclude(*files)
|
460
|
+
filter.exclude *files
|
461
|
+
self
|
462
|
+
end
|
463
|
+
|
464
|
+
# :call-seq:
|
465
|
+
# from(*sources) => self
|
466
|
+
#
|
467
|
+
# Adds additional directories from which to copy resources.
|
468
|
+
#
|
469
|
+
# For example:
|
470
|
+
# resources.from _('src/etc')
|
471
|
+
def from(*sources)
|
472
|
+
filter.from *sources
|
473
|
+
self
|
474
|
+
end
|
475
|
+
|
476
|
+
# Returns the list of source directories (each being a file task).
|
477
|
+
def sources
|
478
|
+
filter.sources
|
479
|
+
end
|
480
|
+
|
481
|
+
# :call-seq:
|
482
|
+
# target => task
|
483
|
+
#
|
484
|
+
# Returns the filter's target directory as a file task.
|
485
|
+
def target
|
486
|
+
filter.into @project.path_to(:target, @usage, :resources) unless filter.target || sources.empty?
|
487
|
+
filter.target
|
488
|
+
end
|
489
|
+
|
490
|
+
def prerequisites #:nodoc:
|
491
|
+
super + filter.sources.flatten
|
492
|
+
end
|
493
|
+
|
494
|
+
protected
|
495
|
+
|
496
|
+
# Associates this task with project and particular usage (:main, :test).
|
497
|
+
def associate_with(project, usage) #:nodoc:
|
498
|
+
@project, @usage = project, usage
|
499
|
+
end
|
500
|
+
|
501
|
+
end
|
502
|
+
|
503
|
+
|
504
|
+
# Methods added to Project for compiling, handling of resources and generating source documentation.
|
505
|
+
module Compile
|
506
|
+
|
507
|
+
include Extension
|
508
|
+
|
509
|
+
first_time do
|
510
|
+
desc 'Compile all projects'
|
511
|
+
Project.local_task('compile') { |name| "Compiling #{name}" }
|
512
|
+
end
|
513
|
+
|
514
|
+
before_define(:compile) do |project|
|
515
|
+
resources = ResourcesTask.define_task('resources')
|
516
|
+
resources.send :associate_with, project, :main
|
517
|
+
project.path_to(:source, :main, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
|
518
|
+
|
519
|
+
compile = CompileTask.define_task('compile'=>resources)
|
520
|
+
compile.send :associate_with, project, :main
|
521
|
+
project.recursive_task('compile')
|
522
|
+
end
|
523
|
+
|
524
|
+
after_define(:compile) do |project|
|
525
|
+
if project.compile.target
|
526
|
+
# This comes last because the target path is set inside the project definition.
|
527
|
+
project.build project.compile.target
|
528
|
+
project.clean do
|
529
|
+
rm_rf project.compile.target.to_s, :verbose=>false
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
|
535
|
+
# :call-seq:
|
536
|
+
# compile(*sources) => CompileTask
|
537
|
+
# compile(*sources) { |task| .. } => CompileTask
|
538
|
+
#
|
539
|
+
# The compile task does what its name suggests. This method returns the project's
|
540
|
+
# CompileTask. It also accepts a list of source directories and files to compile
|
541
|
+
# (equivalent to calling CompileTask#from on the task), and a block for any
|
542
|
+
# post-compilation work.
|
543
|
+
#
|
544
|
+
# The compile task attempts to guess which compiler to use. For example, if it finds
|
545
|
+
# any Java files in the src/main/java directory, it will use the Java compiler and
|
546
|
+
# create class files in the target/classes directory.
|
547
|
+
#
|
548
|
+
# You can also configure it yourself by telling it which compiler to use, pointing
|
549
|
+
# it as source directories and chooing a different target directory.
|
550
|
+
#
|
551
|
+
# For example:
|
552
|
+
# # Include Log4J and the api sub-project artifacts.
|
553
|
+
# compile.with 'log4j:log4j:jar:1.2', project('api')
|
554
|
+
# # Include Apt-generated source files.
|
555
|
+
# compile.from apt
|
556
|
+
# # For JavaC, force target compatibility.
|
557
|
+
# compile.options.source = '1.6'
|
558
|
+
# # Run the OpenJPA bytecode enhancer after compilation.
|
559
|
+
# compile { open_jpa_enhance }
|
560
|
+
# # Pick a given compiler.
|
561
|
+
# compile.using(:scalac).from('src/scala')
|
562
|
+
#
|
563
|
+
# For more information, see CompileTask.
|
564
|
+
def compile(*sources, &block)
|
565
|
+
task('compile').from(sources).enhance &block
|
566
|
+
end
|
567
|
+
|
568
|
+
# :call-seq:
|
569
|
+
# resources(*prereqs) => ResourcesTask
|
570
|
+
# resources(*prereqs) { |task| .. } => ResourcesTask
|
571
|
+
#
|
572
|
+
# The resources task is executed by the compile task to copy resources files
|
573
|
+
# from the resource directory into the target directory. By default the resources
|
574
|
+
# task copies files from the src/main/resources into the target/resources directory.
|
575
|
+
#
|
576
|
+
# This method returns the project's resources task. It also accepts a list of
|
577
|
+
# prerequisites and a block, used to enhance the resources task.
|
578
|
+
#
|
579
|
+
# Resources files are copied and filtered (see Buildr::Filter for more information).
|
580
|
+
# The default filter uses the profile properties for the current environment.
|
581
|
+
#
|
582
|
+
# For example:
|
583
|
+
# resources.from _('src/etc')
|
584
|
+
# resources.filter.using 'Copyright'=>'Acme Inc, 2007'
|
585
|
+
#
|
586
|
+
# Or in your profiles.yaml file:
|
587
|
+
# common:
|
588
|
+
# Copyright: Acme Inc, 2007
|
589
|
+
def resources(*prereqs, &block)
|
590
|
+
task('resources').enhance prereqs, &block
|
591
|
+
end
|
592
|
+
|
593
|
+
end
|
594
|
+
|
595
|
+
|
596
|
+
class Options
|
597
|
+
|
598
|
+
# Returns the debug option (environment variable DEBUG).
|
599
|
+
def debug
|
600
|
+
(ENV['DEBUG'] || ENV['debug']) !~ /(no|off|false)/
|
601
|
+
end
|
602
|
+
|
603
|
+
# Sets the debug option (environment variable DEBUG).
|
604
|
+
#
|
605
|
+
# You can turn this option off directly, or by setting the environment variable
|
606
|
+
# DEBUG to +no+. For example:
|
607
|
+
# buildr build DEBUG=no
|
608
|
+
#
|
609
|
+
# The release tasks runs a build with <tt>DEBUG=no</tt>.
|
610
|
+
def debug=(flag)
|
611
|
+
ENV['debug'] = nil
|
612
|
+
ENV['DEBUG'] = flag.to_s
|
613
|
+
end
|
614
|
+
|
615
|
+
end
|
616
|
+
|
617
|
+
end
|
618
|
+
|
619
|
+
|
620
|
+
class Buildr::Project
|
621
|
+
include Buildr::Compile
|
622
|
+
end
|