paquet 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf85e0be99fffc4220472f97d3091b4b97770a62
4
- data.tar.gz: 13f88a1c078e1a9b0d8786dc5e5885db5282ddc8
3
+ metadata.gz: def4c6e1b73585f73deb5c0dde69c17af8eab210
4
+ data.tar.gz: 5b3144257985bcfb4ae177eae9cc3a701236e937
5
5
  SHA512:
6
- metadata.gz: 8f60ad2025a1569b56b0a768f8fdcb4e972beb1ce9d87278700c4bae32abdabc62db29f21a74d37605d5c32e854debcdf4731f1c6825cb1196ae3ac3c45a6039
7
- data.tar.gz: df9ed2b03e730fbd02890442323731656cfd627ce1cc6e40e82bc8a26a25af5367dbc3ad2b06b83b422b5770e6f3e450b4aa67f257dcc825b5de392e6ab0352e
6
+ metadata.gz: 83ff8cdcd711ed6d3c145aa91f05ececaffd3bfd091a740b64187f9240c840829cec1f2e3cf527053fa75e5c8405e1c64717972b0de6128c368c72b489cabdad
7
+ data.tar.gz: f058a849b1e01fea1a26a8ae37e88b9391922d7b5d664c6e6576c5eb035484c62270bf4c9e317a2b10c3117c57207e474312d60fc858d8c86a3eb04c7ec49b8d
@@ -1,7 +1,9 @@
1
1
  # encoding: utf-8
2
2
  require "paquet/version"
3
+ require "paquet/shell_ui"
4
+ require "paquet/gem"
5
+ require "paquet/dependency"
3
6
  require "paquet/rspec/tasks"
4
7
 
5
8
  module Paquet
6
- # Your code goes here...
7
9
  end
@@ -0,0 +1,19 @@
1
+ module Paquet
2
+ class Dependency
3
+ attr_reader :name, :version, :platform
4
+
5
+ def initialize(name, version, platform)
6
+ @name = name
7
+ @version = version
8
+ @platform = platform
9
+ end
10
+
11
+ def to_s
12
+ "#{name}-#{version}"
13
+ end
14
+
15
+ def ruby?
16
+ platform == "ruby"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+ require "paquet/dependency"
3
+ require "paquet/shell_ui"
4
+ require "paquet/utils"
5
+
6
+ module Paquet
7
+ class Gem
8
+ RUBYGEMS_URI = "https://rubygems.org/downloads"
9
+
10
+ attr_reader :gems, :ignores
11
+
12
+ def initialize(target_path, cache = nil)
13
+ @target_path = target_path
14
+ @gems = []
15
+ @ignores = []
16
+ @cache = cache
17
+ end
18
+
19
+ def add(name)
20
+ @gems << name
21
+ end
22
+
23
+ def ignore(name)
24
+ @ignores << name
25
+ end
26
+
27
+ def pack
28
+ Paquet::ui.info("Cleaning existing target path: #{@target_path}")
29
+
30
+ FileUtils.rm_rf(@target_path)
31
+ FileUtils.mkdir_p(@target_path)
32
+
33
+ package_gems(collect_required_gems)
34
+ end
35
+
36
+ def package_gems(collect_required_gems)
37
+ gems_to_package = collect_required_gems
38
+ .collect { |gem| gem_full_name(gem) }
39
+ .uniq
40
+
41
+ if use_cache?
42
+ gems_to_package.each do |gem_name|
43
+ if gem_file = find_in_cache(gem_name)
44
+ destination = File.join(@target_path, File.basename(gem_file))
45
+ FileUtils.cp(gem_file, destination)
46
+ Paquet::ui.info("Vendoring: #{gem_name}, from cache: #{gem_file}")
47
+ else
48
+ download_gem(gem_name)
49
+ end
50
+ end
51
+ else
52
+ gems_to_package.each do |gem_name|
53
+ download_gem(gem_name)
54
+ end
55
+ end
56
+ end
57
+
58
+ def use_cache?
59
+ @cache
60
+ end
61
+
62
+ def find_in_cache(gem_name)
63
+ filename = File.join(@cache, gem_name)
64
+ File.exist?(filename) ? filename : nil
65
+ end
66
+
67
+ def size
68
+ @gems.size
69
+ end
70
+
71
+ def ignore?(name)
72
+ ignores.include?(name)
73
+ end
74
+
75
+ def collect_required_gems()
76
+ candidates = []
77
+ @gems.each do |name|
78
+ candidates += resolve_dependencies(name)
79
+ end
80
+ candidates.flatten
81
+ end
82
+
83
+ def resolve_dependencies(name)
84
+ return [] if ignore?(name)
85
+
86
+ spec = ::Gem::Specification.find_by_name(name)
87
+ current_dependency = Dependency.new(name, spec.version, spec.platform)
88
+ dependencies = spec.dependencies.select { |dep| dep.type == :runtime }
89
+
90
+ if dependencies.size == 0
91
+ [current_dependency]
92
+ else
93
+ [dependencies.collect { |spec| resolve_dependencies(spec.name) }, current_dependency].flatten.uniq { |s| s.name }
94
+ end
95
+ end
96
+
97
+ def gem_full_name(gem)
98
+ gem.ruby? ? "#{gem.name}-#{gem.version}.gem" : "#{gem.name}-#{gem.version}-#{gem.platform}.gem"
99
+ end
100
+
101
+ def download_gem(gem_name)
102
+ source = "#{RUBYGEMS_URI}/#{gem_name}"
103
+ destination = File.join(@target_path, gem_name)
104
+
105
+ Paquet::ui.info("Vendoring: #{gem_name}, downloading: #{source}")
106
+ Paquet::Utils::download_file(source, destination)
107
+ end
108
+ end
109
+ end
@@ -4,127 +4,20 @@ require "rake"
4
4
  require "rake/tasklib"
5
5
  require "fileutils"
6
6
  require "net/http"
7
+ require "paquet/gem"
7
8
 
9
+ # This class add new rake methods to a an existing ruby gem,
10
+ # these methods allow developpers to create a Uber gem, a uber gem is
11
+ # a tarball that contains the current gems and one or more of his dependencies.
8
12
  #
9
- # Uses bundler/fetcher to download stuff
13
+ # This Tool will take care of looking at the current dependency tree defined in the Gemspec and the gemfile
14
+ # and will traverse all graph and download the gem file into a specified directory.
15
+ #
16
+ # By default, the tool wont fetch everything and the developper need to declare what gems he want to download.
10
17
  module Paquet
11
- class Gem
12
- RUBYGEMS_URI = "https://rubygems.org/downloads"
13
-
14
- attr_reader :gems, :ignores
15
-
16
- def initialize(target_path)
17
- @target_path = target_path
18
- @gems = []
19
- @ignores = []
20
- end
21
-
22
- def add(name)
23
- @gems << name
24
- end
25
-
26
- def ignore(name)
27
- @ignores << name
28
- end
29
-
30
- def pack
31
- FileUtils.rm_rf(@target_path)
32
- FileUtils.mkdir_p(@target_path)
33
-
34
- # need to get the current version and dependencies
35
- required_gems = collect_required_gems
36
- download_gems(required_gems)
37
- end
38
-
39
- def size
40
- @gems.size
41
- end
42
-
43
- private
44
- class Dependency
45
- attr_reader :name, :version, :platform
46
-
47
- def initialize(name, version, platform)
48
- @name = name
49
- @version = version
50
- @platform = platform
51
- end
52
-
53
- def to_s
54
- "#{name}-#{version}"
55
- end
56
-
57
- def ruby?
58
- platform == "ruby"
59
- end
60
- end
61
-
62
- def ignore?(name)
63
- ignores.include?(name)
64
- end
65
-
66
- def collect_required_gems()
67
- candidates = []
68
- @gems.each do |name|
69
- candidates += resolve_dependencies(name)
70
- end
71
- candidates.flatten
72
- end
73
-
74
- def resolve_dependencies(name)
75
- return [] if ignore?(name)
76
-
77
- spec = ::Gem::Specification.find_by_name(name)
78
- current_dependency = Dependency.new(name, spec.version, spec.platform)
79
- dependencies = spec.dependencies.select { |dep| dep.type == :runtime }
80
-
81
- if dependencies.size == 0
82
- [current_dependency]
83
- else
84
- [dependencies.collect { |spec| resolve_dependencies(spec.name) }, current_dependency].flatten.uniq { |s| s.name }
85
- end
86
- end
87
-
88
- def download_gems(required_gems)
89
- required_gems
90
- .collect { |gem| gem.ruby? ? "#{gem.name}-#{gem.version}.gem" : "#{gem.name}-#{gem.version}-#{gem.platform}.gem" }
91
- .uniq
92
- .each do |name|
93
- source = "#{RUBYGEMS_URI}/#{name}"
94
- destination = File.join(@target_path, name)
95
-
96
- puts "Vendoring: #{name}, downloading: #{source}"
97
- download_file(source, destination)
98
- end
99
- end
100
-
101
- def download_file(source, destination, counter = 10)
102
- raise "Too many redirection" if counter == 0
103
-
104
- f = File.open(destination, "w")
105
-
106
- begin
107
- uri = URI.parse(source)
108
- http = Net::HTTP.new(uri.host, uri.port)
109
- http.use_ssl = true
110
- response = http.get(uri.path)
111
-
112
- case response
113
- when Net::HTTPSuccess
114
- f.write(response.body)
115
- when Net::HTTPRedirection
116
- download_file(response['location'], destination, counter)
117
- end
118
-
119
- ensure
120
- f.close
121
- end
122
- end
123
- end
124
-
125
18
  class Task < Rake::TaskLib
126
- def initialize(target_path, &block)
127
- @gem = Gem.new(target_path)
19
+ def initialize(target_path, cache_path = nil, &block)
20
+ @gem = Gem.new(target_path, cache_path)
128
21
 
129
22
  instance_eval(&block)
130
23
 
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module Paquet
3
+ class SilentUI
4
+ class << self
5
+ def debug(message)
6
+ end
7
+ def info(message)
8
+ end
9
+ end
10
+ end
11
+
12
+ class ShellUi
13
+ def debug(message)
14
+ report_message(:debug, message) if debug?
15
+ end
16
+
17
+ def info(message)
18
+ report_message(:info, message)
19
+ end
20
+
21
+ def report_message(level, message)
22
+ puts "[#{level.upcase}]: #{message}"
23
+ end
24
+
25
+ def debug?
26
+ ENV["DEBUG"]
27
+ end
28
+ end
29
+
30
+ def self.ui
31
+ @logger ||= ShellUi.new
32
+ end
33
+
34
+ def self.ui=(new_output)
35
+ @logger = new_output
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ require "fileutils"
3
+ require "uri"
4
+
5
+ module Paquet
6
+ class Utils
7
+ HTTPS_SCHEME = "https"
8
+ REDIRECTION_LIMIT = 5
9
+
10
+ def self.download_file(source, destination, counter = REDIRECTION_LIMIT)
11
+ raise "Too many redirection" if counter == 0
12
+
13
+ begin
14
+ f = File.open(destination, "w")
15
+
16
+ uri = URI.parse(source)
17
+
18
+ http = Net::HTTP.new(uri.host, uri.port, )
19
+ http.use_ssl = uri.scheme == HTTPS_SCHEME
20
+
21
+ response = http.get(uri.path)
22
+
23
+ case response
24
+ when Net::HTTPSuccess
25
+ f.write(response.body)
26
+ when Net::HTTPRedirection
27
+ counter -= 1
28
+ download_file(response['location'], destination, counter)
29
+ else
30
+ raise "Response not handled: #{response.class}, path: #{uri.path}"
31
+ end
32
+ f.path
33
+ rescue => e
34
+ FileUtils.rm_rf(f.path) rescue nil
35
+ raise e
36
+ ensure
37
+ f.close
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Paquet
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,52 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paquet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '1.13'
19
- name: bundler
18
+ version: '0'
19
+ name: rspec
20
20
  prerelease: false
21
21
  type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '1.13'
32
+ version: '0'
33
+ name: pry
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
30
44
  - - "~>"
31
45
  - !ruby/object:Gem::Version
32
- version: '10.0'
33
- name: rake
46
+ version: 2.2.0
47
+ name: webmock
34
48
  prerelease: false
35
49
  type: :development
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: 2.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  requirement: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - ">="
45
59
  - !ruby/object:Gem::Version
46
60
  version: '0'
47
- name: pry
61
+ name: stud
48
62
  prerelease: false
49
- type: :runtime
63
+ type: :development
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
@@ -59,19 +73,14 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - ".gitignore"
63
- - CODE_OF_CONDUCT.md
64
- - Gemfile
65
- - LICENSE
66
- - README.md
67
- - Rakefile
68
- - bin/console
69
- - bin/setup
70
- - lib/paquet.rb
71
- - lib/paquet/rspec/tasks.rb
72
- - lib/paquet/version.rb
73
- - paquet.gemspec
74
- homepage: https://github.com/elastic/paquet
76
+ - "./lib/paquet.rb"
77
+ - "./lib/paquet/dependency.rb"
78
+ - "./lib/paquet/gem.rb"
79
+ - "./lib/paquet/rspec/tasks.rb"
80
+ - "./lib/paquet/shell_ui.rb"
81
+ - "./lib/paquet/utils.rb"
82
+ - "./lib/paquet/version.rb"
83
+ homepage: https://github.com/elastic/logstash
75
84
  licenses:
76
85
  - Apache License (2.0)
77
86
  metadata: {}
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at phpellerin@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in paquet.gemspec
4
- gemspec
data/LICENSE DELETED
@@ -1,13 +0,0 @@
1
- Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
data/README.md DELETED
@@ -1,36 +0,0 @@
1
- # Paquet
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/paquet`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'paquet'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install paquet
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paquet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "paquet"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'paquet/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "paquet"
8
- spec.version = Paquet::VERSION
9
- spec.authors = ["Elastic"]
10
- spec.email = ["info@elastic.co"]
11
- spec.license = "Apache License (2.0)"
12
-
13
- spec.summary = %q{Rake helpers to create a uber gem}
14
- spec.description = %q{This gem add a few rake tasks to create a uber gems that will be shipped as a zip}
15
- spec.homepage = "https://github.com/elastic/paquet"
16
-
17
-
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
- f.match(%r{^(test|spec|features)/})
20
- end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
24
-
25
- spec.add_development_dependency "bundler", "~> 1.13"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_runtime_dependency "pry"
28
- end