@@ -53,36 +53,43 @@ def initialize
5353
5454 private_constant :ARCHITECTURE_PATTERN , :DEFAULT_REPOSITORY_ROOT_PATTERN , :PLATFORM_PATTERN
5555
56- def augment ( raw , pattern , candidates , &block )
57- if raw . respond_to? :map
56+ def augment ( raw , key , pattern , candidates , &block )
57+ if raw . respond_to? :at
5858 raw . map ( &block )
5959 else
60- raw =~ pattern ? candidates . map { |p | raw . gsub pattern , p } : raw
60+ if raw [ :uri ] =~ pattern
61+ candidates . map do |candidate |
62+ dup = raw . clone
63+ dup [ key ] = candidate
64+ dup [ :uri ] = raw [ :uri ] . gsub pattern , candidate
65+
66+ dup
67+ end
68+ else
69+ raw
70+ end
6171 end
6272 end
6373
6474 def augment_architecture ( raw )
65- augment ( raw , ARCHITECTURE_PATTERN , ARCHITECTURES ) { |r | augment_architecture r }
75+ augment ( raw , :architecture , ARCHITECTURE_PATTERN , ARCHITECTURES ) { |r | augment_architecture r }
6676 end
6777
6878 def augment_path ( raw )
69- if raw . respond_to? :map
79+ if raw . respond_to? :at
7080 raw . map { |r | augment_path r }
7181 else
72- "#{ raw . chomp ( '/' ) } /index.yml"
82+ raw [ :uri ] = "#{ raw [ :uri ] . chomp ( '/' ) } /index.yml"
83+ raw
7384 end
7485 end
7586
7687 def augment_platform ( raw )
77- augment ( raw , PLATFORM_PATTERN , PLATFORMS ) { |r | augment_platform r }
88+ augment ( raw , :platform , PLATFORM_PATTERN , PLATFORMS ) { |r | augment_platform r }
7889 end
7990
8091 def augment_repository_root ( raw )
81- if raw . respond_to? :map
82- raw . map { |r | augment_repository_root r }
83- else
84- raw . gsub DEFAULT_REPOSITORY_ROOT_PATTERN , @default_repository_root
85- end
92+ augment ( raw , :repository_root , DEFAULT_REPOSITORY_ROOT_PATTERN , [ @default_repository_root ] ) { |r | augment_repository_root r }
8693 end
8794
8895 def cache
@@ -122,8 +129,9 @@ def default_repository_root
122129 configuration ( 'repository' ) [ 'default_repository_root' ] . chomp ( '/' )
123130 end
124131
125- def index_uris ( configuration )
132+ def index_configuration ( configuration )
126133 [ configuration [ 'repository_root' ] ]
134+ . map { |r | { uri : r } }
127135 . map { |r | augment_repository_root r }
128136 . map { |r | augment_platform r }
129137 . map { |r | augment_architecture r }
@@ -138,12 +146,14 @@ def uris(configurations)
138146 uris = [ ]
139147
140148 configurations . each do |configuration |
141- index_uris ( configuration ) . each do |index_uri |
142- multitask PACKAGE_NAME => [ cache_task ( index_uri ) ]
143-
144- @cache . get ( index_uri ) do |f |
145- index = YAML . load f
146- uris << index [ version ( configuration , index ) . to_s ]
149+ index_configuration ( configuration ) . each do |index_configuration |
150+ multitask PACKAGE_NAME => [ cache_task ( index_configuration [ :uri ] ) ]
151+
152+ @cache . get ( index_configuration [ :uri ] ) do |f |
153+ index = YAML . load f
154+ found_version = version ( configuration , index )
155+ rake_output_message "Unable to resolve version '#{ configuration [ 'version' ] } ' for platform '#{ index_configuration [ :platform ] } '" if found_version . nil?
156+ uris << index [ found_version . to_s ] unless found_version . nil?
147157 end
148158 end
149159 end
0 commit comments