buildpack-support 1.0.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.
- data/LICENSE +202 -0
- data/NOTICE +2 -0
- data/docs/cache.md +77 -0
- data/docs/component.md +1 -0
- data/docs/configuration.md +27 -0
- data/docs/logging.md +54 -0
- data/docs/other.md +1 -0
- data/docs/rake.md +1 -0
- data/docs/repository.md +116 -0
- data/docs/test.md +1 -0
- data/lib/buildpack_support.rb +18 -0
- data/lib/buildpack_support/base_buildpack.rb +166 -0
- data/lib/buildpack_support/buildpack_version.rb +124 -0
- data/lib/buildpack_support/cache.rb +24 -0
- data/lib/buildpack_support/cache/application_cache.rb +41 -0
- data/lib/buildpack_support/cache/cached_file.rb +103 -0
- data/lib/buildpack_support/cache/download_cache.rb +280 -0
- data/lib/buildpack_support/cache/inferred_network_failure.rb +26 -0
- data/lib/buildpack_support/cache/internet_availability.rb +64 -0
- data/lib/buildpack_support/component.rb +24 -0
- data/lib/buildpack_support/component/application.rb +76 -0
- data/lib/buildpack_support/component/base_component.rb +78 -0
- data/lib/buildpack_support/component/base_droplet.rb +96 -0
- data/lib/buildpack_support/component/downloads.rb +88 -0
- data/lib/buildpack_support/component/services.rb +84 -0
- data/lib/buildpack_support/component/versioned_dependency_component.rb +71 -0
- data/lib/buildpack_support/component/versioned_downloads.rb +57 -0
- data/lib/buildpack_support/component/with_timing.rb +40 -0
- data/lib/buildpack_support/configuration_utils.rb +58 -0
- data/lib/buildpack_support/constantize.rb +46 -0
- data/lib/buildpack_support/dash_case.rb +29 -0
- data/lib/buildpack_support/directory_finder.rb +45 -0
- data/lib/buildpack_support/filtering_pathname.rb +227 -0
- data/lib/buildpack_support/format_duration.rb +57 -0
- data/lib/buildpack_support/logging.rb +22 -0
- data/lib/buildpack_support/logging/delegating_logger.rb +48 -0
- data/lib/buildpack_support/logging/logger_factory.rb +148 -0
- data/lib/buildpack_support/qualify_path.rb +36 -0
- data/lib/buildpack_support/rake.rb +22 -0
- data/lib/buildpack_support/rake/buildpack_stage_task.rb +86 -0
- data/lib/buildpack_support/rake/cached_artifact_finder.rb +99 -0
- data/lib/buildpack_support/rake/check_api_doc_task.rb +70 -0
- data/lib/buildpack_support/rake/dependency_cache_task.rb +87 -0
- data/lib/buildpack_support/rake/disable_remote_downloads_task.rb +80 -0
- data/lib/buildpack_support/rake/package_task.rb +133 -0
- data/lib/buildpack_support/rake/package_zip_task.rb +80 -0
- data/lib/buildpack_support/rake/repository_configuration_finder.rb +66 -0
- data/lib/buildpack_support/rake/write_version_file_task.rb +82 -0
- data/lib/buildpack_support/repository.rb +24 -0
- data/lib/buildpack_support/repository/configured_item.rb +81 -0
- data/lib/buildpack_support/repository/repository_index.rb +98 -0
- data/lib/buildpack_support/repository/wildcard_version_resolver.rb +75 -0
- data/lib/buildpack_support/shell.rb +41 -0
- data/lib/buildpack_support/snake_case.rb +30 -0
- data/lib/buildpack_support/space_case.rb +29 -0
- data/lib/buildpack_support/test/application_helper.rb +41 -0
- data/lib/buildpack_support/test/base_component_helper.rb +59 -0
- data/lib/buildpack_support/test/base_droplet_helper.rb +36 -0
- data/lib/buildpack_support/test/console_helper.rb +57 -0
- data/lib/buildpack_support/test/environment_helper.rb +32 -0
- data/lib/buildpack_support/test/internet_availability_helper.rb +29 -0
- data/lib/buildpack_support/test/logging_helper.rb +50 -0
- data/lib/buildpack_support/test/scratch_helper.rb +32 -0
- data/lib/buildpack_support/test/versioned_dependency_component_helper.rb +32 -0
- data/lib/buildpack_support/test/with_load_path_helper.rb +27 -0
- data/lib/buildpack_support/to_b.rb +38 -0
- data/lib/buildpack_support/tokenized_version.rb +157 -0
- data/lib/buildpack_support/version.rb +23 -0
- data/spec/buildpack_support/base_buildpack_spec.rb +112 -0
- data/spec/buildpack_support/buildpack_version_spec.rb +122 -0
- data/spec/buildpack_support/cache/application_cache_spec.rb +56 -0
- data/spec/buildpack_support/cache/cached_file_spec.rb +94 -0
- data/spec/buildpack_support/cache/download_cache_spec.rb +293 -0
- data/spec/buildpack_support/cache/internet_availability_spec.rb +57 -0
- data/spec/buildpack_support/cache/yield_file_with_content.rb +30 -0
- data/spec/buildpack_support/component/application_spec.rb +81 -0
- data/spec/buildpack_support/component/base_component_spec.rb +81 -0
- data/spec/buildpack_support/component/base_droplet_spec.rb +72 -0
- data/spec/buildpack_support/component/downloads_spec.rb +63 -0
- data/spec/buildpack_support/component/services_spec.rb +80 -0
- data/spec/buildpack_support/component/versioned_dependency_component_spec.rb +58 -0
- data/spec/buildpack_support/component/versioned_downloads_spec.rb +58 -0
- data/spec/buildpack_support/component/with_timing_spec.rb +30 -0
- data/spec/buildpack_support/configuration_utils_spec.rb +39 -0
- data/spec/buildpack_support/constantize_spec.rb +34 -0
- data/spec/buildpack_support/dash_case_spec.rb +41 -0
- data/spec/buildpack_support/directory_finder_spec.rb +41 -0
- data/spec/buildpack_support/filtering_pathname_spec.rb +443 -0
- data/spec/buildpack_support/format_duration_spec.rb +60 -0
- data/spec/buildpack_support/logging/delegating_logger_spec.rb +62 -0
- data/spec/buildpack_support/logging/logger_factory_spec.rb +262 -0
- data/spec/buildpack_support/qualify_path_spec.rb +42 -0
- data/spec/buildpack_support/rake/buildpack_stage_task_spec.rb +88 -0
- data/spec/buildpack_support/rake/cached_artifact_finder_spec.rb +73 -0
- data/spec/buildpack_support/rake/check_api_doc_task_spec.rb +69 -0
- data/spec/buildpack_support/rake/dependency_cache_task_spec.rb +133 -0
- data/spec/buildpack_support/rake/disable_remote_downloads_task_spec.rb +91 -0
- data/spec/buildpack_support/rake/package_task_spec.rb +335 -0
- data/spec/buildpack_support/rake/package_zip_task_spec.rb +91 -0
- data/spec/buildpack_support/rake/repository_configuration_finder_spec.rb +61 -0
- data/spec/buildpack_support/rake/write_version_file_task_spec.rb +96 -0
- data/spec/buildpack_support/repository/configured_item_spec.rb +78 -0
- data/spec/buildpack_support/repository/repository_index_spec.rb +118 -0
- data/spec/buildpack_support/repository/wildcard_version_resolver_spec.rb +73 -0
- data/spec/buildpack_support/shell_spec.rb +32 -0
- data/spec/buildpack_support/snake_case_spec.rb +45 -0
- data/spec/buildpack_support/space_case_spec.rb +41 -0
- data/spec/buildpack_support/to_b_spec.rb +41 -0
- data/spec/buildpack_support/tokenized_version_spec.rb +132 -0
- data/spec/fixtures/application/test-file +0 -0
- data/spec/fixtures/config/found-config.yml +2 -0
- data/spec/fixtures/droplet-resources/droplet-resource +0 -0
- data/spec/fixtures/stub-download-with-top-level.zip +0 -0
- data/spec/fixtures/stub-download.tar.gz +0 -0
- data/spec/fixtures/stub-download.zip +0 -0
- data/spec/fixtures/test-cache.yml +18 -0
- data/spec/fixtures/test-index.yml +2 -0
- data/spec/fixtures/test_component.rb +0 -0
- data/spec/fixtures/zip-contents/test-directory/test-deep-file +0 -0
- data/spec/fixtures/zip-contents/test-file +0 -0
- data/spec/spec_helper.rb +30 -0
- metadata +416 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Encoding: utf-8
|
|
2
|
+
# # Copyright 2013-2014 the original author or authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'buildpack_support/rake'
|
|
17
|
+
require 'rake'
|
|
18
|
+
require 'rake/tasklib'
|
|
19
|
+
|
|
20
|
+
module BuildpackSupport
|
|
21
|
+
module Rake
|
|
22
|
+
|
|
23
|
+
# A task generator for the +check_api_doc+ task
|
|
24
|
+
class CheckAPIDocTask < ::Rake::TaskLib
|
|
25
|
+
|
|
26
|
+
# @!attribute [rw] name
|
|
27
|
+
# @return [String] the name of the task. Defaults to +:check_api_doc+.
|
|
28
|
+
attr_accessor :name
|
|
29
|
+
|
|
30
|
+
# @!attribute [rw] verbose
|
|
31
|
+
# @return [Boolean] the verbosity of the task. Defaults to +true+.
|
|
32
|
+
attr_accessor :verbose
|
|
33
|
+
|
|
34
|
+
# Creates a new instance of the +check_api_doc+ task
|
|
35
|
+
def initialize(*args, &task_block)
|
|
36
|
+
setup_ivars args
|
|
37
|
+
|
|
38
|
+
desc 'Check that all APIs have been documented' unless ::Rake.application.last_comment
|
|
39
|
+
task(name, *args) do |_, task_args|
|
|
40
|
+
task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
|
|
41
|
+
run_task verbose
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Run the main task functionality
|
|
46
|
+
#
|
|
47
|
+
# @param [Boolean] verbose whether to print the detailed output of the failure
|
|
48
|
+
# @return [void]
|
|
49
|
+
def run_task(verbose)
|
|
50
|
+
output = `yard stats --list-undoc`
|
|
51
|
+
abort message(output, verbose) if output !~ /100.00% documented/
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def message(output, verbose)
|
|
57
|
+
message = "\nFailed due to undocumented public API"
|
|
58
|
+
message += ":\n\n#{output}" if verbose
|
|
59
|
+
message
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def setup_ivars(args)
|
|
63
|
+
@name = args.shift || :check_api_doc
|
|
64
|
+
@verbose = true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Encoding: utf-8
|
|
2
|
+
# # Copyright 2013-2014 the original author or authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'buildpack_support/cache/download_cache'
|
|
17
|
+
require 'buildpack_support/logging/logger_factory'
|
|
18
|
+
require 'buildpack_support/rake'
|
|
19
|
+
require 'buildpack_support/rake/cached_artifact_finder'
|
|
20
|
+
require 'buildpack_support/rake/repository_configuration_finder'
|
|
21
|
+
require 'rake'
|
|
22
|
+
require 'rake/tasklib'
|
|
23
|
+
require 'pathname'
|
|
24
|
+
# require 'yaml'
|
|
25
|
+
|
|
26
|
+
module BuildpackSupport
|
|
27
|
+
module Rake
|
|
28
|
+
|
|
29
|
+
# A task generator for tasks that download and cache buildpack dependencies
|
|
30
|
+
class DependencyCacheTask < ::Rake::TaskLib
|
|
31
|
+
|
|
32
|
+
# @!attribute [rw] build_dir
|
|
33
|
+
# @return [String] the directory to caching log file into
|
|
34
|
+
attr_accessor :build_dir
|
|
35
|
+
|
|
36
|
+
# @!attribute [rw] package_name
|
|
37
|
+
# @return [String] the name of the package
|
|
38
|
+
attr_accessor :package_name
|
|
39
|
+
|
|
40
|
+
# @!attribute [rw] staging_dir
|
|
41
|
+
# @return [String] the directory to zip the contents of
|
|
42
|
+
attr_accessor :staging_dir
|
|
43
|
+
|
|
44
|
+
# @!attribute [rw] verbose
|
|
45
|
+
# @return [Boolean] the verbosity of the task. Defaults to +false+.
|
|
46
|
+
attr_accessor :verbose
|
|
47
|
+
|
|
48
|
+
def initialize(&task_block)
|
|
49
|
+
@verbose = true
|
|
50
|
+
|
|
51
|
+
task_block.call(*[self].slice(0, task_block.arity)) if task_block
|
|
52
|
+
abort 'build_dir must be configured' unless build_dir
|
|
53
|
+
abort 'package_name must be configured' unless package_name
|
|
54
|
+
abort 'staging_dir must be configured' unless staging_dir
|
|
55
|
+
|
|
56
|
+
BuildpackSupport::Logging::LoggerFactory.instance.setup "#{build_dir}/"
|
|
57
|
+
@cache = BuildpackSupport::Cache::DownloadCache.new(Pathname.new("#{staging_dir}/resources/cache"))
|
|
58
|
+
|
|
59
|
+
create_cache_tasks package_name, verbose
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Runs the task
|
|
63
|
+
#
|
|
64
|
+
# @param [String] target the URI to cache
|
|
65
|
+
# @param [Boolean] verbose whether to print messages to the console
|
|
66
|
+
# @return [void]
|
|
67
|
+
def run_task(target, verbose)
|
|
68
|
+
rake_output_message "Caching #{target}" if verbose
|
|
69
|
+
@cache.get(target) {}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def create_cache_tasks(package_name, verbose)
|
|
75
|
+
configurations = RepositoryConfigurationFinder.new.find
|
|
76
|
+
uris = CachedArtifactFinder.new.find configurations
|
|
77
|
+
|
|
78
|
+
uris.each do |target|
|
|
79
|
+
task package_name => target
|
|
80
|
+
task(target) { |t| run_task t.name, verbose }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Encoding: utf-8
|
|
2
|
+
# # Copyright 2013-2014 the original author or authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'buildpack_support/rake'
|
|
17
|
+
require 'rake'
|
|
18
|
+
require 'rake/tasklib'
|
|
19
|
+
|
|
20
|
+
module BuildpackSupport
|
|
21
|
+
module Rake
|
|
22
|
+
|
|
23
|
+
# A task generator for the task that disables remote downloads
|
|
24
|
+
class DisableRemoteDownloadsTask < ::Rake::TaskLib
|
|
25
|
+
|
|
26
|
+
# @!attribute [rw] package_name
|
|
27
|
+
# @return [String] the name of the package
|
|
28
|
+
attr_accessor :package_name
|
|
29
|
+
|
|
30
|
+
# @!attribute [rw] staging_dir
|
|
31
|
+
# @return [String] the directory to zip the contents of
|
|
32
|
+
attr_accessor :staging_dir
|
|
33
|
+
|
|
34
|
+
# @!attribute [rw] verbose
|
|
35
|
+
# @return [Boolean] the verbosity of the task. Defaults to +true+.
|
|
36
|
+
attr_accessor :verbose
|
|
37
|
+
|
|
38
|
+
def initialize(&task_block)
|
|
39
|
+
@verbose = false
|
|
40
|
+
|
|
41
|
+
task_block.call(*[self].slice(0, task_block.arity)) if task_block
|
|
42
|
+
abort 'package_name must be configured' unless package_name
|
|
43
|
+
abort 'staging_dir must be configured' unless staging_dir
|
|
44
|
+
|
|
45
|
+
create_task package_name, staging_dir, verbose
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Runs the task
|
|
49
|
+
#
|
|
50
|
+
# @param [String] source the name of the file to read from
|
|
51
|
+
# @param [String] target the name of the file to write to
|
|
52
|
+
# @param [Boolean] verbose whether to print messages to the console
|
|
53
|
+
# @return [void]
|
|
54
|
+
def run_task(source, target, verbose)
|
|
55
|
+
RakeFileUtils.verbose(verbose) do
|
|
56
|
+
mkdir_p File.dirname target
|
|
57
|
+
|
|
58
|
+
content = File.open(source, 'r') { |f| f.read.gsub(/enabled/, 'disabled') }
|
|
59
|
+
File.open(target, 'w') { |f| f.write content }
|
|
60
|
+
rake_output_message "Disabled remote downloads in #{target}" if verbose
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def create_task(package_name, staging_dir, verbose)
|
|
67
|
+
target = target(staging_dir)
|
|
68
|
+
|
|
69
|
+
task package_name => target
|
|
70
|
+
file(target) { |t| run_task t.source, t.name, verbose }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def target(staging_dir)
|
|
74
|
+
"#{staging_dir}/config/cache.yml"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Encoding: utf-8
|
|
2
|
+
# # Copyright 2013-2014 the original author or authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'buildpack_support/buildpack_version'
|
|
17
|
+
require 'buildpack_support/rake'
|
|
18
|
+
require 'buildpack_support/rake/buildpack_stage_task'
|
|
19
|
+
require 'buildpack_support/rake/dependency_cache_task'
|
|
20
|
+
require 'buildpack_support/rake/disable_remote_downloads_task'
|
|
21
|
+
require 'buildpack_support/rake/package_zip_task'
|
|
22
|
+
require 'buildpack_support/rake/write_version_file_task'
|
|
23
|
+
require 'rake'
|
|
24
|
+
require 'rake/clean'
|
|
25
|
+
require 'rake/tasklib'
|
|
26
|
+
|
|
27
|
+
module BuildpackSupport
|
|
28
|
+
module Rake
|
|
29
|
+
|
|
30
|
+
# A task generator for the +package+ task. Responsible for creating the +package+ task and all of the sub-tasks
|
|
31
|
+
# that are required to do the work of creating the package
|
|
32
|
+
class PackageTask < ::Rake::TaskLib
|
|
33
|
+
|
|
34
|
+
# @!attribute [rw] build_dir
|
|
35
|
+
# @return [String] the directory to place the created package in. Defaults to +build+.
|
|
36
|
+
attr_accessor :build_dir
|
|
37
|
+
|
|
38
|
+
# @!attribute [rw] files
|
|
39
|
+
# @return [Array<String>] the files to copy to the +staging_dir+
|
|
40
|
+
attr_accessor :files
|
|
41
|
+
|
|
42
|
+
# @!attribute [rw] name
|
|
43
|
+
# @return [String] the name of the task. Defaults to +:package+.
|
|
44
|
+
attr_accessor :name
|
|
45
|
+
|
|
46
|
+
# @!attribute [rw] prefix
|
|
47
|
+
# @return [String] the prefix of the package that is created
|
|
48
|
+
attr_accessor :prefix
|
|
49
|
+
|
|
50
|
+
# @!attribute [rw] staging_dir
|
|
51
|
+
# @return [String] the directory to zip the contents of. Defaults to +build/staging+.
|
|
52
|
+
attr_accessor :staging_dir
|
|
53
|
+
|
|
54
|
+
# @!attribute [rw] verbose
|
|
55
|
+
# @return [Boolean] the verbosity of the task
|
|
56
|
+
attr_accessor :verbose
|
|
57
|
+
|
|
58
|
+
def initialize(*args, &task_block)
|
|
59
|
+
setup_ivars args
|
|
60
|
+
|
|
61
|
+
task_block.call(*[self].slice(0, task_block.arity)) if task_block
|
|
62
|
+
abort 'package prefix must be configured' unless prefix
|
|
63
|
+
|
|
64
|
+
CLEAN.include build_dir, staging_dir
|
|
65
|
+
|
|
66
|
+
desc 'Create packaged buildpack' unless ::Rake.application.last_comment
|
|
67
|
+
task(name, *args)
|
|
68
|
+
task name => package_name
|
|
69
|
+
|
|
70
|
+
add_universal_tasks
|
|
71
|
+
add_offline_tasks if @buildpack_version.offline
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def add_offline_tasks
|
|
77
|
+
DependencyCacheTask.new do |t|
|
|
78
|
+
t.build_dir = build_dir
|
|
79
|
+
t.package_name = package_name
|
|
80
|
+
t.staging_dir = staging_dir
|
|
81
|
+
t.verbose = verbose unless verbose.nil?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
DisableRemoteDownloadsTask.new do |t|
|
|
85
|
+
t.package_name = package_name
|
|
86
|
+
t.staging_dir = staging_dir
|
|
87
|
+
t.verbose = verbose unless verbose.nil?
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def add_universal_tasks
|
|
92
|
+
PackageZipTask.new do |t|
|
|
93
|
+
t.package_name = package_name
|
|
94
|
+
t.staging_dir = staging_dir
|
|
95
|
+
t.verbose = verbose unless verbose.nil?
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
BuildpackStageTask.new do |t|
|
|
99
|
+
t.files = files
|
|
100
|
+
t.package_name = package_name
|
|
101
|
+
t.staging_dir = staging_dir
|
|
102
|
+
t.verbose = verbose unless verbose.nil?
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
WriteVersionFileTask.new do |t|
|
|
106
|
+
t.buildpack_version = @buildpack_version
|
|
107
|
+
t.package_name = package_name
|
|
108
|
+
t.staging_dir = staging_dir
|
|
109
|
+
t.verbose = verbose unless verbose.nil?
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def package_name
|
|
114
|
+
package_name = "#{build_dir}/#{prefix}"
|
|
115
|
+
package_name += '-offline' if @buildpack_version.offline
|
|
116
|
+
package_name + "-#{version}.zip"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def setup_ivars(args)
|
|
120
|
+
@name = args.shift || :package
|
|
121
|
+
@build_dir = 'build'
|
|
122
|
+
@buildpack_version = BuildpackSupport::BuildpackVersion.new(false)
|
|
123
|
+
@staging_dir = 'build/staging'
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def version
|
|
127
|
+
@buildpack_version.version || 'unknown'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Encoding: utf-8
|
|
2
|
+
# # Copyright 2013-2014 the original author or authors.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'buildpack_support/rake'
|
|
17
|
+
require 'rake'
|
|
18
|
+
require 'rake/tasklib'
|
|
19
|
+
require 'zip'
|
|
20
|
+
|
|
21
|
+
module BuildpackSupport
|
|
22
|
+
module Rake
|
|
23
|
+
|
|
24
|
+
# A task generator for the task that creates the package zip file.
|
|
25
|
+
class PackageZipTask < ::Rake::TaskLib
|
|
26
|
+
|
|
27
|
+
# @!attribute [rw] package_name
|
|
28
|
+
# @return [String] the name of the package
|
|
29
|
+
attr_accessor :package_name
|
|
30
|
+
|
|
31
|
+
# @!attribute [rw] staging_dir
|
|
32
|
+
# @return [String] the directory to zip the contents of
|
|
33
|
+
attr_accessor :staging_dir
|
|
34
|
+
|
|
35
|
+
# @!attribute [rw] verbose
|
|
36
|
+
# @return [Boolean] the verbosity of the task. Defaults to +true+.
|
|
37
|
+
attr_accessor :verbose
|
|
38
|
+
|
|
39
|
+
def initialize(&task_block)
|
|
40
|
+
@verbose = false
|
|
41
|
+
|
|
42
|
+
task_block.call(*[self].slice(0, task_block.arity)) if task_block
|
|
43
|
+
abort 'package_name must be configured' unless package_name
|
|
44
|
+
abort 'staging_dir must be configured' unless staging_dir
|
|
45
|
+
|
|
46
|
+
task(package_name) { |t| run_task t.name, staging_dir, verbose }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Runs the task
|
|
50
|
+
#
|
|
51
|
+
# @param [String] name the name of the ZIP file to create
|
|
52
|
+
# @param [String] staging_dir the directory to ZIP up
|
|
53
|
+
# @param [Boolean] verbose whether to print messages to the console
|
|
54
|
+
# @return [void]
|
|
55
|
+
def run_task(name, staging_dir, verbose)
|
|
56
|
+
RakeFileUtils.verbose(verbose) do
|
|
57
|
+
mkdir_p File.dirname(name)
|
|
58
|
+
|
|
59
|
+
Zip::File.open(name, Zip::File::CREATE) do |zipfile|
|
|
60
|
+
Dir[File.join(staging_dir, '**', '**')].each do |file|
|
|
61
|
+
relative_path = relative_path(file, staging_dir)
|
|
62
|
+
rake_output_message "a #{relative_path}" if verbose
|
|
63
|
+
zipfile.add(relative_path, file)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
rake_output_message "Created package #{name}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def relative_path(file, staging_dir)
|
|
74
|
+
file.sub("#{staging_dir}/", '')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|