rvn 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rvn +4 -0
- data/raven.rb +188 -0
- metadata +111 -0
data/bin/rvn
ADDED
data/raven.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'rainbow'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'httparty'
|
5
|
+
require 'terminal-table'
|
6
|
+
|
7
|
+
module Raven
|
8
|
+
|
9
|
+
module PomResource
|
10
|
+
|
11
|
+
def pom_as_doc
|
12
|
+
pom = Nokogiri::XML File.open 'pom.xml'
|
13
|
+
pom.remove_namespaces!
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module Dependencies
|
19
|
+
include PomResource
|
20
|
+
|
21
|
+
def list_dep
|
22
|
+
pom_as_doc.css('dependencies > dependency').map { |node|
|
23
|
+
"#{node.xpath('groupId').text}:#{node.xpath('artifactId').text}:#{node.xpath('version').text}"
|
24
|
+
}.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def search_dep(group_id, artifact_id = nil, version = nil)
|
28
|
+
MavenDependencyResolver.new(group_id, artifact_id, version).resolve
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class Rvn
|
34
|
+
include Dependencies
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@console = Raven::Console.new
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def run(arguments)
|
42
|
+
if arguments.first == "dep"
|
43
|
+
@console.out(list_dep)
|
44
|
+
return
|
45
|
+
elsif arguments.first == "search"
|
46
|
+
if arguments[1]
|
47
|
+
found_info = search_dep(*arguments[1].split(":"))
|
48
|
+
@console.out(found_info)
|
49
|
+
else
|
50
|
+
@console.out("No dependency coordinates provided. Run the help")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
delegate_to_maven(arguments)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def delegate_to_maven(arguments)
|
60
|
+
command = "mvn #{arguments.join(' ')}"
|
61
|
+
IO.popen(command) { |maven|
|
62
|
+
maven.each do |line|
|
63
|
+
@console.out line
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
class MavenDependencyResolver
|
72
|
+
include HTTParty
|
73
|
+
base_uri 'mvnrepository.com/artifact'
|
74
|
+
|
75
|
+
def initialize(group_id, artifact_id = nil, version = nil)
|
76
|
+
@group = group_id
|
77
|
+
@artifact = artifact_id
|
78
|
+
@version = version
|
79
|
+
end
|
80
|
+
|
81
|
+
def resolve
|
82
|
+
return dependency if fetch_dependency?
|
83
|
+
return artifacts if fetch_artifacts?
|
84
|
+
return versions if fetch_versions?
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def dependency
|
90
|
+
if dependency_valid?
|
91
|
+
dependency_as_xml
|
92
|
+
else
|
93
|
+
cannot_find(@group, @artifact, @version)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def versions
|
98
|
+
if group_and_artifact_valid?
|
99
|
+
response_body = self.class.get("/#{@group}/#{@artifact}").body
|
100
|
+
versions = parse_response(response_body, "//table/tr/td/a[@class='versionbutton release']")
|
101
|
+
as_table("Available versions for #{@group}:#{@artifact}", versions)
|
102
|
+
else
|
103
|
+
cannot_find(@group, @artifact)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def artifacts
|
108
|
+
if group_valid?
|
109
|
+
response_body = self.class.get("/#{@group}").body
|
110
|
+
artifacts = parse_response(response_body, "//div[@id='maincontent']/table/tr/td/a[not(@class)]")
|
111
|
+
as_table("Available artifacts for #{@group}", artifacts)
|
112
|
+
else
|
113
|
+
cannot_find(@group)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def parse_response(body, xpath_expression)
|
118
|
+
items_found = []
|
119
|
+
html_doc = Nokogiri::HTML(body)
|
120
|
+
html_doc.xpath(xpath_expression).each do |node|
|
121
|
+
items_found << [node.text]
|
122
|
+
end
|
123
|
+
items_found
|
124
|
+
end
|
125
|
+
|
126
|
+
def dependency_as_xml
|
127
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
128
|
+
xml.dependency {
|
129
|
+
xml.groupId @group
|
130
|
+
xml.artifactId @artifact
|
131
|
+
xml.version @version
|
132
|
+
}
|
133
|
+
end
|
134
|
+
builder.to_xml
|
135
|
+
end
|
136
|
+
|
137
|
+
def as_table(title, rows)
|
138
|
+
Terminal::Table.new :headings => [title], :rows => rows
|
139
|
+
end
|
140
|
+
|
141
|
+
def cannot_find(*coordinates)
|
142
|
+
"Cannot find '#{coordinates.join(":")}' in maven repo"
|
143
|
+
end
|
144
|
+
|
145
|
+
def group_valid?
|
146
|
+
200 == self.class.get("/#{@group}").code
|
147
|
+
end
|
148
|
+
|
149
|
+
def group_and_artifact_valid?
|
150
|
+
200 == self.class.get("/#{@group}/#{@artifact}").code
|
151
|
+
end
|
152
|
+
|
153
|
+
def dependency_valid?
|
154
|
+
200 == self.class.get("/#{@group}/#{@artifact}/#{@version}").code
|
155
|
+
end
|
156
|
+
|
157
|
+
def fetch_artifacts?
|
158
|
+
@group && @artifact.nil? && @version.nil?
|
159
|
+
end
|
160
|
+
|
161
|
+
def fetch_versions?
|
162
|
+
@group && @artifact && @version.nil?
|
163
|
+
end
|
164
|
+
|
165
|
+
def fetch_dependency?
|
166
|
+
@group && @artifact && @version
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
class Console
|
172
|
+
|
173
|
+
def out(content)
|
174
|
+
if content.class == Terminal::Table
|
175
|
+
puts content
|
176
|
+
else
|
177
|
+
content.each_line { |line|
|
178
|
+
line = line.foreground(:red) if line =~ /^\[ERROR\]/
|
179
|
+
line = line.foreground(:green) if line =~ /SUCCESS/
|
180
|
+
line = line.foreground(:yellow) if line =~ /^\[WARNING\]/
|
181
|
+
print line
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rvn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon Caplette
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rainbow
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: httparty
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: terminal-table
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description:
|
79
|
+
email:
|
80
|
+
executables:
|
81
|
+
- rvn
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- bin/rvn
|
86
|
+
- raven.rb
|
87
|
+
homepage: https://github.com/simcap/raven
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.24
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Ruby over the maven command line
|
111
|
+
test_files: []
|