pompompom 1.0.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 (69) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE +20 -0
  4. data/README.mdown +32 -0
  5. data/Rakefile +7 -0
  6. data/TODO +0 -0
  7. data/bin/pompompom +17 -0
  8. data/lib/pom_pom_pom.rb +1 -0
  9. data/lib/pompompom/cli.rb +87 -0
  10. data/lib/pompompom/dependency.rb +55 -0
  11. data/lib/pompompom/downloader.rb +15 -0
  12. data/lib/pompompom/metadata.rb +26 -0
  13. data/lib/pompompom/pom.rb +234 -0
  14. data/lib/pompompom/resolver.rb +149 -0
  15. data/lib/pompompom/url_builder.rb +37 -0
  16. data/lib/pompompom.rb +10 -0
  17. data/pompompom.gemspec +116 -0
  18. data/spec/pompompom/cli_spec.rb +93 -0
  19. data/spec/pompompom/dependency_spec.rb +144 -0
  20. data/spec/pompompom/metadata_spec.rb +38 -0
  21. data/spec/pompompom/pom_spec.rb +221 -0
  22. data/spec/pompompom/resolver_spec.rb +205 -0
  23. data/spec/pompompom/url_builders_shared.rb +33 -0
  24. data/spec/resources/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar +0 -0
  25. data/spec/resources/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.pom +15 -0
  26. data/spec/resources/repository/aopalliance/aopalliance/maven-metadata.xml +5 -0
  27. data/spec/resources/repository/com/example/test/8.8/test-8.8.jar +0 -0
  28. data/spec/resources/repository/com/example/test/8.8/test-8.8.pom +11 -0
  29. data/spec/resources/repository/com/example/test/9.9/test-9.9.jar +0 -0
  30. data/spec/resources/repository/com/example/test/9.9/test-9.9.pom +11 -0
  31. data/spec/resources/repository/com/example/test/maven-metadata.xml +11 -0
  32. data/spec/resources/repository/com/example/test-abc/1.0/test-abc-1.0.jar +0 -0
  33. data/spec/resources/repository/com/example/test-abc/1.0/test-abc-1.0.pom +19 -0
  34. data/spec/resources/repository/com/example/test-abc/maven-metadata.xml +13 -0
  35. data/spec/resources/repository/com/example/test-child/1.0/test-child-1.0.pom +16 -0
  36. data/spec/resources/repository/com/example/test-def/1.0/test-def-1.0.jar +0 -0
  37. data/spec/resources/repository/com/example/test-def/1.0/test-def-1.0.pom +19 -0
  38. data/spec/resources/repository/com/example/test-exclusions/1.0/test-exclusions-1.0.jar +1 -0
  39. data/spec/resources/repository/com/example/test-exclusions/1.0/test-exclusions-1.0.pom +25 -0
  40. data/spec/resources/repository/com/example/test-optional/1.0/test-optional-1.0.jar +1 -0
  41. data/spec/resources/repository/com/example/test-optional/1.0/test-optional-1.0.pom +20 -0
  42. data/spec/resources/repository/com/example/test-parent/1.0/test-parent-1.0.pom +16 -0
  43. data/spec/resources/repository/com/google/google/1/google-1.pom +37 -0
  44. data/spec/resources/repository/com/google/inject/guice/2.0/guice-2.0.jar +1 -0
  45. data/spec/resources/repository/com/google/inject/guice/2.0/guice-2.0.pom +20 -0
  46. data/spec/resources/repository/com/google/inject/guice-parent/2.0/guice-parent-2.0.pom +70 -0
  47. data/spec/resources/repository/com/rabbitmq/amqp-client/1.8.0/amqp-client-1.8.0.jar +1 -0
  48. data/spec/resources/repository/com/rabbitmq/amqp-client/1.8.0/amqp-client-1.8.0.pom +98 -0
  49. data/spec/resources/repository/commons-cli/commons-cli/1.1/commons-cli-1.1.jar +1 -0
  50. data/spec/resources/repository/commons-cli/commons-cli/1.1/commons-cli-1.1.pom +165 -0
  51. data/spec/resources/repository/commons-io/commons-io/1.2/commons-io-1.2.jar +1 -0
  52. data/spec/resources/repository/commons-io/commons-io/1.2/commons-io-1.2.pom +235 -0
  53. data/spec/resources/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar +0 -0
  54. data/spec/resources/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.pom +6 -0
  55. data/spec/resources/repository/net/iconara/pompompom/1.0/pompompom-1.0.jar +0 -0
  56. data/spec/resources/repository/net/iconara/pompompom/1.0/pompompom-1.0.pom +11 -0
  57. data/spec/resources/repository/org/eclipse/jetty/jetty-continuation/7.1.4.v20100610/jetty-continuation-7.1.4.v20100610.pom +73 -0
  58. data/spec/resources/repository/org/eclipse/jetty/jetty-http/7.1.4.v20100610/jetty-http-7.1.4.v20100610.pom +73 -0
  59. data/spec/resources/repository/org/eclipse/jetty/jetty-io/7.1.4.v20100610/jetty-io-7.1.4.v20100610.pom +62 -0
  60. data/spec/resources/repository/org/eclipse/jetty/jetty-parent/15/jetty-parent-15.pom +419 -0
  61. data/spec/resources/repository/org/eclipse/jetty/jetty-project/7.1.4.v20100610/jetty-project-7.1.4.v20100610.pom +368 -0
  62. data/spec/resources/repository/org/eclipse/jetty/jetty-server/7.1.4.v20100610/jetty-server-7.1.4.v20100610.jar +0 -0
  63. data/spec/resources/repository/org/eclipse/jetty/jetty-server/7.1.4.v20100610/jetty-server-7.1.4.v20100610.pom +101 -0
  64. data/spec/resources/repository/org/eclipse/jetty/jetty-util/7.1.4.v20100610/jetty-util-7.1.4.v20100610.pom +80 -0
  65. data/spec/spec_helper.rb +5 -0
  66. data/tasks/gem.rake +18 -0
  67. data/tasks/rdoc.rake +13 -0
  68. data/tasks/spec.rake +17 -0
  69. metadata +142 -0
@@ -0,0 +1,37 @@
1
+ module PomPomPom
2
+ module UrlBuilder
3
+ def jar_url(repository_url)
4
+ file_url(repository_url, 'jar')
5
+ end
6
+
7
+ def pom_url(repository_url)
8
+ file_url(repository_url, 'pom')
9
+ end
10
+
11
+ def file_url(repository_url, type)
12
+ file_name = "#{artifact_id}-#{version}.#{type}"
13
+ "#{append_slash(repository_url)}#{group_path}/#{artifact_id}/#{version}/#{file_name}"
14
+ end
15
+
16
+ def jar_file_name
17
+ "#{artifact_id}-#{version}.jar"
18
+ end
19
+
20
+ def metadata_url(repository_url)
21
+ "#{append_slash(repository_url)}#{group_path}/#{artifact_id}/maven-metadata.xml"
22
+ end
23
+
24
+ def append_slash(repository_url)
25
+ if repository_url[-1,1] == '/'
26
+ repository_url
27
+ else
28
+ repository_url + '/'
29
+ end
30
+ end
31
+
32
+ def group_path
33
+ group_id.split('.').join('/')
34
+ end
35
+ end
36
+ end
37
+
data/lib/pompompom.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'pompompom/url_builder'
2
+ require 'pompompom/metadata'
3
+ require 'pompompom/dependency'
4
+ require 'pompompom/pom'
5
+ require 'pompompom/downloader'
6
+ require 'pompompom/resolver'
7
+
8
+ module PomPomPom
9
+ VERSION = '1.0.0'
10
+ end
data/pompompom.gemspec ADDED
@@ -0,0 +1,116 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pompompom}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Theo Hultberg"]
12
+ s.date = %q{2010-07-08}
13
+ s.default_executable = %q{pompompom}
14
+ s.description = %q{Ruby dependency manager for Maven repository artifacts}
15
+ s.email = %q{theo@iconara.net}
16
+ s.executables = ["pompompom"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.mdown",
20
+ "TODO"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ "Gemfile",
25
+ "LICENSE",
26
+ "README.mdown",
27
+ "Rakefile",
28
+ "bin/pompompom",
29
+ "lib/pom_pom_pom.rb",
30
+ "lib/pompompom.rb",
31
+ "lib/pompompom/cli.rb",
32
+ "lib/pompompom/dependency.rb",
33
+ "lib/pompompom/downloader.rb",
34
+ "lib/pompompom/metadata.rb",
35
+ "lib/pompompom/pom.rb",
36
+ "lib/pompompom/resolver.rb",
37
+ "lib/pompompom/url_builder.rb",
38
+ "pompompom.gemspec",
39
+ "spec/pompompom/cli_spec.rb",
40
+ "spec/pompompom/dependency_spec.rb",
41
+ "spec/pompompom/metadata_spec.rb",
42
+ "spec/pompompom/pom_spec.rb",
43
+ "spec/pompompom/resolver_spec.rb",
44
+ "spec/pompompom/url_builders_shared.rb",
45
+ "spec/resources/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar",
46
+ "spec/resources/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.pom",
47
+ "spec/resources/repository/aopalliance/aopalliance/maven-metadata.xml",
48
+ "spec/resources/repository/com/example/test-abc/1.0/test-abc-1.0.jar",
49
+ "spec/resources/repository/com/example/test-abc/1.0/test-abc-1.0.pom",
50
+ "spec/resources/repository/com/example/test-abc/maven-metadata.xml",
51
+ "spec/resources/repository/com/example/test-child/1.0/test-child-1.0.pom",
52
+ "spec/resources/repository/com/example/test-def/1.0/test-def-1.0.jar",
53
+ "spec/resources/repository/com/example/test-def/1.0/test-def-1.0.pom",
54
+ "spec/resources/repository/com/example/test-exclusions/1.0/test-exclusions-1.0.jar",
55
+ "spec/resources/repository/com/example/test-exclusions/1.0/test-exclusions-1.0.pom",
56
+ "spec/resources/repository/com/example/test-optional/1.0/test-optional-1.0.jar",
57
+ "spec/resources/repository/com/example/test-optional/1.0/test-optional-1.0.pom",
58
+ "spec/resources/repository/com/example/test-parent/1.0/test-parent-1.0.pom",
59
+ "spec/resources/repository/com/example/test/8.8/test-8.8.jar",
60
+ "spec/resources/repository/com/example/test/8.8/test-8.8.pom",
61
+ "spec/resources/repository/com/example/test/9.9/test-9.9.jar",
62
+ "spec/resources/repository/com/example/test/9.9/test-9.9.pom",
63
+ "spec/resources/repository/com/example/test/maven-metadata.xml",
64
+ "spec/resources/repository/com/google/google/1/google-1.pom",
65
+ "spec/resources/repository/com/google/inject/guice-parent/2.0/guice-parent-2.0.pom",
66
+ "spec/resources/repository/com/google/inject/guice/2.0/guice-2.0.jar",
67
+ "spec/resources/repository/com/google/inject/guice/2.0/guice-2.0.pom",
68
+ "spec/resources/repository/com/rabbitmq/amqp-client/1.8.0/amqp-client-1.8.0.jar",
69
+ "spec/resources/repository/com/rabbitmq/amqp-client/1.8.0/amqp-client-1.8.0.pom",
70
+ "spec/resources/repository/commons-cli/commons-cli/1.1/commons-cli-1.1.jar",
71
+ "spec/resources/repository/commons-cli/commons-cli/1.1/commons-cli-1.1.pom",
72
+ "spec/resources/repository/commons-io/commons-io/1.2/commons-io-1.2.jar",
73
+ "spec/resources/repository/commons-io/commons-io/1.2/commons-io-1.2.pom",
74
+ "spec/resources/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar",
75
+ "spec/resources/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.pom",
76
+ "spec/resources/repository/net/iconara/pompompom/1.0/pompompom-1.0.jar",
77
+ "spec/resources/repository/net/iconara/pompompom/1.0/pompompom-1.0.pom",
78
+ "spec/resources/repository/org/eclipse/jetty/jetty-continuation/7.1.4.v20100610/jetty-continuation-7.1.4.v20100610.pom",
79
+ "spec/resources/repository/org/eclipse/jetty/jetty-http/7.1.4.v20100610/jetty-http-7.1.4.v20100610.pom",
80
+ "spec/resources/repository/org/eclipse/jetty/jetty-io/7.1.4.v20100610/jetty-io-7.1.4.v20100610.pom",
81
+ "spec/resources/repository/org/eclipse/jetty/jetty-parent/15/jetty-parent-15.pom",
82
+ "spec/resources/repository/org/eclipse/jetty/jetty-project/7.1.4.v20100610/jetty-project-7.1.4.v20100610.pom",
83
+ "spec/resources/repository/org/eclipse/jetty/jetty-server/7.1.4.v20100610/jetty-server-7.1.4.v20100610.jar",
84
+ "spec/resources/repository/org/eclipse/jetty/jetty-server/7.1.4.v20100610/jetty-server-7.1.4.v20100610.pom",
85
+ "spec/resources/repository/org/eclipse/jetty/jetty-util/7.1.4.v20100610/jetty-util-7.1.4.v20100610.pom",
86
+ "spec/spec_helper.rb",
87
+ "tasks/gem.rake",
88
+ "tasks/rdoc.rake",
89
+ "tasks/spec.rake"
90
+ ]
91
+ s.homepage = %q{http://github.com/iconara/pompompom}
92
+ s.rdoc_options = ["--charset=UTF-8"]
93
+ s.require_paths = ["lib"]
94
+ s.rubygems_version = %q{1.3.7}
95
+ s.summary = %q{Ruby dependency manager for Maven repository artifacts}
96
+ s.test_files = [
97
+ "spec/pompompom/cli_spec.rb",
98
+ "spec/pompompom/dependency_spec.rb",
99
+ "spec/pompompom/metadata_spec.rb",
100
+ "spec/pompompom/pom_spec.rb",
101
+ "spec/pompompom/resolver_spec.rb",
102
+ "spec/pompompom/url_builders_shared.rb",
103
+ "spec/spec_helper.rb"
104
+ ]
105
+
106
+ if s.respond_to? :specification_version then
107
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
108
+ s.specification_version = 3
109
+
110
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
111
+ else
112
+ end
113
+ else
114
+ end
115
+ end
116
+
@@ -0,0 +1,93 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+
5
+
6
+ module PomPomPom
7
+ describe Cli do
8
+ before do
9
+ @repository_path = File.expand_path('../../resources/repository', __FILE__)
10
+ @stdin = StringIO.new
11
+ @stdout = StringIO.new
12
+ @stderr = StringIO.new
13
+ @downloader = FilesystemDownloader.new
14
+ @resolver = Resolver.new([@repository_path])
15
+ @cli = Cli.new(@stdin, @stdout, @stderr)
16
+ @cli.stub!(:create_resolver).and_return(@resolver)
17
+ @cli.stub!(:create_lib_directory!)
18
+ @tmp_dir = File.join(Dir.tmpdir, 'pompompom')
19
+ FileUtils.rm_rf(@tmp_dir)
20
+ Dir.mkdir(@tmp_dir)
21
+ Dir.chdir(@tmp_dir)
22
+ end
23
+
24
+ after do
25
+ FileUtils.rm_rf(@tmp_dir)
26
+ end
27
+
28
+ it 'prints usage if no arguments given' do
29
+ @cli.run!
30
+ @stderr.string.should include('Usage: pompompom <group_id:artifact_id:version> [<group_id:artifact_id:version>]')
31
+ end
32
+
33
+ it 'returns 1 if no arguments given' do
34
+ @cli.run!.should == 1
35
+ end
36
+
37
+ it 'installs any artifacts mentioned on the command line' do
38
+ @cli.run!('net.iconara:pompompom:1.0', 'com.example:test:9.9')
39
+ @stderr.string.should include('Determining transitive dependencies...')
40
+ @stderr.string.should include('Downloading "net.iconara:pompompom:1.0"')
41
+ @stderr.string.should include('Downloading "com.example:test:9.9"')
42
+ end
43
+
44
+ it 'returns 0 if all goes well' do
45
+ @cli.run!('net.iconara:pompompom:1.0', 'com.example:test:9.9').should == 0
46
+ end
47
+
48
+ context 'when artifacts have already been downloaded' do
49
+ before do
50
+ FileUtils.mkdir('lib')
51
+ FileUtils.touch(File.join('lib', 'pompompom-1.0.jar'))
52
+ end
53
+
54
+ it 'does not download them again' do
55
+ @cli.run!('net.iconara:pompompom:1.0', 'com.example:test:9.9')
56
+ @stderr.string.should_not include('Downloading "net.iconara:pompompom:1.0"')
57
+ end
58
+
59
+ it 'warns if none will be downloaded' do
60
+ FileUtils.touch(File.join('lib', 'test-9.9.jar'))
61
+ @cli.run!('net.iconara:pompompom:1.0', 'com.example:test:9.9')
62
+ @stderr.string.should include('All dependencies are met')
63
+ end
64
+
65
+ it 'returns 0' do
66
+ FileUtils.touch(File.join('lib', 'test-9.9.jar'))
67
+ @cli.run!('net.iconara:pompompom:1.0', 'com.example:test:9.9').should == 0
68
+ end
69
+ end
70
+
71
+ it 'complains about malformed artifact coordinates' do
72
+ @cli.run!('net.iconara:pompompom:1.0', 'foobar')
73
+ @stderr.string.should include('Warning: "foobar" is not a valid artifact coordinate')
74
+ end
75
+
76
+ context 'when "lib" exists but is not a directory' do
77
+ before do
78
+ @cli = Cli.new(@stdin, @stdout, @stderr)
79
+ @cli.stub!(:create_resolver).and_return(@resolver)
80
+ FileUtils.touch(File.join(@tmp_dir, 'lib'))
81
+ end
82
+
83
+ it 'complains' do
84
+ @cli.run!('com.example:test:9.9')
85
+ @stderr.string.should include('Warning: Cannot create destination, "lib" is a file!')
86
+ end
87
+
88
+ it 'returns 1' do
89
+ @cli.run!('com.example:test:9.9').should == 1
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,144 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../url_builders_shared', __FILE__)
3
+
4
+
5
+ module PomPomPom
6
+ describe Dependency do
7
+ before do
8
+ @url_builder = Dependency.new('net.iconara', 'pompompom', '1.0')
9
+ end
10
+
11
+ it_should_behave_like 'an URL builder'
12
+
13
+ describe '#initialize' do
14
+ it 'can be created with named arguments' do
15
+ d = Dependency.new(:group_id => 'net.iconara', :artifact_id => 'pompompom', :version => '1.0')
16
+ d.group_id.should == 'net.iconara'
17
+ d.artifact_id.should == 'pompompom'
18
+ d.version.should == '1.0'
19
+ end
20
+
21
+ it 'can be created with a regular argument list' do
22
+ d = Dependency.new('net.iconara', 'pompompom', '1.0')
23
+ d.group_id.should == 'net.iconara'
24
+ d.artifact_id.should == 'pompompom'
25
+ d.version.should == '1.0'
26
+ end
27
+ end
28
+
29
+ describe '#to_s' do
30
+ it 'returns the Maven artifact descriptor' do
31
+ s = Dependency.new('net.iconara', 'pompompom', '1.0').to_s
32
+ s.should == 'net.iconara:pompompom:1.0'
33
+ end
34
+ end
35
+
36
+ describe '#eql?' do
37
+ it 'is equal to another dependency with the same group ID, artifact ID and version' do
38
+ d1 = Dependency.new('net.iconara', 'pompompom', '1.0')
39
+ d2 = Dependency.new('net.iconara', 'pompompom', '1.0')
40
+ d1.should == d2
41
+ end
42
+
43
+ it 'is not equal to another dependency with another version' do
44
+ d1 = Dependency.new('net.iconara', 'pompompom', '1.0')
45
+ d2 = Dependency.new('net.iconara', 'pompompom', '1.1')
46
+ d1.should_not == d2
47
+ end
48
+
49
+ it 'is not equal to another dependency with another group ID' do
50
+ d1 = Dependency.new('net.iconara', 'pompompom', '1.0')
51
+ d2 = Dependency.new('com.example', 'pompompom', '1.0')
52
+ d1.should_not == d2
53
+ end
54
+
55
+ it 'is not equal to another dependency with another artifact ID' do
56
+ d1 = Dependency.new('net.iconara', 'pompompom', '1.0')
57
+ d2 = Dependency.new('net.iconara', 'mopmopmop', '1.0')
58
+ d1.should_not == d2
59
+ end
60
+ end
61
+
62
+ describe '.parse' do
63
+ it 'parses a Maven coordinate' do
64
+ d = Dependency.parse('net.iconara:pompompom:1.0')
65
+ d.group_id.should == 'net.iconara'
66
+ d.artifact_id.should == 'pompompom'
67
+ d.version.should == '1.0'
68
+ end
69
+
70
+ it 'parses a Maven coordinate with packaging label' do
71
+ d = Dependency.parse('net.iconara:pompompom:jar:1.0')
72
+ d.group_id.should == 'net.iconara'
73
+ d.artifact_id.should == 'pompompom'
74
+ d.version.should == '1.0'
75
+ d.packaging.should == 'jar'
76
+ end
77
+
78
+ it 'parses a Maven coordinate with packaging label and classifier' do
79
+ d = Dependency.parse('net.iconara:pompompom:ear:xyz:1.0')
80
+ d.group_id.should == 'net.iconara'
81
+ d.artifact_id.should == 'pompompom'
82
+ d.version.should == '1.0'
83
+ d.packaging.should == 'ear'
84
+ d.classifier.should == 'xyz'
85
+ end
86
+
87
+ it 'raises an exception if the coordinate is malformed' do
88
+ expect { Dependency.parse('net.iconara:pompompom') }.to raise_error
89
+ end
90
+
91
+ it 'raises an exception if the coordinate is empty' do
92
+ expect { Dependency.parse('') }.to raise_error
93
+ end
94
+
95
+ it 'raises an exception if the coordinate is nil' do
96
+ expect { Dependency.parse('') }.to raise_error
97
+ end
98
+ end
99
+
100
+ describe '#has_version?' do
101
+ it 'is true if version is unspecified' do
102
+ d = Dependency.new(:group_id => 'com.example', :artifact_id => 'test')
103
+ d.should_not have_version
104
+ end
105
+
106
+ it 'is false if version is set' do
107
+ d = Dependency.new(:group_id => 'com.example', :artifact_id => 'test', :version => '0.0.1')
108
+ d.should have_version
109
+ end
110
+ end
111
+
112
+ describe '#same_artifact?' do
113
+ it 'returns true if the group and artifact IDs are the same' do
114
+ d1 = Dependency.new(:group_id => 'com.example', :artifact_id => 'hello', :version => '3')
115
+ d2 = Dependency.new(:group_id => 'com.example', :artifact_id => 'hello', :version => '4')
116
+ d1.same_artifact?(d2).should be_true
117
+ end
118
+
119
+ it 'returns false if the group and artifact IDs are the same' do
120
+ d1 = Dependency.new(:group_id => 'com.elpmaxe', :artifact_id => 'hello', :version => '3')
121
+ d2 = Dependency.new(:group_id => 'com.example', :artifact_id => 'hello', :version => '3')
122
+ d1.same_artifact?(d2).should_not be_true
123
+ end
124
+ end
125
+
126
+ describe '#clone' do
127
+ it 'creates an identical copy' do
128
+ d1 = Dependency.new(:group_id => 'com.example', :artifact_id => 'test', :version => '0.0.1')
129
+ d2 = d1.clone
130
+ d1.should == d2
131
+ end
132
+
133
+ it 'creates an identical copy, save for overridden properties' do
134
+ d1 = Dependency.new(:group_id => 'com.example', :artifact_id => 'test', :version => '0.0.1', :classifier => 'foo')
135
+ d2 = d1.clone(:version => '1.0.0')
136
+ d1.should_not == d2
137
+ d2.group_id.should == 'com.example'
138
+ d2.artifact_id.should == 'test'
139
+ d2.classifier.should == 'foo'
140
+ d2.version.should == '1.0.0'
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+
4
+ module PomPomPom
5
+ describe Metadata do
6
+ before do
7
+ @metadata1 = File.open(File.expand_path('../../resources/repository/aopalliance/aopalliance/maven-metadata.xml', __FILE__), 'r') do |f|
8
+ md = Metadata.new(f)
9
+ md.parse!
10
+ md
11
+ end
12
+ @metadata2 = File.open(File.expand_path('../../resources/repository/com/example/test/maven-metadata.xml', __FILE__), 'r') do |f|
13
+ md = Metadata.new(f)
14
+ md.parse!
15
+ md
16
+ end
17
+ @metadata3 = File.open(File.expand_path('../../resources/repository/com/example/test-abc/maven-metadata.xml', __FILE__), 'r') do |f|
18
+ md = Metadata.new(f)
19
+ md.parse!
20
+ md
21
+ end
22
+ end
23
+
24
+ describe '#latest_version' do
25
+ it 'returns the latest version when there is only one' do
26
+ @metadata1.latest_version.should == '1.0'
27
+ end
28
+
29
+ it 'returns the last version' do
30
+ @metadata2.latest_version.should == '9.9'
31
+ end
32
+
33
+ it 'returns the release version when one is specified' do
34
+ @metadata3.latest_version.should == '1.0'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,221 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require File.expand_path('../url_builders_shared', __FILE__)
3
+
4
+
5
+ module PomPomPom
6
+ describe Pom do
7
+ it_should_behave_like 'an URL builder'
8
+
9
+ before do
10
+ @url_builder = Pom.new(StringIO.new('<project><groupId>net.iconara</groupId><artifactId>pompompom</artifactId><version>1.0</version><packaging>jar</packaging></project>'))
11
+ @url_builder.parse!
12
+ end
13
+
14
+ describe '#parse!' do
15
+ context 'when parsing a file' do
16
+ before do
17
+ @example_pom_path = File.expand_path('../../resources/repository/com/rabbitmq/amqp-client/1.8.0/amqp-client-1.8.0.pom', __FILE__)
18
+ @pom = File.open(@example_pom_path, 'r') do |f|
19
+ pom = Pom.new(f)
20
+ pom.parse!
21
+ pom
22
+ end
23
+ end
24
+
25
+ it('finds the right group ID') { @pom.group_id.should == 'com.rabbitmq' }
26
+ it('finds the right artifact ID') { @pom.artifact_id.should == 'amqp-client' }
27
+ it('finds the right version') { @pom.version.should == '1.8.0' }
28
+ it('finds the right packaging type') { @pom.packaging.should == 'jar' }
29
+ it('finds the right name') { @pom.name.should == 'RabbitMQ Java Client' }
30
+ it('finds the right description') { @pom.description.should == 'RabbitMQ AMQP Java Client' }
31
+ it('finds the right URL') { @pom.url.should == 'http://www.rabbitmq.com' }
32
+
33
+ it 'finds two dependencies in the default scope' do
34
+ @pom.dependencies.should have(2).items
35
+ end
36
+
37
+ it 'finds one dependency in the test scope' do
38
+ @pom.dependencies(:test).should have(1).items
39
+ end
40
+
41
+ it 'finds a dependency on JUnit' do
42
+ dep = @pom.dependencies(:test).first
43
+ dep.group_id.should == 'junit'
44
+ end
45
+
46
+ it 'finds a dependency on commons-cli v1.1' do
47
+ dep = @pom.dependencies.select { |d| d.group_id == 'commons-cli' && d.artifact_id == 'commons-cli' && d.version == '1.1' }
48
+ dep.should_not be_empty
49
+ end
50
+ end
51
+
52
+ context 'with exclusions' do
53
+ before do
54
+ @example_pom_path = File.expand_path('../../resources/repository/com/example/test-exclusions/1.0/test-exclusions-1.0.pom', __FILE__)
55
+ @pom = File.open(@example_pom_path, 'r') do |f|
56
+ pom = Pom.new(f)
57
+ pom.parse!
58
+ pom
59
+ end
60
+ end
61
+
62
+ it 'finds exclusions' do
63
+ d = @pom.dependencies.first
64
+ d.exclusions.first.artifact_id.should == 'commons-cli'
65
+ end
66
+ end
67
+
68
+ context 'with optional' do
69
+ before do
70
+ @example_pom_path = File.expand_path('../../resources/repository/com/example/test-optional/1.0/test-optional-1.0.pom', __FILE__)
71
+ @pom = File.open(@example_pom_path, 'r') do |f|
72
+ pom = Pom.new(f)
73
+ pom.parse!
74
+ pom
75
+ end
76
+ end
77
+
78
+ it 'finds exclusions' do
79
+ d = @pom.dependencies.first
80
+ d.should be_optional
81
+ end
82
+ end
83
+
84
+ context 'when properties are inherited from parent' do
85
+ before do
86
+ p = <<-XML
87
+ <project>
88
+ <parent>
89
+ <groupId>com.example</groupId>
90
+ <artifactId>test-parent</artifactId>
91
+ <version>2.0</version>
92
+ </parent>
93
+ <artifactId>pompompom</artifactId>
94
+ <packaging>jar</packaging>
95
+ </project>
96
+ XML
97
+ @pom = Pom.new(StringIO.new(p))
98
+ @pom.parse!
99
+ end
100
+
101
+ it 'finds the group ID from the parent specification' do
102
+ @pom.group_id.should == 'com.example'
103
+ end
104
+
105
+ it 'finds the version from the parent specification' do
106
+ @pom.version.should == '2.0'
107
+ end
108
+
109
+ it 'knows it has a parent' do
110
+ @pom.should have_parent
111
+ end
112
+
113
+ it 'knows the artifact ID of its parent' do
114
+ @pom.parent.group_id.should == 'com.example'
115
+ end
116
+
117
+ it 'knows the group ID of its parent' do
118
+ @pom.parent.artifact_id.should == 'test-parent'
119
+ end
120
+ end
121
+
122
+ context 'property expansion' do
123
+ before do
124
+ @base_pom = <<-XML
125
+ <project>
126
+ <groupId>net.iconara</groupId>
127
+ <artifactId>pompompom</artifactId>
128
+ <version>1.0</version>
129
+ <name>Name</name>
130
+ <description>Description</description>
131
+ <packaging>jar</packaging>
132
+ <properties>
133
+ <foo.bar>baz</foo.bar>
134
+ </properties>
135
+ <dependencies>
136
+ <dependency>
137
+ <groupId>net.iconara</groupId>
138
+ <artifactId>pimpimpim</artifactId>
139
+ <version>9.9</version>
140
+ </dependency>
141
+ </dependencies>
142
+ </project>
143
+ XML
144
+ end
145
+
146
+ it 'knowns how to expand ${version}' do
147
+ pom = Pom.new(StringIO.new(@base_pom.sub('<version>9.9</version>', '<version>${version}</version>')))
148
+ pom.parse!
149
+ pom.dependencies.first.version.should == '1.0'
150
+ end
151
+
152
+ it 'knowns how to expand ${project.version}' do
153
+ pom = Pom.new(StringIO.new(@base_pom.sub('<version>9.9</version>', '<version>${project.version}</version>')))
154
+ pom.parse!
155
+ pom.dependencies.first.version.should == '1.0'
156
+ end
157
+
158
+ it 'knowns how to expand ${project.artifactId}' do
159
+ pom = Pom.new(StringIO.new(@base_pom.sub('<name>Name</name>', '<name>This is ${project.artifactId}</name>')))
160
+ pom.parse!
161
+ pom.name.should == 'This is pompompom'
162
+ end
163
+
164
+ it 'knowns how to expand ${project.groupId}' do
165
+ pom = Pom.new(StringIO.new(@base_pom.sub('<description>Description</description>', '<description>The group ID is ${project.groupId}</description>')))
166
+ pom.parse!
167
+ pom.description.should == 'The group ID is net.iconara'
168
+ end
169
+
170
+ it 'knowns how to expand and environment variable' do
171
+ ENV['JAVA_HOME'] = '/opt/java'
172
+ pom = Pom.new(StringIO.new(@base_pom.sub('<description>Description</description>', '<description>Java is at ${env.JAVA_HOME}</description>')))
173
+ pom.parse!
174
+ pom.description.should == 'Java is at /opt/java'
175
+ end
176
+
177
+ it 'looks up project-specific properties' do
178
+ pom = Pom.new(StringIO.new(@base_pom.sub('<description>Description</description>', '<description>${foo.bar}</description>')))
179
+ pom.parse!
180
+ pom.description.should == 'baz'
181
+ end
182
+
183
+ it 'leaves unexpandable properties in place' do
184
+ pom = Pom.new(StringIO.new(@base_pom.sub('<description>Description</description>', '<description>${plonk}</description>')))
185
+ pom.parse!
186
+ pom.description.should == '${plonk}'
187
+ end
188
+ end
189
+ end
190
+
191
+ describe '#merge' do
192
+ before do
193
+ @child_pom_path = File.expand_path('../../resources/repository/com/example/test-child/1.0/test-child-1.0.pom', __FILE__)
194
+ @parent_pom_path = File.expand_path('../../resources/repository/com/example/test-parent/1.0/test-parent-1.0.pom', __FILE__)
195
+ @child_pom_io = File.open(@child_pom_path, 'r')
196
+ @parent_pom_io = File.open(@parent_pom_path, 'r')
197
+ @child_pom = Pom.new(@child_pom_io)
198
+ @parent_pom = Pom.new(@parent_pom_io)
199
+ @child_pom.parse!
200
+ @parent_pom.parse!
201
+ end
202
+
203
+ after do
204
+ @child_pom_io.close
205
+ @parent_pom_io.close
206
+ end
207
+
208
+ it 'creates a copy' do
209
+ pom = @child_pom.merge(@parent_pom)
210
+ pom.group_id.should == @child_pom.group_id
211
+ pom.artifact_id.should == @child_pom.artifact_id
212
+ pom.version.should == @child_pom.version
213
+ end
214
+
215
+ it 'resolves dependency versions using the parent' do
216
+ pom = @child_pom.merge(@parent_pom)
217
+ pom.dependencies.first.version.should == '8.8'
218
+ end
219
+ end
220
+ end
221
+ end