rnexus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Darrin Holst
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = rnexus
2
+
3
+ A ruby wrapper to perform actions against the Nexus maven repository manager
4
+
5
+ == Synopsis
6
+
7
+ repo = Nexus::Repository.new("http://path/to/nexus")
8
+ artifacts = repo.find_artifacts(:group => 'org.mockito', :name => 'mockito', :type => 'jar')
9
+ jar = repo.download_artifact(artifacts.first)
10
+
11
+ == Install
12
+
13
+ sudo gem install rnexus
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2009 Darrin Holst. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rnexus"
8
+ gem.summary = %Q{a ruby wrapper to interact with a nexus maven repository}
9
+ gem.email = "darrinholst@gmail.com"
10
+ gem.homepage = "http://github.com/darrinholst/rnexus"
11
+ gem.authors = ["Darrin Holst"]
12
+ gem.rubyforge_project = "rnexus"
13
+ gem.add_dependency("rest-client", ">= 1.0.3")
14
+ gem.add_dependency("crack", ">= 0.1.3")
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ Jeweler::RubyforgeTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION.yml')
49
+ config = YAML.load(File.read('VERSION.yml'))
50
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "rnexus #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
60
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/artifact.rb ADDED
@@ -0,0 +1,11 @@
1
+ class Nexus::Artifact
2
+ attr_accessor :group, :name, :version, :type, :uri
3
+
4
+ def initialize(parameters)
5
+ self.group = parameters['groupId']
6
+ self.name = parameters['artifactId']
7
+ self.version = parameters['version']
8
+ self.type = parameters['packaging']
9
+ self.uri = parameters['resourceURI']
10
+ end
11
+ end
data/lib/repository.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'rest_client'
2
+ require 'crack'
3
+ require 'tempfile'
4
+
5
+ class Nexus::Repository
6
+ NEXUS_PARAMETERS = {
7
+ :group => :g,
8
+ :name => :a,
9
+ :type => :p
10
+ }
11
+
12
+ def initialize(baseuri)
13
+ @baseuri = baseuri
14
+ end
15
+
16
+ def find_artifacts(args)
17
+ url = "#{@baseuri}/service/local/data_index/repo_groups/public?#{build_query_parameters_from(args)}"
18
+ response = RestClient.get(url, :accept => 'application/json')
19
+ Crack::JSON.parse(response)['data'].map {|data| Nexus::Artifact.new(data)}
20
+ end
21
+
22
+ def download_artifact(artifact)
23
+ RestClient.get(artifact.uri)
24
+ end
25
+
26
+ private
27
+
28
+ def build_query_parameters_from(args)
29
+ raise "arguments must be a hash" unless args.is_a? Hash
30
+
31
+ query_parameters = args.map do |entry|
32
+ "#{nexus_parameter_for(entry.first)}=#{entry.last}"
33
+ end.join("&")
34
+
35
+ raise "must pass at least one argument #{nexus_parameters_to_s}" if query_parameters.empty?
36
+
37
+ query_parameters
38
+ end
39
+
40
+ def nexus_parameter_for(parameter)
41
+ nexus_param = NEXUS_PARAMETERS[parameter]
42
+ raise "invalid argument passed, valid arguments are #{nexus_parameters_to_s}" unless nexus_param
43
+ nexus_param
44
+ end
45
+
46
+ def nexus_parameters_to_s
47
+ "(#{NEXUS_PARAMETERS.keys.join(', ')})"
48
+ end
49
+ end
data/lib/rnexus.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Nexus
2
+ end
3
+
4
+ require 'artifact'
5
+ require 'repository'
data/rnexus.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rnexus}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Darrin Holst"]
9
+ s.date = %q{2009-07-15}
10
+ s.email = %q{darrinholst@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/artifact.rb",
23
+ "lib/repository.rb",
24
+ "lib/rnexus.rb",
25
+ "rnexus.gemspec",
26
+ "test/artifact_test.rb",
27
+ "test/repository_test.rb",
28
+ "test/test_helper.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/darrinholst/rnexus}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubyforge_project = %q{rnexus}
34
+ s.rubygems_version = %q{1.3.4}
35
+ s.summary = %q{a ruby wrapper to interact with a nexus maven repository}
36
+ s.test_files = [
37
+ "test/artifact_test.rb",
38
+ "test/repository_test.rb",
39
+ "test/test_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.0.3"])
48
+ s.add_runtime_dependency(%q<crack>, [">= 0.1.3"])
49
+ else
50
+ s.add_dependency(%q<rest-client>, [">= 1.0.3"])
51
+ s.add_dependency(%q<crack>, [">= 0.1.3"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rest-client>, [">= 1.0.3"])
55
+ s.add_dependency(%q<crack>, [">= 0.1.3"])
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class ArtifactTest < Test::Unit::TestCase
4
+ def test_construction_from_a_hash
5
+ artifact = Nexus::Artifact.new(
6
+ 'groupId' => 'group',
7
+ 'artifactId' => 'name',
8
+ 'version' => 'version',
9
+ 'packaging' => 'war',
10
+ 'resourceURI' => 'uri')
11
+
12
+ assert_equal('group', artifact.group)
13
+ assert_equal('name', artifact.name)
14
+ assert_equal('version', artifact.version)
15
+ assert_equal('war', artifact.type)
16
+ assert_equal('uri', artifact.uri)
17
+ end
18
+ end
@@ -0,0 +1,92 @@
1
+ require 'test_helper'
2
+
3
+ class RepositoryTest < Test::Unit::TestCase
4
+ JSON = <<-eos
5
+ {
6
+ "data":[
7
+ {
8
+ "resourceURI":"uri1",
9
+ "groupId":"group1",
10
+ "artifactId":"artifact1",
11
+ "version":"version1",
12
+ "packaging":"packaging1"
13
+ },
14
+ {
15
+ "resourceURI":"uri2",
16
+ "groupId":"group2",
17
+ "artifactId":"artifact2",
18
+ "version":"version2",
19
+ "packaging":"packaging2"
20
+ }
21
+ ]
22
+ }
23
+ eos
24
+
25
+ def setup
26
+ @repository = Nexus::Repository.new("http://localhost/nexus")
27
+ end
28
+
29
+ def test_find_artifacts_using_all_options
30
+ expected_url = "http://localhost/nexus/service/local/data_index/repo_groups/public?a=artifact&g=group&p=war"
31
+
32
+ FakeWeb.register_uri(:get, expected_url, :body => JSON)
33
+
34
+ assert_artifacts @repository.find_artifacts(:group => 'group', :name => 'artifact', :type => 'war')
35
+ end
36
+
37
+ def test_find_artifacts_using_artifact_id_only
38
+ expected_url = "http://localhost/nexus/service/local/data_index/repo_groups/public?a=artifact"
39
+
40
+ FakeWeb.register_uri(:get, expected_url, :body => JSON)
41
+
42
+ assert_artifacts @repository.find_artifacts(:name => 'artifact')
43
+ end
44
+
45
+ def test_find_artifacts_when_arguments_is_not_a_hash
46
+ exception = assert_raise RuntimeError do
47
+ @repository.find_artifacts(nil)
48
+ end
49
+
50
+ assert_equal("arguments must be a hash", exception.message)
51
+ end
52
+
53
+ def test_find_artifacts_when_invalid_arguments_passed
54
+ exception = assert_raise RuntimeError do
55
+ @repository.find_artifacts(:a => 'foo', :b => 'bar')
56
+ end
57
+
58
+ assert_equal("invalid argument passed, valid arguments are (type, name, group)", exception.message)
59
+ end
60
+
61
+ def test_find_artifacts_when_empty_arguments_passed
62
+ exception = assert_raise RuntimeError do
63
+ @repository.find_artifacts({})
64
+ end
65
+
66
+ assert_equal("must pass at least one argument (type, name, group)", exception.message)
67
+ end
68
+
69
+ def test_download_artifact
70
+ artifact = Nexus::Artifact.new('resourceURI' => 'http://nexus/artifact')
71
+
72
+ FakeWeb.register_uri(:get, "http://nexus/artifact", :body => 'file content')
73
+
74
+ file = @repository.download_artifact(artifact)
75
+
76
+ assert_equal('file content', file)
77
+ end
78
+
79
+ def assert_artifacts(artifacts)
80
+ assert_equal(2, artifacts.size)
81
+ assert_artifact(artifacts[0], 'group1', 'artifact1', 'version1', 'packaging1', 'uri1')
82
+ assert_artifact(artifacts[1], 'group2', 'artifact2', 'version2', 'packaging2', 'uri2')
83
+ end
84
+
85
+ def assert_artifact(artifact, group, name, version, type, uri)
86
+ assert_equal(group, artifact.group)
87
+ assert_equal(name, artifact.name)
88
+ assert_equal(version, artifact.version)
89
+ assert_equal(type, artifact.type)
90
+ assert_equal(uri, artifact.uri)
91
+ end
92
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'fakeweb'
4
+
5
+ FakeWeb.allow_net_connect = false
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ require 'rnexus'
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rnexus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darrin Holst
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-15 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.3
34
+ version:
35
+ description:
36
+ email: darrinholst@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/artifact.rb
52
+ - lib/repository.rb
53
+ - lib/rnexus.rb
54
+ - rnexus.gemspec
55
+ - test/artifact_test.rb
56
+ - test/repository_test.rb
57
+ - test/test_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/darrinholst/rnexus
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: rnexus
82
+ rubygems_version: 1.3.4
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: a ruby wrapper to interact with a nexus maven repository
86
+ test_files:
87
+ - test/artifact_test.rb
88
+ - test/repository_test.rb
89
+ - test/test_helper.rb