buildr 1.4.6-java → 1.4.7-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/CHANGELOG +81 -0
  2. data/Rakefile +5 -2
  3. data/addon/buildr/antlr.rb +0 -4
  4. data/addon/buildr/bnd.rb +3 -1
  5. data/addon/buildr/checkstyle.rb +201 -0
  6. data/addon/buildr/cobertura.rb +0 -1
  7. data/addon/buildr/drb.rb +0 -2
  8. data/addon/buildr/emma.rb +0 -1
  9. data/addon/buildr/findbugs.rb +227 -0
  10. data/addon/buildr/gwt.rake +82 -0
  11. data/addon/buildr/hibernate.rb +0 -4
  12. data/addon/buildr/javacc.rb +0 -4
  13. data/addon/buildr/javancss.rb +155 -0
  14. data/addon/buildr/jdepend.rb +138 -24
  15. data/addon/buildr/jdepend.rb.orig +178 -0
  16. data/addon/buildr/jetty.rb +0 -5
  17. data/addon/buildr/jibx.rb +85 -86
  18. data/addon/buildr/nailgun.rb +2 -2
  19. data/addon/buildr/openjpa.rb +0 -4
  20. data/addon/buildr/pmd.rb +166 -0
  21. data/addon/buildr/protobuf.rb +0 -1
  22. data/addon/buildr/sonar.rb +142 -0
  23. data/addon/buildr/xmlbeans.rb +0 -5
  24. data/buildr.gemspec +36 -21
  25. data/doc/_layouts/default.html +1 -0
  26. data/doc/contributing.textile +11 -2
  27. data/doc/download.textile +17 -5
  28. data/doc/index.textile +21 -46
  29. data/doc/installing.textile +18 -8
  30. data/doc/installing.textile.orig +282 -0
  31. data/doc/languages.textile +0 -38
  32. data/doc/more_stuff.textile +199 -12
  33. data/doc/more_stuff.textile.orig +1004 -0
  34. data/doc/packaging.textile +10 -0
  35. data/doc/settings_profiles.textile +2 -2
  36. data/etc/KEYS +44 -0
  37. data/lib/buildr.rb +67 -4
  38. data/lib/buildr/clojure.rb +0 -2
  39. data/lib/buildr/core/application.rb +23 -32
  40. data/lib/buildr/core/build.rb +0 -7
  41. data/lib/buildr/core/cc.rb +0 -5
  42. data/lib/buildr/core/checks.rb +0 -4
  43. data/lib/buildr/core/common.rb +0 -5
  44. data/lib/buildr/core/compile.rb +5 -10
  45. data/lib/buildr/core/doc.rb +9 -3
  46. data/lib/buildr/core/environment.rb +0 -1
  47. data/lib/buildr/core/filter.rb +0 -5
  48. data/lib/buildr/core/generate.rb +2 -6
  49. data/lib/buildr/core/help.rb +1 -6
  50. data/lib/buildr/core/linux.rb +0 -1
  51. data/lib/buildr/core/osx.rb +0 -1
  52. data/lib/buildr/core/project.rb +0 -4
  53. data/lib/buildr/core/run.rb +1 -5
  54. data/lib/buildr/core/shell.rb +1 -6
  55. data/lib/buildr/core/test.rb +1 -7
  56. data/lib/buildr/core/transports.rb +4 -6
  57. data/lib/buildr/core/util.rb +2 -65
  58. data/lib/buildr/groovy/doc.rb +0 -3
  59. data/lib/buildr/groovy/shell.rb +0 -2
  60. data/lib/buildr/ide/eclipse.rb +4 -13
  61. data/lib/buildr/ide/eclipse/java.rb +0 -4
  62. data/lib/buildr/ide/eclipse/plugin.rb +0 -4
  63. data/lib/buildr/ide/eclipse/scala.rb +0 -4
  64. data/lib/buildr/ide/idea.rb +284 -52
  65. data/lib/buildr/java/ant.rb +2 -6
  66. data/lib/buildr/java/bdd.rb +5 -123
  67. data/lib/buildr/java/cobertura.rb +16 -10
  68. data/lib/buildr/java/commands.rb +33 -7
  69. data/lib/buildr/java/compiler.rb +0 -7
  70. data/lib/buildr/java/deprecated.rb +0 -4
  71. data/lib/buildr/java/doc.rb +0 -2
  72. data/lib/buildr/java/emma.rb +0 -4
  73. data/lib/buildr/java/jruby.rb +0 -2
  74. data/lib/buildr/java/packaging.rb +0 -4
  75. data/lib/buildr/java/pom.rb +24 -16
  76. data/lib/buildr/java/rjb.rb +1 -1
  77. data/lib/buildr/java/test_result.rb +1 -2
  78. data/lib/buildr/java/tests.rb +68 -6
  79. data/lib/buildr/packaging/archive.rb +0 -1
  80. data/lib/buildr/packaging/artifact.rb +19 -16
  81. data/lib/buildr/packaging/artifact_namespace.rb +51 -24
  82. data/lib/buildr/packaging/artifact_search.rb +1 -2
  83. data/lib/buildr/packaging/gems.rb +1 -13
  84. data/lib/buildr/packaging/package.rb +0 -6
  85. data/lib/buildr/packaging/tar.rb +2 -4
  86. data/lib/buildr/packaging/version_requirement.rb +1 -1
  87. data/lib/buildr/packaging/zip.rb +1 -2
  88. data/lib/buildr/packaging/ziptask.rb +0 -4
  89. data/lib/buildr/run.rb +3 -3
  90. data/lib/buildr/scala/bdd.rb +129 -11
  91. data/lib/buildr/scala/compiler.rb +53 -6
  92. data/lib/buildr/scala/doc.rb +6 -4
  93. data/lib/buildr/scala/org/apache/buildr/Specs2Runner.class +0 -0
  94. data/lib/buildr/scala/org/apache/buildr/Specs2Runner.java +38 -0
  95. data/lib/buildr/scala/shell.rb +0 -4
  96. data/lib/buildr/scala/tests.rb +15 -6
  97. data/lib/buildr/shell.rb +0 -1
  98. data/lib/buildr/version.rb +1 -1
  99. data/rakelib/all-in-one.rake +20 -11
  100. data/rakelib/checks.rake +0 -31
  101. data/rakelib/doc.rake +86 -100
  102. data/rakelib/package.rake +3 -3
  103. data/rakelib/release.rake +1 -1
  104. data/rakelib/rspec.rake +23 -7
  105. data/rakelib/stage.rake +18 -21
  106. data/spec/addon/bnd_spec.rb +2 -2
  107. data/spec/addon/jaxb_xjc_spec.rb +5 -0
  108. data/spec/core/application_spec.rb +11 -64
  109. data/spec/core/cc_spec.rb +12 -5
  110. data/spec/core/compile_spec.rb +11 -0
  111. data/spec/core/doc_spec.rb +1 -1
  112. data/spec/core/run_spec.rb +17 -4
  113. data/spec/core/test_spec.rb +5 -3
  114. data/spec/ide/idea_spec.rb +60 -0
  115. data/spec/java/bdd_spec.rb +8 -218
  116. data/spec/java/cobertura_spec.rb +4 -0
  117. data/spec/java/compiler_spec.rb +11 -8
  118. data/spec/java/emma_spec.rb +4 -1
  119. data/spec/java/java_spec.rb +1 -1
  120. data/spec/java/pom_spec.rb +125 -0
  121. data/spec/java/tests_spec.rb +185 -0
  122. data/spec/packaging/archive_spec.rb +1 -1
  123. data/spec/packaging/artifact_namespace_spec.rb +15 -0
  124. data/spec/packaging/artifact_spec.rb +26 -1
  125. data/spec/sandbox.rb +7 -1
  126. data/spec/scala/bdd_spec.rb +111 -8
  127. data/spec/scala/tests_spec.rb +5 -1
  128. data/spec/spec_helpers.rb +9 -4
  129. data/spec/version_requirement_spec.rb +2 -0
  130. metadata +499 -467
  131. data/lib/buildr/core.rb +0 -34
  132. data/lib/buildr/ide.rb +0 -19
  133. data/lib/buildr/java.rb +0 -25
  134. data/lib/buildr/java/jtestr_result.rb +0 -331
  135. data/lib/buildr/java/jtestr_runner.rb.erb +0 -116
  136. data/lib/buildr/packaging.rb +0 -25
  137. data/rakelib/setup.rake +0 -68
@@ -13,7 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
16
  # Let's see if we can use notify-send. Must be running from console in verbose mode.
18
17
  if $stdout.isatty && verbose
19
18
  system("which notify-send > /dev/null 2>/dev/null")
@@ -13,7 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
16
  # Let's see if we can use Growl. Must be running from console in verbose mode.
18
17
  if $stdout.isatty && verbose
19
18
  def growl_notify(type, title, message)
@@ -13,10 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/util'
18
-
19
-
20
16
  module Buildr
21
17
 
22
18
  # Symbolic mapping for directory layout. Used for both the default and custom layouts.
@@ -13,10 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
- require 'buildr/run'
17
- require 'buildr/java/commands'
18
- require 'buildr/core/util'
19
-
20
16
  module Buildr
21
17
  module Run
22
18
 
@@ -27,7 +23,7 @@ module Buildr
27
23
 
28
24
  def run(task)
29
25
  fail "Missing :main option" unless task.options[:main]
30
- cp = project.compile.dependencies + [project.path_to(:target, :classes)] + task.classpath
26
+ cp = project.compile.dependencies + [project.path_to(:target, :classes), project.path_to(:target, :resources)] + task.classpath
31
27
  Java::Commands.java(task.options[:main], {
32
28
  :properties => jrebel_props(project).merge(task.options[:properties] || {}),
33
29
  :classpath => cp,
@@ -13,11 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/shell'
18
- require 'buildr/java/commands'
19
- require 'buildr/core/util'
20
-
21
16
  module Buildr
22
17
 
23
18
  module Shell
@@ -120,7 +115,7 @@ module Buildr
120
115
 
121
116
  private
122
117
  def jruby_home
123
- @jruby_home ||= RUBY_PLATFORM =~ /java/ ? Config::CONFIG['prefix'] : ENV['JRUBY_HOME']
118
+ @jruby_home ||= RUBY_PLATFORM =~ /java/ ? RbConfig::CONFIG['prefix'] : ENV['JRUBY_HOME']
124
119
  end
125
120
 
126
121
  def jruby_artifact
@@ -13,12 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/core/build'
19
- require 'buildr/core/compile'
20
-
21
-
22
16
  module Buildr
23
17
 
24
18
  # The underlying test framework used by TestTask.
@@ -145,7 +139,7 @@ module Buildr
145
139
  # cases are written in Java, then JUnit is selected as the test framework. You can also select
146
140
  # a specific test framework, for example, to use TestNG instead of JUnit:
147
141
  # test.using :testng
148
- class TestTask < Rake::Task
142
+ class TestTask < ::Rake::Task
149
143
 
150
144
  class << self
151
145
 
@@ -13,20 +13,16 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'uri'
18
16
  require 'net/http'
19
17
  # PATCH: On Windows, Net::SSH 2.0.2 attempts to load the Pageant DLLs which break on JRuby.
20
18
  $LOADED_FEATURES << 'net/ssh/authentication/pageant.rb' if RUBY_PLATFORM =~ /java/
21
- gem 'net-ssh' ; Net.autoload :SSH, 'net/ssh'
22
- gem 'net-sftp' ; Net.autoload :SFTP, 'net/sftp'
19
+ Net.autoload :SSH, 'net/ssh'
20
+ Net.autoload :SFTP, 'net/sftp'
23
21
  autoload :CGI, 'cgi'
24
22
  require 'digest/md5'
25
23
  require 'digest/sha1'
26
- require 'stringio'
27
24
  autoload :ProgressBar, 'buildr/core/progressbar'
28
25
 
29
-
30
26
  # Not quite open-uri, but similar. Provides read and write methods for the resource represented by the URI.
31
27
  # Currently supports reads for URI::HTTP and writes for URI::SFTP. Also provides convenience methods for
32
28
  # downloads and uploads.
@@ -308,6 +304,8 @@ module URI
308
304
  end
309
305
  end
310
306
  return result
307
+ when Net::HTTPUnauthorized
308
+ raise NotFoundError, "Looking for #{self} but repository says Unauthorized/401."
311
309
  when Net::HTTPNotFound
312
310
  raise NotFoundError, "Looking for #{self} and all I got was a 404!"
313
311
  else
@@ -13,17 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'rbconfig'
18
- require 'pathname'
19
- autoload :Tempfile, 'tempfile'
20
- autoload :YAML, 'yaml'
21
- autoload :REXML, 'rexml/document'
22
- gem 'xml-simple' ; autoload :XmlSimple, 'xmlsimple'
23
- gem 'builder' ; autoload :Builder, 'builder' # A different kind of buildr, one we use to create XML.
24
- require 'highline/import'
25
-
26
-
27
16
  module Buildr
28
17
 
29
18
  module Util
@@ -43,7 +32,7 @@ module Buildr
43
32
  # For JRuby, the value for RUBY_PLATFORM will always be 'java'
44
33
  # That's why this function checks on Config::CONFIG['host_os']
45
34
  def win_os?
46
- Config::CONFIG['host_os'] =~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i
35
+ RbConfig::CONFIG['host_os'] =~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i
47
36
  end
48
37
 
49
38
  # Runs Ruby with these command line arguments. The last argument may be a hash,
@@ -54,7 +43,7 @@ module Buildr
54
43
  def ruby(*args)
55
44
  options = Hash === args.last ? args.pop : {}
56
45
  cmd = []
57
- ruby_bin = normalize_path(Config::CONFIG['ruby_install_name'], Config::CONFIG['bindir'])
46
+ ruby_bin = normalize_path(RbConfig::CONFIG['ruby_install_name'], RbConfig::CONFIG['bindir'])
58
47
  if options.delete(:sudo) && !(win_os? || Process.uid == File.stat(ruby_bin).uid)
59
48
  cmd << 'sudo' << '-u' << "##{File.stat(ruby_bin).uid}"
60
49
  end
@@ -131,58 +120,6 @@ module Buildr
131
120
  end
132
121
  end
133
122
 
134
- # Utility methods for running gem commands
135
- module Gems #:nodoc:
136
- extend self
137
-
138
- # Install gems specified by each Gem::Dependency if they are missing. This method prompts the user
139
- # for permission before installing anything.
140
- #
141
- # Returns the installed Gem::Dependency objects or fails if permission not granted or when buildr
142
- # is not running interactively (on a tty)
143
- def install(*dependencies)
144
- raise ArgumentError, "Expected at least one argument" if dependencies.empty?
145
- not_found_deps = []
146
- to_install = []
147
- remote = dependencies.each do |dep|
148
- if spec = Gem.source_index.search(dep).last
149
- # Found in local repo
150
- to_install << spec
151
- elsif (spec = Gem::SpecFetcher.fetcher.fetch(dep, true).map { |spec, source| spec }.last)
152
- # Found in remote repo
153
- to_install << spec
154
- else
155
- # Not found anywhere
156
- not_found_deps << "#{dep.name} #{dep.requirement}"
157
- end
158
- end
159
- fail Gem::LoadError, "Build requires the gems #{not_found_deps.join(', ')}, which cannot be found in local or remote repository." unless not_found_deps.empty?
160
- uses = "This build requires the gems #{to_install.map(&:full_name).join(', ')}:"
161
- fail Gem::LoadError, "#{uses} to install, run Buildr interactively." unless $stdout.isatty
162
- unless agree("#{uses} do you want me to install them? [Y/n]", true)
163
- fail Gem::LoadError, 'Cannot build without these gems.'
164
- end
165
- to_install.each do |spec|
166
- say "Installing #{spec.full_name} ... " if verbose
167
- command 'install', spec.name, '-v', spec.version.to_s, :verbose => false
168
- Gem.source_index.load_gems_in Gem::SourceIndex.installed_spec_directories
169
- end
170
- to_install
171
- end
172
-
173
- # Execute a GemRunner command
174
- def command(cmd, *args)
175
- options = Hash === args.last ? args.pop : {}
176
- gem_home = ENV['GEM_HOME'] || Gem.path.find { |f| File.writable?(f) }
177
- options[:sudo] = :root unless Util.win_os? || gem_home
178
- options[:command] = 'gem'
179
- args << options
180
- args.unshift '-i', gem_home if cmd == 'install' && gem_home && !args.any?{ |a| a[/-i|--install-dir/] }
181
- Util.ruby cmd, *args
182
- end
183
-
184
- end # Gems
185
-
186
123
  end # Util
187
124
  end
188
125
 
@@ -13,9 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
- require 'buildr/core/doc'
17
- require 'buildr/groovy/compiler' # ensure Groovy dependencies are ready
18
-
19
16
  module Buildr
20
17
  module Doc
21
18
 
@@ -13,8 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
- require 'buildr/shell'
17
-
18
16
  module Buildr
19
17
  module Groovy
20
18
  class GroovySH < Buildr::Shell::Base
@@ -13,11 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/packaging'
19
-
20
-
21
16
  module Buildr
22
17
  module Eclipse #:nodoc:
23
18
  include Extension
@@ -255,16 +250,16 @@ module Buildr
255
250
  classpathentry.src project.test.resources
256
251
  end
257
252
 
253
+ project.eclipse.classpath_containers.each { |container|
254
+ classpathentry.con container
255
+ }
256
+
258
257
  # Classpath elements from other projects
259
258
  classpathentry.src_projects project_libs
260
259
 
261
260
  classpathentry.output project.compile.target if project.compile.target
262
261
  classpathentry.lib libs
263
262
  classpathentry.var vars
264
-
265
- project.eclipse.classpath_containers.each { |container|
266
- classpathentry.con container
267
- }
268
263
  end
269
264
  end
270
265
  end
@@ -426,8 +421,4 @@ class Buildr::Project
426
421
  include Buildr::Eclipse
427
422
  end
428
423
 
429
- # Order is significant for auto-detection, from most specific to least
430
- require 'buildr/ide/eclipse/plugin'
431
- require 'buildr/ide/eclipse/scala'
432
- require 'buildr/ide/eclipse/java'
433
424
 
@@ -13,10 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/core/common'
19
-
20
16
  module Buildr
21
17
  module Eclipse
22
18
  module Java
@@ -13,10 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/core/common'
19
-
20
16
  module Buildr
21
17
  module Eclipse
22
18
  module Plugin
@@ -13,10 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/core/common'
19
-
20
16
  module Buildr
21
17
  module Eclipse
22
18
  module Scala
@@ -13,12 +13,6 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- require 'buildr/core/project'
18
- require 'buildr/packaging'
19
- require 'stringio'
20
-
21
-
22
16
  module Buildr
23
17
  module IntellijIdea
24
18
  def self.new_document(value)
@@ -28,11 +22,17 @@ module Buildr
28
22
  # Abstract base class for IdeaModule and IdeaProject
29
23
  class IdeaFile
30
24
  DEFAULT_SUFFIX = ""
25
+ DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE = "MAVEN_REPOSITORY"
31
26
 
32
27
  attr_reader :buildr_project
33
28
  attr_writer :suffix
34
29
  attr_writer :id
35
30
  attr_accessor :template
31
+ attr_accessor :local_repository_env_override
32
+
33
+ def initialize
34
+ @local_repository_env_override = DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE
35
+ end
36
36
 
37
37
  def suffix
38
38
  @suffix ||= DEFAULT_SUFFIX
@@ -50,8 +50,10 @@ module Buildr
50
50
  self.components << create_component(name, attrs, &xml)
51
51
  end
52
52
 
53
+ # IDEA can not handle text content with indents so need to removing indenting
54
+ # Can not pass true as third argument as the ruby library seems broken
53
55
  def write(f)
54
- document.write(f, 2, false, true)
56
+ document.write(f, -1, false, true)
55
57
  end
56
58
 
57
59
  protected
@@ -60,6 +62,32 @@ module Buildr
60
62
  "#{self.id}#{suffix}"
61
63
  end
62
64
 
65
+ def relative(path)
66
+ ::Buildr::Util.relative_path(File.expand_path(path.to_s), self.base_directory)
67
+ end
68
+
69
+ def base_directory
70
+ buildr_project.path_to
71
+ end
72
+
73
+ def resolve_path_from_base(path, base_variable)
74
+ m2repo = Buildr::Repositories.instance.local
75
+ if path.to_s.index(m2repo) == 0 && !self.local_repository_env_override.nil?
76
+ return path.sub(m2repo, "$#{self.local_repository_env_override}$")
77
+ else
78
+ begin
79
+ return "#{base_variable}/#{relative(path)}"
80
+ rescue ArgumentError
81
+ # ArgumentError happens on windows when self.base_directory and path are on different drives
82
+ return path
83
+ end
84
+ end
85
+ end
86
+
87
+ def file_path(path)
88
+ "file://#{resolve_path(path)}"
89
+ end
90
+
63
91
  def create_component(name, attrs = {})
64
92
  target = StringIO.new
65
93
  Builder::XmlMarkup.new(:target => target, :indent => 2).component(attrs.merge({:name => name})) do |xml|
@@ -72,6 +100,24 @@ module Buildr
72
100
  @components ||= self.default_components.compact
73
101
  end
74
102
 
103
+ def create_composite_component(name, components)
104
+ return nil if components.empty?
105
+ component = self.create_component(name)
106
+ components.each do |element|
107
+ element = element.call if element.is_a?(Proc)
108
+ component.add_element element
109
+ end
110
+ component
111
+ end
112
+
113
+ def add_to_composite_component(components)
114
+ components << lambda do
115
+ target = StringIO.new
116
+ yield Builder::XmlMarkup.new(:target => target, :indent => 2)
117
+ Buildr::IntellijIdea.new_document(target.string).root
118
+ end
119
+ end
120
+
75
121
  def load_document(filename)
76
122
  Buildr::IntellijIdea.new_document(File.read(filename))
77
123
  end
@@ -111,16 +157,14 @@ module Buildr
111
157
  # IdeaModule represents an .iml file
112
158
  class IdeaModule < IdeaFile
113
159
  DEFAULT_TYPE = "JAVA_MODULE"
114
- DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE = "MAVEN_REPOSITORY"
115
160
 
116
161
  attr_accessor :type
117
- attr_accessor :local_repository_env_override
118
162
  attr_accessor :group
119
163
  attr_reader :facets
120
164
 
121
165
  def initialize
166
+ super()
122
167
  @type = DEFAULT_TYPE
123
- @local_repository_env_override = DEFAULT_LOCAL_REPOSITORY_ENV_OVERRIDE
124
168
  end
125
169
 
126
170
  def buildr_project=(buildr_project)
@@ -161,13 +205,13 @@ module Buildr
161
205
  attr_writer :main_output_dir
162
206
 
163
207
  def main_output_dir
164
- @main_output_dir ||= buildr_project._(:target, :main, :java)
208
+ @main_output_dir ||= buildr_project._(:target, :main, :idea, :classes)
165
209
  end
166
210
 
167
211
  attr_writer :test_output_dir
168
212
 
169
213
  def test_output_dir
170
- @test_output_dir ||= buildr_project._(:target, :test, :java)
214
+ @test_output_dir ||= buildr_project._(:target, :test, :idea, :classes)
171
215
  end
172
216
 
173
217
  def main_dependencies
@@ -179,11 +223,11 @@ module Buildr
179
223
  end
180
224
 
181
225
  def add_facet(name, type)
182
- target = StringIO.new
183
- Builder::XmlMarkup.new(:target => target, :indent => 2).facet(:name => name, :type => type) do |xml|
184
- yield xml if block_given?
226
+ add_to_composite_component(self.facets) do |xml|
227
+ xml.facet(:name => name, :type => type) do |xml|
228
+ yield xml if block_given?
229
+ end
185
230
  end
186
- self.facets << Buildr::IntellijIdea.new_document(target.string).root
187
231
  end
188
232
 
189
233
  def skip_content?
@@ -194,6 +238,113 @@ module Buildr
194
238
  @skip_content = true
195
239
  end
196
240
 
241
+ def add_gwt_facet(modules = {}, options = {})
242
+ name = options[:name] || "GWT"
243
+ settings =
244
+ {
245
+ :webFacet => "Web",
246
+ :compilerMaxHeapSize => "512",
247
+ :compilerParameters => "-draftCompile -localWorkers 2 -strict",
248
+ :gwtSdkUrl => "file://$GWT_TOOLS$",
249
+ :gwtScriptOutputStyle => "PRETTY"
250
+ }.merge(options[:settings] || {})
251
+
252
+ add_facet(name, "gwt") do |f|
253
+ f.configuration do |c|
254
+ settings.each_pair do |k, v|
255
+ c.setting :name => k.to_s, :value => v.to_s
256
+ end
257
+ c.packaging do |d|
258
+ modules.each_pair do |k, v|
259
+ d.module :name => k, :enabled => v
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ def add_web_facet(options = {})
267
+ name = options[:name] || "Web"
268
+ url_base = options[:url_base] || "/"
269
+ default_webroots = [buildr_project._(:source, :main, :webapp)]
270
+ webroots = options[:webroots] || default_webroots
271
+ web_xml = options[:web_xml] || "#{buildr_project._(:source, :main, :webapp)}/WEB-INF/web.xml"
272
+ version = options[:version] || "3.0"
273
+
274
+ add_facet(name, "web") do |f|
275
+ f.configuration do |c|
276
+ c.descriptors do |d|
277
+ if File.exist?(web_xml) || default_web_xml != web_xml
278
+ d.deploymentDescriptor :name => 'web.xml', :url => file_path(web_xml), :optional => "true", :version => version
279
+ end
280
+ end
281
+ c.webroots do |w|
282
+ webroots.each do |webroot|
283
+ w.root :url => file_path(webroot), :relative => url_base
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+
290
+ def add_jruby_facet(options = {})
291
+ name = options[:name] || "JRuby"
292
+ jruby_version = options[:jruby_version] || "jruby-1.5.2-p249"
293
+ add_facet(name, "JRUBY") do |f|
294
+ f.configuration(:number => 0) do |c|
295
+ c.JRUBY_FACET_CONFIG_ID :NAME => "JRUBY_SDK_NAME", :VALUE => jruby_version
296
+ end
297
+ end
298
+ end
299
+
300
+ def add_jpa_facet(options = {})
301
+ name = options[:name] || "JPA"
302
+ factory_entry = options[:factory_entry] || buildr_project.name.to_s
303
+ validation_enabled = options[:validation_enabled].nil? ? true : options[:validation_enabled]
304
+ provider_enabled = options[:provider_enabled] || 'Hibernate'
305
+ default_persistence_xml = buildr_project._(:source, :main, :resources, "META-INF/persistence.xml")
306
+ persistence_xml = options[:persistence_xml] || default_persistence_xml
307
+ default_orm_xml = buildr_project._(:source, :main, :resources, "META-INF/orm.xml")
308
+ orm_xml = options[:orm_xml] || default_orm_xml
309
+ add_facet(name, "jpa") do |f|
310
+ f.configuration do |c|
311
+ c.setting :name => "validation-enabled", :value => validation_enabled
312
+ c.setting :name => "provider-name", :value => provider_enabled
313
+ c.tag!('datasource-mapping') do |ds|
314
+ ds.tag!('factory-entry', :name => factory_entry)
315
+ end
316
+ if File.exist?(persistence_xml) || default_persistence_xml != persistence_xml
317
+ c.deploymentDescriptor :name => 'persistence.xml', :url => file_path(persistence_xml)
318
+ end
319
+ if File.exist?(orm_xml) || default_orm_xml != orm_xml
320
+ c.deploymentDescriptor :name => 'orm.xml', :url => file_path(orm_xml)
321
+ end
322
+ end
323
+ end
324
+ end
325
+
326
+ def add_ejb_facet(options = {})
327
+ name = options[:name] || "EJB"
328
+ default_ejb_xml = buildr_project._(:source, :main, :resources, "WEB-INF/ejb-jar.xml")
329
+ ejb_xml = options[:ejb_xml] || default_ejb_xml
330
+ ejb_roots = options[:ejb_roots] || [buildr_project.compile.sources, buildr_project.resources.sources].flatten
331
+
332
+ add_facet(name, "ejb") do |facet|
333
+ facet.configuration do |c|
334
+ c.descriptors do |d|
335
+ if File.exist?(ejb_xml) || default_ejb_xml != ejb_xml
336
+ d.deploymentDescriptor :name => 'ejb-jar.xml', :url => file_path(ejb_xml)
337
+ end
338
+ end
339
+ c.ejbRoots do |e|
340
+ ejb_roots.each do |ejb_root|
341
+ e.root :url => file_path(ejb_root)
342
+ end
343
+ end
344
+ end
345
+ end
346
+ end
347
+
197
348
  protected
198
349
 
199
350
  def test_dependency_details
@@ -212,10 +363,6 @@ module Buildr
212
363
  end
213
364
  end
214
365
 
215
- def base_directory
216
- buildr_project.path_to
217
- end
218
-
219
366
  def base_document
220
367
  target = StringIO.new
221
368
  Builder::XmlMarkup.new(:target => target).module(:version => "4", :relativePaths => "true", :type => self.type)
@@ -234,12 +381,7 @@ module Buildr
234
381
  end
235
382
 
236
383
  def facet_component
237
- return nil if self.facets.empty?
238
- fm = self.create_component("FacetManager")
239
- self.facets.each do |facet|
240
- fm.add_element facet
241
- end
242
- fm
384
+ create_composite_component("FacetManager", self.facets)
243
385
  end
244
386
 
245
387
  def module_root_component
@@ -285,10 +427,6 @@ module Buildr
285
427
  "jar://#{resolve_path(path)}!/"
286
428
  end
287
429
 
288
- def file_path(path)
289
- "file://#{resolve_path(path)}"
290
- end
291
-
292
430
  def url_for_path(path)
293
431
  if path =~ /jar$/i
294
432
  jar_path(path)
@@ -298,21 +436,7 @@ module Buildr
298
436
  end
299
437
 
300
438
  def resolve_path(path)
301
- m2repo = Buildr::Repositories.instance.local
302
- if path.to_s.index(m2repo) == 0 && !self.local_repository_env_override.nil?
303
- return path.sub(m2repo, "$#{self.local_repository_env_override}$")
304
- else
305
- begin
306
- return "$MODULE_DIR$/#{relative(path)}"
307
- rescue ArgumentError
308
- # ArgumentError happens on windows when self.base_directory and path are on different drives
309
- return path
310
- end
311
- end
312
- end
313
-
314
- def relative(path)
315
- ::Buildr::Util.relative_path(File.expand_path(path.to_s), self.base_directory)
439
+ resolve_path_from_base(path, "$MODULE_DIR$")
316
440
  end
317
441
 
318
442
  def generate_compile_output(xml)
@@ -395,18 +519,115 @@ module Buildr
395
519
  class IdeaProject < IdeaFile
396
520
  attr_accessor :vcs
397
521
  attr_accessor :extra_modules
522
+ attr_accessor :artifacts
523
+ attr_accessor :configurations
398
524
  attr_writer :jdk_version
399
525
 
400
526
  def initialize(buildr_project)
527
+ super()
401
528
  @buildr_project = buildr_project
402
529
  @vcs = detect_vcs
403
530
  @extra_modules = []
531
+ @artifacts = []
532
+ @configurations = []
404
533
  end
405
534
 
406
535
  def jdk_version
407
536
  @jdk_version ||= buildr_project.compile.options.source || "1.6"
408
537
  end
409
538
 
539
+ def add_artifact(name, type, build_on_make = false)
540
+ add_to_composite_component(self.artifacts) do |xml|
541
+ xml.artifact(:name => name, :type => type, :"build-on-make" => build_on_make) do |xml|
542
+ yield xml if block_given?
543
+ end
544
+ end
545
+ end
546
+
547
+ def add_configuration(name, type, factory_name, default = false)
548
+ add_to_composite_component(self.configurations) do |xml|
549
+ xml.configuration(:name => name, :type => type, :factoryName => factory_name, :default => default) do |xml|
550
+ yield xml if block_given?
551
+ end
552
+ end
553
+ end
554
+
555
+ def add_exploded_war_artifact(project, options = {})
556
+ artifact_name = options[:name] || project.iml.id
557
+ build_on_make = options[:build_on_make].nil? ? false : options[:build_on_make]
558
+
559
+ add_artifact(artifact_name, "exploded-war", build_on_make) do |xml|
560
+ dependencies = (options[:dependencies] || ([project] + project.compile.dependencies)).flatten
561
+ libraries, projects = partition_dependencies(dependencies)
562
+
563
+ ## The content here can not be indented
564
+ output_dir = options[:output_dir] || project._(:artifacts, artifact_name)
565
+ xml.tag!('output-path', output_dir)
566
+
567
+ xml.root :id => "root" do
568
+ xml.element :id => "directory", :name => "WEB-INF" do
569
+ xml.element :id => "directory", :name => "classes" do
570
+ projects.each do |p|
571
+ xml.element :id => "module-output", :name => p.iml.id
572
+ end
573
+ if options[:enable_jpa]
574
+ module_names = options[:jpa_module_names] || [project.iml.id]
575
+ module_names.each do |module_name|
576
+ facet_name = options[:jpa_facet_name] || "JPA"
577
+ xml.element :id => "jpa-descriptors", :facet => "#{module_name}/jpa/#{facet_name}"
578
+ end
579
+ end
580
+ if options[:enable_ejb]
581
+ module_names = options[:ejb_module_names] || [project.iml.id]
582
+ module_names.each do |module_name|
583
+ facet_name = options[:ejb_facet_name] || "EJB"
584
+ xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/ejb/#{facet_name}"
585
+ end
586
+ end
587
+ end
588
+ xml.element :id => "directory", :name => "lib" do
589
+ libraries.each(&:invoke).map(&:to_s).each do |dependency_path|
590
+ xml.element :id => "file-copy", :path => resolve_path(dependency_path)
591
+ end
592
+ end
593
+ end
594
+
595
+ if options[:enable_war].nil? || options[:enable_war]
596
+ module_names = options[:war_module_names] || [project.iml.id]
597
+ module_names.each do |module_name|
598
+ facet_name = options[:war_facet_name] || "Web"
599
+ xml.element :id => "javaee-facet-resources", :facet => "#{module_name}/web/#{facet_name}"
600
+ end
601
+ end
602
+
603
+ if options[:enable_gwt]
604
+ module_names = options[:gwt_module_names] || [project.iml.id]
605
+ module_names.each do |module_name|
606
+ facet_name = options[:gwt_facet_name] || "GWT"
607
+ xml.element :id => "gwt-compiler-output", :facet => "#{module_name}/gwt/#{facet_name}"
608
+ end
609
+ end
610
+ end
611
+ end
612
+ end
613
+
614
+ def add_gwt_configuration(launch_page, project, options = {})
615
+ name = options[:name] || "Run #{launch_page}"
616
+ shell_parameters = options[:shell_parameters] || ""
617
+ vm_parameters = options[:vm_parameters] || "-Xmx512m"
618
+
619
+ add_configuration(name, "GWT.ConfigurationType", "GWT Configuration") do |xml|
620
+ xml.module(:name => project.iml.id)
621
+ xml.option(:name => "RUN_PAGE", :value => launch_page)
622
+ xml.option(:name => "SHELL_PARAMETERS", :value => shell_parameters)
623
+ xml.option(:name => "VM_PARAMETERS", :value => vm_parameters)
624
+
625
+ xml.RunnerSettings(:RunnerId => "Run")
626
+ xml.ConfigurationWrapper(:RunnerId => "Run")
627
+ xml.method()
628
+ end
629
+ end
630
+
410
631
  protected
411
632
 
412
633
  def extension
@@ -430,7 +651,9 @@ module Buildr
430
651
  def default_components
431
652
  [
432
653
  lambda { modules_component },
433
- vcs_component
654
+ vcs_component,
655
+ artifacts_component,
656
+ configurations_component
434
657
  ]
435
658
  end
436
659
 
@@ -469,7 +692,7 @@ module Buildr
469
692
  if subproject.iml.group == true
470
693
  attribs[:group] = subproject.parent.name.gsub(':', '/')
471
694
  elsif !subproject.iml.group.nil?
472
- attribs[:group] = subproject.group.to_s
695
+ attribs[:group] = subproject.iml.group.to_s
473
696
  end
474
697
  xml.module attribs
475
698
  end
@@ -492,6 +715,18 @@ module Buildr
492
715
  end
493
716
  end
494
717
  end
718
+
719
+ def artifacts_component
720
+ create_composite_component("ArtifactManager", self.artifacts)
721
+ end
722
+
723
+ def configurations_component
724
+ create_composite_component("ProjectRunConfigurationManager", self.configurations)
725
+ end
726
+
727
+ def resolve_path(path)
728
+ resolve_path_from_base(path, "$PROJECT_DIR$")
729
+ end
495
730
  end
496
731
 
497
732
  module ProjectExtension
@@ -520,12 +755,9 @@ module Buildr
520
755
 
521
756
  files.each do |ideafile|
522
757
  module_dir = File.dirname(ideafile.filename)
523
- # Need to clear the actions else the extension included as part of buildr will run
524
- file(ideafile.filename).clear_actions
525
- idea.enhance [file(ideafile.filename)]
526
- file(ideafile.filename => [Buildr.application.buildfile]) do |task|
758
+ idea.enhance do |task|
527
759
  mkdir_p module_dir
528
- info "Writing #{task.name}"
760
+ info "Writing #{ideafile.filename}"
529
761
  t = Tempfile.open("buildr-idea")
530
762
  temp_filename = t.path
531
763
  t.close!