realityforge-buildr 1.5.9

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 (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.md +3 -0
  6. data/Rakefile +50 -0
  7. data/addon/buildr/checkstyle-report.xsl +104 -0
  8. data/addon/buildr/checkstyle.rb +254 -0
  9. data/addon/buildr/git_auto_version.rb +36 -0
  10. data/addon/buildr/gpg.rb +90 -0
  11. data/addon/buildr/gwt.rb +413 -0
  12. data/addon/buildr/jacoco.rb +161 -0
  13. data/addon/buildr/pmd.rb +185 -0
  14. data/addon/buildr/single_intermediate_layout.rb +71 -0
  15. data/addon/buildr/spotbugs.rb +265 -0
  16. data/addon/buildr/top_level_generate_dir.rb +37 -0
  17. data/addon/buildr/wsgen.rb +192 -0
  18. data/bin/buildr +20 -0
  19. data/buildr.gemspec +61 -0
  20. data/lib/buildr.rb +86 -0
  21. data/lib/buildr/core/application.rb +705 -0
  22. data/lib/buildr/core/assets.rb +96 -0
  23. data/lib/buildr/core/build.rb +587 -0
  24. data/lib/buildr/core/common.rb +167 -0
  25. data/lib/buildr/core/compile.rb +599 -0
  26. data/lib/buildr/core/console.rb +124 -0
  27. data/lib/buildr/core/doc.rb +275 -0
  28. data/lib/buildr/core/environment.rb +128 -0
  29. data/lib/buildr/core/filter.rb +405 -0
  30. data/lib/buildr/core/help.rb +114 -0
  31. data/lib/buildr/core/progressbar.rb +161 -0
  32. data/lib/buildr/core/project.rb +994 -0
  33. data/lib/buildr/core/test.rb +776 -0
  34. data/lib/buildr/core/transports.rb +456 -0
  35. data/lib/buildr/core/util.rb +77 -0
  36. data/lib/buildr/ide/idea.rb +1664 -0
  37. data/lib/buildr/java/commands.rb +230 -0
  38. data/lib/buildr/java/compiler.rb +85 -0
  39. data/lib/buildr/java/custom_pom.rb +300 -0
  40. data/lib/buildr/java/doc.rb +62 -0
  41. data/lib/buildr/java/packaging.rb +393 -0
  42. data/lib/buildr/java/pom.rb +191 -0
  43. data/lib/buildr/java/test_result.rb +54 -0
  44. data/lib/buildr/java/tests.rb +111 -0
  45. data/lib/buildr/packaging/archive.rb +586 -0
  46. data/lib/buildr/packaging/artifact.rb +1113 -0
  47. data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
  48. data/lib/buildr/packaging/artifact_search.rb +138 -0
  49. data/lib/buildr/packaging/package.rb +237 -0
  50. data/lib/buildr/packaging/version_requirement.rb +189 -0
  51. data/lib/buildr/packaging/zip.rb +189 -0
  52. data/lib/buildr/packaging/ziptask.rb +387 -0
  53. data/lib/buildr/version.rb +18 -0
  54. data/rakelib/release.rake +99 -0
  55. data/spec/addon/checkstyle_spec.rb +58 -0
  56. data/spec/core/application_spec.rb +576 -0
  57. data/spec/core/build_spec.rb +922 -0
  58. data/spec/core/common_spec.rb +670 -0
  59. data/spec/core/compile_spec.rb +656 -0
  60. data/spec/core/console_spec.rb +65 -0
  61. data/spec/core/doc_spec.rb +194 -0
  62. data/spec/core/extension_spec.rb +200 -0
  63. data/spec/core/project_spec.rb +736 -0
  64. data/spec/core/test_spec.rb +1131 -0
  65. data/spec/core/transport_spec.rb +452 -0
  66. data/spec/core/util_spec.rb +154 -0
  67. data/spec/ide/idea_spec.rb +1952 -0
  68. data/spec/java/commands_spec.rb +79 -0
  69. data/spec/java/compiler_spec.rb +274 -0
  70. data/spec/java/custom_pom_spec.rb +165 -0
  71. data/spec/java/doc_spec.rb +55 -0
  72. data/spec/java/packaging_spec.rb +786 -0
  73. data/spec/java/pom_spec.rb +162 -0
  74. data/spec/java/test_coverage_helper.rb +257 -0
  75. data/spec/java/tests_spec.rb +224 -0
  76. data/spec/packaging/archive_spec.rb +686 -0
  77. data/spec/packaging/artifact_namespace_spec.rb +757 -0
  78. data/spec/packaging/artifact_spec.rb +1351 -0
  79. data/spec/packaging/packaging_helper.rb +63 -0
  80. data/spec/packaging/packaging_spec.rb +690 -0
  81. data/spec/sandbox.rb +166 -0
  82. data/spec/spec_helpers.rb +420 -0
  83. data/spec/version_requirement_spec.rb +145 -0
  84. data/spec/xpath_matchers.rb +123 -0
  85. metadata +295 -0
@@ -0,0 +1,77 @@
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
+ module Buildr #:nodoc:
17
+
18
+ module Util
19
+ extend self
20
+
21
+ # Return the path to the first argument, starting from the path provided by the
22
+ # second argument.
23
+ #
24
+ # For example:
25
+ # relative_path('foo/bar', 'foo')
26
+ # => 'bar'
27
+ # relative_path('foo/bar', 'baz')
28
+ # => '../foo/bar'
29
+ # relative_path('foo/bar')
30
+ # => 'foo/bar'
31
+ # relative_path('/foo/bar', 'baz')
32
+ # => '/foo/bar'
33
+ def relative_path(to, from = '.')
34
+ to = Pathname.new(to).cleanpath
35
+ return to.to_s if from.nil?
36
+ to_path = Pathname.new(File.expand_path(to.to_s, "/"))
37
+ from_path = Pathname.new(File.expand_path(from.to_s, "/"))
38
+ to_path.relative_path_from(from_path).to_s
39
+ end
40
+
41
+ # Generally speaking, it's not a good idea to operate on dot files (files starting with dot).
42
+ # These are considered invisible files (.svn, .hg, .irbrc, etc). Dir.glob/FileList ignore them
43
+ # on purpose. There are few cases where we do have to work with them (filter, zip), a better
44
+ # solution is welcome, maybe being more explicit with include. For now, this will do.
45
+ def recursive_with_dot_files(*dirs)
46
+ FileList[dirs.map { |dir| File.join(dir, '/**/{*,.*}') }].reject { |file| File.basename(file) =~ /^[.]{1,2}$/ }
47
+ end
48
+
49
+ # Most platforms requires tools.jar to be on the classpath, tools.jar contains the
50
+ # Java compiler (OS X and AIX are two exceptions we know about, may be more).
51
+ # Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
52
+ # but maybe the JRE. Return nil if not found.
53
+ def tools_jar #:nodoc:
54
+ @tools_jar ||= begin
55
+ home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
56
+ %w[lib/tools.jar ../lib/tools.jar].map { |path| File.expand_path(path, home) }.
57
+ find { |path| File.exist?(path) }
58
+ end
59
+ end
60
+ end # Util
61
+ end
62
+
63
+ class OpenObject < Hash
64
+
65
+ def initialize(source=nil, &block)
66
+ super &block
67
+ update source if source
68
+ end
69
+
70
+ def method_missing(symbol, *args)
71
+ if symbol.to_s =~ /=$/
72
+ self[symbol.to_s[0..-2].to_sym] = args.first
73
+ else
74
+ self[symbol]
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,1664 @@
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
+ module Buildr #:nodoc:
17
+ module IntellijIdea
18
+ def self.new_document(value)
19
+ REXML::Document.new(value, :attribute_quote => :quote)
20
+ end
21
+
22
+ # Abstract base class for IdeaModule and IdeaProject
23
+ class IdeaFile
24
+ DEFAULT_PREFIX = ''
25
+ DEFAULT_SUFFIX = ''
26
+ DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE = 'MAVEN_REPOSITORY'
27
+
28
+ attr_reader :buildr_project
29
+ attr_writer :prefix
30
+ attr_writer :suffix
31
+ attr_writer :id
32
+ attr_accessor :template
33
+ attr_accessor :local_repository_env_override
34
+
35
+ def initialize
36
+ @local_repository_env_override = DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE
37
+ end
38
+
39
+ def prefix
40
+ @prefix ||= DEFAULT_PREFIX
41
+ end
42
+
43
+ def suffix
44
+ @suffix ||= DEFAULT_SUFFIX
45
+ end
46
+
47
+ def filename
48
+ buildr_project.path_to("#{name}.#{extension}")
49
+ end
50
+
51
+ def id
52
+ @id ||= buildr_project.name.split(':').last
53
+ end
54
+
55
+ def add_component(name, attrs = {}, &xml)
56
+ self.components << create_component(name, attrs, &xml)
57
+ end
58
+
59
+ def add_component_from_file(filename)
60
+ self.components << lambda do
61
+ raise "Unable to locate file #{filename} adding component to idea file" unless File.exist?(filename)
62
+ Buildr::IntellijIdea.new_document(IO.read(filename)).root
63
+ end
64
+ end
65
+
66
+ def add_component_from_artifact(artifact)
67
+ self.components << lambda do
68
+ a = Buildr.artifact(artifact)
69
+ a.invoke
70
+ Buildr::IntellijIdea.new_document(IO.read(a.to_s)).root
71
+ end
72
+ end
73
+
74
+ # IDEA can not handle text content with indents so need to removing indenting
75
+ # Can not pass true as third argument as the ruby library seems broken
76
+ def write(f)
77
+ document.write(f, -1, false, true)
78
+ end
79
+
80
+ def name
81
+ "#{prefix}#{self.id}#{suffix}"
82
+ end
83
+
84
+ protected
85
+
86
+ def relative(path)
87
+ ::Buildr::Util.relative_path(File.expand_path(path.to_s), self.base_directory)
88
+ end
89
+
90
+ def base_directory
91
+ buildr_project.path_to
92
+ end
93
+
94
+ def resolve_path_from_base(path, base_variable)
95
+ m2repo = Buildr::Repositories.instance.local
96
+ if path.to_s.index(m2repo) == 0 && !self.local_repository_env_override.nil?
97
+ return path.sub(m2repo, "$#{self.local_repository_env_override}$")
98
+ else
99
+ begin
100
+ return "#{base_variable}/#{relative(path)}"
101
+ rescue ArgumentError
102
+ # ArgumentError happens on windows when self.base_directory and path are on different drives
103
+ return path
104
+ end
105
+ end
106
+ end
107
+
108
+ def file_path(path)
109
+ "file://#{resolve_path(path)}"
110
+ end
111
+
112
+ def create_component(name, attrs = {})
113
+ target = StringIO.new
114
+ Builder::XmlMarkup.new(:target => target, :indent => 2).component({:name => name}.merge(attrs)) do |xml|
115
+ yield xml if block_given?
116
+ end
117
+ Buildr::IntellijIdea.new_document(target.string).root
118
+ end
119
+
120
+ def components
121
+ @components ||= []
122
+ end
123
+
124
+ def create_composite_component(name, attrs, components)
125
+ return nil if components.empty?
126
+ component = self.create_component(name, attrs)
127
+ components.each do |element|
128
+ element = element.call if element.is_a?(Proc)
129
+ component.add_element element
130
+ end
131
+ component
132
+ end
133
+
134
+ def add_to_composite_component(components)
135
+ components << lambda do
136
+ target = StringIO.new
137
+ yield Builder::XmlMarkup.new(:target => target, :indent => 2)
138
+ Buildr::IntellijIdea.new_document(target.string).root
139
+ end
140
+ end
141
+
142
+ def load_document(filename)
143
+ Buildr::IntellijIdea.new_document(File.read(filename))
144
+ end
145
+
146
+ def document
147
+ if File.exist?(self.filename)
148
+ doc = load_document(self.filename)
149
+ else
150
+ doc = base_document
151
+ inject_components(doc, self.initial_components)
152
+ end
153
+ if self.template
154
+ template_doc = load_document(self.template)
155
+ REXML::XPath.each(template_doc, '//component') do |element|
156
+ inject_component(doc, element)
157
+ end
158
+ end
159
+ inject_components(doc, self.default_components.compact + self.components)
160
+
161
+ # Sort the components in the same order the idea sorts them
162
+ sorted = doc.root.get_elements('//component').sort { |s1, s2| s1.attribute('name').value <=> s2.attribute('name').value }
163
+ doc = base_document
164
+ sorted.each do |element|
165
+ doc.root.add_element element
166
+ end
167
+
168
+ doc
169
+ end
170
+
171
+ def inject_components(doc, components)
172
+ components.each do |component|
173
+ # execute deferred components
174
+ component = component.call if Proc === component
175
+ inject_component(doc, component) if component
176
+ end
177
+ end
178
+
179
+ # replace overridden component (if any) with specified component
180
+ def inject_component(doc, component)
181
+ doc.root.delete_element("//component[@name='#{component.attributes['name']}']")
182
+ doc.root.add_element component
183
+ end
184
+ end
185
+
186
+ # IdeaModule represents an .iml file
187
+ class IdeaModule < IdeaFile
188
+ DEFAULT_TYPE = 'JAVA_MODULE'
189
+
190
+ attr_accessor :type
191
+ attr_accessor :group
192
+ attr_reader :facets
193
+ attr_writer :jdk_version
194
+
195
+ def initialize
196
+ super()
197
+ @type = DEFAULT_TYPE
198
+ end
199
+
200
+ def buildr_project=(buildr_project)
201
+ @id = nil
202
+ @facets = []
203
+ @skip_content = false
204
+ @buildr_project = buildr_project
205
+ end
206
+
207
+ def jdk_version
208
+ @jdk_version || buildr_project.compile.options.source || '1.7'
209
+ end
210
+
211
+ def extension
212
+ 'iml'
213
+ end
214
+
215
+ def annotation_paths
216
+ @annotation_paths ||= [buildr_project._(:source, :main, :annotations)].select {|p| File.exist?(p)}
217
+ end
218
+
219
+ def main_source_directories
220
+ @main_source_directories ||= [buildr_project.compile.sources].flatten.compact
221
+ end
222
+
223
+ def main_resource_directories
224
+ @main_resource_directories ||= [buildr_project.resources.sources].flatten.compact
225
+ end
226
+
227
+ def main_generated_source_directories
228
+ @main_generated_source_directories ||= []
229
+ end
230
+
231
+ def main_generated_resource_directories
232
+ @main_generated_resource_directories ||= []
233
+ end
234
+
235
+ def test_source_directories
236
+ @test_source_directories ||= [buildr_project.test.compile.sources].flatten.compact
237
+ end
238
+
239
+ def test_resource_directories
240
+ @test_resource_directories ||= [buildr_project.test.resources.sources].flatten.compact
241
+ end
242
+
243
+ def test_generated_source_directories
244
+ @test_generated_source_directories ||= []
245
+ end
246
+
247
+ def test_generated_resource_directories
248
+ @test_generated_resource_directories ||= []
249
+ end
250
+
251
+ def excluded_directories
252
+ @excluded_directories ||= [
253
+ buildr_project.resources.target,
254
+ buildr_project.test.resources.target,
255
+ buildr_project.path_to(:target, :main),
256
+ buildr_project.path_to(:target, :test),
257
+ buildr_project.path_to(:reports)
258
+ ].flatten.compact
259
+ end
260
+
261
+ attr_writer :main_output_dir
262
+
263
+ def main_output_dir
264
+ @main_output_dir ||= buildr_project._(:target, :main, :idea, :classes)
265
+ end
266
+
267
+ attr_writer :test_output_dir
268
+
269
+ def test_output_dir
270
+ @test_output_dir ||= buildr_project._(:target, :test, :idea, :classes)
271
+ end
272
+
273
+ def main_dependencies
274
+ @main_dependencies ||= buildr_project.compile.dependencies.dup
275
+ end
276
+
277
+ def test_dependencies
278
+ @test_dependencies ||= buildr_project.test.compile.dependencies.dup
279
+ end
280
+
281
+ def add_facet(name, type)
282
+ add_to_composite_component(self.facets) do |xml|
283
+ xml.facet(:name => name, :type => type) do |xml|
284
+ yield xml if block_given?
285
+ end
286
+ end
287
+ end
288
+
289
+ def skip_content?
290
+ !!@skip_content
291
+ end
292
+
293
+ def skip_content!
294
+ @skip_content = true
295
+ end
296
+
297
+ def add_gwt_facet(modules = {}, options = {})
298
+ name = options[:name] || 'GWT'
299
+ detected_gwt_version = nil
300
+ if options[:gwt_dev_artifact]
301
+ a = Buildr.artifact(options[:gwt_dev_artifact])
302
+ a.invoke
303
+ detected_gwt_version = a.to_s
304
+ end
305
+
306
+ settings =
307
+ {
308
+ :webFacet => 'Web',
309
+ :compilerMaxHeapSize => '512',
310
+ :compilerParameters => '-draftCompile -localWorkers 2 -strict',
311
+ :gwtScriptOutputStyle => 'PRETTY'
312
+ }.merge(options[:settings] || {})
313
+
314
+ buildr_project.compile.dependencies.each do |d|
315
+ if d.to_s =~ /\/com\/google\/gwt\/gwt-dev\/(.*)\//
316
+ detected_gwt_version = d.to_s
317
+ break
318
+ end
319
+ end unless detected_gwt_version
320
+
321
+ if detected_gwt_version
322
+ settings[:gwtSdkUrl] = resolve_path(File.dirname(detected_gwt_version))
323
+ settings[:gwtSdkType] = 'maven'
324
+ else
325
+ settings[:gwtSdkUrl] = 'file://$GWT_TOOLS$'
326
+ end
327
+
328
+ add_facet(name, 'gwt') do |f|
329
+ f.configuration do |c|
330
+ settings.each_pair do |k, v|
331
+ c.setting :name => k.to_s, :value => v.to_s
332
+ end
333
+ c.packaging do |d|
334
+ modules.each_pair do |k, v|
335
+ d.module :name => k, :enabled => v
336
+ end
337
+ end
338
+ end
339
+ end
340
+ end
341
+
342
+ def add_web_facet(options = {})
343
+ name = options[:name] || 'Web'
344
+ default_webroots = {}
345
+ default_webroots[buildr_project._(:source, :main, :webapp)] = '/' if File.exist?(buildr_project._(:source, :main, :webapp))
346
+ buildr_project.assets.paths.each {|p| default_webroots[p] = '/' }
347
+ webroots = options[:webroots] || default_webroots
348
+ default_deployment_descriptors = []
349
+ %w(web.xml sun-web.xml glassfish-web.xml jetty-web.xml geronimo-web.xml context.xml weblogic.xml jboss-deployment-structure.xml jboss-web.xml ibm-web-bnd.xml ibm-web-ext.xml ibm-web-ext-pme.xml).
350
+ each do |descriptor|
351
+ webroots.each_pair do |path, relative_url|
352
+ next unless relative_url == '/'
353
+ d = "#{path}/WEB-INF/#{descriptor}"
354
+ default_deployment_descriptors << d if File.exist?(d)
355
+ end
356
+ end
357
+ deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
358
+
359
+ add_facet(name, 'web') do |f|
360
+ f.configuration do |c|
361
+ c.descriptors do |d|
362
+ deployment_descriptors.each do |deployment_descriptor|
363
+ d.deploymentDescriptor :name => File.basename(deployment_descriptor), :url => file_path(deployment_descriptor)
364
+ end
365
+ end
366
+ c.webroots do |w|
367
+ webroots.each_pair do |webroot, relative_url|
368
+ w.root :url => file_path(webroot), :relative => relative_url
369
+ end
370
+ end
371
+ end
372
+ default_enable_jsf = webroots.keys.any?{|webroot| File.exist?("#{webroot}/WEB-INF/faces-config.xml")}
373
+ enable_jsf = options[:enable_jsf].nil? ? default_enable_jsf : options[:enable_jsf]
374
+ enable_jsf = false if buildr_project.root_project.ipr? && buildr_project.root_project.ipr.version >= '13'
375
+ f.facet(:type => 'jsf', :name => 'JSF') do |jsf|
376
+ jsf.configuration
377
+ end if enable_jsf
378
+ end
379
+ end
380
+
381
+ def add_jpa_facet(options = {})
382
+ name = options[:name] || 'JPA'
383
+
384
+ source_roots = [buildr_project.iml.main_source_directories, buildr_project.compile.sources, buildr_project.resources.sources].flatten.compact
385
+ default_deployment_descriptors = []
386
+ %w[orm.xml persistence.xml].
387
+ each do |descriptor|
388
+ source_roots.each do |path|
389
+ d = "#{path}/META-INF/#{descriptor}"
390
+ default_deployment_descriptors << d if File.exist?(d)
391
+ end
392
+ end
393
+ deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
394
+
395
+ factory_entry = options[:factory_entry] || buildr_project.name.to_s
396
+ validation_enabled = options[:validation_enabled].nil? ? true : options[:validation_enabled]
397
+ if options[:provider_enabled]
398
+ provider = options[:provider_enabled]
399
+ else
400
+ provider = nil
401
+ {'org.hibernate.ejb.HibernatePersistence' => 'Hibernate',
402
+ 'org.eclipse.persistence.jpa.PersistenceProvider' => 'EclipseLink'}.
403
+ each_pair do |match, candidate_provider|
404
+ deployment_descriptors.each do |descriptor|
405
+ if File.exist?(descriptor) && /#{Regexp.escape(match)}/ =~ IO.read(descriptor)
406
+ provider = candidate_provider
407
+ end
408
+ end
409
+ end
410
+ end
411
+
412
+ add_facet(name, 'jpa') do |f|
413
+ f.configuration do |c|
414
+ if provider
415
+ c.setting :name => 'validation-enabled', :value => validation_enabled
416
+ c.setting :name => 'provider-name', :value => provider
417
+ end
418
+ c.tag!('datasource-mapping') do |ds|
419
+ ds.tag!('factory-entry', :name => factory_entry)
420
+ end
421
+ deployment_descriptors.each do |descriptor|
422
+ c.deploymentDescriptor :name => File.basename(descriptor), :url => file_path(descriptor)
423
+ end
424
+ end
425
+ end
426
+ end
427
+
428
+ def add_ejb_facet(options = {})
429
+ name = options[:name] || 'EJB'
430
+
431
+ default_ejb_roots = [buildr_project.iml.main_source_directories, buildr_project.compile.sources, buildr_project.resources.sources].flatten.compact
432
+ ejb_roots = options[:ejb_roots] || default_ejb_roots
433
+
434
+ default_deployment_descriptors = []
435
+ %w(ejb-jar.xml glassfish-ejb-jar.xml ibm-ejb-jar-bnd.xml ibm-ejb-jar-ext-pme.xml ibm-ejb-jar-ext.xml jboss.xml jbosscmp-jdbc.xml openejb-jar.xml sun-cmp-mapping.xml sun-ejb-jar.xml weblogic-cmp-rdbms-jar.xml weblogic-ejb-jar.xml).
436
+ each do |descriptor|
437
+ ejb_roots.each do |path|
438
+ d = "#{path}/WEB-INF/#{descriptor}"
439
+ default_deployment_descriptors << d if File.exist?(d)
440
+ d = "#{path}/META-INF/#{descriptor}"
441
+ default_deployment_descriptors << d if File.exist?(d)
442
+ end
443
+ end
444
+ deployment_descriptors = options[:deployment_descriptors] || default_deployment_descriptors
445
+
446
+ add_facet(name, 'ejb') do |facet|
447
+ facet.configuration do |c|
448
+ c.descriptors do |d|
449
+ deployment_descriptors.each do |deployment_descriptor|
450
+ d.deploymentDescriptor :name => File.basename(deployment_descriptor), :url => file_path(deployment_descriptor)
451
+ end
452
+ end
453
+ c.ejbRoots do |e|
454
+ ejb_roots.each do |ejb_root|
455
+ e.root :url => file_path(ejb_root)
456
+ end
457
+ end
458
+ end
459
+ end
460
+ end
461
+
462
+ protected
463
+
464
+ def main_dependency_details
465
+ target_dir = buildr_project.compile.target.to_s
466
+ main_dependencies.select { |d| d.to_s != target_dir }.collect do |d|
467
+ dependency_path = d.to_s
468
+ export = true
469
+ source_path = nil
470
+ annotations_path = nil
471
+ if d.is_a?(Buildr::Artifact)
472
+ source_spec = d.to_spec_hash.merge(:classifier => 'sources')
473
+ source_path = Buildr.artifact(source_spec).to_s
474
+ source_path = nil unless File.exist?(source_path)
475
+ end
476
+ if d.is_a?(Buildr::Artifact)
477
+ annotations_spec = d.to_spec_hash.merge(:classifier => 'annotations')
478
+ annotations_path = Buildr.artifact(annotations_spec).to_s
479
+ annotations_path = nil unless File.exist?(annotations_path)
480
+ end
481
+ [dependency_path, export, source_path, annotations_path]
482
+ end
483
+ end
484
+
485
+ def test_dependency_details
486
+ main_dependencies_paths = main_dependencies.map(&:to_s)
487
+ target_dir = buildr_project.compile.target.to_s
488
+ test_dependencies.select { |d| d.to_s != target_dir }.collect do |d|
489
+ dependency_path = d.to_s
490
+ export = main_dependencies_paths.include?(dependency_path)
491
+ source_path = nil
492
+ annotations_path = nil
493
+ if d.is_a?(Buildr::Artifact)
494
+ source_spec = d.to_spec_hash.merge(:classifier => 'sources')
495
+ source_path = Buildr.artifact(source_spec).to_s
496
+ source_path = nil unless File.exist?(source_path)
497
+ end
498
+ if d.is_a?(Buildr::Artifact)
499
+ annotations_spec = d.to_spec_hash.merge(:classifier => 'annotations')
500
+ annotations_path = Buildr.artifact(annotations_spec).to_s
501
+ annotations_path = nil unless File.exist?(annotations_path)
502
+ end
503
+ [dependency_path, export, source_path, annotations_path]
504
+ end
505
+ end
506
+
507
+ def base_document
508
+ target = StringIO.new
509
+ Builder::XmlMarkup.new(:target => target).module(:version => '4', :relativePaths => 'true', :type => self.type)
510
+ Buildr::IntellijIdea.new_document(target.string)
511
+ end
512
+
513
+ def initial_components
514
+ []
515
+ end
516
+
517
+ def default_components
518
+ [
519
+ lambda { module_root_component },
520
+ lambda { facet_component }
521
+ ]
522
+ end
523
+
524
+ def facet_component
525
+ create_composite_component('FacetManager', {}, self.facets)
526
+ end
527
+
528
+ def module_root_component
529
+ options = { 'inherit-compiler-output' => 'false' }
530
+ options['LANGUAGE_LEVEL'] = "JDK_#{jdk_version.gsub(/\./, '_')}" unless jdk_version == buildr_project.root_project.compile.options.source
531
+ create_component('NewModuleRootManager', options) do |xml|
532
+ generate_compile_output(xml)
533
+ generate_content(xml) unless skip_content?
534
+ generate_initial_order_entries(xml)
535
+ project_dependencies = []
536
+
537
+ # If a project dependency occurs as a main dependency then add it to the list
538
+ # that are excluded from list of test modules
539
+ self.main_dependency_details.each do |dependency_path, export, source_path|
540
+ next unless export
541
+ project_for_dependency = Buildr.projects.detect do |project|
542
+ [project.packages, project.compile.target, project.resources.target, project.test.compile.target, project.test.resources.target].flatten.
543
+ detect { |artifact| artifact.to_s == dependency_path }
544
+ end
545
+ project_dependencies << project_for_dependency if project_for_dependency
546
+ end
547
+
548
+ main_project_dependencies = project_dependencies.dup
549
+ self.test_dependency_details.each do |dependency_path, export, source_path, annotations_path|
550
+ next if export
551
+ generate_lib(xml, dependency_path, export, source_path, annotations_path, project_dependencies)
552
+ end
553
+
554
+ test_project_dependencies = project_dependencies - main_project_dependencies
555
+ self.main_dependency_details.each do |dependency_path, export, source_path, annotations_path|
556
+ next unless export
557
+ generate_lib(xml, dependency_path, export, source_path, annotations_path, test_project_dependencies)
558
+ end
559
+
560
+ xml.orderEntryProperties
561
+ end
562
+ end
563
+
564
+ def generate_lib(xml, dependency_path, export, source_path, annotations_path, project_dependencies)
565
+ project_for_dependency = Buildr.projects.detect do |project|
566
+ [project.packages, project.compile.target, project.resources.target, project.test.compile.target, project.test.resources.target].flatten.
567
+ detect { |artifact| artifact.to_s == dependency_path }
568
+ end
569
+ if project_for_dependency
570
+ if project_for_dependency.iml? &&
571
+ !project_dependencies.include?(project_for_dependency) &&
572
+ project_for_dependency != self.buildr_project
573
+ generate_project_dependency(xml, project_for_dependency.iml.name, export, !export)
574
+ end
575
+ project_dependencies << project_for_dependency
576
+ else
577
+ generate_module_lib(xml, url_for_path(dependency_path), export, (source_path ? url_for_path(source_path) : nil), (annotations_path ? url_for_path(annotations_path) : nil), !export)
578
+ end
579
+ end
580
+
581
+ def jar_path(path)
582
+ "jar://#{resolve_path(path)}!/"
583
+ end
584
+
585
+ def url_for_path(path)
586
+ if path =~ /jar$/i
587
+ jar_path(path)
588
+ else
589
+ file_path(path)
590
+ end
591
+ end
592
+
593
+ def resolve_path(path)
594
+ resolve_path_from_base(path, '$MODULE_DIR$')
595
+ end
596
+
597
+ def generate_compile_output(xml)
598
+ xml.output(:url => file_path(self.main_output_dir.to_s))
599
+ xml.tag!('output-test', :url => file_path(self.test_output_dir.to_s))
600
+ xml.tag!('exclude-output')
601
+ paths = self.annotation_paths
602
+ unless paths.empty?
603
+ xml.tag!('annotation-paths') do |xml|
604
+ paths.each do |path|
605
+ xml.root(:url=> file_path(path))
606
+ end
607
+ end
608
+ end
609
+ end
610
+
611
+ def generate_content(xml)
612
+ xml.content(:url => 'file://$MODULE_DIR$') do
613
+ # Source folders
614
+ [
615
+ {:dirs => (self.main_source_directories.dup - self.main_generated_source_directories)},
616
+ {:dirs => self.main_generated_source_directories, :generated => true},
617
+ {:type => 'resource', :dirs => (self.main_resource_directories.dup - self.main_generated_resource_directories)},
618
+ {:type => 'resource', :dirs => self.main_generated_resource_directories, :generated => true},
619
+ {:test => true, :dirs => (self.test_source_directories - self.test_generated_source_directories)},
620
+ {:test => true, :dirs => self.test_generated_source_directories, :generated => true},
621
+ {:test => true, :type => 'resource', :dirs => (self.test_resource_directories - self.test_generated_resource_directories)},
622
+ {:test => true, :type => 'resource', :dirs => self.test_generated_resource_directories, :generated => true},
623
+ ].each do |content|
624
+ content[:dirs].map { |dir| dir.to_s }.compact.sort.uniq.each do |dir|
625
+ options = {}
626
+ options[:url] = file_path(dir)
627
+ options[:isTestSource] = (content[:test] ? 'true' : 'false') if content[:type] != 'resource'
628
+ options[:type] = 'java-resource' if content[:type] == 'resource' && !content[:test]
629
+ options[:type] = 'java-test-resource' if content[:type] == 'resource' && content[:test]
630
+ options[:generated] = 'true' if content[:generated]
631
+ xml.sourceFolder options
632
+ end
633
+ end
634
+
635
+ # Exclude target directories
636
+ self.net_excluded_directories.
637
+ collect { |dir| file_path(dir) }.
638
+ select { |dir| relative_dir_inside_dir?(dir) }.
639
+ sort.each do |dir|
640
+ xml.excludeFolder :url => dir
641
+ end
642
+ end
643
+ end
644
+
645
+ def relative_dir_inside_dir?(dir)
646
+ !dir.include?('../')
647
+ end
648
+
649
+ def generate_initial_order_entries(xml)
650
+ xml.orderEntry :type => 'sourceFolder', :forTests => 'false'
651
+ xml.orderEntry :type => 'jdk', :jdkName => jdk_version, :jdkType => 'JavaSDK'
652
+ end
653
+
654
+ def generate_project_dependency(xml, other_project, export, test = false)
655
+ attribs = {:type => 'module', 'module-name' => other_project}
656
+ attribs[:exported] = '' if export
657
+ attribs[:scope] = 'TEST' if test
658
+ xml.orderEntry attribs
659
+ end
660
+
661
+ def generate_module_lib(xml, path, export, source_path, annotations_path, test = false)
662
+ attribs = {:type => 'module-library'}
663
+ attribs[:exported] = '' if export
664
+ attribs[:scope] = 'TEST' if test
665
+ xml.orderEntry attribs do
666
+ xml.library do
667
+ xml.ANNOTATIONS do
668
+ xml.root :url => annotations_path
669
+ end if annotations_path
670
+ xml.CLASSES do
671
+ xml.root :url => path
672
+ end
673
+ xml.JAVADOC
674
+ xml.SOURCES do
675
+ if source_path
676
+ xml.root :url => source_path
677
+ end
678
+ end
679
+ end
680
+ end
681
+ end
682
+
683
+ # Don't exclude things that are subdirectories of other excluded things
684
+ def net_excluded_directories
685
+ net = []
686
+ all = self.excluded_directories.map { |dir| buildr_project._(dir.to_s) }.sort_by { |d| d.size }
687
+ all.each_with_index do |dir, i|
688
+ unless all[0 ... i].find { |other| dir =~ /^#{other}/ }
689
+ net << dir
690
+ end
691
+ end
692
+ net
693
+ end
694
+ end
695
+
696
+ # IdeaModule represents an .ipr file
697
+ class IdeaProject < IdeaFile
698
+ attr_accessor :extra_modules
699
+ attr_accessor :artifacts
700
+ attr_accessor :data_sources
701
+ attr_accessor :configurations
702
+ attr_writer :jdk_version
703
+ attr_writer :version
704
+
705
+ def initialize(buildr_project)
706
+ super()
707
+ @buildr_project = buildr_project
708
+ @extra_modules = []
709
+ @artifacts = []
710
+ @data_sources = []
711
+ @configurations = []
712
+ end
713
+
714
+ def version
715
+ @version || '13'
716
+ end
717
+
718
+ def jdk_version
719
+ @jdk_version ||= buildr_project.compile.options.source || '1.7'
720
+ end
721
+
722
+ def add_artifact(name, type, build_on_make = false)
723
+ add_to_composite_component(self.artifacts) do |xml|
724
+ xml.artifact(:name => name, :type => type, 'build-on-make' => build_on_make) do |xml|
725
+ yield xml if block_given?
726
+ end
727
+ end
728
+ end
729
+
730
+ def add_configuration(name, type, factory_name = nil, default = false, options = {})
731
+ add_to_composite_component(self.configurations) do |xml|
732
+ params = options.dup
733
+ params[:type] = type
734
+ params[:factoryName] = factory_name if factory_name
735
+ params[:name] = name unless default
736
+ params[:default] = !!default
737
+ xml.configuration(params) do
738
+ yield xml if block_given?
739
+ end
740
+ end
741
+ end
742
+
743
+ def add_default_configuration(type, factory_name)
744
+ add_configuration(nil, type, factory_name, true) do |xml|
745
+ yield xml if block_given?
746
+ end
747
+ end
748
+
749
+ def mssql_dialect_mapping
750
+ sql_dialect_mappings(buildr_project.base_dir => 'TSQL')
751
+ end
752
+
753
+ def postgres_dialect_mapping
754
+ sql_dialect_mappings(buildr_project.base_dir => 'PostgreSQL')
755
+ end
756
+
757
+ def sql_dialect_mappings(mappings)
758
+ add_component('SqlDialectMappings') do |component|
759
+ mappings.each_pair do |path, dialect|
760
+ file_path = file_path(path).gsub(/\/.$/, '')
761
+ component.file :url => file_path, :dialect => dialect
762
+ end
763
+ end
764
+ end
765
+
766
+ def add_postgres_data_source(name, options = {})
767
+ if options[:url].nil? && options[:database]
768
+ default_url = "jdbc:postgresql://#{(options[:host] || '127.0.0.1')}:#{(options[:port] || '5432')}/#{options[:database]}"
769
+ end
770
+
771
+ params = {
772
+ :driver => 'org.postgresql.Driver',
773
+ :url => default_url,
774
+ :username => ENV['USER'],
775
+ :dialect => 'PostgreSQL',
776
+ :classpath => ['org.postgresql:postgresql:jar:9.2-1003-jdbc4']
777
+ }.merge(options)
778
+ add_data_source(name, params)
779
+ end
780
+
781
+ def add_sql_server_data_source(name, options = {})
782
+ default_url = nil
783
+ if options[:url].nil? && options[:database]
784
+ default_url = "jdbc:jtds:sqlserver://#{(options[:host] || '127.0.0.1')}:#{(options[:port] || '1433')}/#{options[:database]}"
785
+ end
786
+
787
+ params = {
788
+ :driver => 'net.sourceforge.jtds.jdbc.Driver',
789
+ :url => default_url,
790
+ :username => ENV['USER'],
791
+ :dialect => 'TSQL',
792
+ :classpath => ['net.sourceforge.jtds:jtds:jar:1.2.7']
793
+ }.merge(options)
794
+
795
+ if params[:url]
796
+ if /jdbc\:jtds\:sqlserver\:\/\/[^:\\]+(\:\d+)?\/([^;]*)(\;.*)?/ =~ params[:url]
797
+ database_name = $2
798
+ params[:schema_pattern] = "#{database_name}.*"
799
+ params[:default_schemas] = "#{database_name}.*"
800
+ end
801
+ end
802
+
803
+ add_data_source(name, params)
804
+ end
805
+
806
+ def add_less_compiler_component(project, options = {})
807
+ source_dir = options[:source_dir] || project._(:source, :main, :webapp, :less).to_s
808
+ source_pattern = options[:pattern] || '*.less'
809
+ exclude_pattern = options[:exclude_pattern] || '_*.less'
810
+ target_subdir = options[:target_subdir] || 'css'
811
+ target_dir = options[:target_dir] || project._(:artifacts, project.name)
812
+
813
+ add_component('LessManager') do |component|
814
+ component.option :name => 'lessProfiles' do |outer_option|
815
+ outer_option.map do |map|
816
+ map.entry :key => project.name do |entry|
817
+ entry.value do |value|
818
+ value.LessProfile do |profile|
819
+ profile.option :name => 'cssDirectories' do |option|
820
+ option.list do |list|
821
+ list.CssDirectory do |css_dir|
822
+ css_dir.option :name => 'path', :value => "#{target_dir}#{target_subdir.nil? ? '' : "/#{target_subdir}"}"
823
+ end
824
+ end
825
+ end
826
+ profile.option :name => 'includePattern', :value => source_pattern
827
+ profile.option :name => 'excludePattern', :value => exclude_pattern
828
+ profile.option :name => 'lessDirPath', :value => source_dir
829
+ profile.option :name => 'name', :value => project.name
830
+ end
831
+ end
832
+ end
833
+ end
834
+ end
835
+ end
836
+ end
837
+
838
+ def add_data_source(name, options = {})
839
+ add_to_composite_component(self.data_sources) do |xml|
840
+ data_source_options = {
841
+ :source => 'LOCAL',
842
+ :name => name,
843
+ :uuid => SecureRandom.uuid
844
+ }
845
+ classpath = options[:classpath] || []
846
+ xml.tag!('data-source', data_source_options) do |xml|
847
+ xml.tag!('synchronize', (options[:synchronize]||'true'))
848
+ xml.tag!('jdbc-driver', options[:driver]) if options[:driver]
849
+ xml.tag!('jdbc-url', options[:url]) if options[:url]
850
+ xml.tag!('user-name', options[:username]) if options[:username]
851
+ xml.tag!('user-password', encrypt(options[:password])) if options[:password]
852
+ xml.tag!('schema-pattern', options[:schema_pattern]) if options[:schema_pattern]
853
+ xml.tag!('default-schemas', options[:default_schemas]) if options[:default_schemas]
854
+ xml.tag!('table-pattern', options[:table_pattern]) if options[:table_pattern]
855
+ xml.tag!('default-dialect', options[:dialect]) if options[:dialect]
856
+
857
+ xml.libraries do |xml|
858
+ classpath.each do |classpath_element|
859
+ a = Buildr.artifact(classpath_element)
860
+ a.invoke
861
+ xml.library do |xml|
862
+ xml.tag!('url', resolve_path(a.to_s))
863
+ end
864
+ end
865
+ end if classpath.size > 0
866
+ end
867
+ end
868
+ end
869
+
870
+ def add_war_artifact(project, options = {})
871
+ artifact_name = to_artifact_name(project, options)
872
+ artifacts = options[:artifacts] || []
873
+
874
+ add_artifact(artifact_name, 'war', build_on_make(options)) do |xml|
875
+ dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
876
+ libraries, projects = partition_dependencies(dependencies)
877
+
878
+ emit_output_path(xml, artifact_name, options)
879
+ xml.root :id => 'archive', :name => "#{artifact_name}.war" do
880
+ xml.element :id => 'directory', :name => 'WEB-INF' do
881
+ xml.element :id => 'directory', :name => 'classes' do
882
+ artifact_content(xml, project, projects, options)
883
+ end
884
+ xml.element :id => 'directory', :name => 'lib' do
885
+ emit_libraries(xml, libraries)
886
+ emit_jar_artifacts(xml, artifacts)
887
+ end
888
+ end
889
+
890
+ if options[:enable_war].nil? || options[:enable_war] || (options[:war_module_names] && options[:war_module_names].size > 0)
891
+ module_names = options[:war_module_names] || [project.iml.name]
892
+ module_names.each do |module_name|
893
+ facet_name = options[:war_facet_name] || 'Web'
894
+ xml.element :id => 'javaee-facet-resources', :facet => "#{module_name}/web/#{facet_name}"
895
+ end
896
+ end
897
+
898
+ if options[:enable_gwt] || (options[:gwt_module_names] && options[:gwt_module_names].size > 0)
899
+ module_names = options[:gwt_module_names] || [project.iml.name]
900
+ module_names.each do |module_name|
901
+ facet_name = options[:gwt_facet_name] || 'GWT'
902
+ xml.element :id => 'gwt-compiler-output', :facet => "#{module_name}/gwt/#{facet_name}"
903
+ end
904
+ end
905
+ end
906
+ end
907
+ end
908
+
909
+ def add_exploded_war_artifact(project, options = {})
910
+ artifact_name = to_artifact_name(project, options)
911
+ artifacts = options[:artifacts] || []
912
+
913
+ add_artifact(artifact_name, 'exploded-war', build_on_make(options)) do |xml|
914
+ dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
915
+ libraries, projects = partition_dependencies(dependencies)
916
+
917
+ emit_output_path(xml, artifact_name, options)
918
+ xml.root :id => 'root' do
919
+ xml.element :id => 'directory', :name => 'WEB-INF' do
920
+ xml.element :id => 'directory', :name => 'classes' do
921
+ artifact_content(xml, project, projects, options)
922
+ end
923
+ xml.element :id => 'directory', :name => 'lib' do
924
+ emit_libraries(xml, libraries)
925
+ emit_jar_artifacts(xml, artifacts)
926
+ end
927
+ end
928
+
929
+ if options[:enable_war].nil? || options[:enable_war] || (options[:war_module_names] && options[:war_module_names].size > 0)
930
+ module_names = options[:war_module_names] || [project.iml.name]
931
+ module_names.each do |module_name|
932
+ facet_name = options[:war_facet_name] || 'Web'
933
+ xml.element :id => 'javaee-facet-resources', :facet => "#{module_name}/web/#{facet_name}"
934
+ end
935
+ end
936
+
937
+ if options[:enable_gwt] || (options[:gwt_module_names] && options[:gwt_module_names].size > 0)
938
+ module_names = options[:gwt_module_names] || [project.iml.name]
939
+ module_names.each do |module_name|
940
+ facet_name = options[:gwt_facet_name] || 'GWT'
941
+ xml.element :id => 'gwt-compiler-output', :facet => "#{module_name}/gwt/#{facet_name}"
942
+ end
943
+ end
944
+ end
945
+ end
946
+ end
947
+
948
+ def add_exploded_ear_artifact(project, options ={})
949
+ artifact_name = to_artifact_name(project, options)
950
+
951
+ add_artifact(artifact_name, 'exploded-ear', build_on_make(options)) do |xml|
952
+ dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
953
+ libraries, projects = partition_dependencies(dependencies)
954
+
955
+ emit_output_path(xml, artifact_name, options)
956
+ xml.root :id => 'root' do
957
+ emit_module_output(xml, projects)
958
+ xml.element :id => 'directory', :name => 'lib' do
959
+ emit_libraries(xml, libraries)
960
+ end
961
+ end
962
+ end
963
+ end
964
+
965
+ def add_jar_artifact(project, options = {})
966
+ artifact_name = to_artifact_name(project, options)
967
+
968
+ dependencies = (options[:dependencies] || [project]).flatten
969
+ libraries, projects = partition_dependencies(dependencies)
970
+ raise "Unable to add non-project dependencies (#{libraries.inspect}) to jar artifact" if libraries.size > 0
971
+
972
+ jar_name = "#{artifact_name}.jar"
973
+ add_artifact(jar_name, 'jar', build_on_make(options)) do |xml|
974
+ emit_output_path(xml, artifact_name, options)
975
+ xml.root(:id => 'archive', :name => jar_name) do
976
+ artifact_content(xml, project, projects, options)
977
+ end
978
+ end
979
+ end
980
+
981
+ def add_exploded_ejb_artifact(project, options = {})
982
+ artifact_name = to_artifact_name(project, options)
983
+
984
+ add_artifact(artifact_name, 'exploded-ejb', build_on_make(options)) do |xml|
985
+ dependencies = (options[:dependencies] || [project]).flatten
986
+ libraries, projects = partition_dependencies(dependencies)
987
+ raise "Unable to add non-project dependencies (#{libraries.inspect}) to ejb artifact" if libraries.size > 0
988
+
989
+ emit_output_path(xml, artifact_name, options)
990
+ xml.root :id => 'root' do
991
+ artifact_content(xml, project, projects, options)
992
+ end
993
+ end
994
+ end
995
+
996
+ def add_java_configuration(project, classname, options = {})
997
+ args = options[:args] || ''
998
+ dir = options[:dir] || 'file://$PROJECT_DIR$/'
999
+ debug_port = options[:debug_port] || 2599
1000
+ module_name = options[:module_name] || project.iml.name
1001
+ jvm_args = options[:jvm_args] || ''
1002
+ name = options[:name] || classname
1003
+
1004
+ add_to_composite_component(self.configurations) do |xml|
1005
+ xml.configuration(:name => name, :type => 'Application', :factoryName => 'Application', :default => !!options[:default]) do |xml|
1006
+ xml.extension(:name => 'coverage', :enabled => 'false', :merge => 'false', :sample_coverage => 'true', :runner => 'idea')
1007
+ xml.option(:name => 'MAIN_CLASS_NAME', :value => classname)
1008
+ xml.option(:name => 'VM_PARAMETERS', :value => jvm_args)
1009
+ xml.option(:name => 'PROGRAM_PARAMETERS', :value => args)
1010
+ xml.option(:name => 'WORKING_DIRECTORY', :value => dir)
1011
+ xml.option(:name => 'ALTERNATIVE_JRE_PATH_ENABLED', :value => 'false')
1012
+ xml.option(:name => 'ALTERNATIVE_JRE_PATH', :value => '')
1013
+ xml.option(:name => 'ENABLE_SWING_INSPECTOR', :value => 'false')
1014
+ xml.option(:name => 'ENV_VARIABLES')
1015
+ xml.option(:name => 'PASS_PARENT_ENVS', :value => 'true')
1016
+ xml.module(:name => module_name)
1017
+ xml.envs
1018
+ xml.RunnerSettings(:RunnerId => 'Debug') do |xml|
1019
+ xml.option(:name => 'DEBUG_PORT', :value => debug_port.to_s)
1020
+ xml.option(:name => 'TRANSPORT', :value => '0')
1021
+ xml.option(:name => 'LOCAL', :value => 'true')
1022
+ end
1023
+ xml.RunnerSettings(:RunnerId => 'Run')
1024
+ xml.ConfigurationWrapper(:RunnerId => 'Debug')
1025
+ xml.ConfigurationWrapper(:RunnerId => 'Run')
1026
+ xml.method
1027
+ end
1028
+ end
1029
+ end
1030
+
1031
+ def add_ruby_script_configuration(project, script, options = {})
1032
+ args = options[:args] || ''
1033
+ path = ::Buildr::Util.relative_path(File.expand_path(script), project.base_dir)
1034
+ name = options[:name] || File.basename(script)
1035
+ dir = options[:dir] || "$MODULE_DIR$/#{path}"
1036
+ sdk = options[:sdk]
1037
+
1038
+ add_to_composite_component(self.configurations) do |xml|
1039
+ xml.configuration(:name => name, :type => 'RubyRunConfigurationType', :factoryName => 'Ruby', :default => !!options[:default]) do |xml|
1040
+
1041
+ xml.module(:name => project.iml.name)
1042
+ xml.RUBY_RUN_CONFIG(:NAME => 'RUBY_ARGS', :VALUE => '-e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift)')
1043
+ xml.RUBY_RUN_CONFIG(:NAME => 'WORK DIR', :VALUE => dir)
1044
+ xml.RUBY_RUN_CONFIG(:NAME => 'SHOULD_USE_SDK', :VALUE => 'true')
1045
+ xml.RUBY_RUN_CONFIG(:NAME => 'ALTERN_SDK_NAME', :VALUE => sdk)
1046
+ xml.RUBY_RUN_CONFIG(:NAME => 'myPassParentEnvs', :VALUE => 'true')
1047
+
1048
+ xml.envs
1049
+ xml.EXTENSION(:ID => 'BundlerRunConfigurationExtension', :bundleExecEnabled => 'false')
1050
+ xml.EXTENSION(:ID => 'JRubyRunConfigurationExtension')
1051
+
1052
+ xml.RUBY_RUN_CONFIG(:NAME => 'SCRIPT_PATH', :VALUE => script)
1053
+ xml.RUBY_RUN_CONFIG(:NAME => 'SCRIPT_ARGS', :VALUE => args)
1054
+ xml.RunnerSettings(:RunnerId => 'RubyDebugRunner')
1055
+ xml.ConfigurationWrapper(:RunnerId => 'RubyDebugRunner')
1056
+ end
1057
+ end
1058
+ end
1059
+
1060
+ def add_gwt_configuration(project, options = {})
1061
+ launch_page = options[:launch_page]
1062
+ name = options[:name] || (launch_page ? "Run #{launch_page}" : "Run #{project.name} DevMode")
1063
+ shell_parameters = options[:shell_parameters]
1064
+ vm_parameters = options[:vm_parameters] || '-Xmx512m'
1065
+ singleton = options[:singleton].nil? ? true : !!options[:singleton]
1066
+ super_dev = options[:super_dev].nil? ? true : !!options[:super_dev]
1067
+ gwt_module = options[:gwt_module]
1068
+
1069
+ start_javascript_debugger = options[:start_javascript_debugger].nil? ? true : !!options[:start_javascript_debugger]
1070
+
1071
+ add_configuration(name, 'GWT.ConfigurationType', 'GWT Configuration', false, :singleton => singleton) do |xml|
1072
+ xml.module(:name => options[:iml_name] || project.iml.name)
1073
+
1074
+ xml.option(:name => 'VM_PARAMETERS', :value => vm_parameters)
1075
+ xml.option(:name => 'RUN_PAGE', :value => launch_page) if launch_page
1076
+ xml.option(:name => 'GWT_MODULE', :value => gwt_module) if gwt_module
1077
+
1078
+ # noinspection RubySimplifyBooleanInspection
1079
+ xml.option(:name => 'OPEN_IN_BROWSER', :value => false) if options[:open_in_browser] == false
1080
+ xml.option(:name => 'START_JAVASCRIPT_DEBUGGER', :value => start_javascript_debugger)
1081
+ xml.option(:name => 'USE_SUPER_DEV_MODE', :value => super_dev)
1082
+ xml.option(:name => 'SHELL_PARAMETERS', :value => shell_parameters) if shell_parameters
1083
+
1084
+ xml.RunnerSettings(:RunnerId => 'Debug') do
1085
+ xml.option(:name => 'DEBUG_PORT', :value => '')
1086
+ xml.option(:name => 'TRANSPORT', :value => 0)
1087
+ xml.option(:name => 'LOCAL', :value => true)
1088
+ end
1089
+
1090
+ xml.RunnerSettings(:RunnerId => 'Run')
1091
+ xml.ConfigurationWrapper(:RunnerId => 'Run')
1092
+ xml.ConfigurationWrapper(:RunnerId => 'Debug')
1093
+ xml.method
1094
+ end
1095
+ end
1096
+
1097
+ def add_glassfish_configuration(project, options = {})
1098
+ version = options[:version] || '4.1.0'
1099
+ server_name = options[:server_name] || "GlassFish #{version}"
1100
+ configuration_name = options[:configuration_name] || server_name
1101
+ domain_name = options[:domain] || project.iml.id
1102
+ domain_port = options[:port] || '9009'
1103
+ packaged = options[:packaged] || {}
1104
+ exploded = options[:exploded] || {}
1105
+ artifacts = options[:artifacts] || {}
1106
+
1107
+ add_to_composite_component(self.configurations) do |xml|
1108
+ xml.configuration(:name => configuration_name, :type => 'GlassfishConfiguration', :factoryName => 'Local', :default => false, :APPLICATION_SERVER_NAME => server_name) do |xml|
1109
+ xml.option(:name => 'OPEN_IN_BROWSER', :value => 'false')
1110
+ xml.option(:name => 'UPDATING_POLICY', :value => 'restart-server')
1111
+
1112
+ xml.deployment do |deployment|
1113
+ packaged.each do |name, deployable|
1114
+ artifact = Buildr.artifact(deployable)
1115
+ artifact.invoke
1116
+ deployment.file(:path => resolve_path(artifact.to_s)) do |file|
1117
+ file.settings do |settings|
1118
+ settings.option(:name => 'contextRoot', :value => "/#{name}")
1119
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1120
+ end
1121
+ end
1122
+ end
1123
+ exploded.each do |deployable_name, context_root|
1124
+ deployment.artifact(:name => deployable_name) do |file|
1125
+ file.settings do |settings|
1126
+ settings.option(:name => 'contextRoot', :value => "/#{context_root}")
1127
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1128
+ end
1129
+ end
1130
+ end
1131
+ artifacts.each do |deployable_name, context_root|
1132
+ deployment.artifact(:name => deployable_name) do |file|
1133
+ file.settings do |settings|
1134
+ settings.option(:name => 'contextRoot', :value => "/#{context_root}")
1135
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1136
+ end
1137
+ end
1138
+ end
1139
+ end
1140
+
1141
+ xml.tag! 'server-settings' do |server_settings|
1142
+ server_settings.option(:name => 'VIRTUAL_SERVER')
1143
+ server_settings.option(:name => 'DOMAIN', :value => domain_name.to_s)
1144
+ server_settings.option(:name => 'PRESERVE', :value => 'false')
1145
+ server_settings.option(:name => 'USERNAME', :value => 'admin')
1146
+ server_settings.option(:name => 'PASSWORD', :value => '')
1147
+ end
1148
+
1149
+ xml.predefined_log_file(:id => 'GlassFish', :enabled => 'true')
1150
+
1151
+ xml.extension(:name => 'coverage', :enabled => 'false', :merge => 'false', :sample_coverage => 'true', :runner => 'idea')
1152
+
1153
+ xml.RunnerSettings(:RunnerId => 'Cover')
1154
+
1155
+ add_glassfish_runner_settings(xml, 'Cover')
1156
+ add_glassfish_configuration_wrapper(xml, 'Cover')
1157
+
1158
+ add_glassfish_runner_settings(xml, 'Debug', {
1159
+ :DEBUG_PORT => domain_port.to_s,
1160
+ :TRANSPORT => '0',
1161
+ :LOCAL => 'true',
1162
+ })
1163
+ add_glassfish_configuration_wrapper(xml, 'Debug')
1164
+
1165
+ add_glassfish_runner_settings(xml, 'Run')
1166
+ add_glassfish_configuration_wrapper(xml, 'Run')
1167
+
1168
+ xml.method do |method|
1169
+ method.option(:name => 'BuildArtifacts', :enabled => 'true') do |option|
1170
+ exploded.keys.each do |deployable_name|
1171
+ option.artifact(:name => deployable_name)
1172
+ end
1173
+ artifacts.keys.each do |deployable_name|
1174
+ option.artifact(:name => deployable_name)
1175
+ end
1176
+ end
1177
+ end
1178
+ end
1179
+ end
1180
+ end
1181
+
1182
+ def add_glassfish_remote_configuration(project, options = {})
1183
+ artifact_name = options[:name] || project.iml.id
1184
+ version = options[:version] || '4.1.0'
1185
+ server_name = options[:server_name] || "GlassFish #{version}"
1186
+ configuration_name = options[:configuration_name] || "Remote #{server_name}"
1187
+ domain_port = options[:port] || '9009'
1188
+ packaged = options[:packaged] || {}
1189
+ exploded = options[:exploded] || {}
1190
+ artifacts = options[:artifacts] || {}
1191
+
1192
+ add_to_composite_component(self.configurations) do |xml|
1193
+ xml.configuration(:name => configuration_name, :type => 'GlassfishConfiguration', :factoryName => 'Remote', :default => false, :APPLICATION_SERVER_NAME => server_name) do |xml|
1194
+ xml.option(:name => 'LOCAL', :value => 'false')
1195
+ xml.option(:name => 'OPEN_IN_BROWSER', :value => 'false')
1196
+ xml.option(:name => 'UPDATING_POLICY', :value => 'redeploy-artifacts')
1197
+
1198
+ xml.deployment do |deployment|
1199
+ packaged.each do |name, deployable|
1200
+ artifact = Buildr.artifact(deployable)
1201
+ artifact.invoke
1202
+ deployment.file(:path => resolve_path(artifact.to_s)) do |file|
1203
+ file.settings do |settings|
1204
+ settings.option(:name => 'contextRoot', :value => "/#{name}")
1205
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1206
+ end
1207
+ end
1208
+ end
1209
+ exploded.each do |deployable_name, context_root|
1210
+ deployment.artifact(:name => deployable_name) do |file|
1211
+ file.settings do |settings|
1212
+ settings.option(:name => 'contextRoot', :value => "/#{context_root}")
1213
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1214
+ end
1215
+ end
1216
+ end
1217
+ artifacts.each do |deployable_name, context_root|
1218
+ deployment.artifact(:name => deployable_name) do |file|
1219
+ file.settings do |settings|
1220
+ settings.option(:name => 'contextRoot', :value => "/#{context_root}")
1221
+ settings.option(:name => 'defaultContextRoot', :value => 'false')
1222
+ end
1223
+ end
1224
+ end
1225
+ end
1226
+
1227
+ xml.tag! 'server-settings' do |server_settings|
1228
+ server_settings.option(:name => 'VIRTUAL_SERVER')
1229
+ server_settings.data do |data|
1230
+ data.option(:name => 'adminServerHost', :value => '')
1231
+ data.option(:name => 'clusterName', :value => '')
1232
+ data.option(:name => 'stagingRemotePath', :value => '')
1233
+ data.option(:name => 'transportHostId')
1234
+ data.option(:name => 'transportStagingTarget') do |option|
1235
+ option.TransportTarget do |tt|
1236
+ tt.option(:name => 'id', :value => 'X')
1237
+ end
1238
+ end
1239
+ end
1240
+ end
1241
+
1242
+ xml.predefined_log_file(:id => 'GlassFish', :enabled => 'true')
1243
+
1244
+ add_glassfish_runner_settings(xml, 'Debug', {
1245
+ :DEBUG_PORT => domain_port.to_s,
1246
+ :TRANSPORT => '0',
1247
+ :LOCAL => 'false',
1248
+ })
1249
+ add_glassfish_configuration_wrapper(xml, 'Debug')
1250
+
1251
+ add_glassfish_runner_settings(xml, 'Run')
1252
+ add_glassfish_configuration_wrapper(xml, 'Run')
1253
+
1254
+ xml.method do |method|
1255
+ method.option(:name => 'BuildArtifacts', :enabled => 'true') do |option|
1256
+ exploded.keys.each do |deployable_name|
1257
+ option.artifact(:name => deployable_name)
1258
+ end
1259
+ artifacts.keys.each do |deployable_name|
1260
+ option.artifact(:name => deployable_name)
1261
+ end
1262
+ end
1263
+ end
1264
+ end
1265
+ end
1266
+ end
1267
+
1268
+ def add_testng_configuration(name, options = {})
1269
+ jvm_args = options[:jvm_args] || '-ea'
1270
+ module_name = options[:module] || ''
1271
+ dir = options[:dir]
1272
+
1273
+ opts = {}
1274
+ opts[:folderName] = options[:folderName] if options[:folderName]
1275
+ add_configuration(name, 'TestNG', nil, false, opts) do |xml|
1276
+ xml.module(:name => module_name)
1277
+ xml.option(:name => 'SUITE_NAME', :value => '')
1278
+ xml.option(:name => 'PACKAGE_NAME', :value => options[:package_name] || '')
1279
+ xml.option(:name => 'MAIN_CLASS_NAME', :value => options[:class_name] || '')
1280
+ xml.option(:name => 'METHOD_NAME', :value => options[:method_name] || '')
1281
+ xml.option(:name => 'GROUP_NAME', :value => options[:group_name] || '')
1282
+ xml.option(:name => 'TEST_OBJECT', :value => (!options[:class_name].nil? ? 'CLASS' : 'PACKAGE'))
1283
+ xml.option(:name => 'VM_PARAMETERS', :value => jvm_args)
1284
+ xml.option(:name => 'PARAMETERS', :value => '-configfailurepolicy continue')
1285
+ xml.option(:name => 'WORKING_DIRECTORY', :value => dir) if dir
1286
+ xml.option(:name => 'OUTPUT_DIRECTORY', :value => '')
1287
+ xml.option(:name => 'PROPERTIES_FILE', :value => '')
1288
+ xml.properties
1289
+ xml.listeners
1290
+ xml.method(:v => '2') do
1291
+ xml.option(:name => 'Make', :enabled => 'true')
1292
+ end
1293
+ end
1294
+ end
1295
+
1296
+ def add_default_testng_configuration(options = {})
1297
+ jvm_args = options[:jvm_args] || '-ea'
1298
+ dir = options[:dir] || '$PROJECT_DIR$'
1299
+
1300
+ add_default_configuration('TestNG', 'TestNG') do |xml|
1301
+ xml.extension(:name => 'coverage', :enabled => 'false', :merge => 'false', :sample_coverage => 'true', :runner => 'idea')
1302
+ xml.module(:name => '')
1303
+ xml.option(:name => 'ALTERNATIVE_JRE_PATH_ENABLED', :value => 'false')
1304
+ xml.option(:name => 'ALTERNATIVE_JRE_PATH')
1305
+ xml.option(:name => 'SUITE_NAME')
1306
+ xml.option(:name => 'PACKAGE_NAME')
1307
+ xml.option(:name => 'MAIN_CLASS_NAME')
1308
+ xml.option(:name => 'METHOD_NAME')
1309
+ xml.option(:name => 'GROUP_NAME')
1310
+ xml.option(:name => 'TEST_OBJECT', :value => 'CLASS')
1311
+ xml.option(:name => 'VM_PARAMETERS', :value => jvm_args)
1312
+ xml.option(:name => 'PARAMETERS')
1313
+ xml.option(:name => 'WORKING_DIRECTORY', :value => dir)
1314
+ xml.option(:name => 'OUTPUT_DIRECTORY')
1315
+ xml.option(:name => 'ANNOTATION_TYPE')
1316
+ xml.option(:name => 'ENV_VARIABLES')
1317
+ xml.option(:name => 'PASS_PARENT_ENVS', :value => 'true')
1318
+ xml.option(:name => 'TEST_SEARCH_SCOPE') do |opt|
1319
+ opt.value(:defaultName => 'moduleWithDependencies')
1320
+ end
1321
+ xml.option(:name => 'USE_DEFAULT_REPORTERS', :value => 'false')
1322
+ xml.option(:name => 'PROPERTIES_FILE')
1323
+ xml.envs
1324
+ xml.properties
1325
+ xml.listeners
1326
+ xml.method
1327
+ end
1328
+ end
1329
+
1330
+ protected
1331
+
1332
+ def add_glassfish_runner_settings(xml, name, options = {})
1333
+ xml.RunnerSettings(:RunnerId => name.to_s) do |runner_settings|
1334
+ options.each do |key, value|
1335
+ runner_settings.option(:name => key.to_s, :value => value.to_s)
1336
+ end
1337
+ end
1338
+ end
1339
+
1340
+ def add_glassfish_configuration_wrapper(xml, name)
1341
+ xml.ConfigurationWrapper(:VM_VAR => 'JAVA_OPTS', :RunnerId => name.to_s) do |configuration_wrapper|
1342
+ configuration_wrapper.option(:name => 'USE_ENV_VARIABLES', :value => 'true')
1343
+ configuration_wrapper.STARTUP do |startup|
1344
+ startup.option(:name => 'USE_DEFAULT', :value => 'true')
1345
+ startup.option(:name => 'SCRIPT', :value => '')
1346
+ startup.option(:name => 'VM_PARAMETERS', :value => '')
1347
+ startup.option(:name => 'PROGRAM_PARAMETERS', :value => '')
1348
+ end
1349
+ configuration_wrapper.SHUTDOWN do |shutdown|
1350
+ shutdown.option(:name => 'USE_DEFAULT', :value => 'true')
1351
+ shutdown.option(:name => 'SCRIPT', :value => '')
1352
+ shutdown.option(:name => 'VM_PARAMETERS', :value => '')
1353
+ shutdown.option(:name => 'PROGRAM_PARAMETERS', :value => '')
1354
+ end
1355
+ end
1356
+ end
1357
+
1358
+ def artifact_content(xml, project, projects, options)
1359
+ emit_module_output(xml, projects)
1360
+ emit_jpa_descriptors(xml, project, options)
1361
+ emit_ejb_descriptors(xml, project, options)
1362
+ end
1363
+
1364
+ def extension
1365
+ 'ipr'
1366
+ end
1367
+
1368
+ def base_document
1369
+ target = StringIO.new
1370
+ Builder::XmlMarkup.new(:target => target).project(:version => '4')
1371
+ Buildr::IntellijIdea.new_document(target.string)
1372
+ end
1373
+
1374
+ def default_components
1375
+ [
1376
+ lambda { modules_component },
1377
+ vcs_component,
1378
+ artifacts_component,
1379
+ lambda { data_sources_component },
1380
+ configurations_component,
1381
+ lambda { framework_detection_exclusion_component }
1382
+ ]
1383
+ end
1384
+
1385
+ def framework_detection_exclusion_component
1386
+ create_component('FrameworkDetectionExcludesConfiguration') do |xml|
1387
+ xml.file :url => file_path(buildr_project._(:artifacts))
1388
+ end
1389
+ end
1390
+
1391
+ def initial_components
1392
+ [
1393
+ lambda { project_root_manager_component },
1394
+ lambda { project_details_component }
1395
+ ]
1396
+ end
1397
+
1398
+ def project_root_manager_component
1399
+ attribs = {}
1400
+ attribs['version'] = '2'
1401
+ attribs['languageLevel'] = "JDK_#{self.jdk_version.gsub('.', '_')}"
1402
+ attribs['assert-keyword'] = 'true'
1403
+ attribs['jdk-15'] = (jdk_version >= '1.5').to_s
1404
+ attribs['project-jdk-name'] = self.jdk_version
1405
+ attribs['project-jdk-type'] = 'JavaSDK'
1406
+ create_component('ProjectRootManager', attribs) do |xml|
1407
+ xml.output('url' => file_path(buildr_project._(:target, :idea, :project_out)))
1408
+ end
1409
+ end
1410
+
1411
+ def project_details_component
1412
+ create_component('ProjectDetails') do |xml|
1413
+ xml.option('name' => 'projectName', 'value' => self.name)
1414
+ end
1415
+ end
1416
+
1417
+ def modules_component
1418
+ create_component('ProjectModuleManager') do |xml|
1419
+ xml.modules do
1420
+ buildr_project.projects.select { |subp| subp.iml? }.each do |subproject|
1421
+ module_path = subproject.base_dir.gsub(/^#{buildr_project.base_dir}\//, '')
1422
+ path = "#{module_path}/#{subproject.iml.name}.iml"
1423
+ attribs = {:fileurl => "file://$PROJECT_DIR$/#{path}", :filepath => "$PROJECT_DIR$/#{path}"}
1424
+ if subproject.iml.group == true
1425
+ attribs[:group] = subproject.parent.name.gsub(':', '/')
1426
+ elsif !subproject.iml.group.nil?
1427
+ attribs[:group] = subproject.iml.group.to_s
1428
+ end
1429
+ xml.module attribs
1430
+ end
1431
+ self.extra_modules.each do |iml_file|
1432
+ xml.module :fileurl => "file://$PROJECT_DIR$/#{iml_file}",
1433
+ :filepath => "$PROJECT_DIR$/#{iml_file}"
1434
+ end
1435
+ if buildr_project.iml?
1436
+ xml.module :fileurl => "file://$PROJECT_DIR$/#{buildr_project.iml.name}.iml",
1437
+ :filepath => "$PROJECT_DIR$/#{buildr_project.iml.name}.iml"
1438
+ end
1439
+ end
1440
+ end
1441
+ end
1442
+
1443
+ def vcs_component
1444
+ project_directories = buildr_project.projects.select { |p| p.iml? }.collect { |p| p.base_dir }
1445
+ project_directories << buildr_project.base_dir
1446
+ # Guess the iml file is in the same dir as base dir
1447
+ project_directories += self.extra_modules.collect { |p| File.dirname(p) }
1448
+
1449
+ project_directories = project_directories.sort.uniq
1450
+
1451
+ mappings = {}
1452
+
1453
+ project_directories.each do |dir|
1454
+ if File.directory?("#{dir}/.git")
1455
+ mappings[dir] = 'Git'
1456
+ elsif File.directory?("#{dir}/.svn")
1457
+ mappings[dir] = 'svn'
1458
+ end
1459
+ end
1460
+
1461
+ return nil if 0 == mappings.size
1462
+
1463
+ create_component('VcsDirectoryMappings') do |xml|
1464
+ mappings.each_pair do |dir, vcs_type|
1465
+ resolved_dir = resolve_path(dir)
1466
+ mapped_dir = resolved_dir == '$PROJECT_DIR$/.' ? buildr_project.base_dir : resolved_dir
1467
+ xml.mapping :directory => mapped_dir, :vcs => vcs_type
1468
+ end
1469
+ end
1470
+ end
1471
+
1472
+ def data_sources_component
1473
+ create_composite_component('DataSourceManagerImpl', {:format => 'xml', :hash => '3208837817'}, self.data_sources)
1474
+ end
1475
+
1476
+ def artifacts_component
1477
+ create_composite_component('ArtifactManager', {}, self.artifacts)
1478
+ end
1479
+
1480
+ def configurations_component
1481
+ create_composite_component('ProjectRunConfigurationManager', {}, self.configurations)
1482
+ end
1483
+
1484
+ def resolve_path(path)
1485
+ resolve_path_from_base(path, '$PROJECT_DIR$')
1486
+ end
1487
+
1488
+ private
1489
+
1490
+ def to_artifact_name(project, options)
1491
+ options[:name] || project.iml.id
1492
+ end
1493
+
1494
+ def build_on_make(options)
1495
+ options[:build_on_make].nil? ? false : options[:build_on_make]
1496
+ end
1497
+
1498
+ def emit_jar_artifacts(xml, artifacts)
1499
+ artifacts.each do |p|
1500
+ xml.element :id => 'artifact', 'artifact-name' => "#{p}.jar"
1501
+ end
1502
+ end
1503
+
1504
+ def emit_libraries(xml, libraries)
1505
+ libraries.each(&:invoke).map(&:to_s).each do |dependency_path|
1506
+ xml.element :id => 'file-copy', :path => resolve_path(dependency_path)
1507
+ end
1508
+ end
1509
+
1510
+ def emit_module_output(xml, projects)
1511
+ projects.each do |p|
1512
+ xml.element :id => 'module-output', :name => p.iml.name
1513
+ end
1514
+ end
1515
+
1516
+ def emit_output_path(xml, artifact_name, options)
1517
+ ## The content here can not be indented
1518
+ output_dir = options[:output_dir] || buildr_project._(:artifacts, artifact_name)
1519
+ xml.tag!('output-path', resolve_path(output_dir))
1520
+ end
1521
+
1522
+ def emit_ejb_descriptors(xml, project, options)
1523
+ if options[:enable_ejb] || (options[:ejb_module_names] && options[:ejb_module_names].size > 0)
1524
+ module_names = options[:ejb_module_names] || [project.iml.name]
1525
+ module_names.each do |module_name|
1526
+ facet_name = options[:ejb_facet_name] || 'EJB'
1527
+ xml.element :id => 'javaee-facet-resources', :facet => "#{module_name}/ejb/#{facet_name}"
1528
+ end
1529
+ end
1530
+ end
1531
+
1532
+ def emit_jpa_descriptors(xml, project, options)
1533
+ if options[:enable_jpa] || (options[:jpa_module_names] && options[:jpa_module_names].size > 0)
1534
+ module_names = options[:jpa_module_names] || [project.iml.name]
1535
+ module_names.each do |module_name|
1536
+ facet_name = options[:jpa_facet_name] || 'JPA'
1537
+ xml.element :id => 'jpa-descriptors', :facet => "#{module_name}/jpa/#{facet_name}"
1538
+ end
1539
+ end
1540
+ end
1541
+
1542
+ def encrypt(password)
1543
+ password.bytes.inject('') { |x, y| x + (y ^ 0xdfaa).to_s(16) }
1544
+ end
1545
+
1546
+ def partition_dependencies(dependencies)
1547
+ libraries = []
1548
+ projects = []
1549
+
1550
+ dependencies.each do |dependency|
1551
+ artifacts = Buildr.artifacts(dependency)
1552
+ artifacts_as_strings = artifacts.map(&:to_s)
1553
+ all_projects = Buildr::Project.instance_variable_get('@projects').keys
1554
+ project = Buildr.projects(all_projects).detect do |project|
1555
+ [project.packages, project.compile.target, project.resources.target, project.test.compile.target, project.test.resources.target].flatten.
1556
+ detect { |component| artifacts_as_strings.include?(component.to_s) }
1557
+ end
1558
+ if project
1559
+ projects << project
1560
+ else
1561
+ libraries += artifacts
1562
+ end
1563
+ end
1564
+ return libraries.uniq, projects.uniq
1565
+ end
1566
+ end
1567
+
1568
+ module ProjectExtension
1569
+ include Extension
1570
+
1571
+ first_time do
1572
+ desc 'Generate Intellij IDEA artifacts for all projects'
1573
+ Project.local_task 'idea' => 'artifacts'
1574
+
1575
+ desc 'Delete the generated Intellij IDEA artifacts'
1576
+ Project.local_task 'idea:clean'
1577
+ end
1578
+
1579
+ before_define do |project|
1580
+ project.recursive_task('idea')
1581
+ project.recursive_task('idea:clean')
1582
+ end
1583
+
1584
+ after_define do |project|
1585
+ idea = project.task('idea')
1586
+
1587
+ files = [
1588
+ (project.iml if project.iml?),
1589
+ (project.ipr if project.ipr?)
1590
+ ].compact
1591
+
1592
+ files.each do |ideafile|
1593
+ module_dir = File.dirname(ideafile.filename)
1594
+ idea.enhance do |task|
1595
+ mkdir_p module_dir
1596
+ info "Writing #{ideafile.filename}"
1597
+ t = Tempfile.open('buildr-idea')
1598
+ temp_filename = t.path
1599
+ t.close!
1600
+ File.open(temp_filename, 'w') do |f|
1601
+ ideafile.write f
1602
+ end
1603
+ mv temp_filename, ideafile.filename
1604
+ end
1605
+ if project.ipr?
1606
+ filename = project._("#{project.ipr.name}.ids")
1607
+ rm_rf filename if File.exists?(filename)
1608
+ end
1609
+ end
1610
+
1611
+ project.task('idea:clean') do
1612
+ files.each do |f|
1613
+ info "Removing #{f.filename}" if File.exist?(f.filename)
1614
+ rm_rf f.filename
1615
+ end
1616
+ end
1617
+ end
1618
+
1619
+ def ipr
1620
+ if ipr?
1621
+ @ipr ||= IdeaProject.new(self)
1622
+ else
1623
+ raise 'Only the root project has an IPR'
1624
+ end
1625
+ end
1626
+
1627
+ def ipr?
1628
+ !@no_ipr && self.parent.nil?
1629
+ end
1630
+
1631
+ def iml
1632
+ if iml?
1633
+ unless @iml
1634
+ inheritable_iml_source = self.parent
1635
+ while inheritable_iml_source && !inheritable_iml_source.iml?
1636
+ inheritable_iml_source = inheritable_iml_source.parent;
1637
+ end
1638
+ @iml = inheritable_iml_source ? inheritable_iml_source.iml.clone : IdeaModule.new
1639
+ @iml.buildr_project = self
1640
+ end
1641
+ return @iml
1642
+ else
1643
+ raise "IML generation is disabled for #{self.name}"
1644
+ end
1645
+ end
1646
+
1647
+ def no_ipr
1648
+ @no_ipr = true
1649
+ end
1650
+
1651
+ def no_iml
1652
+ @has_iml = false
1653
+ end
1654
+
1655
+ def iml?
1656
+ @has_iml = @has_iml.nil? ? true : @has_iml
1657
+ end
1658
+ end
1659
+ end
1660
+ end
1661
+
1662
+ class Buildr::Project
1663
+ include Buildr::IntellijIdea::ProjectExtension
1664
+ end