buildr 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -81,7 +81,7 @@ module Buildr
81
81
  OPTIONS.each { |name| send "#{name}=", nil }
82
82
  end
83
83
 
84
- def to_s()
84
+ def to_s() #:nodoc:
85
85
  OPTIONS.inject({}){ |hash, name| hash[name] = send(name) ; hash }.reject{ |name,value| value.nil? }.inspect
86
86
  end
87
87
 
@@ -191,8 +191,9 @@ module Buildr
191
191
  #
192
192
  # For example:
193
193
  # compile.using(:warnings=>true, :source=>"1.5")
194
- def using(hash)
195
- hash.each { |k, v| options.send "#{k}=", v }
194
+ def using(*args)
195
+ args.pop.each { |key, value| options.send "#{key}=", value } if Hash === args.last
196
+ args.each { |key| options.send "#{key}=", value = true }
196
197
  self
197
198
  end
198
199
 
@@ -254,7 +255,7 @@ module Buildr
254
255
  def initialize(*args) #:nodoc:
255
256
  super
256
257
  @filter = Buildr::Filter.new
257
- enhance { filter.run }
258
+ enhance { filter.run if filter.source && filter.target }
258
259
  end
259
260
 
260
261
  # :call-seq:
@@ -385,8 +386,9 @@ module Buildr
385
386
  #
386
387
  # For example:
387
388
  # javadoc.using :windowtitle=>"My application"
388
- def using(options)
389
- options.each { |key, value| @options[key] = value }
389
+ def using(*args)
390
+ args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
391
+ args.each { |key| @options[key.to_sym] = true }
390
392
  self
391
393
  end
392
394
 
@@ -448,19 +450,9 @@ module Buildr
448
450
 
449
451
  class Project
450
452
 
451
- # :call-seq:
452
- # prepare(*prereqs) => task
453
- # prepare(*prereqs) { |task| .. } => task
454
- #
455
- # The prepare task executes before the #compile task. Use it for pre-compilation
456
- # tasks, e.g. generating source code.
457
- #
458
- # This method returns the project's prepare task. It also accepts a list of
459
- # prerequisites and a block, used to enhance the prepare task.
460
- #
461
- # For example:
462
- # prepare { schema_to_java }
453
+ # *Deprecated* Add a prerequisite to the compile task instead.
463
454
  def prepare(*prereqs, &block)
455
+ warn_deprecated "Add a prerequisite to the compile task instead of using the prepare task."
464
456
  task("prepare").enhance prereqs, &block
465
457
  end
466
458
 
@@ -536,7 +528,7 @@ module Buildr
536
528
  prepare = task("prepare")
537
529
  # Resources task is a filter.
538
530
  resources = Java::ResourcesTask.define_task("resources")
539
- resources.filter.from project.path_to("src/main/resources")
531
+ project.path_to("src/main/resources").tap { |dir| resources.filter.from dir if File.exist?(dir) }
540
532
  # Compile task requires prepare and performs resources, if anything compiled.
541
533
  compile = Java::CompileTask.define_task("compile"=>[prepare, resources])
542
534
  project.path_to("src/main/java").tap { |dir| compile.from dir if File.exist?(dir) }
@@ -564,12 +556,12 @@ module Buildr
564
556
  #
565
557
  # You can turn this option off directly, or by setting the environment variable
566
558
  # DEBUG to "no". For example:
567
- # rake build DEBUG=no
559
+ # buildr build DEBUG=no
568
560
  #
569
561
  # The release tasks runs a build with <tt>DEBUG=no</tt>.
570
562
  attr_accessor :debug
571
563
 
572
- def debug()
564
+ def debug() #:nodoc:
573
565
  @debug = (ENV["DEBUG"] || ENV["debug"]) !~ /(no|off|false)/ if @debug.nil?
574
566
  @debug
575
567
  end
@@ -15,9 +15,9 @@ module Buildr
15
15
 
16
16
  # We need paths relative to the top project's base directory.
17
17
  root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir } ; f[p] }[project]
18
- # We want the Eclipse files changed every time the Rakefile changes, but also anything loaded by
19
- # the Rakefile (buildr.rb, separate file listing dependencies, etc), so we add anything required
20
- # after the Rakefile. So which don't know where Buildr shows up exactly, ignore files that show
18
+ # We want the Eclipse files changed every time the Buildfile changes, but also anything loaded by
19
+ # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
20
+ # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
21
21
  # in $LOADED_FEATURES that we cannot resolve.
22
22
  sources = ($LOADED_FEATURES - Buildr.instance_eval("@loaded_features_to_ignore")).
23
23
  map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
@@ -27,7 +27,7 @@ module Buildr
27
27
  if project.packages.detect { |pkg| pkg.type.to_s =~ /(jar)|(war)|(rar)|(mar)|(aar)/ }
28
28
  eclipse.enhance [ file(project.path_to(".classpath")), file(project.path_to(".project")) ]
29
29
 
30
- # The only thing we need to look for is a change in the Rakefile.
30
+ # The only thing we need to look for is a change in the Buildfile.
31
31
  file(project.path_to(".classpath")=>sources) do |task|
32
32
  puts "Writing #{task.name}" if verbose
33
33
 
@@ -107,7 +107,7 @@ module Buildr
107
107
  end
108
108
  end
109
109
 
110
- # The only thing we need to look for is a change in the Rakefile.
110
+ # The only thing we need to look for is a change in the Buildfile.
111
111
  file(project.path_to(".project")=>sources) do |task|
112
112
  puts "Writing #{task.name}" if verbose
113
113
  File.open(task.name, "w") do |file|
@@ -0,0 +1,284 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4" relativePaths="false">
3
+ <component name="AntConfiguration">
4
+ <defaultAnt bundledAnt="true" />
5
+ </component>
6
+ <component name="BuildJarProjectSettings">
7
+ <option name="BUILD_JARS_ON_MAKE" value="false" />
8
+ </component>
9
+ <component name="CodeStyleManager">
10
+ <option name="USE_DEFAULT_CODE_STYLE_SCHEME" value="true" />
11
+ <option name="CODE_STYLE_SCHEME" value="" />
12
+ </component>
13
+ <component name="CodeStyleProjectProfileManger">
14
+ <option name="PROJECT_PROFILE" />
15
+ <option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
16
+ </component>
17
+ <component name="CodeStyleSettingsManager">
18
+ <option name="PER_PROJECT_SETTINGS" />
19
+ <option name="USE_PER_PROJECT_SETTINGS" value="false" />
20
+ </component>
21
+ <component name="CompilerConfiguration">
22
+ <option name="DEFAULT_COMPILER" value="Javac" />
23
+ <option name="DEPLOY_AFTER_MAKE" value="0" />
24
+ <resourceExtensions />
25
+ <wildcardResourcePatterns>
26
+ <entry name="!?*.java" />
27
+ </wildcardResourcePatterns>
28
+ </component>
29
+ <component name="DataSourceManager" />
30
+ <component name="DataSourceManagerImpl" />
31
+ <component name="DependenciesAnalyzeManager">
32
+ <option name="myForwardDirection" value="false" />
33
+ </component>
34
+ <component name="DependencyValidationManager" />
35
+ <component name="EclipseCompilerSettings">
36
+ <option name="DEBUGGING_INFO" value="true" />
37
+ <option name="GENERATE_NO_WARNINGS" value="true" />
38
+ <option name="DEPRECATION" value="false" />
39
+ <option name="ADDITIONAL_OPTIONS_STRING" value="" />
40
+ <option name="MAXIMUM_HEAP_SIZE" value="128" />
41
+ </component>
42
+ <component name="EclipseEmbeddedCompilerSettings">
43
+ <option name="DEBUGGING_INFO" value="true" />
44
+ <option name="GENERATE_NO_WARNINGS" value="true" />
45
+ <option name="DEPRECATION" value="false" />
46
+ <option name="ADDITIONAL_OPTIONS_STRING" value="" />
47
+ <option name="MAXIMUM_HEAP_SIZE" value="128" />
48
+ </component>
49
+ <component name="EntryPointsManager">
50
+ <entry_points />
51
+ </component>
52
+ <component name="ExportToHTMLSettings">
53
+ <option name="PRINT_LINE_NUMBERS" value="false" />
54
+ <option name="OPEN_IN_BROWSER" value="false" />
55
+ <option name="OUTPUT_DIRECTORY" />
56
+ </component>
57
+ <component name="GUI Designer component loader factory" />
58
+ <component name="IdProvider" IDEtalkID="0246D33576B8D4BC3331F9A5BB848389" />
59
+ <component name="ImportConfiguration">
60
+ <option name="VENDOR" />
61
+ <option name="RELEASE_TAG" />
62
+ <option name="LOG_MESSAGE" />
63
+ <option name="CHECKOUT_AFTER_IMPORT" value="true" />
64
+ </component>
65
+ <component name="InspectionProjectProfileManager">
66
+ <option name="PROJECT_PROFILE" value="Project Default" />
67
+ <option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
68
+ <scopes />
69
+ <profiles>
70
+ <profile version="1.0" is_locked="false">
71
+ <option name="myName" value="Project Default" />
72
+ <option name="myLocal" value="false" />
73
+ <used_levels>
74
+ <error>
75
+ <option name="myName" value="ERROR" />
76
+ <option name="myVal" value="400" />
77
+ </error>
78
+ <warning>
79
+ <option name="myName" value="WARNING" />
80
+ <option name="myVal" value="300" />
81
+ </warning>
82
+ <information>
83
+ <option name="myName" value="INFO" />
84
+ <option name="myVal" value="200" />
85
+ </information>
86
+ <server>
87
+ <option name="myName" value="SERVER PROBLEM" />
88
+ <option name="myVal" value="100" />
89
+ </server>
90
+ </used_levels>
91
+ </profile>
92
+ </profiles>
93
+ </component>
94
+ <component name="JUnitProjectSettings">
95
+ <option name="TEST_RUNNER" value="UI" />
96
+ </component>
97
+ <component name="JavacSettings">
98
+ <option name="DEBUGGING_INFO" value="true" />
99
+ <option name="GENERATE_NO_WARNINGS" value="false" />
100
+ <option name="DEPRECATION" value="true" />
101
+ <option name="ADDITIONAL_OPTIONS_STRING" value="" />
102
+ <option name="MAXIMUM_HEAP_SIZE" value="128" />
103
+ </component>
104
+ <component name="JavadocGenerationManager">
105
+ <option name="OUTPUT_DIRECTORY" />
106
+ <option name="OPTION_SCOPE" value="protected" />
107
+ <option name="OPTION_HIERARCHY" value="false" />
108
+ <option name="OPTION_NAVIGATOR" value="false" />
109
+ <option name="OPTION_INDEX" value="false" />
110
+ <option name="OPTION_SEPARATE_INDEX" value="false" />
111
+ <option name="OPTION_DOCUMENT_TAG_USE" value="false" />
112
+ <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
113
+ <option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
114
+ <option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="false" />
115
+ <option name="OPTION_DEPRECATED_LIST" value="false" />
116
+ <option name="OTHER_OPTIONS" />
117
+ <option name="HEAP_SIZE" />
118
+ <option name="LOCALE" />
119
+ <option name="OPEN_IN_BROWSER" value="false" />
120
+ </component>
121
+ <component name="JikesSettings">
122
+ <option name="JIKES_PATH" value="" />
123
+ <option name="DEBUGGING_INFO" value="true" />
124
+ <option name="DEPRECATION" value="true" />
125
+ <option name="GENERATE_NO_WARNINGS" value="false" />
126
+ <option name="IS_EMACS_ERRORS_MODE" value="true" />
127
+ <option name="ADDITIONAL_OPTIONS_STRING" value="" />
128
+ </component>
129
+ <component name="LogConsolePreferences">
130
+ <option name="FILTER_ERRORS" value="false" />
131
+ <option name="FILTER_WARNINGS" value="false" />
132
+ <option name="FILTER_INFO" value="true" />
133
+ <option name="CUSTOM_FILTER" />
134
+ </component>
135
+ <component name="Palette2">
136
+ <group name="Swing">
137
+ <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
138
+ <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
139
+ </item>
140
+ <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
141
+ <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
142
+ </item>
143
+ <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
144
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
145
+ </item>
146
+ <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
147
+ <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
148
+ </item>
149
+ <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
150
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
151
+ <initial-values>
152
+ <property name="text" value="Button" />
153
+ </initial-values>
154
+ </item>
155
+ <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
156
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
157
+ <initial-values>
158
+ <property name="text" value="RadioButton" />
159
+ </initial-values>
160
+ </item>
161
+ <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
162
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
163
+ <initial-values>
164
+ <property name="text" value="CheckBox" />
165
+ </initial-values>
166
+ </item>
167
+ <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
168
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
169
+ <initial-values>
170
+ <property name="text" value="Label" />
171
+ </initial-values>
172
+ </item>
173
+ <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
174
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
175
+ <preferred-size width="150" height="-1" />
176
+ </default-constraints>
177
+ </item>
178
+ <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
179
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
180
+ <preferred-size width="150" height="-1" />
181
+ </default-constraints>
182
+ </item>
183
+ <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
184
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
185
+ <preferred-size width="150" height="-1" />
186
+ </default-constraints>
187
+ </item>
188
+ <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
189
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
190
+ <preferred-size width="150" height="50" />
191
+ </default-constraints>
192
+ </item>
193
+ <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
194
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
195
+ <preferred-size width="150" height="50" />
196
+ </default-constraints>
197
+ </item>
198
+ <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
199
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
200
+ <preferred-size width="150" height="50" />
201
+ </default-constraints>
202
+ </item>
203
+ <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
204
+ <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
205
+ </item>
206
+ <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
207
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
208
+ <preferred-size width="150" height="50" />
209
+ </default-constraints>
210
+ </item>
211
+ <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
212
+ <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
213
+ <preferred-size width="150" height="50" />
214
+ </default-constraints>
215
+ </item>
216
+ <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
217
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
218
+ <preferred-size width="150" height="50" />
219
+ </default-constraints>
220
+ </item>
221
+ <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
222
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
223
+ <preferred-size width="200" height="200" />
224
+ </default-constraints>
225
+ </item>
226
+ <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
227
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
228
+ <preferred-size width="200" height="200" />
229
+ </default-constraints>
230
+ </item>
231
+ <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
232
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
233
+ </item>
234
+ <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
235
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
236
+ </item>
237
+ <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
238
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
239
+ </item>
240
+ <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
241
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
242
+ </item>
243
+ <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
244
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
245
+ <preferred-size width="-1" height="20" />
246
+ </default-constraints>
247
+ </item>
248
+ <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
249
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
250
+ </item>
251
+ <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
252
+ <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
253
+ </item>
254
+ </group>
255
+ </component>
256
+ <component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" />
257
+ <component name="ProjectRunConfigurationManager" />
258
+ <component name="RmicSettings">
259
+ <option name="IS_EANABLED" value="false" />
260
+ <option name="DEBUGGING_INFO" value="true" />
261
+ <option name="GENERATE_NO_WARNINGS" value="false" />
262
+ <option name="GENERATE_IIOP_STUBS" value="false" />
263
+ <option name="ADDITIONAL_OPTIONS_STRING" value="" />
264
+ </component>
265
+ <component name="StarteamVcsAdapter" />
266
+ <component name="VssVcs" />
267
+ <component name="com.intellij.jsf.UserDefinedFacesConfigs">
268
+ <option name="USER_DEFINED_CONFIGS">
269
+ <value>
270
+ <list size="0" />
271
+ </value>
272
+ </option>
273
+ </component>
274
+ <component name="uidesigner-configuration">
275
+ <option name="INSTRUMENT_CLASSES" value="true" />
276
+ <option name="COPY_FORMS_RUNTIME_TO_OUTPUT" value="true" />
277
+ <option name="DEFAULT_LAYOUT_MANAGER" value="GridLayoutManager" />
278
+ </component>
279
+ <UsedPathMacros>
280
+ <macro name="M2_REPO" />
281
+ </UsedPathMacros>
282
+ </project>
283
+
284
+
@@ -1,6 +1,8 @@
1
1
  require "pathname"
2
2
  require "core/project"
3
3
  require "java/artifact"
4
+ require 'stringio'
5
+ require 'rexml/document'
4
6
 
5
7
  module Buildr
6
8
 
@@ -15,109 +17,142 @@ module Buildr
15
17
 
16
18
  # We need paths relative to the top project's base directory.
17
19
  root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir } ; f[p] }[project]
18
- # We want the Eclipse files changed every time the Rakefile changes, but also anything loaded by
19
- # the Rakefile (buildr.rb, separate file listing dependencies, etc), so we add anything required
20
- # after the Rakefile. So which don't know where Buildr shows up exactly, ignore files that show
20
+ # We want the Eclipse files changed every time the Buildfile changes, but also anything loaded by
21
+ # the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
22
+ # after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
21
23
  # in $LOADED_FEATURES that we cannot resolve.
22
24
  sources = ($LOADED_FEATURES - Buildr.instance_eval("@loaded_features_to_ignore")).
23
25
  map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
24
26
  sources << File.expand_path(Rake.application.rakefile, root_path) if Rake.application.rakefile
25
27
 
26
- # Only for projects that are packagable.
27
- if project.packages.detect { |pkg| pkg.type.to_s =~ /(jar)|(war)|(rar)|(mar)|(aar)/ }
28
- task_name = project.path_to("#{project.name.sub(':', '-')}.iml")
29
- idea.enhance [ file(task_name) ]
30
-
31
- # The only thing we need to look for is a change in the Rakefile.
32
- file(task_name=>sources) do |task|
33
- puts "Writing #{task.name}" # if verbose
28
+ # Find a path relative to the project's root directory.
29
+ relative = lambda do |path|
30
+ msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
31
+ path = path.__send__(msg)
32
+ Pathname.new(path).relative_path_from(Pathname.new(project.path_to)).to_s
33
+ end
34
34
 
35
- # Find a path relative to the project's root directory.
36
- relative = lambda do |path|
37
- msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
38
- path = path.__send__(msg)
39
- Pathname.new(path).relative_path_from(Pathname.new(project.path_to)).to_s
40
- end
35
+ m2repo = Buildr::Repositories.instance.local
36
+ excludes = [ '**/.svn/', '**/CVS/' ].join('|')
41
37
 
42
- m2repo = Buildr::Repositories.instance.local
43
- excludes = [ '**/.svn/', '**/CVS/' ].join('|')
38
+ # Only for projects that are packageable.
39
+ task_name = project.path_to("#{project.name.sub(':', '-')}.iml")
40
+ idea.enhance [ file(task_name) ]
44
41
 
45
- # Idea handles modules slightly differently if they're WARs
46
- idea_types = {"jar"=>"JAVA_MODULE", "war"=>"J2EE_WEB_MODULE"}
47
- idea_types["rar"] = idea_types["mar"] = idea_types["jar"]
42
+ # The only thing we need to look for is a change in the Buildfile.
43
+ file(task_name=>sources) do |task|
44
+ puts "Writing #{task.name}" if verbose
48
45
 
49
- # Note: Use the test classpath since Eclipse compiles both "main" and "test" classes using the same classpath
50
- cp = project.test.compile.classpath.map(&:to_s) - [ project.compile.target.to_s ]
46
+ # Idea handles modules slightly differently if they're WARs
47
+ idea_types = Hash.new("JAVA_MODULE")
48
+ idea_types["war"] = "J2EE_WEB_MODULE"
51
49
 
52
- # Convert classpath elements into applicable Project objects
53
- cp.collect! { |path| projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
50
+ # 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 ]
54
52
 
55
- # project_libs: artifacts created by other projects
56
- project_libs, others = cp.partition { |path| path.is_a?(Project) }
53
+ # Convert classpath elements into applicable Project objects
54
+ cp.collect! { |path| projects.detect { |prj| prj.packages.detect { |pkg| pkg.to_s == path } } || path }
57
55
 
58
- # Separate artifacts from Maven2 repository
59
- m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
56
+ # project_libs: artifacts created by other projects
57
+ project_libs, others = cp.partition { |path| path.is_a?(Project) }
60
58
 
61
- # Generated: classpath elements in the project are assumed to be generated
62
- generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
59
+ # Separate artifacts from Maven2 repository
60
+ m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
63
61
 
64
- File.open(task.name, "w") do |file|
65
- xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
66
- # Project type is going to be the first package type
67
- xml.module(:version=>"4", :relativePaths=>"false", :type=>idea_types[project.packages.first.type.to_s]) do
62
+ # Generated: classpath elements in the project are assumed to be generated
63
+ generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
68
64
 
69
- xml.component :name=>"ModuleRootManager"
70
- xml.component "name"=>"NewModuleRootManager", "inherit-compiler-output"=>"false" do
71
- xml.output :url=>"file://$MODULE_DIR$/#{relative[project.compile.target]}"
65
+ File.open(task.name, "w") do |file|
66
+ xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
67
+ # Project type is going to be the first package type
68
+ xml.module(:version=>"4", :relativePaths=>"false", :type=>idea_types[project.packages.first.type.to_s]) do
72
69
 
73
- # TODO project.test.target isn't recognized, what's the proper way to get the test compile path?
74
- xml.tag! "output-test", :url=>"file://$MODULE_DIR$/target/test-classes"
75
- xml.tag! "exclude-output"
70
+ xml.component :name=>"ModuleRootManager"
71
+ xml.component "name"=>"NewModuleRootManager", "inherit-compiler-output"=>"false" do
72
+ xml.output :url=>"file://$MODULE_DIR$/#{relative[project.compile.target]}"
73
+ xml.tag! "exclude-output"
76
74
 
77
- xml.content do
78
- srcs = project.compile.sources.map { |src| relative[src] } + generated.map { |src| relative[src] }
79
- srcs.sort.uniq.each do |path|
80
- xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"false"
81
- end
82
- test_sources = project.test.compile.sources.map { |src| relative[src] }
83
- test_sources.each do |paths|
84
- paths.sort.uniq.each do |path|
85
- xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"true"
86
- end
75
+ # TODO project.test.target isn't recognized, what's the proper way to get the test compile path?
76
+ xml.tag! "output-test", :url=>"file://$MODULE_DIR$/target/test-classes"
77
+
78
+ xml.content(:url=>"file://$MODULE_DIR$") do
79
+ srcs = project.compile.sources.map { |src| relative[src] } + generated.map { |src| relative[src] }
80
+ srcs.sort.uniq.each do |path|
81
+ xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"false"
82
+ end
83
+ test_sources = project.test.compile.sources.map { |src| relative[src] }
84
+ test_sources.each do |paths|
85
+ paths.sort.uniq.each do |path|
86
+ xml.sourceFolder :url=>"file://$MODULE_DIR$/#{path}", :isTestSource=>"true"
87
87
  end
88
- xml.excludeFolder :url=>"file://$MODULE_DIR$/#{relative[project.compile.target]}"
89
88
  end
89
+ {"src/main/resources"=>false, "src/test/resources"=>true}.each do |key, value|
90
+ xml.sourceFolder :url=>"file://$MODULE_DIR$/#{key}", :isTestSource=>"#{value}" if File.exist?(project.path_to(key))
91
+ end
92
+ xml.excludeFolder :url=>"file://$MODULE_DIR$/#{relative[project.compile.target]}"
93
+ end
90
94
 
91
- xml.orderEntry :type=>"sourceFolder", :forTests=>"false"
92
- xml.orderEntry :type=>"inheritedJdk"
95
+ xml.orderEntry :type=>"sourceFolder", :forTests=>"false"
96
+ xml.orderEntry :type=>"inheritedJdk"
93
97
 
94
- # Classpath elements from other projects
95
- project_libs.map(&:id).sort.uniq.each do |project_id|
96
- xml.orderEntry :type=>'module', :name=>project_id
97
- end
98
+ # Classpath elements from other projects
99
+ project_libs.map(&:id).sort.uniq.each do |project_id|
100
+ xml.orderEntry :type=>'module', "module-name"=>project_id
101
+ end
98
102
 
99
- # Libraries
100
- ext_libs = libs.map {|path| "$MODULE_DIR$/#{path.to_s}" } +
101
- m2_libs.map { |path| path.to_s.sub(m2repo, "$M2_REPO$") }
102
- ext_libs.each do |path|
103
- xml.orderEntry :type=>"module-library" do
104
- xml.library do
105
- xml.CLASSES do
106
- xml.root :url=>"jar://#{path}!/"
107
- end
108
- xml.JAVADOC
109
- xml.SOURCES
103
+ # Libraries
104
+ ext_libs = libs.map {|path| "$MODULE_DIR$/#{path.to_s}" } +
105
+ m2_libs.map { |path| path.to_s.sub(m2repo, "$M2_REPO$") }
106
+ ext_libs.each do |path|
107
+ xml.orderEntry :type=>"module-library" do
108
+ xml.library do
109
+ xml.CLASSES do
110
+ xml.root :url=>"jar://#{path}!/"
110
111
  end
112
+ xml.JAVADOC
113
+ xml.SOURCES
111
114
  end
112
115
  end
113
-
114
- xml.orderEntryProperties
115
116
  end
117
+
118
+ xml.orderEntryProperties
116
119
  end
117
120
  end
118
121
  end
122
+ end
123
+
124
+ # Root project aggregates all the subprojects.
125
+ if project.parent == nil
126
+ task_name = project.path_to("#{project.name.sub(':', '-')}.ipr")
127
+ idea.enhance [ file(task_name) ]
128
+
129
+ file(task_name=>sources) do |task|
130
+ puts "Writing #{task.name}" if verbose
131
+
132
+ # Generating just the little stanza that chanages from one project to another
133
+ partial = StringIO.new
134
+ xml = Builder::XmlMarkup.new(:target=>partial, :indent=>2)
135
+ xml.component(:name=>"ProjectModuleManager") do
136
+ xml.modules do
137
+ project.projects.each do |subp|
138
+ module_name = subp.name.gsub(":", "-")
139
+ module_path = subp.name[/:(.*)/][1..-1]
140
+ path = "#{module_path}/#{module_name}.iml"
141
+ xml.module :fileurl=>"file://$PROJECT_DIR$/#{path}", :filepath=>"$PROJECT_DIR$/#{path}"
142
+ end
143
+ xml.module :fileurl=>"file://$PROJECT_DIR$/#{project.name}.iml", :filepath=>"$PROJECT_DIR$/#{project.name}.iml"
144
+ end
145
+ end
119
146
 
147
+ # Loading the whole fairly constant crap
148
+ template_xml = REXML::Document.new(File.open(File.dirname(__FILE__)+"/idea.ipr.template"))
149
+ include_xml = REXML::Document.new(partial.string)
150
+ template_xml.root.add_element(include_xml.root)
151
+ template_xml.write(File.new(task.name, "w"))
152
+
153
+ end
120
154
  end
155
+
121
156
  end
122
157
  end
123
158