rake_dependencies 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 367faff5b3881767b54429942817ee6be43a5d87
4
+ data.tar.gz: 674c117979433ff6aaf05b93c4d22d4a0fe66022
5
+ SHA512:
6
+ metadata.gz: bc54f045b53e2080bb2745fe0ae614ba0d718aac202dc050c475c5f056633f43d695230779f73d63c637d82342b6fc7411f0a0d626f659a68739c9ba50fc5f35
7
+ data.tar.gz: d32dc30e38aef1cc4fae7d1161a4330f475519174f23b0cc7be2259d8f5c7c61c0dcdc4daa5e640aec4b513bc2c3970e8397e564d877ca650465ec13b00dbbeb
data/.gitignore ADDED
@@ -0,0 +1,31 @@
1
+ ## Standard stuff:
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ .rspec_status
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ ## Documentation cache and generated files:
16
+ /.yardoc/
17
+ /_yardoc/
18
+ /doc/
19
+ /rdoc/
20
+ /coverage/
21
+
22
+ ## Environment normalization:
23
+ /.bundle/
24
+ /vendor/bundle
25
+ /lib/bundler/man/
26
+
27
+ ## IDE:
28
+ .idea
29
+ *.ipr
30
+ *.iws
31
+ *.iml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p648
@@ -0,0 +1,74 @@
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 tobyclemson@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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rake_dependencies.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rake_dependencies (0.14.1)
5
+ hamster (~> 3.0)
6
+ minitar (~> 0.6)
7
+ rubyzip (~> 1.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.2.7.1)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ concurrent-ruby (1.0.5)
19
+ diff-lcs (1.3)
20
+ docile (1.1.5)
21
+ fakefs (0.10.2)
22
+ gem-release (0.7.4)
23
+ hamster (3.0.0)
24
+ concurrent-ruby (~> 1.0)
25
+ i18n (0.8.0)
26
+ json (1.8.6)
27
+ minitar (0.6.1)
28
+ minitest (5.10.1)
29
+ rake (11.2.2)
30
+ rspec (3.5.0)
31
+ rspec-core (~> 3.5.0)
32
+ rspec-expectations (~> 3.5.0)
33
+ rspec-mocks (~> 3.5.0)
34
+ rspec-core (3.5.4)
35
+ rspec-support (~> 3.5.0)
36
+ rspec-expectations (3.5.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.5.0)
39
+ rspec-mocks (3.5.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-support (3.5.0)
43
+ rubyzip (1.2.1)
44
+ simplecov (0.13.0)
45
+ docile (~> 1.1.0)
46
+ json (>= 1.8, < 3)
47
+ simplecov-html (~> 0.10.0)
48
+ simplecov-html (0.10.0)
49
+ thread_safe (0.3.5)
50
+ tzinfo (1.2.2)
51
+ thread_safe (~> 0.1)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ activesupport (~> 4.2)
58
+ bundler (~> 1.14)
59
+ fakefs (~> 0.10)
60
+ gem-release (~> 0.7)
61
+ rake (~> 11.0)
62
+ rake_dependencies!
63
+ rspec (~> 3.0)
64
+ simplecov (~> 0.13)
65
+
66
+ BUNDLED WITH
67
+ 1.14.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Toby Clemson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # RakeDependencies
2
+
3
+ Rake tasks for managing build dependencies.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rake_dependencies'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rake_dependencies
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tobyclemson/rake_dependencies. 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.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,2 @@
1
+ * Handle uncompressed downloads
2
+ * Add documentation
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rake_dependencies"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,7 @@
1
+ require 'rake_dependencies/tasks'
2
+ require 'rake_dependencies/extractors'
3
+ require 'rake_dependencies/template'
4
+ require 'rake_dependencies/version'
5
+
6
+ module RakeDependencies
7
+ end
@@ -0,0 +1,4 @@
1
+ module RakeDependencies
2
+ class RequiredParameterUnset < ::StandardError
3
+ end
4
+ end
@@ -0,0 +1,76 @@
1
+ require 'zip'
2
+ require 'zlib'
3
+ require 'pathname'
4
+ require 'archive/tar/minitar'
5
+
6
+ module RakeDependencies
7
+ module Extractors
8
+ class ZipExtractor
9
+ def initialize(file_path, extract_path, options = {})
10
+ @file_path = file_path
11
+ @extract_path = extract_path
12
+ @options = options
13
+ end
14
+
15
+ def extract
16
+ FileUtils.mkdir_p(@extract_path)
17
+ Zip::File.open(@file_path) do |zip_file_entries|
18
+ zip_file_entries.each do |entry|
19
+ entry_pathname = Pathname.new(entry.name)
20
+ strip_pathname = Pathname.new(@options[:strip_path] || '')
21
+ target_pathname = entry_pathname.relative_path_from(strip_pathname)
22
+
23
+ file_path = File.join(@extract_path, target_pathname)
24
+ FileUtils.mkdir_p(File.dirname(file_path))
25
+ zip_file_entries.extract(entry, file_path) unless File.exist?(file_path)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ class TarGzExtractor
32
+ def initialize(file_path, extract_path, options = {})
33
+ @file_path = file_path
34
+ @extract_path = extract_path
35
+ @options = options
36
+ end
37
+
38
+ def extract
39
+ FileUtils.mkdir_p(@extract_path)
40
+ Zlib::GzipReader.open(@file_path) do |tar_file|
41
+ Archive::Tar::Minitar.open(tar_file) do |tar_file_entries|
42
+ tar_file_entries.each do |entry|
43
+ entry_pathname = Pathname.new(entry.name)
44
+ strip_pathname = Pathname.new(@options[:strip_path] || '')
45
+ target_pathname = entry_pathname.relative_path_from(strip_pathname)
46
+
47
+ file_path = File.join(@extract_path, target_pathname)
48
+ FileUtils.mkdir_p(File.dirname(file_path))
49
+ if entry.file? && !File.exist?(file_path)
50
+ File.open(file_path, 'w', entry.mode) { |f| f.write(entry.read) }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ class UncompressedExtractor
59
+ def initialize(file_path, extract_path, options = {})
60
+ @file_path = file_path
61
+ @extract_path = extract_path
62
+ @options = options
63
+ end
64
+
65
+ def extract
66
+ target_name = @options[:rename_to] || File.basename(@file_path)
67
+ source = @file_path
68
+ destination = File.join(@extract_path, target_name)
69
+
70
+ FileUtils.mkdir_p(@extract_path)
71
+ FileUtils.cp(source, destination)
72
+ FileUtils.chmod(0755, destination)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,98 @@
1
+ require 'rake/tasklib'
2
+ require_relative 'exceptions'
3
+
4
+ module RakeDependencies
5
+ class TaskLib < ::Rake::TaskLib
6
+ class << self
7
+ def parameter_definitions
8
+ @parameter_definitions ||= {}
9
+ end
10
+
11
+ def parameter(name, options = {})
12
+ parameter_definition = ParameterDefinition.new(
13
+ name, options[:default], options[:required])
14
+ name = parameter_definition.name
15
+
16
+ attr_accessor(name)
17
+
18
+ parameter_definitions[name] = parameter_definition
19
+ end
20
+
21
+ def setup_defaults_for(instance)
22
+ parameter_definitions.values.each do |parameter_definition|
23
+ parameter_definition.apply_default_to(instance)
24
+ end
25
+ end
26
+
27
+ def check_required_for(instance)
28
+ dissatisfied = parameter_definitions.values.reject do |definition|
29
+ definition.satisfied_by?(instance)
30
+ end
31
+ unless dissatisfied.empty?
32
+ names = dissatisfied.map(&:name)
33
+ raise RequiredParameterUnset,
34
+ "Required parameter#{names.length > 1 ? 's' : ''} #{names.join(',')} unset."
35
+ end
36
+ end
37
+ end
38
+
39
+ def initialize(*args, &block)
40
+ setup_defaults
41
+ process_arguments(args)
42
+ process_block(block)
43
+ check_required
44
+ define
45
+ end
46
+
47
+ def setup_defaults
48
+ self.class.setup_defaults_for(self)
49
+ end
50
+
51
+ def process_arguments(_)
52
+ end
53
+
54
+ def process_block(block)
55
+ block.call(self) if block
56
+ end
57
+
58
+ def check_required
59
+ self.class.check_required_for(self)
60
+ end
61
+
62
+ def define
63
+ end
64
+
65
+ private
66
+
67
+ class ParameterDefinition
68
+ attr_reader :name
69
+
70
+ def initialize(name, default = nil, required = false)
71
+ @name = name.to_sym
72
+ @default = default
73
+ @required = required
74
+ end
75
+
76
+ def writer_method
77
+ "#{name}="
78
+ end
79
+
80
+ def reader_method
81
+ name
82
+ end
83
+
84
+ def apply_default_to(instance)
85
+ instance.__send__(writer_method, @default) if @default
86
+ end
87
+
88
+ def dissatisfied_by?(instance)
89
+ value = instance.__send__(reader_method)
90
+ @required && value.nil?
91
+ end
92
+
93
+ def satisfied_by?(instance)
94
+ !dissatisfied_by?(instance)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'tasks/clean'
2
+ require_relative 'tasks/download'
3
+ require_relative 'tasks/extract'
4
+ require_relative 'tasks/fetch'
5
+ require_relative 'tasks/ensure'
6
+ require_relative 'tasks/all'
@@ -0,0 +1,105 @@
1
+ require_relative 'clean'
2
+ require_relative 'download'
3
+ require_relative 'ensure'
4
+ require_relative 'extract'
5
+ require_relative 'fetch'
6
+ require_relative '../tasklib'
7
+
8
+ module RakeDependencies
9
+ module Tasks
10
+ class All < TaskLib
11
+ parameter :containing_namespace
12
+
13
+ parameter :dependency, :required => true
14
+ parameter :version
15
+ parameter :path, :required => true
16
+ parameter :type, :default => :zip
17
+
18
+ parameter :os_ids, default: {mac: 'mac', linux: 'linux'}
19
+
20
+ parameter :distribution_directory, default: 'dist'
21
+ parameter :binary_directory, default: 'bin'
22
+
23
+ parameter :uri_template, :required => true
24
+ parameter :file_name_template, :required => true
25
+ parameter :target_name_template
26
+ parameter :strip_path_template
27
+
28
+ parameter :needs_fetch, :required => true
29
+
30
+ parameter :clean_task_name, :default => :clean
31
+ parameter :download_task_name, :default => :download
32
+ parameter :extract_task_name, :default => :extract
33
+ parameter :fetch_task_name, :default => :fetch
34
+ parameter :ensure_task_name, :default => :ensure
35
+
36
+ alias namespace= containing_namespace=
37
+
38
+ def define
39
+ namespace containing_namespace do
40
+ Clean.new do |t|
41
+ t.name = clean_task_name
42
+
43
+ t.dependency = dependency
44
+ t.path = path
45
+ end
46
+ Download.new do |t|
47
+ t.name = download_task_name
48
+
49
+ t.dependency = dependency
50
+ t.version = version
51
+ t.path = path
52
+ t.type = type
53
+
54
+ t.os_ids = os_ids
55
+
56
+ t.distribution_directory = distribution_directory
57
+
58
+ t.uri_template = uri_template
59
+ t.file_name_template = file_name_template
60
+ end
61
+ Extract.new do |t|
62
+ t.name = extract_task_name
63
+
64
+ t.dependency = dependency
65
+ t.version = version
66
+ t.path = path
67
+ t.type = type
68
+
69
+ t.os_ids = os_ids
70
+
71
+ t.distribution_directory = distribution_directory
72
+ t.binary_directory = binary_directory
73
+
74
+ t.file_name_template = file_name_template
75
+ t.strip_path_template = strip_path_template
76
+ t.target_name_template = target_name_template
77
+ end
78
+ Fetch.new do |t|
79
+ t.name = fetch_task_name
80
+
81
+ t.dependency = dependency
82
+
83
+ t.download_task = download_task_name
84
+ t.extract_task = extract_task_name
85
+ end
86
+ Ensure.new do |t|
87
+ t.name = ensure_task_name
88
+
89
+ t.dependency = dependency
90
+ t.version = version
91
+ t.path = path
92
+
93
+ t.binary_directory = binary_directory
94
+
95
+ t.needs_fetch = needs_fetch
96
+
97
+ t.clean_task = clean_task_name
98
+ t.download_task = download_task_name
99
+ t.extract_task = extract_task_name
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../tasklib'
2
+
3
+ module RakeDependencies
4
+ module Tasks
5
+ class Clean < TaskLib
6
+ parameter :name, :default => :clean
7
+ parameter :path, :required => true
8
+ parameter :dependency, :required => true
9
+
10
+ def process_arguments(args)
11
+ self.name = args[0] if args[0]
12
+ end
13
+
14
+ def define
15
+ desc "Clean vendored #{dependency}"
16
+ task name do
17
+ rm_rf path
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,78 @@
1
+ require 'open-uri'
2
+ require_relative '../tasklib'
3
+ require_relative '../template'
4
+
5
+ module RakeDependencies
6
+ module Tasks
7
+ class Download < TaskLib
8
+ parameter :name, default: :download
9
+
10
+ parameter :type, default: :zip
11
+ parameter :os_ids, default: {mac: 'mac', linux: 'linux'}
12
+
13
+ parameter :distribution_directory, default: 'dist'
14
+
15
+ parameter :dependency, required: true
16
+ parameter :version
17
+ parameter :path, required: true
18
+ parameter :uri_template, required: true
19
+ parameter :file_name_template, required: true
20
+
21
+ def process_arguments(args)
22
+ super(args)
23
+ self.name = args[0] if args[0]
24
+ end
25
+
26
+ def define
27
+ desc "Download #{dependency} distribution"
28
+ task name do
29
+ parameters = {
30
+ version: version,
31
+ platform: platform,
32
+ os_id: os_id,
33
+ ext: ext
34
+ }
35
+
36
+ uri = Template.new(uri_template)
37
+ .with_parameters(parameters)
38
+ .render
39
+ download_file_name = Template.new(file_name_template)
40
+ .with_parameters(parameters)
41
+ .render
42
+ download_file_directory = File.join(path, distribution_directory)
43
+ download_file_path = File.join(download_file_directory, download_file_name)
44
+
45
+ temporary_file = open(uri)
46
+
47
+ mkdir_p download_file_directory
48
+ cp temporary_file.path, download_file_path
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def os_id
55
+ os_ids[platform]
56
+ end
57
+
58
+ def platform
59
+ RUBY_PLATFORM =~ /darwin/ ? :mac : :linux
60
+ end
61
+
62
+ def resolved_type
63
+ type.is_a?(Hash) ? type[platform].to_sym : type.to_sym
64
+ end
65
+
66
+ def ext
67
+ case resolved_type
68
+ when :tar_gz then '.tar.gz'
69
+ when :tgz then '.tgz'
70
+ when :zip then '.zip'
71
+ when :uncompressed then ''
72
+ else
73
+ raise "Unknown type: #{type}"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../tasklib'
2
+
3
+ module RakeDependencies
4
+ module Tasks
5
+ class Ensure < TaskLib
6
+ parameter :name, default: :ensure
7
+
8
+ parameter :dependency, required: true
9
+ parameter :version
10
+ parameter :path, required: true
11
+
12
+ parameter :binary_directory, default: 'bin'
13
+
14
+ parameter :needs_fetch, default: lambda { |_| true }
15
+
16
+ parameter :clean_task, default: :clean
17
+ parameter :download_task, default: :download
18
+ parameter :extract_task, default: :extract
19
+
20
+ def process_arguments args
21
+ super(args)
22
+ self.name = args[0] if args[0]
23
+ end
24
+
25
+ def define
26
+ clean = Rake::Task[scoped_task_name(clean_task)]
27
+ download = Rake::Task[scoped_task_name(download_task)]
28
+ extract = Rake::Task[scoped_task_name(extract_task)]
29
+
30
+ desc "Ensure #{dependency} present"
31
+ task name do
32
+ parameters = {
33
+ path: path,
34
+ version: version,
35
+ binary_directory: binary_directory
36
+ }
37
+ if needs_fetch.call(parameters)
38
+ [clean, download, extract].map(&:invoke)
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def scoped_task_name(task_name)
46
+ Rake.application.current_scope.path_with_task_name(task_name)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,108 @@
1
+ require 'zip'
2
+ require_relative '../tasklib'
3
+ require_relative '../template'
4
+ require_relative '../extractors'
5
+
6
+ module RakeDependencies
7
+ module Tasks
8
+ class Extract < TaskLib
9
+ parameter :name, default: :extract
10
+
11
+ parameter :type, default: :zip
12
+ parameter :os_ids, default: {
13
+ mac: 'mac',
14
+ linux: 'linux'
15
+ }
16
+ parameter :extractors, default: {
17
+ zip: Extractors::ZipExtractor,
18
+ tar_gz: Extractors::TarGzExtractor,
19
+ tgz: Extractors::TarGzExtractor,
20
+ uncompressed: Extractors::UncompressedExtractor
21
+ }
22
+
23
+ parameter :distribution_directory, default: 'dist'
24
+ parameter :binary_directory, default: 'bin'
25
+
26
+ parameter :dependency, required: true
27
+ parameter :version
28
+ parameter :path, required: true
29
+ parameter :file_name_template, required: true
30
+ parameter :target_name_template
31
+ parameter :strip_path_template
32
+
33
+ def process_arguments args
34
+ super(args)
35
+ self.name = args[0] if args[0]
36
+ end
37
+
38
+ def define
39
+ desc "Extract #{dependency} archive"
40
+ task name do
41
+ parameters = {
42
+ version: version,
43
+ platform: platform,
44
+ os_id: os_id,
45
+ ext: ext
46
+ }
47
+
48
+ distribution_file_name = Template.new(file_name_template)
49
+ .with_parameters(parameters)
50
+ .render
51
+ distribution_file_directory = File.join(path, distribution_directory)
52
+ distribution_file_path = File.join(
53
+ distribution_file_directory, distribution_file_name)
54
+
55
+ extraction_path = File.join(path, binary_directory)
56
+
57
+ options = {}
58
+ if strip_path_template
59
+ options[:strip_path] = Template.new(strip_path_template)
60
+ .with_parameters(parameters)
61
+ .render
62
+ end
63
+
64
+ if target_name_template
65
+ options[:rename_to] = Template.new(target_name_template)
66
+ .with_parameters(parameters)
67
+ .render
68
+ end
69
+
70
+ extractor = extractor_for_extension.new(
71
+ distribution_file_path,
72
+ extraction_path,
73
+ options)
74
+ extractor.extract
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def extractor_for_extension
81
+ extractors[resolved_type]
82
+ end
83
+
84
+ def os_id
85
+ os_ids[platform]
86
+ end
87
+
88
+ def platform
89
+ RUBY_PLATFORM =~ /darwin/ ? :mac : :linux
90
+ end
91
+
92
+ def resolved_type
93
+ type.is_a?(Hash) ? type[platform].to_sym : type.to_sym
94
+ end
95
+
96
+ def ext
97
+ case resolved_type
98
+ when :tar_gz then '.tar.gz'
99
+ when :tgz then '.tgz'
100
+ when :zip then '.zip'
101
+ when :uncompressed then ''
102
+ else
103
+ raise "Unknown type: #{type}"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../tasklib'
2
+
3
+ module RakeDependencies
4
+ module Tasks
5
+ class Fetch < TaskLib
6
+ parameter :name, default: :fetch
7
+ parameter :dependency, required: true
8
+ parameter :download_task, default: :download
9
+ parameter :extract_task, default: :extract
10
+
11
+ def process_arguments args
12
+ super(args)
13
+ self.name = args[0] if args[0]
14
+ end
15
+
16
+ def define
17
+ desc "Fetch #{dependency}"
18
+ task name => [
19
+ scoped_task_name(download_task),
20
+ scoped_task_name(extract_task)
21
+ ]
22
+ end
23
+
24
+ private
25
+
26
+ def scoped_task_name(task_name)
27
+ Rake.application.current_scope.path_with_task_name(task_name)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'hamster'
2
+ require 'erb'
3
+
4
+ module RakeDependencies
5
+ class Template
6
+ def initialize(
7
+ template,
8
+ parameters = {})
9
+ @template = template
10
+ @parameters = Hamster::Hash.new(parameters)
11
+ end
12
+
13
+ def with_parameter key, value
14
+ Template.new(@template, @parameters.put(key, value))
15
+ end
16
+
17
+ def with_parameters **pairs
18
+ pairs.to_a.reduce(self) do |memo, parameter|
19
+ memo.with_parameter(*parameter)
20
+ end
21
+ end
22
+
23
+ def render
24
+ context = Object.new
25
+ @parameters.each do |key, value|
26
+ context.instance_variable_set("@#{key}", value)
27
+ end
28
+ context_binding = context.instance_eval { binding }
29
+ ERB.new(@template).result(context_binding)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RakeDependencies
2
+ VERSION = "0.14.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rake_dependencies/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rake_dependencies'
8
+ spec.version = RakeDependencies::VERSION
9
+ spec.authors = ['Toby Clemson']
10
+ spec.email = ['tobyclemson@gmail.com']
11
+
12
+ spec.date = '2017-01-31'
13
+ spec.summary = 'Rake tasks for managing build dependencies.'
14
+ spec.description = 'Provides rake tasks for downloading and extracting tools depended on for further build activities.'
15
+ spec.homepage = 'https://github.com/tobyclemson/rake_dependencies'
16
+ spec.license = 'MIT'
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.required_ruby_version = '>= 2.0'
26
+
27
+ spec.add_dependency 'hamster', '~> 3.0'
28
+ spec.add_dependency 'rubyzip', '~> 1.1'
29
+ spec.add_dependency 'minitar', '~> 0.6'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.14'
32
+ spec.add_development_dependency 'rake', '~> 11.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'gem-release', '~> 0.7'
35
+ spec.add_development_dependency 'activesupport', '~> 4.2'
36
+ spec.add_development_dependency 'fakefs', '~> 0.10'
37
+ spec.add_development_dependency 'simplecov', '~> 0.13'
38
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake_dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.14.1
5
+ platform: ruby
6
+ authors:
7
+ - Toby Clemson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hamster
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '11.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '11.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: gem-release
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '4.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '4.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fakefs
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.10'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '0.10'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '0.13'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '0.13'
153
+ description: Provides rake tasks for downloading and extracting tools depended on
154
+ for further build activities.
155
+ email:
156
+ - tobyclemson@gmail.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - .gitignore
162
+ - .rspec
163
+ - .ruby-version
164
+ - CODE_OF_CONDUCT.md
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - TODO.md
171
+ - bin/console
172
+ - bin/setup
173
+ - lib/rake_dependencies.rb
174
+ - lib/rake_dependencies/exceptions.rb
175
+ - lib/rake_dependencies/extractors.rb
176
+ - lib/rake_dependencies/tasklib.rb
177
+ - lib/rake_dependencies/tasks.rb
178
+ - lib/rake_dependencies/tasks/all.rb
179
+ - lib/rake_dependencies/tasks/clean.rb
180
+ - lib/rake_dependencies/tasks/download.rb
181
+ - lib/rake_dependencies/tasks/ensure.rb
182
+ - lib/rake_dependencies/tasks/extract.rb
183
+ - lib/rake_dependencies/tasks/fetch.rb
184
+ - lib/rake_dependencies/template.rb
185
+ - lib/rake_dependencies/version.rb
186
+ - rake_dependencies.gemspec
187
+ homepage: https://github.com/tobyclemson/rake_dependencies
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '2.0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 2.0.14.1
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Rake tasks for managing build dependencies.
211
+ test_files: []