maven_dependency 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9942e14db12387ec688fda1821162aac023b0118
4
+ data.tar.gz: e4c825d68ee08c7702e056799131048e9821424c
5
+ SHA512:
6
+ metadata.gz: 182966303dcc7c1b10d197f0ab20a39204609b627a0a9d33d361d329a2a895035da71ea452c5e579185a66d23da4ef97fde00c1554766b723c141c990fea5978
7
+ data.tar.gz: 95f087f2547a3c31c634a0c7d9dfa8dae106e26796de4770ea16d199ddc138aa438cadeff4e6bfe2a8c1c095cf1c5f490110f449645842218c4cb06e21938ddb
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in maven_dependency.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Junegunn Choi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # maven_depenceny
2
+
3
+ A Ruby gem to download dependent jars using
4
+ [maven-dependency-plugin](http://maven.apache.org/plugins/maven-dependency-plugin/).
5
+
6
+ Requires mvn executable.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'maven_dependency'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install maven_dependency
21
+
22
+ ## Usage
23
+
24
+ ### Ruby
25
+
26
+ ```ruby
27
+ jars = MavenDependency.resolve('redis.clients/jedis@2.5.1')
28
+ jars = MavenDependency.resolve('redis.clients/jedis@2.5.1', 'org.clojure/clojure@1.5.1')
29
+
30
+ MavenDependency.resolve(
31
+ 'org.apache.hadoop/hadoop-common@2.3.0-cdh5.0.0',
32
+ :repositories => [{
33
+ :url => 'https://repository.cloudera.com/artifactory/cloudera-repos'
34
+ }], :verbose => true).each do |jar|
35
+ # In JRuby
36
+ require jar
37
+ end
38
+ ```
39
+
40
+ ### maven_dependency_fetch_jars executable
41
+
42
+ ```sh
43
+ maven_dependency_fetch_jars redis.clients/jedis@2.5.1 org.clojure/clojure@1.5.1
44
+ ```
45
+
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'maven_dependency'
5
+ require 'optparse'
6
+ require 'fileutils'
7
+
8
+ verbose = true
9
+ dir = '.'
10
+ pom = false
11
+ me = File.basename $0
12
+ op = OptionParser.new do |o|
13
+ o.banner = "usage: #{me} [OPTIONS] <group.id/artifactid[@version] ...>"
14
+ o.separator ''
15
+
16
+ o.on('-q', '--quiet', 'Suppress output') do |v|
17
+ verbose = !v
18
+ end
19
+
20
+ o.on('-d DIR', '--directory=DIR', 'Directory to put jars (default: .)') do |v|
21
+ raise "not a directory: #{v}" unless File.directory?(v.to_s)
22
+ dir = v
23
+ end
24
+
25
+ o.on('', '--pom', 'Print pom file only') do |v|
26
+ pom = true
27
+ end
28
+
29
+ o.on('-h', '--help', 'Show this message') do
30
+ puts o
31
+ exit
32
+ end
33
+ end
34
+
35
+ begin
36
+ op.parse!
37
+ rescue SystemExit
38
+ exit
39
+ rescue Exception => e
40
+ puts e
41
+ puts op
42
+ exit 1
43
+ end
44
+
45
+ if ARGV.empty?
46
+ puts op
47
+ exit 1
48
+ end
49
+
50
+ if pom
51
+ puts MavenDependency.pom(*ARGV)
52
+ else
53
+ MavenDependency.resolve(*ARGV, :verbose => verbose).each do |dep|
54
+ puts "Copy #{dep} to #{dir}" if verbose
55
+ FileUtils.cp dep, dir
56
+ end
57
+ end
58
+
@@ -0,0 +1,64 @@
1
+ require "maven_dependency/version"
2
+ require 'erb'
3
+ require 'tempfile'
4
+
5
+ module MavenDependency
6
+ DEFAULT_OPTIONS = {
7
+ :verbose => false,
8
+ :repositories => []
9
+ }
10
+
11
+ class << self
12
+ def resolve(*args)
13
+ args, opts = args_opts args
14
+
15
+ pom, dep = 2.times.map { Tempfile.new('maven_dependency') }
16
+ redirection = opts[:verbose] ? '' : '> /dev/null'
17
+ begin
18
+ pom << pom_(args, opts)
19
+ pom.close
20
+ dep.close
21
+ system(%[mvn
22
+ org.apache.maven.plugins:maven-dependency-plugin:build-classpath
23
+ -Dsilent=true -Dmdep.outputFile=#{dep.path} -f #{pom.path}
24
+ #{redirection}
25
+ ].gsub($/, ' '))
26
+ unless (x = $?.exitstatus) == 0
27
+ raise RuntimeError, "mvn: exit status #{x}"
28
+ end
29
+
30
+ File.read(dep).split(':')
31
+ ensure
32
+ pom.unlink
33
+ dep.unlink
34
+ end
35
+ end
36
+
37
+ def pom(*args)
38
+ pom_(*args_opts(args))
39
+ end
40
+
41
+ private
42
+ def args_opts args
43
+ args = args.dup
44
+ opts = DEFAULT_OPTIONS.merge(args.last.is_a?(Hash) ? args.pop : {})
45
+ [args, opts]
46
+ end
47
+
48
+ def pom_ args, opts
49
+ @template ||= File.read(
50
+ File.expand_path('../maven_dependency/template.xml.erb', __FILE__))
51
+
52
+ _specs = args.map { |spec|
53
+ g, a, v, x = spec.split(/[\@\/:]/)
54
+ if x || a.nil? || v.nil?
55
+ raise ArgumentError, "invalid dependency format: #{spec}"
56
+ end
57
+ [g, a, v]
58
+ }
59
+ _repos = opts[:repositories]
60
+ ERB.new(@template).result(binding)
61
+ end
62
+ end
63
+ end
64
+
@@ -0,0 +1,28 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+
5
+ <groupId>kr.junegunn</groupId>
6
+ <artifactId>maven-dependency</artifactId>
7
+ <version>1</version>
8
+ <packaging>jar</packaging>
9
+
10
+ <dependencies><% _specs.each do |g, a, v| %>
11
+ <dependency>
12
+ <groupId><%= g %></groupId>
13
+ <artifactId><%= a %></artifactId>
14
+ <version><%= v %></version>
15
+ <scope>compile</scope>
16
+ </dependency><% end %>
17
+ </dependencies>
18
+ <% unless _repos.empty? %>
19
+ <repositories><% _repos.each_with_index do |repo, idx| %>
20
+ <repository>
21
+ <% unless repo.has_key? :id %><id>repo-<%= idx %></id><% end %>
22
+ <url><%= repo.fetch :url %></url>
23
+ <snapshots>
24
+ <enabled><%= repo.fetch :snapshots, false %></enabled>
25
+ </snapshots>
26
+ </repository><% end %>
27
+ </repositories><% end %>
28
+ </project>
@@ -0,0 +1,3 @@
1
+ module MavenDependency
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'maven_dependency/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'maven_dependency'
8
+ spec.version = MavenDependency::VERSION
9
+ spec.authors = ['Junegunn Choi']
10
+ spec.email = ['junegunn.c@gmail.com']
11
+ spec.summary = 'Resolve Maven dependencies using maven-dependency-plugin'
12
+ spec.description = 'Resolve Maven dependencies using maven-dependency-plugin'
13
+ spec.homepage = 'https://github.com/junegunn/maven_dependency'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,29 @@
1
+ $VERBOSE = true
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'maven_dependency'
5
+ require 'minitest/autorun'
6
+
7
+ class TestMavenDependency < MiniTest::Unit::TestCase
8
+ def test_resolve
9
+ deps = MavenDependency.resolve('redis.clients/jedis@2.5.1',
10
+ 'org.clojure:clojure@1.5.1', :verbose => true)
11
+ assert_equal(
12
+ Set[*%w[jedis-2.5.1.jar commons-pool2-2.0.jar clojure-1.5.1.jar]],
13
+ Set.new(deps.map { |dep| File.basename dep }))
14
+ end
15
+
16
+ def test_resolve_with_repository
17
+ args = [
18
+ 'org.apache.zookeeper/zookeeper@3.4.5-cdh5.0.1',
19
+ :repositories => [{
20
+ :url => 'https://repository.cloudera.com/artifactory/cloudera-repos'
21
+ }], :verbose => true
22
+ ]
23
+ puts MavenDependency.pom(*args)
24
+ deps = MavenDependency.resolve(*args)
25
+ assert Set.new(deps.map { |dep| File.basename dep }).
26
+ include?('zookeeper-3.4.5-cdh5.0.1.jar')
27
+ end
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maven_dependency
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Junegunn Choi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Resolve Maven dependencies using maven-dependency-plugin
42
+ email:
43
+ - junegunn.c@gmail.com
44
+ executables:
45
+ - maven_dependency_fetch_jars
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/maven_dependency_fetch_jars
55
+ - lib/maven_dependency.rb
56
+ - lib/maven_dependency/template.xml.erb
57
+ - lib/maven_dependency/version.rb
58
+ - maven_dependency.gemspec
59
+ - test/test_maven_dependency.rb
60
+ homepage: https://github.com/junegunn/maven_dependency
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.0
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Resolve Maven dependencies using maven-dependency-plugin
84
+ test_files:
85
+ - test/test_maven_dependency.rb