fig 0.1.73 → 0.1.75

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Changes +75 -0
  2. data/lib/fig.rb +1 -1
  3. data/lib/fig/command.rb +36 -12
  4. data/lib/fig/command/action.rb +1 -1
  5. data/lib/fig/command/action/dump_package_definition_parsed.rb +4 -6
  6. data/lib/fig/command/action/run_command_statement.rb +3 -2
  7. data/lib/fig/command/options.rb +12 -3
  8. data/lib/fig/command/options/parser.rb +2 -0
  9. data/lib/fig/command/package_loader.rb +1 -0
  10. data/lib/fig/config_file_error.rb +1 -1
  11. data/lib/fig/grammar/base.rb +214 -0
  12. data/lib/fig/grammar/base.treetop +29 -0
  13. data/lib/fig/grammar/v0.rb +1493 -0
  14. data/lib/fig/grammar/v0.treetop +167 -0
  15. data/lib/fig/grammar/v1.rb +1478 -0
  16. data/lib/fig/grammar/v1.treetop +174 -0
  17. data/lib/fig/grammar/version.rb +144 -0
  18. data/lib/fig/grammar/version.treetop +22 -0
  19. data/lib/fig/grammar/version_identification.rb +113 -0
  20. data/lib/fig/grammar/version_identification.treetop +27 -0
  21. data/lib/fig/log4r_config_error.rb +1 -1
  22. data/lib/fig/no_such_package_config_error.rb +1 -1
  23. data/lib/fig/not_found_error.rb +7 -0
  24. data/lib/fig/operating_system.rb +31 -20
  25. data/lib/fig/package.rb +8 -3
  26. data/lib/fig/package_definition_text_assembler.rb +88 -0
  27. data/lib/fig/package_descriptor_parse_error.rb +1 -1
  28. data/lib/fig/parser.rb +115 -29
  29. data/lib/fig/parser_package_build_state.rb +38 -11
  30. data/lib/fig/repository.rb +5 -8
  31. data/lib/fig/repository_package_publisher.rb +114 -96
  32. data/lib/fig/runtime_environment.rb +42 -14
  33. data/lib/fig/statement.rb +133 -0
  34. data/lib/fig/statement/archive.rb +6 -4
  35. data/lib/fig/statement/asset.rb +28 -34
  36. data/lib/fig/statement/command.rb +6 -2
  37. data/lib/fig/statement/configuration.rb +4 -12
  38. data/lib/fig/statement/grammar_version.rb +22 -0
  39. data/lib/fig/statement/include.rb +5 -6
  40. data/lib/fig/statement/override.rb +6 -3
  41. data/lib/fig/statement/path.rb +12 -2
  42. data/lib/fig/statement/resource.rb +8 -8
  43. data/lib/fig/statement/retrieve.rb +11 -3
  44. data/lib/fig/statement/set.rb +12 -2
  45. data/lib/fig/unparser.rb +127 -0
  46. data/lib/fig/unparser/v0.rb +84 -0
  47. data/lib/fig/unparser/v1.rb +77 -0
  48. data/lib/fig/url.rb +7 -0
  49. metadata +139 -25
  50. data/lib/fig/grammar.treetop +0 -147
@@ -4,6 +4,7 @@ require 'fig/statement'
4
4
  require 'fig/statement/archive'
5
5
  require 'fig/statement/command'
6
6
  require 'fig/statement/configuration'
7
+ require 'fig/statement/grammar_version'
7
8
  require 'fig/statement/include'
8
9
  require 'fig/statement/override'
9
10
  require 'fig/statement/path'
@@ -43,22 +44,45 @@ class Fig::ParserPackageBuildState
43
44
  )
44
45
  end
45
46
 
46
- def new_package_statement(directory, statements)
47
+ def new_package_statement(directory, grammar_node, statement_nodes)
48
+ grammar_statement = nil
49
+ if grammar_node && ! grammar_node.empty?
50
+ grammar_statement = grammar_node.to_package_statement(self)
51
+ else
52
+ grammar_statement = Fig::Statement::GrammarVersion.new(
53
+ nil,
54
+ %Q<[synthetic statement created in #{__FILE__} line #{__LINE__}]>,
55
+ 0 # Grammar version
56
+ )
57
+ end
58
+ statement_objects = [grammar_statement]
59
+
60
+ statement_nodes.elements.each do
61
+ |node|
62
+
63
+ statement_objects << node.to_package_statement(self)
64
+ end
65
+
47
66
  return Fig::Package.new(
48
67
  descriptor.name,
49
68
  descriptor.version,
50
69
  directory,
51
- statements.elements.map do
52
- |statement|
53
- statement.to_package_statement(self)
54
- end
70
+ statement_objects
71
+ )
72
+ end
73
+
74
+ def new_grammar_version_statement(keyword_node, version_node)
75
+ return Fig::Statement::GrammarVersion.new(
76
+ node_location(keyword_node),
77
+ source_description,
78
+ version_node.text_value.to_i
55
79
  )
56
80
  end
57
81
 
58
82
  def new_asset_statement(statement_class, keyword_node, url_node)
59
83
  url = url_node.text_value
60
84
 
61
- statement_class.validate_url(url) {
85
+ need_to_glob = statement_class.validate_and_process_escapes_in_url!(url) {
62
86
  |error_description|
63
87
 
64
88
  raise_invalid_value_parse_error(
@@ -67,7 +91,7 @@ class Fig::ParserPackageBuildState
67
91
  }
68
92
 
69
93
  return statement_class.new(
70
- node_location(keyword_node), source_description, url
94
+ node_location(keyword_node), source_description, url, need_to_glob
71
95
  )
72
96
  end
73
97
 
@@ -87,14 +111,17 @@ class Fig::ParserPackageBuildState
87
111
  )
88
112
  end
89
113
 
114
+ statement_objects = statements.elements.map do
115
+ |statement|
116
+
117
+ statement.to_config_statement(self)
118
+ end
119
+
90
120
  return Fig::Statement::Configuration.new(
91
121
  node_location(keyword_node),
92
122
  source_description,
93
123
  name_node.text_value,
94
- statements.elements.map do
95
- |statement|
96
- statement.to_config_statement(self)
97
- end
124
+ statement_objects
98
125
  )
99
126
  end
100
127
 
@@ -13,6 +13,7 @@ require 'fig/package_descriptor'
13
13
  require 'fig/parser'
14
14
  require 'fig/repository_error'
15
15
  require 'fig/repository_package_publisher'
16
+ require 'fig/url'
16
17
 
17
18
  module Fig; end
18
19
 
@@ -25,10 +26,6 @@ class Fig::Repository
25
26
  VERSION_FILE_NAME = 'repository-format-version'
26
27
  VERSION_SUPPORTED = 1
27
28
 
28
- def self.is_url?(url)
29
- not (/ftp:\/\/|https?:\/\/|file:\/\/|ssh:\/\// =~ url).nil?
30
- end
31
-
32
29
  def initialize(
33
30
  os,
34
31
  local_repository_directory,
@@ -268,9 +265,9 @@ class Fig::Repository
268
265
  temp_dir = package_download_temp_dir(descriptor)
269
266
  begin
270
267
  install_package(descriptor, temp_dir)
271
- rescue Fig::NotFoundError
268
+ rescue Fig::NotFoundError => error
272
269
  Fig::Logging.fatal \
273
- "Package not found in remote repository: #{descriptor.to_string()}"
270
+ "Package #{descriptor.to_string()} not found in remote repository. (Was looking for #{error.path}.)"
274
271
 
275
272
  delete_local_package(descriptor)
276
273
 
@@ -303,13 +300,13 @@ class Fig::Repository
303
300
  package = read_package_from_directory(temp_dir, descriptor)
304
301
 
305
302
  package.archive_urls.each do |archive_url|
306
- if not Fig::Repository.is_url?(archive_url)
303
+ if not Fig::URL.is_url?(archive_url)
307
304
  archive_url = remote_dir_for_package(descriptor) + '/' + archive_url
308
305
  end
309
306
  @operating_system.download_and_unpack_archive(archive_url, temp_dir)
310
307
  end
311
308
  package.resource_urls.each do |resource_url|
312
- if not Fig::Repository.is_url?(resource_url)
309
+ if not Fig::URL.is_url?(resource_url)
313
310
  resource_url =
314
311
  remote_dir_for_package(descriptor) + '/' + resource_url
315
312
  end
@@ -9,29 +9,42 @@ require 'fig/at_exit'
9
9
  require 'fig/logging'
10
10
  require 'fig/not_found_error'
11
11
  require 'fig/package_cache'
12
+ require 'fig/package_definition_text_assembler'
12
13
  require 'fig/package_descriptor'
13
14
  require 'fig/package_parse_error'
14
15
  require 'fig/parser'
15
16
  require 'fig/repository'
16
17
  require 'fig/repository_error'
17
18
  require 'fig/statement/archive'
19
+ require 'fig/statement/grammar_version'
18
20
  require 'fig/statement/resource'
21
+ require 'fig/url'
19
22
 
20
23
  module Fig; end
21
24
 
25
+ # Handles package publishing for the Repository.
22
26
  class Fig::RepositoryPackagePublisher
23
- attr_accessor :operating_system
24
- attr_accessor :publish_listeners
25
- attr_accessor :package_statements
26
- attr_accessor :descriptor
27
- attr_accessor :source_package
28
- attr_accessor :was_forced
29
- attr_accessor :base_temp_dir
30
- attr_accessor :local_dir_for_package
31
- attr_accessor :remote_dir_for_package
32
- attr_accessor :local_fig_file_for_package
33
- attr_accessor :remote_fig_file_for_package
34
- attr_accessor :local_only
27
+ attr_writer :operating_system
28
+ attr_writer :publish_listeners
29
+ attr_writer :descriptor
30
+ attr_writer :source_package
31
+ attr_writer :was_forced
32
+ attr_writer :base_temp_dir
33
+ attr_writer :local_dir_for_package
34
+ attr_writer :remote_dir_for_package
35
+ attr_writer :local_fig_file_for_package
36
+ attr_writer :remote_fig_file_for_package
37
+ attr_writer :local_only
38
+
39
+ def initialize()
40
+ @text_assembler = Fig::PackageDefinitionTextAssembler.new
41
+
42
+ return
43
+ end
44
+
45
+ def package_statements=(statements)
46
+ @text_assembler.add_input(statements)
47
+ end
35
48
 
36
49
  def publish_package()
37
50
  derive_publish_metadata()
@@ -47,9 +60,9 @@ class Fig::RepositoryPackagePublisher
47
60
 
48
61
  publish_package_contents
49
62
  if not @local_only
50
- @operating_system.upload(fig_file, remote_fig_file_for_package())
63
+ @operating_system.upload(fig_file, @remote_fig_file_for_package)
51
64
  end
52
- @operating_system.copy(fig_file, local_fig_file_for_package())
65
+ @operating_system.copy(fig_file, @local_fig_file_for_package)
53
66
 
54
67
  notify_listeners
55
68
 
@@ -60,8 +73,16 @@ class Fig::RepositoryPackagePublisher
60
73
 
61
74
  private
62
75
 
76
+ def derive_publish_metadata()
77
+ @publish_time = Time.now()
78
+ @publish_login = Sys::Admin.get_login()
79
+ @publish_host = Socket.gethostname()
80
+
81
+ return
82
+ end
83
+
63
84
  def validate_asset_names()
64
- asset_statements = @package_statements.select { |s| s.is_asset? }
85
+ asset_statements = @text_assembler.asset_input_statements
65
86
 
66
87
  asset_names = Set.new()
67
88
  asset_statements.each do
@@ -85,27 +106,12 @@ class Fig::RepositoryPackagePublisher
85
106
  end
86
107
  end
87
108
 
88
- def derive_publish_metadata()
89
- @publish_time = Time.now()
90
- @publish_login = Sys::Admin.get_login()
91
- @publish_host = Socket.gethostname()
92
-
93
- return
94
- end
95
-
96
109
  def derive_definition_file()
97
- @definition_file_lines = []
98
-
99
110
  add_package_metadata_comments()
100
- add_statements_to_publish_and_create_resource_archive()
111
+ add_output_statements_and_create_resource_archive()
101
112
  add_unparsed_text()
102
113
 
103
- @definition_file_lines.flatten!
104
- file_content = @definition_file_lines.join("\n")
105
- file_content.gsub!(/\n{3,}/, "\n\n")
106
- file_content.strip!
107
- file_content << "\n"
108
-
114
+ file_content = @text_assembler.assemble_package_definition()
109
115
  begin
110
116
  Fig::Parser.new(nil, false).parse_package(
111
117
  @descriptor,
@@ -123,34 +129,20 @@ class Fig::RepositoryPackagePublisher
123
129
  end
124
130
 
125
131
  def add_package_metadata_comments()
126
- @definition_file_lines <<
132
+ @text_assembler.add_header(
127
133
  %Q<# Publishing information for #{@descriptor.to_string()}:>
128
- @definition_file_lines << %q<#>
134
+ )
135
+ @text_assembler.add_header %q<#>
129
136
 
130
- @definition_file_lines <<
137
+ @text_assembler.add_header(
131
138
  %Q<# Time: #{@publish_time} (epoch: #{@publish_time.to_i()})>
139
+ )
132
140
 
133
- @definition_file_lines << %Q<# User: #{@publish_login}>
134
- @definition_file_lines << %Q<# Host: #{@publish_host}>
135
- @definition_file_lines << %Q<# Args: "#{ARGV.join %q[", "]}">
136
- @definition_file_lines << %Q<# Fig: v#{Fig::VERSION}>
137
- @definition_file_lines << %q<#>
138
-
139
- asset_statements =
140
- @package_statements.select { |statement| statement.is_asset? }
141
- asset_strings =
142
- asset_statements.collect { |statement| statement.unparse('# ') }
143
-
144
- if asset_strings.empty?
145
- @definition_file_lines <<
146
- %q<# There were no asset statements in the unpublished package definition.>
147
- else
148
- @definition_file_lines << %q<# Original asset statements: >
149
- @definition_file_lines << %q<#>
150
- @definition_file_lines << asset_strings
151
- end
152
-
153
- @definition_file_lines << %Q<\n>
141
+ @text_assembler.add_header %Q<# User: #{@publish_login}>
142
+ @text_assembler.add_header %Q<# Host: #{@publish_host}>
143
+ @text_assembler.add_header %Q<# Args: "#{ARGV.join %q[", "]}">
144
+ @text_assembler.add_header %Q<# Fig: v#{Fig::VERSION}>
145
+ @text_assembler.add_header %Q<\n>
154
146
 
155
147
  return
156
148
  end
@@ -159,37 +151,64 @@ class Fig::RepositoryPackagePublisher
159
151
  # files (those where the statement references a URL as opposed to a local
160
152
  # file) and then copies all files into the local repository and the remote
161
153
  # repository (if not a local-only publish).
162
- def add_statements_to_publish_and_create_resource_archive()
163
- initialize_statements_to_publish()
154
+ def add_output_statements_and_create_resource_archive()
155
+ assemble_output_statements()
164
156
  create_resource_archive()
165
157
 
166
- @statements_to_publish.each do
158
+ return
159
+ end
160
+
161
+ def assemble_output_statements()
162
+ @resource_paths = []
163
+
164
+ if (
165
+ @text_assembler.input_statements.empty? \
166
+ || ! @text_assembler.input_statements[0].is_a?(Fig::Statement::GrammarVersion)
167
+ )
168
+ @text_assembler.add_output Fig::Statement::GrammarVersion.new(
169
+ nil,
170
+ %Q<[synthetic statement created in #{__FILE__} line #{__LINE__}]>,
171
+ 0 # Grammar version
172
+ )
173
+ end
174
+
175
+ @text_assembler.input_statements.each do
167
176
  |statement|
168
177
 
169
178
  if statement.is_asset?
170
- @definition_file_lines <<
171
- statement.class.new(nil, nil, statement.asset_name).unparse('')
179
+ add_asset_to_output_statements(statement)
172
180
  else
173
- @definition_file_lines << statement.unparse('')
181
+ @text_assembler.add_output statement
174
182
  end
175
183
  end
176
184
 
177
185
  return
178
186
  end
179
187
 
180
- def initialize_statements_to_publish()
181
- @resource_paths = []
182
-
183
- @statements_to_publish = @package_statements.reject do |statement|
184
- if (
185
- statement.is_a?(Fig::Statement::Resource) &&
186
- ! Fig::Repository.is_url?(statement.url)
187
- )
188
- @resource_paths << statement.url
189
- true
188
+ def add_asset_to_output_statements(asset_statement)
189
+ if Fig::URL.is_url? asset_statement.url
190
+ @text_assembler.add_output asset_statement
191
+ elsif asset_statement.is_a? Fig::Statement::Archive
192
+ if asset_statement.requires_globbing?
193
+ expand_globs_from( [asset_statement.url] ).each do
194
+ |file|
195
+
196
+ @text_assembler.add_output(
197
+ Fig::Statement::Archive.new(
198
+ nil,
199
+ %Q<[synthetic statement created in #{__FILE__} line #{__LINE__}]>,
200
+ file,
201
+ false # No globbing
202
+ )
203
+ )
204
+ end
190
205
  else
191
- false
206
+ @text_assembler.add_output asset_statement
192
207
  end
208
+ elsif asset_statement.requires_globbing?
209
+ @resource_paths.concat expand_globs_from( [asset_statement.url] )
210
+ else
211
+ @resource_paths << asset_statement.url
193
212
  end
194
213
 
195
214
  return
@@ -197,15 +216,19 @@ class Fig::RepositoryPackagePublisher
197
216
 
198
217
  def create_resource_archive()
199
218
  if @resource_paths.size > 0
200
- asset_paths = expand_globs_from(@resource_paths)
201
- check_asset_paths(asset_paths)
219
+ check_asset_paths(@resource_paths)
202
220
 
203
221
  file = Fig::Repository::RESOURCES_FILE
204
- @operating_system.create_archive(file, asset_paths)
222
+ @operating_system.create_archive(file, @resource_paths)
205
223
  Fig::AtExit.add { File.delete(file) }
206
224
 
207
- @statements_to_publish.unshift(
208
- Fig::Statement::Archive.new(nil, nil, file)
225
+ @text_assembler.add_output(
226
+ Fig::Statement::Archive.new(
227
+ nil,
228
+ %Q<[synthetic statement created in #{__FILE__} line #{__LINE__}]>,
229
+ file,
230
+ false # No globbing
231
+ )
209
232
  )
210
233
  end
211
234
 
@@ -213,7 +236,7 @@ class Fig::RepositoryPackagePublisher
213
236
  end
214
237
 
215
238
  def publish_package_contents()
216
- @statements_to_publish.each do
239
+ @text_assembler.output_statements.each do
217
240
  |statement|
218
241
 
219
242
  if statement.is_asset?
@@ -226,9 +249,9 @@ class Fig::RepositoryPackagePublisher
226
249
 
227
250
  def publish_asset(asset_statement)
228
251
  asset_name = asset_statement.asset_name()
229
- asset_remote = "#{remote_dir_for_package()}/#{asset_name}"
252
+ asset_remote = "#{@remote_dir_for_package}/#{asset_name}"
230
253
 
231
- if Fig::Repository.is_url?(asset_statement.url)
254
+ if Fig::URL.is_url? asset_statement.url
232
255
  asset_local = File.join(publish_temp_dir(), asset_name)
233
256
 
234
257
  begin
@@ -243,9 +266,7 @@ class Fig::RepositoryPackagePublisher
243
266
  end
244
267
 
245
268
  if not @local_only
246
- @operating_system.upload(
247
- asset_local, asset_remote
248
- )
269
+ @operating_system.upload(asset_local, asset_remote)
249
270
  end
250
271
 
251
272
  @operating_system.copy(
@@ -255,20 +276,17 @@ class Fig::RepositoryPackagePublisher
255
276
  @operating_system.unpack_archive(@local_dir_for_package, asset_name)
256
277
  end
257
278
 
258
- @definition_file_lines <<
259
- asset_statement.class.new(nil, nil, asset_name).unparse('')
260
-
261
279
  return
262
280
  end
263
281
 
264
282
  def add_unparsed_text()
265
283
  if @source_package && @source_package.unparsed_text
266
-
267
- @definition_file_lines << ''
268
- @definition_file_lines << '# Original, unparsed package text:'
269
- @definition_file_lines << '#'
270
- @definition_file_lines <<
284
+ @text_assembler.add_footer ''
285
+ @text_assembler.add_footer '# Original, unparsed package text:'
286
+ @text_assembler.add_footer '#'
287
+ @text_assembler.add_footer(
271
288
  @source_package.unparsed_text.gsub(/^(?=[^\n]+$)/, '# ').gsub(/^$/, '#')
289
+ )
272
290
  end
273
291
 
274
292
  return
@@ -299,7 +317,7 @@ class Fig::RepositoryPackagePublisher
299
317
  end
300
318
 
301
319
  def publish_temp_dir()
302
- File.join(base_temp_dir(), 'publish')
320
+ File.join(@base_temp_dir, 'publish')
303
321
  end
304
322
 
305
323
  def check_asset_path(asset_path)
@@ -328,12 +346,12 @@ class Fig::RepositoryPackagePublisher
328
346
  return
329
347
  end
330
348
 
331
- # 'resources' is an Array of fileglob patterns: ['tmp/foo/file1',
349
+ # 'paths' is an Array of fileglob patterns: ['tmp/foo/file1',
332
350
  # 'tmp/foo/*.jar']
333
- def expand_globs_from(resources)
351
+ def expand_globs_from(paths)
334
352
  expanded_files = []
335
353
 
336
- resources.each do
354
+ paths.each do
337
355
  |path|
338
356
 
339
357
  globbed_files = Dir.glob(path)