|
21 | 21 | require 'java_buildpack/util/configuration_utils' |
22 | 22 | require 'java_buildpack/util/cache/download_cache' |
23 | 23 | require 'java_buildpack/util/snake_case' |
24 | | -require 'offline' |
| 24 | +require 'rake/tasklib' |
| 25 | +require 'rakelib/package' |
25 | 26 | require 'pathname' |
26 | 27 | require 'yaml' |
27 | 28 |
|
28 | | -module Offline |
| 29 | +module Package |
29 | 30 |
|
30 | 31 | class DependencyCacheTask < Rake::TaskLib |
31 | | - include Offline |
32 | | - |
33 | | - attr_reader :targets |
| 32 | + include Package |
34 | 33 |
|
35 | 34 | def initialize |
36 | | - JavaBuildpack::Logging::LoggerFactory.instance.setup "#{BUILD_DIR}/" |
| 35 | + if OFFLINE |
| 36 | + JavaBuildpack::Logging::LoggerFactory.instance.setup "#{BUILD_DIR}/" |
37 | 37 |
|
38 | | - @default_repository_root = configuration('repository')['default_repository_root'].chomp('/') |
39 | | - @cache = cache |
| 38 | + @default_repository_root = default_repository_root |
| 39 | + @cache = cache |
40 | 40 |
|
41 | | - configurations = component_ids.map { |component_id| configurations(configuration(component_id)) }.flatten |
42 | | - @targets = uris(configurations).each { |uri| create_task(uri) } |
| 41 | + configurations = component_ids.map { |component_id| configurations(configuration(component_id)) }.flatten |
| 42 | + uris(configurations).each { |uri| create_task(uri) } |
| 43 | + end |
43 | 44 | end |
44 | 45 |
|
45 | | - end |
| 46 | + private |
46 | 47 |
|
47 | | - private |
| 48 | + ARCHITECTURE_PATTERN = /\{architecture\}/.freeze |
48 | 49 |
|
49 | | - ARCHITECTURE_PATTERN = /\{architecture\}/.freeze |
| 50 | + DEFAULT_REPOSITORY_ROOT_PATTERN = /\{default.repository.root\}/.freeze |
50 | 51 |
|
51 | | - DEFAULT_REPOSITORY_ROOT_PATTERN = /\{default.repository.root\}/.freeze |
| 52 | + PLATFORM_PATTERN = /\{platform\}/.freeze |
52 | 53 |
|
53 | | - PLATFORM_PATTERN = /\{platform\}/.freeze |
| 54 | + def augment(raw, pattern, candidates, &block) |
| 55 | + if raw.respond_to? :map |
| 56 | + raw.map(&block) |
| 57 | + else |
| 58 | + raw =~ pattern ? candidates.map { |p| raw.gsub pattern, p } : raw |
| 59 | + end |
| 60 | + end |
54 | 61 |
|
55 | | - def augment(raw, pattern, candidates, &block) |
56 | | - if raw.respond_to? :map |
57 | | - raw.map(&block) |
58 | | - else |
59 | | - raw =~ pattern ? candidates.map { |p| raw.gsub pattern, p } : raw |
| 62 | + def augment_architecture(raw) |
| 63 | + augment(raw, ARCHITECTURE_PATTERN, ARCHITECTURES) { |r| augment_architecture r } |
60 | 64 | end |
61 | | - end |
62 | 65 |
|
63 | | - def augment_architecture(raw) |
64 | | - augment(raw, ARCHITECTURE_PATTERN, ARCHITECTURES) { |r| augment_architecture r } |
65 | | - end |
| 66 | + def augment_path(raw) |
| 67 | + if raw.respond_to? :map |
| 68 | + raw.map { |r| augment_path r } |
| 69 | + else |
| 70 | + "#{raw.chomp('/')}/index.yml" |
| 71 | + end |
| 72 | + end |
66 | 73 |
|
67 | | - def augment_path(raw) |
68 | | - if raw.respond_to? :map |
69 | | - raw.map { |r| augment_path r } |
70 | | - else |
71 | | - "#{raw.chomp('/')}/index.yml" |
| 74 | + def augment_platform(raw) |
| 75 | + augment(raw, PLATFORM_PATTERN, PLATFORMS) { |r| augment_platform r } |
72 | 76 | end |
73 | | - end |
74 | 77 |
|
75 | | - def augment_platform(raw) |
76 | | - augment(raw, PLATFORM_PATTERN, PLATFORMS) { |r| augment_platform r } |
77 | | - end |
| 78 | + def augment_repository_root(raw) |
| 79 | + if raw.respond_to? :map |
| 80 | + raw.map { |r| augment_repository_root r } |
| 81 | + else |
| 82 | + raw.gsub DEFAULT_REPOSITORY_ROOT_PATTERN, @default_repository_root |
| 83 | + end |
| 84 | + end |
78 | 85 |
|
79 | | - def augment_repository_root(raw) |
80 | | - if raw.respond_to? :map |
81 | | - raw.map { |r| augment_repository_root r } |
82 | | - else |
83 | | - raw.gsub DEFAULT_REPOSITORY_ROOT_PATTERN, @default_repository_root |
| 86 | + def cache |
| 87 | + JavaBuildpack::Util::Cache::DownloadCache.new(Pathname.new("#{STAGING_DIR}/resources/cache")).freeze |
84 | 88 | end |
85 | | - end |
86 | 89 |
|
87 | | - def cache |
88 | | - JavaBuildpack::Util::Cache::DownloadCache.new(Pathname.new("#{STAGING_DIR}/resources/cache")).freeze |
89 | | - end |
| 90 | + def component_ids |
| 91 | + configuration('components').values.flatten.map { |component| component.split('::').last.snake_case } |
| 92 | + end |
90 | 93 |
|
91 | | - def component_ids |
92 | | - configuration('components').values.flatten.map { |component| component.split('::').last.snake_case } |
93 | | - end |
| 94 | + def configuration(id) |
| 95 | + JavaBuildpack::Util::ConfigurationUtils.load id, false |
| 96 | + end |
94 | 97 |
|
95 | | - def configuration(id) |
96 | | - JavaBuildpack::Util::ConfigurationUtils.load(id, false) |
97 | | - end |
| 98 | + def configurations(configuration) |
| 99 | + configurations = [] |
98 | 100 |
|
99 | | - def configurations(configuration) |
100 | | - configurations = [] |
| 101 | + if repository_configuration?(configuration) |
| 102 | + configurations << configuration |
| 103 | + else |
| 104 | + configurations << configuration.values.map { |v| configurations(v) } |
| 105 | + end |
101 | 106 |
|
102 | | - if repository_configuration?(configuration) |
103 | | - configurations << configuration |
104 | | - else |
105 | | - configurations << configuration.values.map { |v| configurations(v) } |
| 107 | + configurations |
106 | 108 | end |
107 | 109 |
|
108 | | - configurations |
109 | | - end |
| 110 | + def default_repository_root |
| 111 | + configuration('repository')['default_repository_root'].chomp('/') |
| 112 | + end |
110 | 113 |
|
111 | | - def index_uris(configuration) |
112 | | - [configuration['repository_root']] |
113 | | - .map { |r| augment_repository_root r } |
114 | | - .map { |r| augment_platform r } |
115 | | - .map { |r| augment_architecture r } |
116 | | - .map { |r| augment_path r }.flatten |
117 | | - end |
| 114 | + def index_uris(configuration) |
| 115 | + [configuration['repository_root']] |
| 116 | + .map { |r| augment_repository_root r } |
| 117 | + .map { |r| augment_platform r } |
| 118 | + .map { |r| augment_architecture r } |
| 119 | + .map { |r| augment_path r }.flatten |
| 120 | + end |
118 | 121 |
|
119 | | - def repository_configuration?(configuration) |
120 | | - configuration['version'] && configuration['repository_root'] |
121 | | - end |
| 122 | + def repository_configuration?(configuration) |
| 123 | + configuration['version'] && configuration['repository_root'] |
| 124 | + end |
122 | 125 |
|
123 | | - def uris(configurations) |
124 | | - uris = [] |
| 126 | + def uris(configurations) |
| 127 | + uris = [] |
125 | 128 |
|
126 | | - configurations.each do |configuration| |
127 | | - index_uris(configuration).each do |index_uri| |
128 | | - @cache.get(index_uri) do |file| |
129 | | - index = YAML.load(file) |
130 | | - uris << index[version(configuration, index).to_s] |
| 129 | + configurations.each do |configuration| |
| 130 | + index_uris(configuration).each do |index_uri| |
| 131 | + @cache.get(index_uri) do |f| |
| 132 | + index = YAML.load f |
| 133 | + uris << index[version(configuration, index).to_s] |
| 134 | + end |
131 | 135 | end |
132 | 136 | end |
| 137 | + |
| 138 | + uris |
133 | 139 | end |
134 | 140 |
|
135 | | - uris |
136 | | - end |
| 141 | + def version(configuration, index) |
| 142 | + JavaBuildpack::Repository::VersionResolver.resolve(JavaBuildpack::Util::TokenizedVersion.new(configuration['version']), index.keys) |
| 143 | + end |
137 | 144 |
|
138 | | - def version(configuration, index) |
139 | | - JavaBuildpack::Repository::VersionResolver.resolve(JavaBuildpack::Util::TokenizedVersion.new(configuration['version']), index.keys) |
140 | | - end |
| 145 | + def create_task(uri) |
| 146 | + task uri do |t| |
| 147 | + rake_output_message "Caching #{t.name}" |
| 148 | + cache.get(t.name) {} |
| 149 | + end |
141 | 150 |
|
142 | | - def create_task(uri) |
143 | | - task uri do |t| |
144 | | - rake_output_message "Caching #{t.name}" |
145 | | - cache.get(t.name) |
| 151 | + task PACKAGE_NAME => [uri] |
146 | 152 | end |
147 | 153 |
|
148 | | - uri |
149 | 154 | end |
150 | 155 |
|
151 | 156 | end |
0 commit comments