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,120 @@
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 'yaml'
18
+
19
+
20
+ module Buildr
21
+
22
+ # Collection of options for controlling Buildr.
23
+ class Options
24
+
25
+ # We use this to present environment variable as arrays.
26
+ class EnvArray < Array #:nodoc:
27
+
28
+ def initialize(name)
29
+ @name = name.upcase
30
+ replace((ENV[@name] || ENV[@name.downcase] || '').split(/\s*,\s*/).reject(&:empty?))
31
+ end
32
+
33
+ (Array.instance_methods - Object.instance_methods - Enumerable.instance_methods).sort.each do |method|
34
+ class_eval %{def #{method}(*args, &block) ; result = super ; write ; result ; end}
35
+ end
36
+
37
+ private
38
+
39
+ def write
40
+ ENV[@name.downcase] = nil
41
+ ENV[@name] = map(&:to_s).join(',')
42
+ end
43
+
44
+ end
45
+
46
+
47
+ # Wraps around the proxy environment variables:
48
+ # * :http -- HTTP_PROXY
49
+ # * :exclude -- NO_PROXY
50
+ class Proxies
51
+
52
+ # Returns the HTTP_PROXY URL.
53
+ def http
54
+ ENV['HTTP_PROXY'] || ENV['http_proxy']
55
+ end
56
+
57
+ # Sets the HTTP_PROXY URL.
58
+ def http=(url)
59
+ ENV['http_proxy'] = nil
60
+ ENV['HTTP_PROXY'] = url
61
+ end
62
+
63
+ # Returns list of hosts to exclude from proxying (NO_PROXY).
64
+ def exclude
65
+ @exclude ||= EnvArray.new('NO_PROXY')
66
+ end
67
+
68
+ # Sets list of hosts to exclude from proxy (NO_PROXY). Accepts host name, array of names,
69
+ # or nil to clear the list.
70
+ def exclude=(url)
71
+ exclude.clear
72
+ exclude.concat [url].flatten if url
73
+ exclude
74
+ end
75
+
76
+ end
77
+
78
+ # :call-seq:
79
+ # proxy => options
80
+ #
81
+ # Returns the proxy options. Currently supported options are:
82
+ # * :http -- HTTP proxy for use when downloading.
83
+ # * :exclude -- Do not use proxy for these hosts/domains.
84
+ #
85
+ # For example:
86
+ # options.proxy.http = 'http://proxy.acme.com:8080'
87
+ # You can also set it using the environment variable HTTP_PROXY.
88
+ #
89
+ # You can exclude individual hosts from being proxied, or entire domains, for example:
90
+ # options.proxy.exclude = 'optimus'
91
+ # options.proxy.exclude = ['optimus', 'prime']
92
+ # options.proxy.exclude << '*.internal'
93
+ def proxy
94
+ @proxy ||= Proxies.new
95
+ end
96
+
97
+ end
98
+
99
+
100
+ class << self
101
+
102
+ # :call-seq:
103
+ # options => Options
104
+ #
105
+ # Returns the Buildr options. See Options.
106
+ def options
107
+ @options ||= Options.new
108
+ end
109
+
110
+ end
111
+
112
+ # :call-seq:
113
+ # options => Options
114
+ #
115
+ # Returns the Buildr options. See Options.
116
+ def options
117
+ Buildr.options
118
+ end
119
+
120
+ end
@@ -0,0 +1,258 @@
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
+ module Buildr
18
+
19
+ # A filter knows how to copy files from one directory to another, applying mappings to the
20
+ # contents of these files.
21
+ #
22
+ # You can specify the mapping using a Hash, and it will map ${key} fields found in each source
23
+ # file into the appropriate value in the target file. For example:
24
+ #
25
+ # filter.using 'version'=>'1.2', 'build'=>Time.now
26
+ #
27
+ # will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and <tt>${build}</tt>
28
+ # with the current date/time.
29
+ #
30
+ # You can also specify the mapping by passing a proc or a method, that will be called for
31
+ # each source file, with the file name and content, returning the modified content.
32
+ #
33
+ # Without any mapping, the filter simply copies files from the source directory into the target
34
+ # directory.
35
+ #
36
+ # A filter has one target directory, but you can specify any number of source directories,
37
+ # either when creating the filter or calling #from. Include/exclude patterns are specified
38
+ # relative to the source directories, so:
39
+ # filter.include '*.png'
40
+ # will only include PNG files from any of the source directories.
41
+ #
42
+ # See Buildr#filter.
43
+ class Filter
44
+
45
+ def initialize #:nodoc:
46
+ clear
47
+ end
48
+
49
+ # Returns the list of source directories (each being a file task).
50
+ attr_reader :sources
51
+
52
+ # :call-seq:
53
+ # clear => self
54
+ #
55
+ # Clear filter sources and include/exclude patterns
56
+ def clear
57
+ @include = []
58
+ @exclude = []
59
+ @sources = []
60
+ self
61
+ end
62
+
63
+ # :call-seq:
64
+ # from(*sources) => self
65
+ #
66
+ # Adds additional directories from which to copy resources.
67
+ #
68
+ # For example:
69
+ # filter.from('src').into('target').using('build'=>Time.now)
70
+ def from(*sources)
71
+ @sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s)) }
72
+ self
73
+ end
74
+
75
+ # The target directory as a file task.
76
+ attr_reader :target
77
+
78
+ # :call-seq:
79
+ # into(dir) => self
80
+ #
81
+ # Sets the target directory into which files are copied and returns self.
82
+ #
83
+ # For example:
84
+ # filter.from('src').into('target').using('build'=>Time.now)
85
+ def into(dir)
86
+ @target = file(File.expand_path(dir.to_s)) { |task| run if target == task && !sources.empty? }
87
+ self
88
+ end
89
+
90
+ # :call-seq:
91
+ # include(*files) => self
92
+ #
93
+ # Specifies files to include and returns self. See FileList#include.
94
+ #
95
+ # By default all files are included. You can use this method to only include specific
96
+ # files form the source directory.
97
+ def include(*files)
98
+ @include += files
99
+ self
100
+ end
101
+ alias :add :include
102
+
103
+ # :call-seq:
104
+ # exclude(*files) => self
105
+ #
106
+ # Specifies files to exclude and returns self. See FileList#exclude.
107
+ def exclude(*files)
108
+ @exclude += files
109
+ self
110
+ end
111
+
112
+ # The mapping. See #using.
113
+ attr_accessor :mapping
114
+
115
+ # The mapper to use. See #using.
116
+ attr_accessor :mapper
117
+
118
+ # :call-seq:
119
+ # using(mapping) => self
120
+ # using { |file_name, contents| ... } => self
121
+ #
122
+ # Specifies the mapping to use and returns self.
123
+ #
124
+ # The most typical mapping uses a Hash, and the default mapping uses the Maven style, so
125
+ # <code>${key}</code> are mapped to the values. You can change that by passing a different
126
+ # format as the first argument. Currently supports:
127
+ # * :ant -- Map <code>@key@</code>.
128
+ # * :maven -- Map <code>${key}</code> (default).
129
+ # * :ruby -- Map <code>#{key}</code>.
130
+ # * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
131
+ #
132
+ # For example:
133
+ # filter.using 'version'=>'1.2'
134
+ # Is the same as:
135
+ # filter.using :maven, 'version'=>'1.2'
136
+ #
137
+ # You can also pass a proc or method. It will be called with the file name and content,
138
+ # to return the mapped content.
139
+ #
140
+ # Without any mapping, all files are copied as is.
141
+ def using(*args, &block)
142
+ case args.first
143
+ when Hash # Maven hash mapping
144
+ using :maven, *args
145
+ when Symbol # Mapping from a method
146
+ raise ArgumentError, 'Expected mapper type followed by mapping hash' unless args.size == 2 && Hash === args[1]
147
+ @mapper, @mapping = *args
148
+ when Regexp # Mapping using a regular expression
149
+ raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1]
150
+ @mapper, @mapping = *args
151
+ else
152
+ raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block)
153
+ @mapping = args.first || block
154
+ end
155
+ self
156
+ end
157
+
158
+ # :call-seq:
159
+ # run => boolean
160
+ #
161
+ # Runs the filter.
162
+ def run
163
+ raise 'No source directory specified, where am I going to find the files to filter?' if sources.empty?
164
+ sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
165
+ raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
166
+
167
+ copy_map = sources.flatten.map(&:to_s).inject({}) do |map, source|
168
+ files = Util.recursive_with_dot_files(source).
169
+ map { |file| Util.relative_path(file, source) }.
170
+ select { |file| @include.empty? || @include.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }.
171
+ reject { |file| @exclude.any? { |pattern| File.fnmatch(pattern, file, File::FNM_PATHNAME) } }
172
+ files.each do |file|
173
+ src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
174
+ map[file] = src if !File.exist?(dest) || File.stat(src).mtime > File.stat(dest).mtime
175
+ end
176
+ map
177
+ end
178
+
179
+ return false if copy_map.empty?
180
+
181
+ verbose(Buildr.application.options.trace || false) do
182
+ mkpath target.to_s
183
+ copy_map.each do |path, source|
184
+ dest = File.expand_path(path, target.to_s)
185
+ if File.directory?(source)
186
+ mkpath dest
187
+ else
188
+ mkpath File.dirname(dest)
189
+ case mapping
190
+ when Proc, Method # Call on input, accept output.
191
+ mapped = mapping.call(path, File.open(source, 'rb') { |file| file.read })
192
+ File.open(dest, 'wb') { |file| file.write mapped }
193
+ when Hash # Map ${key} to value
194
+ content = File.open(source, 'rb') { |file| file.read }
195
+ if Symbol === @mapper
196
+ mapped = send("#{@mapper}_mapper", content) { |key| mapping[key] }
197
+ else
198
+ mapped = regexp_mapper(content) { |key| mapping[key] }
199
+ end
200
+ #gsub(/\$\{[^}]*\}/) { |str| mapping[str[2..-2]] || str }
201
+ File.open(dest, 'wb') { |file| file.write mapped }
202
+ when nil # No mapping.
203
+ cp source, dest
204
+ File.chmod(0664, dest)
205
+ else
206
+ fail "Filter can be a hash (key=>value), or a proc/method; I don't understand #{mapping}"
207
+ end
208
+ end
209
+ end
210
+ touch target.to_s
211
+ end
212
+ true
213
+ end
214
+
215
+ # Returns the target directory.
216
+ def to_s
217
+ @target.to_s
218
+ end
219
+
220
+ private
221
+
222
+ def maven_mapper(content)
223
+ content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
224
+ end
225
+
226
+ def ant_mapper(content)
227
+ content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
228
+ end
229
+
230
+ def ruby_mapper(content)
231
+ content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
232
+ end
233
+
234
+ def regexp_mapper(content)
235
+ content.gsub(@mapper) { |str| yield(str.scan(@mapper).join) || str }
236
+ end
237
+
238
+ end
239
+
240
+ # :call-seq:
241
+ # filter(*source) => Filter
242
+ #
243
+ # Creates a filter that will copy files from the source directory(ies) into the target directory.
244
+ # You can extend the filter to modify files by mapping <tt>${key}</tt> into values in each
245
+ # of the copied files, and by including or excluding specific files.
246
+ #
247
+ # A filter is not a task, you must call the Filter#run method to execute it.
248
+ #
249
+ # For example, to copy all files from one directory to another:
250
+ # filter('src/files').into('target/classes').run
251
+ # To include only the text files, and replace each instance of <tt>${build}</tt> with the current
252
+ # date/time:
253
+ # filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
254
+ def filter(*sources)
255
+ Filter.new.from(*sources)
256
+ end
257
+
258
+ end
@@ -0,0 +1,195 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/java/pom'
18
+
19
+
20
+ module Buildr
21
+ module Generate #:nodoc:
22
+
23
+ task "generate" do
24
+ script = nil
25
+ choose do |menu|
26
+ menu.header = "To use Buildr you need a buildfile. Do you want me to create one?"
27
+
28
+ menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom(true).join("\n") } if File.exists?("pom.xml")
29
+ menu.choice("From directory structure") { script = Generate.from_directory(true).join("\n") }
30
+ menu.choice("Skip") { }
31
+ end
32
+
33
+ if script
34
+ buildfile = File.expand_path(Buildr::Application::DEFAULT_BUILDFILES.first)
35
+ File.open(buildfile, "w") { |file| file.write script }
36
+ puts "Created #{buildfile}"
37
+ end
38
+ end
39
+
40
+ class << self
41
+
42
+
43
+ HEADER = "# Generated by Buildr #{Buildr::VERSION}, change to your liking\n\n"
44
+
45
+
46
+ def from_directory(root = false)
47
+ name = File.basename(Dir.pwd)
48
+ if root
49
+ script = HEADER.split("\n")
50
+ header = <<-EOF
51
+ # Version number for this release
52
+ VERSION_NUMBER = "1.0.0"
53
+ # Version number for the next release
54
+ NEXT_VERSION = "1.0.1"
55
+ # Group identifier for your projects
56
+ GROUP = "#{name}"
57
+ COPYRIGHT = ""
58
+
59
+ # Specify Maven 2.0 remote repositories here, like this:
60
+ repositories.remote << "http://www.ibiblio.org/maven2/"
61
+
62
+ desc "The #{name.capitalize} project"
63
+ define "#{name}" do
64
+
65
+ project.version = VERSION_NUMBER
66
+ project.group = GROUP
67
+ manifest["Implementation-Vendor"] = COPYRIGHT
68
+ EOF
69
+ script += header.split("\n")
70
+ else
71
+ script = [ %{define "#{name}" do} ]
72
+ end
73
+ script << " compile.with # Add classpath dependencies" if File.exist?("src/main/java")
74
+ script << " resources" if File.exist?("src/main/resources")
75
+ script << " test.compile.with # Add classpath dependencies" if File.exist?("src/test/java")
76
+ script << " test.resources" if File.exist?("src/test/resources")
77
+ if File.exist?("src/main/webapp")
78
+ script << " package(:war)"
79
+ elsif File.exist?("src/main/java")
80
+ script << " package(:jar)"
81
+ end
82
+ dirs = FileList["*"].exclude("src", "target", "report").
83
+ select { |file| File.directory?(file) && File.exist?(File.join(file, "src")) }
84
+ unless dirs.empty?
85
+ script << ""
86
+ dirs.sort.each do |dir|
87
+ Dir.chdir(dir) { script << from_directory.flatten.map { |line| " " + line } << "" }
88
+ end
89
+ end
90
+ script << "end"
91
+ script.flatten
92
+ end
93
+
94
+ def from_maven2_pom(root = false)
95
+ pom = Buildr::POM.load('pom.xml')
96
+ project = pom.project
97
+
98
+ artifactId = project['artifactId'].first
99
+ description = project['name'] || "The #{artifactId} project"
100
+ project_name = File.basename(Dir.pwd)
101
+
102
+ if root
103
+ script = HEADER.split("\n")
104
+
105
+ settings_file = ENV["M2_SETTINGS"] || File.join(ENV['HOME'], ".m2/settings.xml")
106
+ settings = XmlSimple.xml_in(IO.read(settings_file)) if File.exists?(settings_file)
107
+
108
+ if settings
109
+ proxy = settings['proxies'].first['proxy'].find { |proxy|
110
+ proxy["active"].nil? || proxy["active"].to_s =~ /true/
111
+ } rescue nil
112
+
113
+ if proxy
114
+ url = %{#{proxy["protocol"].first}://#{proxy["host"].first}:#{proxy["port"].first}}
115
+ exclude = proxy["nonProxyHosts"].to_s.gsub("|", ",") if proxy["nonProxyHosts"]
116
+ script << "options.proxy.http = '#{url}'"
117
+ script << "options.proxy.exclude << '#{exclude}'" if exclude
118
+ script << ''
119
+ # In addition, we need to use said proxies to download artifacts.
120
+ Buildr.options.proxy.http = url
121
+ Buildr.options.proxy.exclude << exclude if exclude
122
+ end
123
+ end
124
+
125
+ repositories = project["repositories"].first["repository"].select { |repository|
126
+ legacy = repository["layout"].to_s =~ /legacy/
127
+ !legacy
128
+ } rescue nil
129
+ repositories = [{"name" => "Standard maven2 repository", "url" => "http://www.ibiblio.org/maven2/"}] if repositories.nil? || repositories.empty?
130
+ repositories.each do |repository|
131
+ name, url = repository["name"], repository["url"]
132
+ script << "# #{name}"
133
+ script << "repositories.remote << '#{url}'"
134
+ # In addition we need to use said repositores to download artifacts.
135
+ Buildr.repositories.remote << url.to_s
136
+ end
137
+ script << ""
138
+ else
139
+ script = []
140
+ end
141
+
142
+ script << "desc '#{description}'"
143
+ script << "define '#{project_name}' do"
144
+
145
+ groupId = project['groupId']
146
+ script << " project.group = '#{groupId}'" if groupId
147
+
148
+ version = project['version']
149
+ script << " project.version = '#{version}'" if version
150
+
151
+ #get plugins configurations
152
+ plugins = project['build'].first['plugins'].first['plugin'] rescue {}
153
+ compile_plugin = plugins.find{|pl| (pl['groupId'].nil? or pl['groupId'].first == 'org.apache.maven.plugins') and pl['artifactId'].first == 'maven-compiler-plugin'}
154
+ if compile_plugin
155
+ source = compile_plugin.first['configuration'].first['source'] rescue nil
156
+ target = compile_plugin.first['configuration'].first['target'] rescue nil
157
+
158
+ script << " compile.options.source = '#{source}'" if source
159
+ script << " compile.options.target = '#{target}'" if target
160
+ end
161
+
162
+ compile_dependencies = pom.dependencies
163
+ dependencies = compile_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
164
+ script << " compile.with #{dependencies}" unless dependencies.empty?
165
+
166
+ test_dependencies = (pom.dependencies(['test']) - compile_dependencies).reject{|d| d =~ /^junit:junit:jar:/ }
167
+ #check if we have testng
168
+ use_testng = test_dependencies.find{|d| d =~ /^org.testng:testng:jar:/}
169
+ if use_testng
170
+ script << " test.using :testng"
171
+ test_dependencies = pom.dependencies(['test']).reject{|d| d =~ /^org.testng:testng:jar:/ }
172
+ end
173
+
174
+ test_dependencies = test_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
175
+ script << " test.with #{test_dependencies}" unless test_dependencies.empty?
176
+
177
+ packaging = project['packaging'] ? project['packaging'].first : 'jar'
178
+ if %w(jar war).include?(packaging)
179
+ script << " package :#{packaging}, :id => '#{artifactId}'"
180
+ end
181
+
182
+ modules = project['modules'].first['module'] rescue nil
183
+ if modules
184
+ script << ""
185
+ modules.each do |mod|
186
+ chdir(mod) { script << from_maven2_pom.flatten.map { |line| " " + line } << "" }
187
+ end
188
+ end
189
+ script << "end"
190
+ script.flatten
191
+ end
192
+
193
+ end
194
+ end
195
+ end