buildr-dependency-extensions 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,3 @@
1
+ module BuildrDependencyExtensions
2
+ VERSION = '0.2'.freeze
3
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/buildr-dependency-extensions'))
4
+ require File.expand_path(File.join('spec', 'spec_helpers'), Gem::GemPathSearcher.new.find('buildr').full_gem_path)
5
+
6
+ describe 'Compile dependencies' do
7
+ before(:each) do
8
+ write artifact('foo:bar:jar:1.0').pom.to_s, <<-XML
9
+ <project>
10
+ <artifactId>bar</artifactId>
11
+ <groupId>foo</groupId>
12
+ </project>
13
+ XML
14
+
15
+ write artifact('foo:foobar:jar:1.0').pom.to_s, <<-XML
16
+ <project>
17
+ <artifactId>foobar</artifactId>
18
+ <groupId>foo</groupId>
19
+ </project>
20
+ XML
21
+
22
+ write artifact('transitive:dependencies:jar:1.0').pom.to_s, <<-XML
23
+ <project>
24
+ <artifactId>transitive</artifactId>
25
+ <groupId>dependencies</groupId>
26
+
27
+ <dependencies>
28
+ <dependency>
29
+ <groupId>foo</groupId>
30
+ <artifactId>foobar</artifactId>
31
+ <version>1.0</version>
32
+ <scope>compile</scope>
33
+ </dependency>
34
+ <dependency>
35
+ <groupId>foo</groupId>
36
+ <artifactId>bar</artifactId>
37
+ <version>1.0</version>
38
+ <scope>runtime</scope>
39
+ </dependency>
40
+ </dependencies>
41
+ </project>
42
+ XML
43
+ end
44
+
45
+ describe 'maven dependency mechanism' do
46
+ it 'transitively adds compile dependencies and runtime dependencies of this project runtime dependencies to the runtime dependencies' do
47
+ define "TestProject" do
48
+ extend TransitiveDependencies
49
+ project.version = '1.0'
50
+
51
+ project.transitive_scopes = [:compile]
52
+
53
+ compile.with 'transitive:dependencies:jar:1.0'
54
+ end
55
+
56
+ expected_dependencies = [artifact('foo:foobar:jar:1.0'), artifact('transitive:dependencies:jar:1.0')]
57
+ project('TestProject').compile.dependencies.should ==(expected_dependencies)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,135 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/buildr-dependency-extensions'))
4
+ require File.expand_path(File.join('spec', 'spec_helpers'), Gem::GemPathSearcher.new.find('buildr').full_gem_path)
5
+
6
+ describe BuildrDependencyExtensions::DependencyCaching do
7
+ before(:each) do
8
+ write artifact('foo:bar:jar:1.0').pom.to_s, <<-XML
9
+ <project>
10
+ <artifactId>bar</artifactId>
11
+ <groupId>foo</groupId>
12
+ </project>
13
+ XML
14
+ end
15
+
16
+ after(:each) do
17
+ FileUtils.rm_f(project('TestProject').path_to('dependency.cache'))
18
+ end
19
+
20
+ it 'reads and write the runtime dependencies to and from a dependency cache file' do
21
+ define "TestProject" do
22
+ end
23
+
24
+ project = project('TestProject')
25
+ project.run.with(artifact('foo:bar:jar:1.1'))
26
+
27
+ dependency_caching = DependencyCaching.new(project)
28
+
29
+ dependency_caching.write_cache
30
+
31
+ project.run.classpath = []
32
+
33
+ dependency_cache = dependency_caching.read_cache
34
+
35
+ dependency_cache['runtime'].should ==([artifact('foo:bar:jar:1.1')])
36
+ end
37
+
38
+ it 'reads and write the compile dependencies to and from a dependency cache file' do
39
+ define "TestProject" do
40
+ end
41
+
42
+ project = project('TestProject')
43
+ project.compile.with(artifact('foo:bar:jar:1.1'))
44
+
45
+ dependency_caching = DependencyCaching.new(project)
46
+
47
+ dependency_caching.write_cache
48
+
49
+ project.compile.dependencies = []
50
+
51
+ dependency_cache = dependency_caching.read_cache
52
+
53
+ dependency_cache['compile'].should ==([artifact('foo:bar:jar:1.1')])
54
+ end
55
+
56
+ it 'reads and write the test dependencies to and from a dependency cache file' do
57
+ define "TestProject" do
58
+ end
59
+
60
+ project = project('TestProject')
61
+ project.test.with(artifact('foo:bar:jar:1.1'))
62
+
63
+ dependency_caching = DependencyCaching.new(project)
64
+
65
+ dependency_caching.write_cache
66
+
67
+ project.test.dependencies = project.test.compile.dependencies = []
68
+
69
+ dependency_cache = dependency_caching.read_cache
70
+
71
+ dependency_cache['test'].should ==([artifact('foo:bar:jar:1.1')])
72
+ end
73
+
74
+ it 'return nil if no dependency cache file exist' do
75
+ define "TestProject" do
76
+ end
77
+
78
+ project = project('TestProject')
79
+
80
+ dependency_caching = DependencyCaching.new(project)
81
+
82
+ dependency_caching.read_cache.should ==(nil)
83
+ end
84
+
85
+ describe('cache_dependencies property') do
86
+ it 'causes the plugin to save the dependency cache file if it does not exist when set to true' do
87
+ dependency_caching_mock = stub('dependency_caching_mock')
88
+ dependency_caching_mock.should_receive(:read_cache).and_return(nil)
89
+ dependency_caching_mock.should_receive(:write_cache)
90
+ DependencyCaching.stub!(:new).and_return(dependency_caching_mock)
91
+ DependencyCaching.should_receive(:new).and_return(dependency_caching_mock)
92
+
93
+ define "TestProject" do
94
+ extend TransitiveDependencies
95
+
96
+ project.transitive_scopes = [:compile]
97
+ project.cache_dependencies = true
98
+
99
+ compile.with artifact('foo:bar:jar:1.0')
100
+ end
101
+ end
102
+
103
+ it 'causes the plugin to load the dependency cache file if it exists when set to true' do
104
+ dependency_caching_mock = stub('dependency_caching_mock')
105
+ dependency_caching_mock.should_receive(:read_cache).and_return({'compile' => [artifact('foo:bar:jar:1.0')]})
106
+ dependency_caching_mock.should_not_receive(:write_cache)
107
+ DependencyCaching.stub!(:new).and_return(dependency_caching_mock)
108
+ DependencyCaching.should_receive(:new).and_return(dependency_caching_mock)
109
+
110
+ define "TestProject" do
111
+ extend TransitiveDependencies
112
+
113
+ project.transitive_scopes = [:compile]
114
+ project.cache_dependencies = true
115
+ end
116
+
117
+ project('TestProject').compile.dependencies.should ==([artifact('foo:bar:jar:1.0')])
118
+ end
119
+
120
+ it 'does not load the dependency cache file when set to false' do
121
+ dependency_caching_mock = stub('dependency_caching_mock')
122
+ dependency_caching_mock.should_receive(:read_cache).and_return({'compile' => [artifact('foo:bar:jar:1.0')]})
123
+ dependency_caching_mock.should_receive(:write_cache)
124
+ DependencyCaching.should_receive(:new).and_return(dependency_caching_mock)
125
+
126
+ define "TestProject" do
127
+ extend TransitiveDependencies
128
+
129
+ project.transitive_scopes = [:compile]
130
+ end
131
+
132
+ project('TestProject').compile.dependencies.should ==([])
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/buildr-dependency-extensions'))
4
+
5
+ module BuildrDependencyExtensions
6
+
7
+ describe HelperFunctions do
8
+ describe 'get_unique_group_artifact' do
9
+ it 'should return a set of artifacts with version set to 0 given a set of artifacts' do
10
+ original_set = ['foo:bar:jar:1.0', 'bar:foo:jar:2.0']
11
+ actual_set = HelperFunctions.get_unique_group_artifact original_set
12
+ expected_set = ['foo:bar:jar:0', 'bar:foo:jar:0']
13
+ actual_set.should == expected_set
14
+ end
15
+
16
+ it 'should return a array of unique artifacts given a set of artifacts' do
17
+ original_set = ['foo:bar:jar:1.0', 'foo:bar:jar:2.0']
18
+ actual_set = HelperFunctions.get_unique_group_artifact original_set
19
+ expected_set = ['foo:bar:jar:0']
20
+ actual_set.should == expected_set
21
+ end
22
+
23
+ end
24
+
25
+ describe 'get_all_versions' do
26
+ it 'should return all versions in descending order given an artifact and a set of artifacts' do
27
+ artifact = 'foo:bar:jar:0'
28
+ original_set = ['foo:bar:jar:1.0', 'foo:bar:jar:2.0']
29
+ actual_versions = HelperFunctions.get_all_versions artifact, original_set
30
+ expected_versions = [Version.new('2.0'), Version.new('1.0')]
31
+ actual_versions.should == expected_versions
32
+ end
33
+
34
+ it 'should return one version only if given an artifact and a set of artifacts with one occurence of the given artifact' do
35
+ artifact = 'foo:foobar:jar:0'
36
+ original_set = ['foo:bar:jar:1.0', 'foo:bar:jar:2.0', 'foo:foobar:jar:1.0']
37
+ actual_versions = HelperFunctions.get_all_versions artifact, original_set
38
+ expected_versions = [Version.new('1.0')]
39
+ actual_versions.should == expected_versions
40
+ end
41
+
42
+ it 'should not return repeated versions' do
43
+ artifact = 'foo:bar:jar:0'
44
+ original_set = ['foo:bar:jar:1.0', 'foo:bar:jar:1.0']
45
+ actual_versions = HelperFunctions.get_all_versions artifact, original_set
46
+ expected_versions = [Version.new('1.0')]
47
+ actual_versions.should == expected_versions
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'buildr-dependency-extensions'))
4
+ require File.expand_path(File.join('spec', 'spec_helpers'), Gem::GemPathSearcher.new.find('buildr').full_gem_path)
5
+
6
+ describe 'Issue 1, mockito 1.8.1-rc1 is chosen instead of 1.8.5' do
7
+ before(:each) do
8
+ write artifact('foo:bar:jar:1.2').pom.to_s, <<-XML
9
+ <project>
10
+ <artifactId>bar</artifactId>
11
+ <groupId>fuu</groupId>
12
+
13
+ <dependencies>
14
+ <dependency>
15
+ <groupId>org.mockito</groupId>
16
+ <artifactId>mockito</artifactId>
17
+ <version>1.8.1-rc1</version>
18
+ <scope>test</scope>
19
+ </dependency>
20
+ </dependencies>
21
+ </project>
22
+ XML
23
+
24
+ write artifact('org.mockito:mockito:jar:1.8.5').pom.to_s, <<-XML
25
+ <project>
26
+ <artifactId>mockito</artifactId>
27
+ <groupId>org.mockito</groupId>
28
+ </project>
29
+ XML
30
+
31
+ write artifact('org.mockito:mockito:jar:1.8.1-rc1').pom.to_s, <<-XML
32
+ <project>
33
+ <artifactId>mockito</artifactId>
34
+ <groupId>org.mockito</groupId>
35
+ </project>
36
+ XML
37
+
38
+ end
39
+
40
+ it 'should not use mockito 1.8.5 instead of 1.8.1-rc1' do
41
+ define "Issue1Project" do
42
+ extend TransitiveDependencies
43
+ project.version = '1.0'
44
+ project.transitive_scopes = [:compile, :test]
45
+
46
+ compile.with 'foo:bar:jar:1.2'
47
+ test.with 'org.mockito:mockito:jar:1.8.5'
48
+ end
49
+
50
+ expected_test_dependencies = [artifact('org.mockito:mockito:jar:1.8.5'), artifact('foo:bar:jar:1.2')]
51
+ actual_test_dependencies = project('Issue1Project').test.dependencies
52
+ actual_test_dependencies.should == expected_test_dependencies
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/buildr-dependency-extensions'))
4
+ require File.expand_path(File.join('spec', 'spec_helpers'), Gem::GemPathSearcher.new.find('buildr').full_gem_path)
5
+
6
+ describe 'dependency resolution with jar dependencies' do
7
+ it 'throws exception: undefined method depth= for JarTask' do
8
+ define "TestProject" do
9
+ project.version = '1.0'
10
+ extend TransitiveDependencies
11
+ project.transitive_scopes = [:compile]
12
+
13
+ define 'bar' do
14
+ extend TransitiveDependencies
15
+ project.transitive_scopes = [:compile]
16
+ package :jar
17
+ end
18
+
19
+ define 'baz' do
20
+ extend TransitiveDependencies
21
+ project.transitive_scopes = [:compile]
22
+ compile.with project("bar")
23
+ package :jar
24
+ end
25
+ end
26
+
27
+ project('TestProject:baz').compile.dependencies[0].depth
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/buildr-dependency-extensions'))
3
+ require File.expand_path(File.join('spec', 'spec_helpers'), Gem::GemPathSearcher.new.find('buildr').full_gem_path)
4
+
5
+ describe 'Maven' do
6
+ before(:each) do
7
+ write artifact('foo:bar:jar:2.0').pom.to_s, <<-XML
8
+ <project>
9
+ <artifactId>bar</artifactId>
10
+ <groupId>foo</groupId>
11
+ </project>
12
+ XML
13
+
14
+ write artifact('foo:bar:jar:2.1').pom.to_s, <<-XML
15
+ <project>
16
+ <artifactId>bar</artifactId>
17
+ <groupId>foo</groupId>
18
+ </project>
19
+ XML
20
+
21
+ write artifact('transitive:dependencies:jar:2.0').pom.to_s, <<-XML
22
+ <project>
23
+ <artifactId>transitive</artifactId>
24
+ <groupId>dependencies</groupId>
25
+
26
+ <dependencies>
27
+ <dependency>
28
+ <groupId>foo</groupId>
29
+ <artifactId>bar</artifactId>
30
+ <version>2.1</version>
31
+ <scope>runtime</scope>
32
+ </dependency>
33
+ </dependencies>
34
+ </project>
35
+ XML
36
+ end
37
+
38
+ describe 'version conflict resolver' do
39
+ it 'uses the depth of the dependency to resolve version conflicts' do
40
+ define "TestProject" do
41
+ extend TransitiveDependencies
42
+ project.version = '1.0'
43
+
44
+ project.transitive_scopes = [:run]
45
+
46
+ run.with 'foo:bar:jar:2.0'
47
+ run.with 'transitive:dependencies:jar:2.0'
48
+
49
+ end
50
+
51
+ expected_dependencies = [artifact('foo:bar:jar:2.0'), artifact('transitive:dependencies:jar:2.0')]
52
+ project('TestProject').run.classpath.should ==(expected_dependencies)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,187 @@
1
+ require 'rubygems'
2
+ require 'buildr'
3
+ require 'xmlsimple'
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib/buildr-dependency-extensions'))
5
+
6
+
7
+ describe BuildrDependencyExtensions::PomGenerator do
8
+ before(:each) do
9
+ write artifact('foo:bar:jar:1.0').pom.to_s, <<-XML
10
+ <project>
11
+ <artifactId>bar</artifactId>
12
+ <groupId>foo</groupId>
13
+ </project>
14
+ XML
15
+
16
+ write artifact('foo:bar:jar:1.1').pom.to_s, <<-XML
17
+ <project>
18
+ <artifactId>bar</artifactId>
19
+ <groupId>foo</groupId>
20
+ </project>
21
+ XML
22
+
23
+ write artifact('foo:foobar:jar:1.0').pom.to_s, <<-XML
24
+ <project>
25
+ <artifactId>foobar</artifactId>
26
+ <groupId>foo</groupId>
27
+ </project>
28
+ XML
29
+ end
30
+
31
+ it "should not add any dependencies if PomGenerator isn't included" do
32
+ define "TestProject" do
33
+ extend TransitiveDependencies
34
+
35
+ project.version = '1.0-SNAPSHOT'
36
+ project.group = 'foo.bar'
37
+ compile.with 'foo:bar:jar:1.0'
38
+ end
39
+
40
+ pom = project('TestProject').package(:jar).pom
41
+ pom.invoke
42
+ generated_pom_hash = XmlSimple.xml_in(File.open(pom.to_s).read, {'ForceArray' => false})
43
+ expected_pom_hash = {
44
+ 'modelVersion' => '4.0.0',
45
+ 'groupId' => 'foo.bar',
46
+ 'artifactId' => 'TestProject',
47
+ 'version' => '1.0-SNAPSHOT'
48
+ }
49
+ generated_pom_hash.should eql expected_pom_hash
50
+ end
51
+
52
+ it 'should add all compile dependencies with compile scope' do
53
+ define "TestProject" do
54
+ extend PomGenerator
55
+
56
+ project.version = '1.0-SNAPSHOT'
57
+ project.group = 'foo.bar'
58
+ compile.with 'foo:bar:jar:1.0'
59
+ end
60
+
61
+ pom = project('TestProject').package(:jar).pom
62
+ pom.invoke
63
+ generated_pom_hash = XmlSimple.xml_in(File.open(pom.to_s).read, {'ForceArray' => ['dependencies']})
64
+ expected_pom_hash = {
65
+ 'modelVersion' => '4.0.0',
66
+ 'groupId' => 'foo.bar',
67
+ 'artifactId' => 'TestProject',
68
+ 'version' => '1.0-SNAPSHOT',
69
+ 'dependencies' =>
70
+ [{ 'dependency' => {
71
+ 'groupId' => 'foo',
72
+ 'artifactId' => 'bar',
73
+ 'version' => '1.0',
74
+ 'scope' => 'compile',
75
+ 'type' => 'jar'
76
+ }
77
+ }]
78
+ }
79
+ generated_pom_hash.should eql expected_pom_hash
80
+ end
81
+
82
+ it 'should add all runtime dependencies with runtime scope' do
83
+ define "TestProject" do
84
+ extend PomGenerator
85
+
86
+ project.version = '1.0-SNAPSHOT'
87
+ project.group = 'foo.bar'
88
+ run.with ['foo:bar:jar:1.0', 'foo:foobar:jar:1.0']
89
+ end
90
+
91
+ pom = project('TestProject').package(:jar).pom
92
+ pom.invoke
93
+ generated_pom_hash = XmlSimple.xml_in(File.open(pom.to_s).read, {'ForceArray' => ['dependency', 'plugin']})
94
+ expected_pom_hash = {
95
+ 'modelVersion' => '4.0.0',
96
+ 'groupId' => 'foo.bar',
97
+ 'artifactId' => 'TestProject',
98
+ 'version' => '1.0-SNAPSHOT',
99
+ 'dependencies' => { 'dependency' =>
100
+ [{
101
+ 'groupId' => 'foo',
102
+ 'artifactId' => 'bar',
103
+ 'version' => '1.0',
104
+ 'scope' => 'runtime',
105
+ 'type' => 'jar'
106
+ },
107
+ {
108
+ 'groupId' => 'foo',
109
+ 'artifactId' => 'foobar',
110
+ 'version' => '1.0',
111
+ 'scope' => 'runtime',
112
+ 'type' => 'jar'
113
+ }]
114
+ }
115
+ }
116
+ generated_pom_hash.should eql expected_pom_hash
117
+ end
118
+
119
+ it 'should add all test dependencies with test scope' do
120
+ define "TestProject" do
121
+ extend PomGenerator
122
+
123
+ project.version = '1.0-SNAPSHOT'
124
+ project.group = 'foo.bar'
125
+ test.with 'foo:bar:jar:1.0'
126
+ end
127
+
128
+ pom = project('TestProject').package(:jar).pom
129
+ pom.invoke
130
+ generated_pom_hash = XmlSimple.xml_in(File.open(pom.to_s).read, {'ForceArray' => ['dependency', 'plugin']})
131
+ expected_pom_hash = {
132
+ 'modelVersion' => '4.0.0',
133
+ 'groupId' => 'foo.bar',
134
+ 'artifactId' => 'TestProject',
135
+ 'version' => '1.0-SNAPSHOT',
136
+ 'dependencies' => { 'dependency' =>
137
+ [{
138
+ 'groupId' => 'foo',
139
+ 'artifactId' => 'bar',
140
+ 'version' => '1.0',
141
+ 'scope' => 'test',
142
+ 'type' => 'jar'
143
+ }]
144
+ }
145
+ }
146
+ generated_pom_hash.should eql expected_pom_hash
147
+ end
148
+
149
+
150
+ it 'adds all extra pom sections to the generated pom' do
151
+ define "TestProject" do
152
+ extend PomGenerator
153
+
154
+ project.version = '1.0-SNAPSHOT'
155
+ project.group = 'foo.bar'
156
+ test.with 'foo:bar:jar:1.0'
157
+
158
+ project.extra_pom_sections['plugins'] = [{'plugin' => {'groupId' => 'foo', 'artifactId' => 'bar'}}]
159
+ end
160
+
161
+ pom = project('TestProject').package(:jar).pom
162
+ pom.invoke
163
+ generated_pom_hash = XmlSimple.xml_in(File.open(pom.to_s).read, {'ForceArray' => ['dependency', 'plugin']})
164
+ expected_pom_hash = {
165
+ 'modelVersion' => '4.0.0',
166
+ 'groupId' => 'foo.bar',
167
+ 'artifactId' => 'TestProject',
168
+ 'version' => '1.0-SNAPSHOT',
169
+ 'dependencies' => { 'dependency' =>
170
+ [{
171
+ 'groupId' => 'foo',
172
+ 'artifactId' => 'bar',
173
+ 'version' => '1.0',
174
+ 'scope' => 'test',
175
+ 'type' => 'jar'
176
+ }]
177
+ },
178
+ 'plugins' => { 'plugin' =>
179
+ [{
180
+ 'groupId' => 'foo',
181
+ 'artifactId' => 'bar'
182
+ }]
183
+ }
184
+ }
185
+ generated_pom_hash.should eql expected_pom_hash
186
+ end
187
+ end