buildr 1.2.10 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. data/CHANGELOG +566 -268
  2. data/DISCLAIMER +7 -1
  3. data/KEYS +151 -0
  4. data/NOTICE +23 -8
  5. data/README +122 -22
  6. data/Rakefile +49 -229
  7. data/{lib → addon}/buildr/antlr.rb +23 -10
  8. data/addon/buildr/cobertura.rb +232 -0
  9. data/{lib → addon}/buildr/hibernate.rb +20 -4
  10. data/{lib → addon}/buildr/javacc.rb +27 -12
  11. data/addon/buildr/jdepend.rb +60 -0
  12. data/{lib → addon}/buildr/jetty.rb +34 -18
  13. data/addon/buildr/nailgun.rb +892 -0
  14. data/{lib → addon}/buildr/openjpa.rb +23 -6
  15. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  18. data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
  19. data/{lib → addon}/buildr/xmlbeans.rb +39 -14
  20. data/bin/buildr +21 -7
  21. data/buildr.gemspec +50 -0
  22. data/doc/css/default.css +225 -0
  23. data/doc/css/print.css +95 -0
  24. data/doc/css/syntax.css +43 -0
  25. data/doc/images/apache-incubator-logo.png +0 -0
  26. data/doc/images/buildr-hires.png +0 -0
  27. data/doc/images/buildr.png +0 -0
  28. data/doc/images/note.png +0 -0
  29. data/doc/images/tip.png +0 -0
  30. data/doc/images/zbuildr.tif +0 -0
  31. data/doc/pages/artifacts.textile +317 -0
  32. data/doc/pages/building.textile +501 -0
  33. data/doc/pages/contributing.textile +178 -0
  34. data/doc/pages/download.textile +25 -0
  35. data/doc/pages/extending.textile +229 -0
  36. data/doc/pages/getting_started.textile +337 -0
  37. data/doc/pages/index.textile +63 -0
  38. data/doc/pages/mailing_lists.textile +17 -0
  39. data/doc/pages/more_stuff.textile +367 -0
  40. data/doc/pages/packaging.textile +592 -0
  41. data/doc/pages/projects.textile +449 -0
  42. data/doc/pages/recipes.textile +127 -0
  43. data/doc/pages/settings_profiles.textile +339 -0
  44. data/doc/pages/testing.textile +475 -0
  45. data/doc/pages/troubleshooting.textile +121 -0
  46. data/doc/pages/whats_new.textile +389 -0
  47. data/doc/print.haml +52 -0
  48. data/doc/print.toc.yaml +28 -0
  49. data/doc/scripts/buildr-git.rb +411 -0
  50. data/doc/scripts/install-jruby.sh +44 -0
  51. data/doc/scripts/install-linux.sh +64 -0
  52. data/doc/scripts/install-osx.sh +52 -0
  53. data/doc/site.haml +55 -0
  54. data/doc/site.toc.yaml +44 -0
  55. data/lib/buildr.rb +28 -45
  56. data/lib/buildr/core.rb +27 -0
  57. data/lib/buildr/core/application.rb +373 -0
  58. data/lib/buildr/core/application_cli.rb +134 -0
  59. data/lib/{core → buildr/core}/build.rb +91 -77
  60. data/lib/{core → buildr/core}/checks.rb +116 -95
  61. data/lib/buildr/core/common.rb +155 -0
  62. data/lib/buildr/core/compile.rb +594 -0
  63. data/lib/buildr/core/environment.rb +120 -0
  64. data/lib/buildr/core/filter.rb +258 -0
  65. data/lib/{core → buildr/core}/generate.rb +22 -5
  66. data/lib/buildr/core/help.rb +118 -0
  67. data/lib/buildr/core/progressbar.rb +156 -0
  68. data/lib/{core → buildr/core}/project.rb +468 -213
  69. data/lib/buildr/core/test.rb +690 -0
  70. data/lib/{core → buildr/core}/transports.rb +107 -127
  71. data/lib/buildr/core/util.rb +235 -0
  72. data/lib/buildr/ide.rb +19 -0
  73. data/lib/{java → buildr/ide}/eclipse.rb +86 -60
  74. data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
  75. data/lib/buildr/ide/idea.rb +194 -0
  76. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  77. data/lib/buildr/ide/idea7x.rb +210 -0
  78. data/lib/buildr/java.rb +26 -0
  79. data/lib/buildr/java/ant.rb +71 -0
  80. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  81. data/lib/buildr/java/commands.rb +210 -0
  82. data/lib/buildr/java/compilers.rb +432 -0
  83. data/lib/buildr/java/deprecated.rb +141 -0
  84. data/lib/buildr/java/groovyc.rb +137 -0
  85. data/lib/buildr/java/jruby.rb +99 -0
  86. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  89. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  91. data/lib/buildr/java/packaging.rb +706 -0
  92. data/lib/{java → buildr/java}/pom.rb +20 -4
  93. data/lib/buildr/java/rjb.rb +142 -0
  94. data/lib/buildr/java/test_frameworks.rb +290 -0
  95. data/lib/buildr/java/version_requirement.rb +172 -0
  96. data/lib/buildr/packaging.rb +21 -0
  97. data/lib/{java → buildr/packaging}/artifact.rb +170 -179
  98. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  99. data/lib/buildr/packaging/artifact_search.rb +140 -0
  100. data/lib/buildr/packaging/gems.rb +102 -0
  101. data/lib/buildr/packaging/package.rb +233 -0
  102. data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
  103. data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
  104. data/rakelib/apache.rake +126 -0
  105. data/rakelib/changelog.rake +56 -0
  106. data/rakelib/doc.rake +103 -0
  107. data/rakelib/package.rake +44 -0
  108. data/rakelib/release.rake +53 -0
  109. data/rakelib/rspec.rake +81 -0
  110. data/rakelib/rubyforge.rake +45 -0
  111. data/rakelib/scm.rake +49 -0
  112. data/rakelib/setup.rake +59 -0
  113. data/rakelib/stage.rake +45 -0
  114. data/spec/application_spec.rb +316 -0
  115. data/spec/archive_spec.rb +494 -0
  116. data/spec/artifact_namespace_spec.rb +635 -0
  117. data/spec/artifact_spec.rb +738 -0
  118. data/spec/build_spec.rb +193 -0
  119. data/spec/checks_spec.rb +537 -0
  120. data/spec/common_spec.rb +579 -0
  121. data/spec/compile_spec.rb +561 -0
  122. data/spec/groovy_compilers_spec.rb +239 -0
  123. data/spec/java_bdd_frameworks_spec.rb +238 -0
  124. data/spec/java_compilers_spec.rb +446 -0
  125. data/spec/java_packaging_spec.rb +1042 -0
  126. data/spec/java_test_frameworks_spec.rb +414 -0
  127. data/spec/packaging_helper.rb +63 -0
  128. data/spec/packaging_spec.rb +589 -0
  129. data/spec/project_spec.rb +739 -0
  130. data/spec/sandbox.rb +116 -0
  131. data/spec/scala_compilers_spec.rb +239 -0
  132. data/spec/spec.opts +6 -0
  133. data/spec/spec_helpers.rb +283 -0
  134. data/spec/test_spec.rb +871 -0
  135. data/spec/transport_spec.rb +300 -0
  136. data/spec/version_requirement_spec.rb +115 -0
  137. metadata +188 -77
  138. data/lib/buildr/cobertura.rb +0 -89
  139. data/lib/buildr/jdepend.rb +0 -40
  140. data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
  141. data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
  142. data/lib/buildr/jetty/JettyWrapper.class +0 -0
  143. data/lib/buildr/scala.rb +0 -368
  144. data/lib/core/application.rb +0 -188
  145. data/lib/core/common.rb +0 -562
  146. data/lib/core/help.rb +0 -72
  147. data/lib/core/rake_ext.rb +0 -81
  148. data/lib/java/ant.rb +0 -71
  149. data/lib/java/compile.rb +0 -589
  150. data/lib/java/idea.rb +0 -159
  151. data/lib/java/java.rb +0 -432
  152. data/lib/java/packaging.rb +0 -581
  153. data/lib/java/test.rb +0 -795
  154. data/lib/tasks/concat.rb +0 -35
@@ -0,0 +1,19 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/ide/eclipse'
18
+ require 'buildr/ide/idea'
19
+ require 'buildr/ide/idea7x'
@@ -1,18 +1,40 @@
1
- require "pathname"
2
- require "core/project"
3
- require "java/artifact"
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/core/project'
18
+ require 'buildr/packaging'
19
+
4
20
 
5
21
  module Buildr
22
+ module Eclipse #:nodoc:
6
23
 
7
- # Global task "eclipse" generates artifacts for all projects.
8
- desc "Generate Eclipse artifacts for all projects"
9
- Project.local_task "eclipse"=>"artifacts"
24
+ include Extension
10
25
 
11
- Project.on_define do |project|
12
- eclipse = project.recursive_task("eclipse")
26
+ first_time do
27
+ # Global task "eclipse" generates artifacts for all projects.
28
+ desc "Generate Eclipse artifacts for all projects"
29
+ Project.local_task "eclipse"=>"artifacts"
30
+ end
13
31
 
14
- project.enhance do |project|
32
+ before_define do |project|
33
+ project.recursive_task("eclipse")
34
+ end
15
35
 
36
+ after_define do |project|
37
+ eclipse = project.task("eclipse")
16
38
  # We need paths relative to the top project's base directory.
17
39
  root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir } ; f[p] }[project]
18
40
 
@@ -20,14 +42,17 @@ module Buildr
20
42
  # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
21
43
  # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
22
44
  # in $LOADED_FEATURES that we cannot resolve.
23
- sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
24
- sources << File.expand_path(Rake.application.rakefile, root_path) if Rake.application.rakefile
45
+ sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
46
+ sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile
25
47
 
26
48
  # Check if project has scala facet
27
- scala = project.task("scalac") if Rake::Task.task_defined?(project.name+":"+"scalac")
28
-
29
- # Only for projects that are Eclipse packagable.
30
- if project.packages.detect { |pkg| pkg.type.to_s =~ /(jar)|(war)|(rar)|(mar)|(aar)/ }
49
+ scala = project.compile.language == :scala
50
+
51
+ # Only for projects that we support
52
+ supported_languages = [:java, :scala]
53
+ supported_packaging = %w(jar war rar mar aar)
54
+ if (supported_languages.include? project.compile.language ||
55
+ project.packages.detect { |pkg| supported_packaging.include?(pkg.type.to_s) })
31
56
  eclipse.enhance [ file(project.path_to(".classpath")), file(project.path_to(".project")) ]
32
57
 
33
58
  # The only thing we need to look for is a change in the Buildfile.
@@ -36,9 +61,10 @@ module Buildr
36
61
 
37
62
  # Find a path relative to the project's root directory.
38
63
  relative = lambda do |path|
64
+ path or raise "Invalid path '#{path.inspect}'"
39
65
  msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
40
66
  path = path.__send__(msg)
41
- Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(project.path_to)).to_s
67
+ Util.relative_path(File.expand_path(path), project.path_to)
42
68
  end
43
69
 
44
70
  m2repo = Buildr::Repositories.instance.local
@@ -48,12 +74,11 @@ module Buildr
48
74
  xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
49
75
  xml.classpath do
50
76
  # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
51
- cp = project.test.compile.classpath.map(&:to_s) - [ project.compile.target.to_s ]
52
- cp += scala.classpath.map(&:to_s) if scala
77
+ cp = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s, project.resources.target.to_s ]
53
78
  cp = cp.uniq
54
79
 
55
80
  # Convert classpath elements into applicable Project objects
56
- cp.collect! { |path| projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
81
+ cp.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
57
82
 
58
83
  # project_libs: artifacts created by other projects
59
84
  project_libs, others = cp.partition { |path| path.is_a?(Project) }
@@ -64,59 +89,54 @@ module Buildr
64
89
  # Generated: classpath elements in the project are assumed to be generated
65
90
  generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
66
91
 
67
- xml.classpathentry :kind=>'con', :path=>'org.eclipse.jdt.launching.JRE_CONTAINER'
68
- xml.classpathentry :kind=>'con', :path=>'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' if scala
69
-
70
92
  srcs = project.compile.sources
71
- srcs << scala.sources if scala
72
-
73
- # hack until we have sunit task
74
- project.path_to("src/test/scala").tap do |dir|
75
- srcs += dir if scala and File.exist?(dir)
76
- end
77
-
93
+
78
94
  srcs = srcs.map { |src| relative[src] } + generated.map { |src| relative[src] }
79
95
  srcs.sort.uniq.each do |path|
80
96
  xml.classpathentry :kind=>'src', :path=>path, :excluding=>excludes
81
97
  end
82
98
 
83
- { :output => relative[project.compile.target],
84
- :lib => libs.map(&:to_s),
85
- :var => m2_libs.map { |path| path.to_s.sub(m2repo, 'M2_REPO') }
86
- }.each do |kind, paths|
87
- paths.sort.uniq.each do |path|
88
- xml.classpathentry :kind=>kind, :path=>path
89
- end
90
- end
91
-
92
- # Classpath elements from other projects
93
- project_libs.map(&:id).sort.uniq.each do |project_id|
94
- xml.classpathentry :kind=>'src', :combineaccessrules=>"false", :path=>"/#{project_id}"
95
- end
96
-
97
99
  # Main resources implicitly copied into project.compile.target
98
- # TODO: find solution that uses project.test.resources.filter.sources
99
- [ "src/main/resources" ].each do |path|
100
+ main_resource_sources = project.resources.sources.map { |src| relative[src] }
101
+ main_resource_sources.each do |path|
100
102
  if File.exist? project.path_to(path)
101
103
  xml.classpathentry :kind=>'src', :path=>path, :excluding=>excludes
102
104
  end
103
105
  end
104
106
 
105
- # Test classes are generated in a separate output directory
106
- test_sources = project.test.compile.sources.map { |src| relative[src] }
107
- test_sources.each do |paths|
108
- paths.sort.uniq.each do |path|
109
- xml.classpathentry :kind=>'src', :path=>path, :output => relative[project.test.compile.target], :excluding=>excludes
107
+ if project.test.compile.target
108
+ # Test classes are generated in a separate output directory
109
+ test_sources = project.test.compile.sources.map { |src| relative[src] }
110
+ test_sources.each do |paths|
111
+ paths.sort.uniq.each do |path|
112
+ xml.classpathentry :kind=>'src', :path=>path, :output => relative[project.test.compile.target], :excluding=>excludes
113
+ end
114
+ end
115
+
116
+ # Test resources go in separate output directory as well
117
+ project.test.resources.sources.each do |path|
118
+ if File.exist? project.path_to(path)
119
+ xml.classpathentry :kind=>'src', :path=>relative[path], :output => relative[project.test.compile.target], :excluding=>excludes
120
+ end
110
121
  end
111
122
  end
112
123
 
113
- # Test resources go in separate output directory as well
114
- # TODO: find solution that uses project.test.resources.filter.sources
115
- [ "src/test/resources" ].each do |path|
116
- if File.exist? project.path_to(path)
117
- xml.classpathentry :kind=>'src', :path=>path, :output => relative[project.test.compile.target], :excluding=>excludes
124
+ # Classpath elements from other projects
125
+ project_libs.map(&:id).sort.uniq.each do |project_id|
126
+ xml.classpathentry :kind=>'src', :combineaccessrules=>"false", :path=>"/#{project_id}"
127
+ end
128
+
129
+ { :output => relative[project.compile.target],
130
+ :lib => libs.map(&:to_s),
131
+ :var => m2_libs.map { |path| path.to_s.sub(m2repo, 'M2_REPO') }
132
+ }.each do |kind, paths|
133
+ paths.sort.uniq.each do |path|
134
+ xml.classpathentry :kind=>kind, :path=>path
118
135
  end
119
136
  end
137
+
138
+ xml.classpathentry :kind=>'con', :path=>'org.eclipse.jdt.launching.JRE_CONTAINER'
139
+ xml.classpathentry :kind=>'con', :path=>'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' if scala
120
140
  end
121
141
  end
122
142
  end
@@ -135,21 +155,27 @@ module Buildr
135
155
  end
136
156
  if scala
137
157
  xml.buildCommand do
138
- #xml.name "ch.epfl.lamp.sdt.core.scalabuilder"
139
- xml.name "scala.plugin.scalabuilder"
158
+ xml.name "ch.epfl.lamp.sdt.core.scalabuilder"
159
+ #xml.name "scala.plugin.scalabuilder"
140
160
  end
141
161
  end
142
162
  end
143
163
  xml.natures do
144
164
  xml.nature "org.eclipse.jdt.core.javanature"
145
- #xml.nature "ch.epfl.lamp.sdt.core.scalanature" if scala
146
- xml.nature "scala.plugin.scalanature" if scala
165
+ xml.nature "ch.epfl.lamp.sdt.core.scalanature" if scala
166
+ #xml.nature "scala.plugin.scalanature" if scala
147
167
  end
148
168
  end
149
169
  end
150
170
  end
151
171
  end
172
+
152
173
  end
153
- end
154
174
 
175
+ end
155
176
  end # module Buildr
177
+
178
+
179
+ class Buildr::Project
180
+ include Buildr::Eclipse
181
+ end
@@ -1,4 +1,20 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with this
5
+ work for additional information regarding copyright ownership. The ASF
6
+ licenses this file to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ License for the specific language governing permissions and limitations under
16
+ the License.
17
+ -->
2
18
  <project version="4" relativePaths="false">
3
19
  <component name="AntConfiguration">
4
20
  <defaultAnt bundledAnt="true" />
@@ -0,0 +1,194 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/core/project'
18
+ require 'buildr/packaging'
19
+ require 'stringio'
20
+ require 'rexml/document'
21
+
22
+
23
+ module Buildr
24
+ module Idea #:nodoc:
25
+
26
+ include Extension
27
+
28
+ first_time do
29
+ # Global task "idea" generates artifacts for all projects.
30
+ desc "Generate Idea artifacts for all projects"
31
+ Project.local_task "idea"=>"artifacts"
32
+ end
33
+
34
+ before_define do |project|
35
+ project.recursive_task("idea")
36
+ end
37
+
38
+ after_define do |project|
39
+ idea = project.task("idea")
40
+ # We need paths relative to the top project's base directory.
41
+ root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir }; f[p] }[project]
42
+ # We want the Eclipse files changed every time the Buildfile changes, but also anything loaded by
43
+ # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
44
+ # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
45
+ # in $LOADED_FEATURES that we cannot resolve.
46
+ sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
47
+ sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile
48
+
49
+ # Find a path relative to the project's root directory.
50
+ relative = lambda { |path| Util.relative_path(path.to_s, project.path_to) }
51
+
52
+ m2repo = Buildr::Repositories.instance.local
53
+ excludes = [ '**/.svn/', '**/CVS/' ].join('|')
54
+
55
+ # Only for projects that are packageable.
56
+ task_name = project.path_to("#{project.name.gsub(':', '-')}.iml")
57
+ idea.enhance [ file(task_name) ]
58
+
59
+ # The only thing we need to look for is a change in the Buildfile.
60
+ file(task_name=>sources) do |task|
61
+ puts "Writing #{task.name}" if verbose
62
+
63
+ # Idea handles modules slightly differently if they're WARs
64
+ idea_types = Hash.new("JAVA_MODULE")
65
+ idea_types["war"] = "J2EE_WEB_MODULE"
66
+
67
+ # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
68
+ deps = project.test.compile.dependencies.map(&:to_s) - [ project.compile.target.to_s ]
69
+
70
+ # Convert classpath elements into applicable Project objects
71
+ deps.collect! { |path| Buildr.projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
72
+
73
+ # project_libs: artifacts created by other projects
74
+ project_libs, others = deps.partition { |path| path.is_a?(Project) }
75
+
76
+ # Separate artifacts from Maven2 repository
77
+ m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
78
+
79
+ # Generated: classpath elements in the project are assumed to be generated
80
+ generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
81
+
82
+ # Project type is going to be the first package type
83
+ if package = project.packages.first
84
+ File.open(task.name, "w") do |file|
85
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
86
+
87
+ xml.module(:version=>"4", :relativePaths=>"false", :type=>idea_types[package.type.to_s]) do
88
+ xml.component :name=>"ModuleRootManager"
89
+ xml.component "name"=>"NewModuleRootManager", "inherit-compiler-output"=>"false" do
90
+ has_compile_sources = project.compile.target.to_s.size > 0
91
+ xml.output :url=>"file://$MODULE_DIR$/#{relative[project.compile.target.to_s]}" if has_compile_sources
92
+ xml.tag! "exclude-output"
93
+
94
+ # TODO project.test.target isn't recognized, what's the proper way to get the test compile path?
95
+ xml.tag! "output-test", :url=>"file://$MODULE_DIR$/target/test-classes"
96
+
97
+ xml.content(:url=>"file://$MODULE_DIR$") do
98
+ if has_compile_sources
99
+ srcs = project.compile.sources.map { |src| relative[src.to_s] } + generated.map { |src| relative[src.to_s] }
100
+ srcs.sort.uniq.each do |path|
101
+ xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"false"
102
+ end
103
+
104
+ test_sources = project.test.compile.sources.map { |src| relative[src.to_s] }
105
+ test_sources.each do |paths|
106
+ paths.sort.uniq.each do |path|
107
+ xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"true"
108
+ end
109
+ end
110
+ end
111
+ [project.resources=>false, project.test.resources=>true].each do |resources, test|
112
+ resources.each do |path|
113
+ path[0].sources.each do |srcpath|
114
+ xml.sourceFolder :url=>"file://#{srcpath}", :isTestSource=>path[1].to_s
115
+ end
116
+ end
117
+ end
118
+ xml.excludeFolder :url=>"file://$MODULE_DIR$/#{relative[project.compile.target.to_s]}" if has_compile_sources
119
+ end
120
+
121
+ xml.orderEntry :type=>"sourceFolder", :forTests=>"false"
122
+ xml.orderEntry :type=>"inheritedJdk"
123
+
124
+ # Classpath elements from other projects
125
+ project_libs.map(&:id).sort.uniq.each do |project_id|
126
+ xml.orderEntry :type=>'module', "module-name"=>project_id
127
+ end
128
+
129
+ # Libraries
130
+ ext_libs = libs.map {|path| "$MODULE_DIR$/#{path.to_s}" } +
131
+ m2_libs.map { |path| path.to_s.sub(m2repo, "$M2_REPO$") }
132
+ ext_libs.each do |path|
133
+ xml.orderEntry :type=>"module-library" do
134
+ xml.library do
135
+ xml.CLASSES do
136
+ xml.root :url=>"jar://#{path}!/"
137
+ end
138
+ xml.JAVADOC
139
+ xml.SOURCES
140
+ end
141
+ end
142
+ end
143
+
144
+ xml.orderEntryProperties
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ # Root project aggregates all the subprojects.
152
+ if project.parent == nil
153
+ task_name = project.path_to("#{project.name.gsub(':', '-')}.ipr")
154
+ idea.enhance [ file(task_name) ]
155
+
156
+ file(task_name=>sources) do |task|
157
+ puts "Writing #{task.name}" if verbose
158
+
159
+ # Generating just the little stanza that chanages from one project to another
160
+ partial = StringIO.new
161
+ xml = Builder::XmlMarkup.new(:target=>partial, :indent=>2)
162
+ xml.component(:name=>"ProjectModuleManager") do
163
+ xml.modules do
164
+ project.projects.each do |subp|
165
+ module_name = subp.name.gsub(":", "-")
166
+ module_path = subp.name.split(":"); module_path.shift
167
+ module_path = module_path.join("/")
168
+ path = "#{module_path}/#{module_name}.iml"
169
+ xml.module :fileurl=>"file://$PROJECT_DIR$/#{path}", :filepath=>"$PROJECT_DIR$/#{path}"
170
+ end
171
+ if package = project.packages.first
172
+ xml.module :fileurl=>"file://$PROJECT_DIR$/#{project.name}.iml", :filepath=>"$PROJECT_DIR$/#{project.name}.iml"
173
+ end
174
+ end
175
+ end
176
+
177
+ # Loading the whole fairly constant crap
178
+ template_xml = REXML::Document.new(File.open(File.dirname(__FILE__)+"/idea.ipr.template"))
179
+ include_xml = REXML::Document.new(partial.string)
180
+ template_xml.root.add_element(include_xml.root)
181
+ template_xml.write(File.new(task.name, "w"))
182
+
183
+ end
184
+ end
185
+
186
+ end #after define
187
+
188
+ end #module Idea
189
+ end # module Buildr
190
+
191
+
192
+ class Buildr::Project
193
+ include Buildr::Idea
194
+ end