buildr 1.2.10 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. data/CHANGELOG +566 -268
  2. data/DISCLAIMER +7 -1
  3. data/KEYS +151 -0
  4. data/NOTICE +23 -8
  5. data/README +122 -22
  6. data/Rakefile +49 -229
  7. data/{lib → addon}/buildr/antlr.rb +23 -10
  8. data/addon/buildr/cobertura.rb +232 -0
  9. data/{lib → addon}/buildr/hibernate.rb +20 -4
  10. data/{lib → addon}/buildr/javacc.rb +27 -12
  11. data/addon/buildr/jdepend.rb +60 -0
  12. data/{lib → addon}/buildr/jetty.rb +34 -18
  13. data/addon/buildr/nailgun.rb +892 -0
  14. data/{lib → addon}/buildr/openjpa.rb +23 -6
  15. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  18. data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
  19. data/{lib → addon}/buildr/xmlbeans.rb +39 -14
  20. data/bin/buildr +21 -7
  21. data/buildr.gemspec +50 -0
  22. data/doc/css/default.css +225 -0
  23. data/doc/css/print.css +95 -0
  24. data/doc/css/syntax.css +43 -0
  25. data/doc/images/apache-incubator-logo.png +0 -0
  26. data/doc/images/buildr-hires.png +0 -0
  27. data/doc/images/buildr.png +0 -0
  28. data/doc/images/note.png +0 -0
  29. data/doc/images/tip.png +0 -0
  30. data/doc/images/zbuildr.tif +0 -0
  31. data/doc/pages/artifacts.textile +317 -0
  32. data/doc/pages/building.textile +501 -0
  33. data/doc/pages/contributing.textile +178 -0
  34. data/doc/pages/download.textile +25 -0
  35. data/doc/pages/extending.textile +229 -0
  36. data/doc/pages/getting_started.textile +337 -0
  37. data/doc/pages/index.textile +63 -0
  38. data/doc/pages/mailing_lists.textile +17 -0
  39. data/doc/pages/more_stuff.textile +367 -0
  40. data/doc/pages/packaging.textile +592 -0
  41. data/doc/pages/projects.textile +449 -0
  42. data/doc/pages/recipes.textile +127 -0
  43. data/doc/pages/settings_profiles.textile +339 -0
  44. data/doc/pages/testing.textile +475 -0
  45. data/doc/pages/troubleshooting.textile +121 -0
  46. data/doc/pages/whats_new.textile +389 -0
  47. data/doc/print.haml +52 -0
  48. data/doc/print.toc.yaml +28 -0
  49. data/doc/scripts/buildr-git.rb +411 -0
  50. data/doc/scripts/install-jruby.sh +44 -0
  51. data/doc/scripts/install-linux.sh +64 -0
  52. data/doc/scripts/install-osx.sh +52 -0
  53. data/doc/site.haml +55 -0
  54. data/doc/site.toc.yaml +44 -0
  55. data/lib/buildr.rb +28 -45
  56. data/lib/buildr/core.rb +27 -0
  57. data/lib/buildr/core/application.rb +373 -0
  58. data/lib/buildr/core/application_cli.rb +134 -0
  59. data/lib/{core → buildr/core}/build.rb +91 -77
  60. data/lib/{core → buildr/core}/checks.rb +116 -95
  61. data/lib/buildr/core/common.rb +155 -0
  62. data/lib/buildr/core/compile.rb +594 -0
  63. data/lib/buildr/core/environment.rb +120 -0
  64. data/lib/buildr/core/filter.rb +258 -0
  65. data/lib/{core → buildr/core}/generate.rb +22 -5
  66. data/lib/buildr/core/help.rb +118 -0
  67. data/lib/buildr/core/progressbar.rb +156 -0
  68. data/lib/{core → buildr/core}/project.rb +468 -213
  69. data/lib/buildr/core/test.rb +690 -0
  70. data/lib/{core → buildr/core}/transports.rb +107 -127
  71. data/lib/buildr/core/util.rb +235 -0
  72. data/lib/buildr/ide.rb +19 -0
  73. data/lib/{java → buildr/ide}/eclipse.rb +86 -60
  74. data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
  75. data/lib/buildr/ide/idea.rb +194 -0
  76. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  77. data/lib/buildr/ide/idea7x.rb +210 -0
  78. data/lib/buildr/java.rb +26 -0
  79. data/lib/buildr/java/ant.rb +71 -0
  80. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  81. data/lib/buildr/java/commands.rb +210 -0
  82. data/lib/buildr/java/compilers.rb +432 -0
  83. data/lib/buildr/java/deprecated.rb +141 -0
  84. data/lib/buildr/java/groovyc.rb +137 -0
  85. data/lib/buildr/java/jruby.rb +99 -0
  86. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  89. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  91. data/lib/buildr/java/packaging.rb +706 -0
  92. data/lib/{java → buildr/java}/pom.rb +20 -4
  93. data/lib/buildr/java/rjb.rb +142 -0
  94. data/lib/buildr/java/test_frameworks.rb +290 -0
  95. data/lib/buildr/java/version_requirement.rb +172 -0
  96. data/lib/buildr/packaging.rb +21 -0
  97. data/lib/{java → buildr/packaging}/artifact.rb +170 -179
  98. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  99. data/lib/buildr/packaging/artifact_search.rb +140 -0
  100. data/lib/buildr/packaging/gems.rb +102 -0
  101. data/lib/buildr/packaging/package.rb +233 -0
  102. data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
  103. data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
  104. data/rakelib/apache.rake +126 -0
  105. data/rakelib/changelog.rake +56 -0
  106. data/rakelib/doc.rake +103 -0
  107. data/rakelib/package.rake +44 -0
  108. data/rakelib/release.rake +53 -0
  109. data/rakelib/rspec.rake +81 -0
  110. data/rakelib/rubyforge.rake +45 -0
  111. data/rakelib/scm.rake +49 -0
  112. data/rakelib/setup.rake +59 -0
  113. data/rakelib/stage.rake +45 -0
  114. data/spec/application_spec.rb +316 -0
  115. data/spec/archive_spec.rb +494 -0
  116. data/spec/artifact_namespace_spec.rb +635 -0
  117. data/spec/artifact_spec.rb +738 -0
  118. data/spec/build_spec.rb +193 -0
  119. data/spec/checks_spec.rb +537 -0
  120. data/spec/common_spec.rb +579 -0
  121. data/spec/compile_spec.rb +561 -0
  122. data/spec/groovy_compilers_spec.rb +239 -0
  123. data/spec/java_bdd_frameworks_spec.rb +238 -0
  124. data/spec/java_compilers_spec.rb +446 -0
  125. data/spec/java_packaging_spec.rb +1042 -0
  126. data/spec/java_test_frameworks_spec.rb +414 -0
  127. data/spec/packaging_helper.rb +63 -0
  128. data/spec/packaging_spec.rb +589 -0
  129. data/spec/project_spec.rb +739 -0
  130. data/spec/sandbox.rb +116 -0
  131. data/spec/scala_compilers_spec.rb +239 -0
  132. data/spec/spec.opts +6 -0
  133. data/spec/spec_helpers.rb +283 -0
  134. data/spec/test_spec.rb +871 -0
  135. data/spec/transport_spec.rb +300 -0
  136. data/spec/version_requirement_spec.rb +115 -0
  137. metadata +188 -77
  138. data/lib/buildr/cobertura.rb +0 -89
  139. data/lib/buildr/jdepend.rb +0 -40
  140. data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
  141. data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
  142. data/lib/buildr/jetty/JettyWrapper.class +0 -0
  143. data/lib/buildr/scala.rb +0 -368
  144. data/lib/core/application.rb +0 -188
  145. data/lib/core/common.rb +0 -562
  146. data/lib/core/help.rb +0 -72
  147. data/lib/core/rake_ext.rb +0 -81
  148. data/lib/java/ant.rb +0 -71
  149. data/lib/java/compile.rb +0 -589
  150. data/lib/java/idea.rb +0 -159
  151. data/lib/java/java.rb +0 -432
  152. data/lib/java/packaging.rb +0 -581
  153. data/lib/java/test.rb +0 -795
  154. data/lib/tasks/concat.rb +0 -35
@@ -1,72 +0,0 @@
1
- require "core/common"
2
- require "core/project"
3
-
4
-
5
- task "help" do
6
- # Greeater.
7
- Rake.application.usage
8
- puts
9
-
10
- # Show only the top-level projects.
11
- projects.reject(&:parent).tap do |top_level|
12
- unless top_level.empty?
13
- puts "Top-level projects (buildr help:projects for full list):"
14
- width = [top_level.map(&:name).map(&:size), 20].flatten.max
15
- top_level.each do |project|
16
- puts project.comment.blank? ? project.name : (" %-#{width}s # %s" % [project.name, project.comment])
17
- end
18
- puts
19
- end
20
- end
21
-
22
- # Show all the top-level tasks, excluding projects.
23
- puts "Common tasks:"
24
- task("help:tasks").invoke
25
- puts
26
- puts "For help on command line options:"
27
- puts " buildr --help"
28
- end
29
-
30
-
31
- module Buildr
32
-
33
- # :call-seq:
34
- # help() { ... }
35
- #
36
- # Use this to enhance the help task, e.g. to print some important information about your build,
37
- # configuration options, build instructions, etc.
38
- def help(&block)
39
- Rake.application["help"].enhance &block
40
- end
41
-
42
- end
43
-
44
-
45
- namespace "help" do
46
-
47
- desc "List all projects defined by this buildfile"
48
- task "projects" do
49
- width = projects.map(&:name).map(&:size).max
50
- projects.each do |project|
51
- puts project.comment.blank? ? " #{project.name}" : (" %-#{width}s # %s" % [project.name, project.comment])
52
- end
53
- end
54
-
55
- desc "List all tasks available from this buildfile"
56
- task "tasks" do
57
- Rake.application.tasks.select(&:comment).reject { |task| Project === task }.tap do |tasks|
58
- width = [tasks.map(&:name).map(&:size), 20].flatten.max
59
- tasks.each do |task|
60
- printf " %-#{width}s # %s\n", task.name, task.comment
61
- end
62
- puts
63
- end
64
- end
65
-
66
- end
67
-
68
-
69
- task "projects" do
70
- warn_deprecated "Please run help:projects instead."
71
- task("help:projects").invoke
72
- end
@@ -1,81 +0,0 @@
1
- module Rake #:nodoc
2
- class Task #:nodoc:
3
-
4
- def invoke()
5
- fail "Circular dependency " + (stack + [name]).join("=>") if stack.include?(name)
6
- @lock.synchronize do
7
- puts "** Invoke #{name} #{format_trace_flags}" if application.options.trace
8
- return if @already_invoked
9
- begin
10
- stack.push name
11
- @already_invoked = true
12
- invoke_prerequisites
13
- execute if needed?
14
- ensure
15
- stack.pop
16
- end
17
- end
18
- end
19
-
20
- def execute
21
- if application.options.dryrun
22
- puts "** Execute (dry run) #{name}"
23
- return
24
- end
25
- puts "** Execute #{name}" if application.options.trace
26
- application.enhance_with_matching_rule(name) if @actions.empty?
27
- @actions.each { |act| result = act.call(self) }
28
- end
29
-
30
- def invoke_prerequisites()
31
- prerequisites.each { |n| application[n, @scope].invoke }
32
- end
33
-
34
- def inspect()
35
- "#{self.class}: #{name}"
36
- end
37
-
38
- protected
39
-
40
- def stack()
41
- Thread.current[:rake_stack] ||= []
42
- end
43
-
44
- end
45
-
46
- class MultiTask #:nodoc:
47
- def invoke_prerequisites()
48
- threads = @prerequisites.collect do |p|
49
- copy = stack.dup
50
- Thread.new(p) { |r| stack.replace copy ; application[r].invoke }
51
- end
52
- threads.each { |t| t.join }
53
- end
54
- end
55
-
56
- class Application #:nodoc:
57
-
58
- def in_namespace_with_global_scope(name, &block)
59
- if name =~ /^:/
60
- begin
61
- scope, @scope = @scope, name.split(":")[1...-1]
62
- in_namespace_without_global_scope name.split(":").last, &block
63
- ensure
64
- @scope = scope
65
- end
66
- else
67
- in_namespace_without_global_scope name, &block
68
- end
69
- end
70
- alias_method_chain :in_namespace, :global_scope
71
-
72
- end
73
-
74
- class FileList
75
- class << self
76
- def recursive(*dirs)
77
- FileList[dirs.map { |dir| File.join(dir, "/**/{*,.*}") }].reject { |file| File.basename(file) =~ /^[.]{1,2}$/ }
78
- end
79
- end
80
- end
81
- end
@@ -1,71 +0,0 @@
1
- require "core/project"
2
- require "java/java"
3
- require "antwrap"
4
- require "core/help"
5
-
6
-
7
- module Buildr
8
- module Ant
9
-
10
- # Which version of Ant we're using by default.
11
- VERSION = "1.7.0"
12
-
13
- # Libraries used by Ant.
14
- REQUIRES = [ "org.apache.ant:ant:jar:#{VERSION}", "org.apache.ant:ant-launcher:jar:#{VERSION}", "xerces:xercesImpl:jar:2.6.2" ]
15
- Java.wrapper.setup { |jw| jw.classpath << REQUIRES }
16
-
17
- class << self
18
-
19
- # *Deprecated* Use ant { ... } instead.
20
- def declarative(name, options = nil, &block)
21
- warn_deprecated "Use ant { ... } instead."
22
- Buildr.ant name, options, &block
23
- end
24
-
25
- # *Deprecated* Use ant { ... } instead.
26
- def executable(name, options = nil, &block)
27
- warn_deprecated "Use ant { ... } instead."
28
- Buildr.ant name, options, &block
29
- end
30
-
31
- end
32
-
33
- # :call-seq:
34
- # ant(name) { |AntProject| ... } => AntProject
35
- #
36
- # Creates a new AntProject with the specified name, yield to the block for defining various
37
- # Ant tasks, and executes each task as it's defined.
38
- #
39
- # For example:
40
- # ant("hibernatedoclet") do |doclet|
41
- # doclet.taskdef :name=>"hibernatedoclet",
42
- # :classname=>"xdoclet.modules.hibernate.HibernateDocletTask", :classpath=>DOCLET
43
- # doclet.hibernatedoclet :destdir=>dest_dir, :force=>"true" do
44
- # hibernate :version=>"3.0"
45
- # fileset :dir=>source, :includes=>"**/*.java"
46
- # end
47
- # end
48
- def ant(name, options=nil, &block)
49
- warn_deprecated "Options are ignored." if options
50
- options = { :name=>name, :basedir=>Dir.pwd, :declarative=>true }
51
- options.merge!(:logger=> Logger.new(STDOUT), :loglevel=> Logger::DEBUG) if Rake.application.options.trace
52
- Java.wrapper do
53
- AntProject.new(options).tap do |project|
54
- # Set Ant logging level to debug (--trace), info (default) or error only (--quiet).
55
- project.project.getBuildListeners().get(0).
56
- setMessageOutputLevel((Rake.application.options.trace && 4) || (verbose && 2) || 0)
57
- yield project if block_given?
58
- end
59
- end
60
- end
61
-
62
- end
63
-
64
- include Ant
65
-
66
- task("help") do
67
- puts
68
- puts "Using Java #{Java.version}, Ant #{Ant::VERSION}."
69
- end
70
-
71
- end
@@ -1,589 +0,0 @@
1
- require "core/project"
2
- require "core/build"
3
- require "core/common"
4
- require "java/artifact"
5
- require "java/java"
6
-
7
- module Buildr
8
- module Java
9
-
10
- # Wraps Javac in a task that does all the heavy lifting.
11
- #
12
- # Accepts multiple source directories that are invoked as prerequisites before compilation.
13
- # You can pass a task as a source directory, e.g. compile.from(apt).
14
- #
15
- # Likewise, classpath dependencies are invoked before compiling. All classpath dependencies
16
- # are evaluated as #artifacts, so you can pass artifact specifications and even projects.
17
- #
18
- # Creates a file task for the target directory, so executing that task as a dependency will
19
- # execute the compile task first.
20
- #
21
- # Compiler options are inherited form a parent task, e.g. the foo:bar:compile task inherits
22
- # its options from the foo:compile task. Even if foo is an empty project that does not compile
23
- # any classes itself, you can use it to set compile options for all its sub-projects.
24
- #
25
- # Normally, the project will take care of setting the source and target directory, and you
26
- # only need to set options and classpath dependencies. See Project#compile.
27
- class CompileTask < Rake::Task
28
-
29
- # Compiler options, accessible from CompileTask#options.
30
- #
31
- # Supported options are:
32
- # - warnings -- Generate warnings if true (opposite of -nowarn).
33
- # - deprecation -- Output source locations where deprecated APIs are used.
34
- # - source -- Source compatibility with specified release.
35
- # - target -- Class file compatibility with specified release.
36
- # - lint -- Value to pass to xlint argument. Use true to enable default lint
37
- # options, or pass a specific setting as string or array of strings.
38
- # - debug -- Generate debugging info.
39
- # - other -- Array of options to pass to the Java compiler as is.
40
- #
41
- # For example:
42
- # compile.options.warnings = true
43
- # compile.options.source = options.target = "1.6"
44
- class Options
45
-
46
- include InheritedAttributes
47
-
48
- OPTIONS = [:warnings, :deprecation, :source, :target, :lint, :debug, :other]
49
-
50
- # Generate warnings (opposite of -nowarn).
51
- attr_accessor :warnings
52
- inherited_attr(:warnings) { verbose }
53
- # Output source locations where deprecated APIs are used.
54
- attr_accessor :deprecation
55
- inherited_attr :deprecation, false
56
- # Provide source compatibility with specified release.
57
- attr_accessor :source
58
- inherited_attr :source
59
- # Generate class files for specific VM version.
60
- attr_accessor :target
61
- inherited_attr :target
62
- # Values to pass to Xlint: string or array. Use true to enable
63
- # Xlint with no values.
64
- attr_accessor :lint
65
- inherited_attr :lint, false
66
- # Generate all debugging info.
67
- attr_accessor :debug
68
- inherited_attr(:debug) { Buildr.options.debug }
69
- # Array of arguments passed to the Java compiler as is.
70
- attr_accessor :other
71
- inherited_attr :other
72
-
73
- def initialize(parent = nil) #:nodoc:
74
- @parent = parent
75
- end
76
-
77
- attr_reader :parent # :nodoc:
78
-
79
- # Resets all the options.
80
- def clear()
81
- OPTIONS.each { |name| send "#{name}=", nil }
82
- end
83
-
84
- def to_s() #:nodoc:
85
- OPTIONS.inject({}){ |hash, name| hash[name] = send(name) ; hash }.reject{ |name,value| value.nil? }.inspect
86
- end
87
-
88
- # Returns Javac command line arguments from the set of options.
89
- def javac_args()
90
- args = []
91
- args << "-nowarn" unless warnings
92
- args << "-verbose" if Rake.application.options.trace
93
- args << "-g" if debug
94
- args << "-deprecation" if deprecation
95
- args << "-source" << source.to_s if source
96
- args << "-target" << target.to_s if target
97
- case lint
98
- when Array
99
- args << "-Xlint:#{lint.join(',')}"
100
- when String
101
- args << "-Xlint:#{lint}"
102
- when true
103
- args << "-Xlint"
104
- end
105
- args.concat(other.to_a) if other
106
- args
107
- end
108
-
109
- end
110
-
111
-
112
- def initialize(*args) #:nodoc:
113
- super
114
- parent = Project.task_in_parent_project(name)
115
- if parent && parent.respond_to?(:options)
116
- @options = Options.new(parent.options)
117
- else
118
- @options = Options.new
119
- end
120
- @sources = []
121
- @classpath = []
122
-
123
- enhance do |task|
124
- mkpath target.to_s, :verbose=>false
125
- Java.javac source_files.keys, :sourcepath=>sources.map(&:to_s).select { |source| File.directory?(source) }.uniq,
126
- :classpath=>classpath, :output=>target, :javac_args=>options.javac_args, :name=>task.name
127
- # By touching the target we let other tasks know we did something,
128
- # and also prevent recompiling again for classpath dependencies.
129
- touch target.to_s, :verbose=>false
130
- end
131
- end
132
-
133
- # Source directories and files to compile.
134
- attr_accessor :sources
135
-
136
- # :call-seq:
137
- # from(*sources) => self
138
- #
139
- # Adds source directories and files to compile, and returns self.
140
- #
141
- # For example:
142
- # compile.from("src/java").into("classes").with("module1.jar")
143
- def from(*sources)
144
- @sources |= sources.flatten
145
- self
146
- end
147
-
148
- # Classpath dependencies.
149
- attr_accessor :classpath
150
-
151
- # :call-seq:
152
- # with(*artifacts) => self
153
- #
154
- # Adds files and artifacts as classpath dependencies, and returns self.
155
- #
156
- # Calls #artifacts on the arguments, so you can pass artifact specifications,
157
- # tasks, projects, etc. Use this rather than setting the classpath directly.
158
- #
159
- # For example:
160
- # compile.with("module1.jar", "log4j:log4j:jar:1.0", project("foo"))
161
- def with(*specs)
162
- @classpath |= Buildr.artifacts(specs.flatten).uniq
163
- self
164
- end
165
-
166
- # The target directory for the generated class files.
167
- attr_reader :target
168
-
169
- # :call-seq:
170
- # into(path) => self
171
- #
172
- # Sets the target directory and returns self. This will also set the compile task
173
- # as a prerequisite to a file task on the target directory.
174
- #
175
- # For example:
176
- # compile(src_dir).into(target_dir).with(artifacts)
177
- # Both compile.invoke and file(target_dir).invoke will compile the source files.
178
- def into(path)
179
- path = File.expand_path(path.to_s)
180
- @target = file(path).enhance([self]) unless @target && @target.to_s == path
181
- self
182
- end
183
-
184
- # Returns the compiler options.
185
- attr_reader :options
186
-
187
- # :call-seq:
188
- # using(options) => self
189
- #
190
- # Sets the compiler options from a hash and returns self.
191
- #
192
- # For example:
193
- # compile.using(:warnings=>true, :source=>"1.5")
194
- def using(*args)
195
- args.pop.each { |key, value| options.send "#{key}=", value } if Hash === args.last
196
- args.each { |key| options.send "#{key}=", value = true }
197
- self
198
- end
199
-
200
- def timestamp() #:nodoc:
201
- # If we compiled successfully, then the target directory reflects that.
202
- # If we didn't, see needed?
203
- target ? target.timestamp : Rake::EARLY
204
- end
205
-
206
- def needed?() #:nodoc:
207
- return false if source_files.empty?
208
- return true unless File.exist?(target.to_s)
209
- return true if source_files.any? { |j, c| !File.exist?(c) || File.stat(j).mtime > File.stat(c).mtime }
210
- oldest = source_files.map { |j, c| File.stat(c).mtime }.min
211
- return classpath.any? { |path| application[path].timestamp > oldest }
212
- end
213
-
214
- def prerequisites() #:nodoc:
215
- super + classpath + sources
216
- end
217
-
218
- def invoke_prerequisites() #:nodoc:
219
- prerequisites.each { |n| application[n, @scope].invoke }
220
- end
221
-
222
- # Returns the files to compile. This list is derived from the list of sources,
223
- # expanding directories into files, and includes only source files that are
224
- # newer than the corresponding class file. Includes all files if one or more
225
- # classpath dependency has been updated.
226
- def source_files()
227
- @source_files ||= @sources.map(&:to_s).inject({}) do |map, source|
228
- raise "Compile task #{name} has source files, but no target directory" unless target
229
- target_dir = target.to_s
230
- if File.directory?(source)
231
- base = Pathname.new(source)
232
- FileList["#{source}/**/*.java"].reject { |file| File.directory?(file) }.
233
- each { |file| map[file] = File.join(target_dir, Pathname.new(file).relative_path_from(base).to_s.ext('.class')) }
234
- else
235
- map[source] = File.join(target_dir, File.basename(source).ext('.class'))
236
- end
237
- map
238
- end
239
- end
240
-
241
- end
242
-
243
-
244
- # The resources task is executed by the compile task to copy resource files over
245
- # to the target directory. You can enhance this task in the normal way, but mostly
246
- # you will use the task's filter.
247
- #
248
- # For example:
249
- # resources.filter.using "Copyright"=>"Acme Inc, 2007"
250
- class ResourcesTask < Rake::Task
251
-
252
- # Returns the filter used to copy resources over. See Buildr::Filter.
253
- attr_reader :filter
254
-
255
- def initialize(*args) #:nodoc:
256
- super
257
- @filter = Buildr::Filter.new
258
- enhance { filter.run unless filter.sources.empty? }
259
- end
260
-
261
- # :call-seq:
262
- # include(*files) => self
263
- #
264
- # Includes the specified files in the filter and returns self.
265
- def include(*files)
266
- filter.include *files
267
- self
268
- end
269
-
270
- # :call-seq:
271
- # exclude(*files) => self
272
- #
273
- # Excludes the specified files in the filter and returns self.
274
- def exclude(*files)
275
- filter.exclude *files
276
- self
277
- end
278
-
279
- # :call-seq:
280
- # from(*sources) => self
281
- #
282
- # Adds additional directories from which to copy resources.
283
- #
284
- # For example:
285
- # resources.from _("src/etc")
286
- def from(*sources)
287
- filter.from *sources
288
- self
289
- end
290
-
291
- # *Deprecated* Use #sources instead.
292
- def source()
293
- warn_deprecated "Please use sources instead."
294
- filter.source
295
- end
296
-
297
- # Returns the list of source directories (each being a file task).
298
- def sources()
299
- filter.sources
300
- end
301
-
302
- # :call-seq:
303
- # target() => task
304
- #
305
- # Returns the filter's target directory as a file task.
306
- def target()
307
- filter.target
308
- end
309
-
310
- def prerequisites() #:nodoc:
311
- super + filter.sources.flatten
312
- end
313
-
314
- end
315
-
316
-
317
- # A convenient task for creating Javadocs from the project's compile task. Minimizes all
318
- # the hard work to calling #from and #using.
319
- #
320
- # For example:
321
- # javadoc.from(projects("myapp:foo", "myapp:bar")).using(:windowtitle=>"My App")
322
- # Or, short and sweet:
323
- # desc "My App"
324
- # define "myapp" do
325
- # . . .
326
- # javadoc projects("myapp:foo", "myapp:bar")
327
- # end
328
- class JavadocTask < Rake::Task
329
-
330
- def initialize(*args) #:nodoc:
331
- super
332
- @options = {}
333
- @classpath = []
334
- @sourcepath = []
335
- @files = FileList[]
336
- enhance do |task|
337
- rm_rf target.to_s, :verbose=>false
338
- Java.javadoc source_files, options.merge(:classpath=>classpath, :sourcepath=>sourcepath, :name=>name, :output=>target.to_s)
339
- touch target.to_s, :verbose=>false
340
- end
341
- end
342
-
343
- # The target directory for the generated Javadoc files.
344
- attr_reader :target
345
-
346
- # :call-seq:
347
- # into(path) => self
348
- #
349
- # Sets the target directory and returns self. This will also set the Javadoc task
350
- # as a prerequisite to a file task on the target directory.
351
- #
352
- # For example:
353
- # package :zip, :classifier=>"docs", :include=>javadoc.target
354
- def into(path)
355
- path = File.expand_path(path.to_s)
356
- @target = file(path).enhance([self]) unless @target && @target.to_s == path
357
- self
358
- end
359
-
360
- # :call-seq:
361
- # include(*files) => self
362
- #
363
- # Includes additional source files and directories when generating the documentation
364
- # and returns self. When specifying a directory, includes all .java files in that directory.
365
- def include(*files)
366
- @files.include *files
367
- self
368
- end
369
-
370
- # :call-seq:
371
- # exclude(*files) => self
372
- #
373
- # Excludes source files and directories from generating the documentation.
374
- def exclude(*files)
375
- @files.exclude *files
376
- self
377
- end
378
-
379
- # Classpath dependencies.
380
- attr_accessor :classpath
381
-
382
- # :call-seq:
383
- # with(*artifacts) => self
384
- #
385
- # Adds files and artifacts as classpath dependencies, and returns self.
386
- def with(*specs)
387
- @classpath |= Buildr.artifacts(specs.flatten).uniq
388
- self
389
- end
390
-
391
- # Additional sourcepaths that are not part of the documented files.
392
- attr_accessor :sourcepath
393
-
394
- # Returns the Javadoc options.
395
- attr_reader :options
396
-
397
- # :call-seq:
398
- # using(options) => self
399
- #
400
- # Sets the Javadoc options from a hash and returns self.
401
- #
402
- # For example:
403
- # javadoc.using :windowtitle=>"My application"
404
- def using(*args)
405
- args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
406
- args.each { |key| @options[key.to_sym] = true }
407
- self
408
- end
409
-
410
- # :call-seq:
411
- # from(*sources) => self
412
- #
413
- # Includes files, directories and projects in the Javadoc documentation and returns self.
414
- #
415
- # You can call this method with Java source files and directories containing Java source files
416
- # to include these files in the Javadoc documentation, similar to #include. You can also call
417
- # this method with projects. When called with a project, it includes all the source files compiled
418
- # by that project and classpath dependencies used when compiling.
419
- #
420
- # For example:
421
- # javadoc.from projects("myapp:foo", "myapp:bar")
422
- def from(*sources)
423
- sources.flatten.each do |source|
424
- case source
425
- when Project
426
- self.include source.compile.sources
427
- self.with source.compile.classpath
428
- when Rake::Task, String
429
- self.include source
430
- else
431
- fail "Don't know how to generate Javadocs from #{source || 'nil'}"
432
- end
433
- end
434
- self
435
- end
436
-
437
- def prerequisites() #:nodoc:
438
- super + @files + classpath + sourcepath
439
- end
440
-
441
- def source_files() #:nodoc:
442
- @source_files ||= @files.map(&:to_s).
443
- map { |file| File.directory?(file) ? FileList[File.join(file, "**/*.java")] : file }.
444
- flatten.reject { |file| @files.exclude?(file) }
445
- end
446
-
447
- def needed?() #:nodoc:
448
- return false if source_files.empty?
449
- return true unless File.exist?(target.to_s)
450
- source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
451
- end
452
-
453
- end
454
-
455
- end
456
-
457
-
458
- # Local task to execute the compile task of the current project.
459
- # This task is not itself a compile task.
460
- desc "Compile all projects"
461
- Project.local_task("compile") { |name| "Compiling #{name}" }
462
-
463
- desc "Create the Javadocs for this project"
464
- Project.local_task("javadoc")
465
-
466
- class Project
467
-
468
- # *Deprecated* Add a prerequisite to the compile task instead.
469
- def prepare(*prereqs, &block)
470
- warn_deprecated "Add a prerequisite to the compile task instead of using the prepare task."
471
- task("prepare").enhance prereqs, &block
472
- end
473
-
474
- # :call-seq:
475
- # compile(*sources) => CompileTask
476
- # compile(*sources) { |task| .. } => CompileTask
477
- #
478
- # The compile task does what its name suggests. This method returns the project's
479
- # CompileTask. It also accepts a list of source directories and files to compile
480
- # (equivalent to calling CompileTask#from on the task), and a block for any
481
- # post-compilation work.
482
- #
483
- # The compile task will pick all the source files in the src/main/java directory,
484
- # and unless specified, compile them into the target/classes directory. It will pick
485
- # the default values for compiler options from the parent project's compile task.
486
- #
487
- # For example:
488
- # # Force target compatibility.
489
- # compile.options.source = "1.6"
490
- # # Include Apt-generated source files.
491
- # compile.from apt
492
- # # Include Log4J and the api sub-project artifacts.
493
- # compile.with "log4j:log4j:jar:1.2", project("api")
494
- # # Run the OpenJPA bytecode enhancer after compilation.
495
- # compile { open_jpa_enhance }
496
- #
497
- # For more information, see Java::CompileTask.
498
- def compile(*sources, &block)
499
- task("compile").from(sources).enhance &block
500
- end
501
-
502
- # :call-seq:
503
- # resources(*prereqs) => ResourcesTask
504
- # resources(*prereqs) { |task| .. } => ResourcesTask
505
- #
506
- # The resources task is executed by the compile task to copy resources files
507
- # from the resource directory into the target directory.
508
- #
509
- # This method returns the project's resources task. It also accepts a list of
510
- # prerequisites and a block, used to enhance the resources task.
511
- #
512
- # By default the resources task copies files from the src/main/resources into the
513
- # same target directory as the #compile task. It does so using a filter that you
514
- # can access by calling resources.filter (see Buildr::Filter).
515
- #
516
- # For example:
517
- # resources.from _("src/etc")
518
- # resources.filter.using "Copyright"=>"Acme Inc, 2007"
519
- def resources(*prereqs, &block)
520
- task("resources").enhance prereqs, &block
521
- end
522
-
523
- # :call-seq:
524
- # javadoc(*sources) => JavadocTask
525
- #
526
- # This method returns the project's Javadoc task. It also accepts a list of source files,
527
- # directories and projects to include when generating the Javadocs.
528
- #
529
- # By default the Javadoc task uses all the source directories from compile.sources and generates
530
- # Javadocs in the target/javadoc directory. This method accepts sources and adds them by calling
531
- # JavadocsTask#from.
532
- #
533
- # For example, if you want to generate Javadocs for a given project that includes all source files
534
- # in two of its sub-projects:
535
- # javadoc projects("myapp:foo", "myapp:bar").using(:windowtitle=>"Docs for foo and bar")
536
- def javadoc(*sources, &block)
537
- task("javadoc").from(*sources).enhance &block
538
- end
539
-
540
- end
541
-
542
- Project.on_define do |project|
543
- prepare = task("prepare")
544
- # Resources task is a filter.
545
- resources = Java::ResourcesTask.define_task("resources")
546
- project.path_to("src/main/resources").tap { |dir| resources.from dir if File.exist?(dir) }
547
- # Compile task requires prepare and performs resources, if anything compiled.
548
- compile = Java::CompileTask.define_task("compile"=>[prepare, resources])
549
- project.path_to("src/main/java").tap { |dir| compile.from dir if File.exist?(dir) }
550
- compile.into project.path_to(:target, "classes")
551
- resources.filter.into project.compile.target
552
- Java::JavadocTask.define_task("javadoc"=>prepare).tap do |javadoc|
553
- javadoc.into project.path_to(:target, "javadoc")
554
- javadoc.using :windowtitle=>project.comment || project.name
555
- end
556
- project.recursive_task("compile")
557
-
558
- project.enhance do |project|
559
- # This comes last because the target path may change.
560
- project.build project.compile.target
561
- # This comes last so we can determine all the source paths and classpath dependencies.
562
- project.javadoc.from project
563
- project.clean { verbose(false) { rm_rf project.compile.target.to_s } }
564
- end
565
- end
566
-
567
-
568
- class Options
569
-
570
- # Returns the debug option (environment variable DEBUG).
571
- def debug()
572
- (ENV["DEBUG"] || ENV["debug"]) !~ /(no|off|false)/
573
- end
574
-
575
- # Sets the debug option (environment variable DEBUG).
576
- #
577
- # You can turn this option off directly, or by setting the environment variable
578
- # DEBUG to "no". For example:
579
- # buildr build DEBUG=no
580
- #
581
- # The release tasks runs a build with <tt>DEBUG=no</tt>.
582
- def debug=(flag)
583
- ENV["debug"] = nil
584
- ENV["DEBUG"] = flag.to_s
585
- end
586
-
587
- end
588
-
589
- end