buildr-iidea 0.0.2

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.
@@ -0,0 +1,92 @@
1
+ require 'stringio'
2
+
3
+ module Buildr
4
+ module IntellijIdea
5
+ module ProjectExtension
6
+
7
+ include Extension
8
+
9
+ first_time do
10
+ desc "Generate Intellij IDEA artifacts for all projects"
11
+ Project.local_task "iidea:generate" => "artifacts"
12
+
13
+ desc "Delete the generated Intellij IDEA artifacts"
14
+ Project.local_task "iidea:clean"
15
+ end
16
+
17
+ before_define do |project|
18
+ project.recursive_task("iidea:generate")
19
+ project.recursive_task("iidea:clean")
20
+ end
21
+
22
+ after_define do |project|
23
+ iidea = project.task("iidea:generate")
24
+
25
+ files = [
26
+ (project.iml if project.iml?),
27
+ (project.ipr if project.ipr?)
28
+ ].compact
29
+
30
+ files.each do |ideafile|
31
+ module_dir = File.dirname(ideafile.filename)
32
+ # Need to clear the actions else the extension included as part of buildr will run
33
+ file(ideafile.filename).clear_actions
34
+ directory(module_dir)
35
+ iidea.enhance [ file(ideafile.filename) ]
36
+ file(ideafile.filename => [Buildr.application.buildfile, module_dir]) do |task|
37
+ info "Writing #{task.name}"
38
+ temp_filename = nil
39
+ Tempfile.open("buildr-iidea") do |f|
40
+ temp_filename = f.path
41
+ ideafile.write f
42
+ end
43
+ mv temp_filename, ideafile.filename
44
+ end
45
+ end
46
+
47
+ project.task("iidea:clean") do
48
+ files.each do |f|
49
+ info "Removing #{f.filename}" if File.exist?(f.filename)
50
+ rm_rf f.filename
51
+ end
52
+ end
53
+ end
54
+
55
+ def ipr
56
+ if ipr?
57
+ @ipr ||= IdeaProject.new(self)
58
+ else
59
+ raise "Only the root project has an IPR"
60
+ end
61
+ end
62
+
63
+ def ipr?
64
+ self.parent.nil?
65
+ end
66
+
67
+ def iml
68
+ if iml?
69
+ unless @iml
70
+ @iml = self.parent ? self.parent.iml.clone : IdeaModule.new
71
+ @iml.buildr_project = self
72
+ end
73
+ return @iml
74
+ else
75
+ raise "IML generation is disabled for #{self.name}"
76
+ end
77
+ end
78
+
79
+ def no_iml
80
+ @has_iml = false
81
+ end
82
+
83
+ def iml?
84
+ @has_iml = @has_iml.nil? ? true : @has_iml
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ class Buildr::Project
91
+ include Buildr::IntellijIdea::ProjectExtension
92
+ end
@@ -0,0 +1,5 @@
1
+ require 'buildr'
2
+ require File.expand_path(File.dirname(__FILE__) + '/buildr/intellij_idea/idea_file')
3
+ require File.expand_path(File.dirname(__FILE__) + '/buildr/intellij_idea/idea_module')
4
+ require File.expand_path(File.dirname(__FILE__) + '/buildr/intellij_idea/idea_project')
5
+ require File.expand_path(File.dirname(__FILE__) + '/buildr/intellij_idea/project_extension')
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "iidea:clean" do
4
+ before do
5
+ write "foo.ipr"
6
+ write "foo.iml"
7
+ write "other.ipr"
8
+ write "other.iml"
9
+ mkdir_p 'bar'
10
+ write "bar/bar.iml"
11
+ write "bar/other.ipr"
12
+ write "bar/other.iml"
13
+
14
+ @foo = define "foo" do
15
+ define "bar"
16
+ end
17
+ invoke_clean_task
18
+ end
19
+
20
+ it "should remove the ipr file" do
21
+ File.exists?("foo.ipr").should be_false
22
+ end
23
+
24
+ it "should remove the project iml file" do
25
+ File.exists?("foo.iml").should be_false
26
+ end
27
+
28
+ it "should remove the subproject iml file" do
29
+ File.exists?("foo.iml").should be_false
30
+ end
31
+
32
+ it "should not remove other iml and ipr files" do
33
+ File.exists?("other.ipr").should be_true
34
+ File.exists?("other.iml").should be_true
35
+ File.exists?("bar/other.ipr").should be_true
36
+ File.exists?("bar/other.iml").should be_true
37
+ end
38
+ end
@@ -0,0 +1,85 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ ORDER_ENTRY_XPATH = "/module/component[@name='NewModuleRootManager']/orderEntry"
4
+ DEPENDENCY_NAME = 'group:id:jar:1.0'
5
+ DEPENDENCY2_NAME = 'group:id2:jar:1.0'
6
+
7
+ describe "iidea:generate" do
8
+
9
+ describe "with a single dependency" do
10
+ before do
11
+ @artifact = artifact(DEPENDENCY_NAME) { |t| write t.to_s }
12
+ end
13
+
14
+ describe "of type compile" do
15
+ before do
16
+ @foo = define "foo" do
17
+ compile.with DEPENDENCY_NAME
18
+ end
19
+ invoke_generate_task
20
+ end
21
+
22
+ it "generates one exported 'module-library' orderEntry in IML" do
23
+ root_module_xml(@foo).should have_nodes("#{ORDER_ENTRY_XPATH}[@type='module-library', @exported='']", 1)
24
+ end
25
+ end
26
+
27
+ describe "of type test" do
28
+ before do
29
+ @foo = define "foo" do
30
+ test.with DEPENDENCY_NAME
31
+ end
32
+ invoke_generate_task
33
+ end
34
+
35
+ it "generates one non-exported 'module-library' orderEntry in IML" do
36
+ root_module_xml(@foo).should have_nodes("#{ORDER_ENTRY_XPATH}[@type='module-library' and @exported]", 0)
37
+ root_module_xml(@foo).should have_nodes("#{ORDER_ENTRY_XPATH}[@type='module-library']", 1)
38
+ end
39
+ end
40
+
41
+ describe "with local_repository_env_override set to nil" do
42
+ before do
43
+ @foo = define "foo" do
44
+ iml.local_repository_env_override = nil
45
+ compile.with DEPENDENCY_NAME
46
+ end
47
+ invoke_generate_task
48
+ end
49
+
50
+ it "generates orderEntry with absolute path for classes jar" do
51
+ root_module_xml(@foo).should match_xpath("#{ORDER_ENTRY_XPATH}/library/CLASSES/root/@url",
52
+ "jar://#{@artifact.to_s}!/")
53
+ end
54
+ end
55
+ describe "with local_repository_env_override set to MAVEN_REPOSITORY" do
56
+ before do
57
+ @foo = define "foo" do
58
+ iml.local_repository_env_override = 'MAVEN_REPOSITORY'
59
+ compile.with DEPENDENCY_NAME
60
+ end
61
+ invoke_generate_task
62
+ end
63
+
64
+ it "generates orderEntry with absolute path for classes jar" do
65
+ root_module_xml(@foo).should match_xpath("#{ORDER_ENTRY_XPATH}/library/CLASSES/root/@url",
66
+ "jar://$MAVEN_REPOSITORY$/group/id/1.0/id-1.0.jar!/")
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "with multiple dependencies" do
72
+ before do
73
+ @artifact1 = artifact(DEPENDENCY_NAME) { |t| write t.to_s }
74
+ @artifact2 = artifact(DEPENDENCY2_NAME) { |t| write t.to_s }
75
+ @foo = define "foo" do
76
+ compile.with DEPENDENCY_NAME, DEPENDENCY2_NAME
77
+ end
78
+ invoke_generate_task
79
+ end
80
+
81
+ it "generates multiple 'module-library' orderEntry in IML" do
82
+ root_module_xml(@foo).should have_nodes("#{ORDER_ENTRY_XPATH}[@type='module-library']", 2)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "iidea:generate" do
4
+ describe "with extra_modules specified" do
5
+ before do
6
+ @foo = define "foo" do
7
+ ipr.extra_modules << 'other.iml'
8
+ ipr.extra_modules << 'other_other.iml'
9
+ end
10
+ invoke_generate_task
11
+ end
12
+
13
+ it "generate an IPR with extra modules specified" do
14
+ doc = xml_document(@foo._("foo.ipr"))
15
+ doc.should have_nodes("#{xpath_to_module}", 3)
16
+ module_ref = "$PROJECT_DIR$/foo.iml"
17
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
18
+ module_ref = "$PROJECT_DIR$/other.iml"
19
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
20
+ module_ref = "$PROJECT_DIR$/other_other.iml"
21
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ FACET_XPATH = "/module/component[@name='FacetManager']/facet"
4
+
5
+ describe "iidea:generate" do
6
+ describe "with web and webservice facet added to root project" do
7
+ before do
8
+ @foo = define "foo" do
9
+ iml.add_facet("Web", "web") do |facet|
10
+ facet.configuration do |conf|
11
+ conf.descriptors do |desc|
12
+ desc.deploymentDescriptor :name => 'web.xml',
13
+ :url => "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
14
+ :optional => "false", :version => "2.4"
15
+ end
16
+ conf.webroots do |webroots|
17
+ webroots.root :url => "file://$MODULE_DIR$/src/main/webapp", :relative => "/"
18
+ end
19
+ end
20
+ end
21
+ iml.add_facet("WebServices Client", "WebServicesClient") do |facet|
22
+ facet.configuration "ws.engine" => "Glassfish / JAX-WS 2.X RI / Metro 1.X / JWSDP 2.0"
23
+ end
24
+ define 'bar'
25
+ end
26
+ invoke_generate_task
27
+ end
28
+
29
+ it "generates an IML for root project with a web and webservice facet" do
30
+ doc = xml_document(@foo._("foo.iml"))
31
+ doc.should have_nodes(FACET_XPATH, 2)
32
+ doc.should have_xpath("#{FACET_XPATH}[@type='web', @name='Web']")
33
+ doc.should have_xpath("#{FACET_XPATH}[@type='WebServicesClient', @name='WebServices Client']")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "iidea:generate" do
4
+ describe "with iml.group specified" do
5
+ before do
6
+ @foo = define "foo" do
7
+ iml.group = true
8
+ define 'bar' do
9
+ define 'baz' do
10
+
11
+ end
12
+ end
13
+ define 'rab' do
14
+ iml.group = "MyGroup"
15
+ end
16
+ end
17
+ invoke_generate_task
18
+ end
19
+
20
+ it "generate an IPR with correct group references" do
21
+ doc = xml_document(@foo._("foo.ipr"))
22
+ doc.should have_nodes("#{xpath_to_module}", 4)
23
+ module_ref = "$PROJECT_DIR$/foo.iml"
24
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']")
25
+ module_ref = "$PROJECT_DIR$/rab/rab.iml"
26
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'MyGroup']")
27
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
28
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'foo']")
29
+ module_ref = "$PROJECT_DIR$/bar/baz/baz.iml"
30
+ doc.should have_xpath("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}' @group = 'foo/bar']")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,177 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe "iidea:generate" do
4
+ describe "with a single project definition" do
5
+ describe "and default naming" do
6
+ before do
7
+ @foo = define "foo"
8
+ invoke_generate_task
9
+ end
10
+
11
+ it "generates a single IPR" do
12
+ Dir[@foo._("**/*.ipr")].should have(1).entry
13
+ end
14
+
15
+ it "generate an IPR in the root directory" do
16
+ File.should be_exist(@foo._("foo.ipr"))
17
+ end
18
+
19
+ it "generates a single IML" do
20
+ Dir[@foo._("**/*.iml")].should have(1).entry
21
+ end
22
+
23
+ it "generates an IML in the root directory" do
24
+ File.should be_exist(@foo._("foo.iml"))
25
+ end
26
+
27
+ it "generate an IPR with the reference to correct module file" do
28
+ File.should be_exist(@foo._("foo.ipr"))
29
+ doc = xml_document(@foo._("foo.ipr"))
30
+ module_ref = "$PROJECT_DIR$/foo.iml"
31
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
32
+ end
33
+ end
34
+
35
+ describe "with no_iml generation disabled" do
36
+ before do
37
+ @foo = define "foo" do
38
+ project.no_iml
39
+ end
40
+ invoke_generate_task
41
+ end
42
+
43
+ it "generates no IML" do
44
+ Dir[@foo._("**/*.iml")].should have(0).entry
45
+ end
46
+
47
+ it "generate an IPR with no references" do
48
+ File.should be_exist(@foo._("foo.ipr"))
49
+ doc = xml_document(@foo._("foo.ipr"))
50
+ doc.should have_nodes("#{xpath_to_module}", 0)
51
+ end
52
+ end
53
+
54
+ describe "and id overrides" do
55
+ before do
56
+ @foo = define "foo" do
57
+ ipr.id = 'fooble'
58
+ iml.id = 'feap'
59
+ define "bar" do
60
+ iml.id = "baz"
61
+ end
62
+ end
63
+ invoke_generate_task
64
+ end
65
+
66
+ it "generate an IPR in the root directory" do
67
+ File.should be_exist(@foo._("fooble.ipr"))
68
+ end
69
+
70
+ it "generates an IML in the root directory" do
71
+ File.should be_exist(@foo._("feap.iml"))
72
+ end
73
+
74
+ it "generates an IML in the subproject directory" do
75
+ File.should be_exist(@foo._("bar/baz.iml"))
76
+ end
77
+
78
+ it "generate an IPR with the reference to correct module file" do
79
+ File.should be_exist(@foo._("fooble.ipr"))
80
+ doc = xml_document(@foo._("fooble.ipr"))
81
+ module_ref = "$PROJECT_DIR$/feap.iml"
82
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
83
+ end
84
+ end
85
+
86
+ describe "and a suffix defined" do
87
+ before do
88
+ @foo = define "foo" do
89
+ ipr.suffix = '-ipr-suffix'
90
+ iml.suffix = '-iml-suffix'
91
+ end
92
+ invoke_generate_task
93
+ end
94
+
95
+ it "generate an IPR in the root directory" do
96
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
97
+ end
98
+
99
+ it "generates an IML in the root directory" do
100
+ File.should be_exist(@foo._("foo-iml-suffix.iml"))
101
+ end
102
+
103
+ it "generate an IPR with the reference to correct module file" do
104
+ File.should be_exist(@foo._("foo-ipr-suffix.ipr"))
105
+ doc = xml_document(@foo._("foo-ipr-suffix.ipr"))
106
+ doc.should have_nodes("#{xpath_to_module}", 1)
107
+ module_ref = "$PROJECT_DIR$/foo-iml-suffix.iml"
108
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
109
+ end
110
+ end
111
+ end
112
+
113
+ describe "with a subproject" do
114
+ before do
115
+ @foo = define "foo" do
116
+ define 'bar'
117
+ end
118
+ invoke_generate_task
119
+ end
120
+
121
+ it "creates the subproject directory" do
122
+ File.should be_exist(@foo._("bar"))
123
+ end
124
+
125
+ it "generates an IML in the subproject directory" do
126
+ File.should be_exist(@foo._("bar/bar.iml"))
127
+ end
128
+
129
+ it "generate an IPR with the reference to correct module file" do
130
+ File.should be_exist(@foo._("foo.ipr"))
131
+ doc = xml_document(@foo._("foo.ipr"))
132
+ doc.should have_nodes("#{xpath_to_module}", 2)
133
+ module_ref = "$PROJECT_DIR$/foo.iml"
134
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
135
+ module_ref = "$PROJECT_DIR$/bar/bar.iml"
136
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://#{module_ref}', @filepath='#{module_ref}']", 1)
137
+ end
138
+ end
139
+
140
+ describe "with base_dir specified" do
141
+ before do
142
+ @foo = define "foo" do
143
+ define('bar', :base_dir => 'fe') do
144
+ define('baz', :base_dir => 'fi') do
145
+ define('foe')
146
+ end
147
+ define('fum')
148
+ end
149
+ end
150
+ invoke_generate_task
151
+ end
152
+
153
+ it "generates a subproject IML in the specified directory" do
154
+ File.should be_exist(@foo._("fe/bar.iml"))
155
+ end
156
+
157
+ it "generates a sub-subproject IML in the specified directory" do
158
+ File.should be_exist(@foo._("fi/baz.iml"))
159
+ end
160
+
161
+ it "generates a sub-sub-subproject IML that inherits the specified directory" do
162
+ File.should be_exist(@foo._("fi/foe/foe.iml"))
163
+ end
164
+
165
+ it "generates a sub-subproject IML that inherits the specified directory" do
166
+ File.should be_exist(@foo._("fe/fum/fum.iml"))
167
+ end
168
+
169
+ it "generate an IPR with the references to correct module files" do
170
+ doc = xml_document(@foo._("foo.ipr"))
171
+ doc.should have_nodes("#{xpath_to_module}", 5)
172
+ ["foo.iml", "fe/bar.iml", "fi/baz.iml", "fi/foe/foe.iml","fe/fum/fum.iml"].each do |module_ref|
173
+ doc.should have_nodes("#{xpath_to_module}[@fileurl='file://$PROJECT_DIR$/#{module_ref}', @filepath='$PROJECT_DIR$/#{module_ref}']", 1)
174
+ end
175
+ end
176
+ end
177
+ end