fig 0.1.73 → 0.1.75
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +75 -0
- data/lib/fig.rb +1 -1
- data/lib/fig/command.rb +36 -12
- data/lib/fig/command/action.rb +1 -1
- data/lib/fig/command/action/dump_package_definition_parsed.rb +4 -6
- data/lib/fig/command/action/run_command_statement.rb +3 -2
- data/lib/fig/command/options.rb +12 -3
- data/lib/fig/command/options/parser.rb +2 -0
- data/lib/fig/command/package_loader.rb +1 -0
- data/lib/fig/config_file_error.rb +1 -1
- data/lib/fig/grammar/base.rb +214 -0
- data/lib/fig/grammar/base.treetop +29 -0
- data/lib/fig/grammar/v0.rb +1493 -0
- data/lib/fig/grammar/v0.treetop +167 -0
- data/lib/fig/grammar/v1.rb +1478 -0
- data/lib/fig/grammar/v1.treetop +174 -0
- data/lib/fig/grammar/version.rb +144 -0
- data/lib/fig/grammar/version.treetop +22 -0
- data/lib/fig/grammar/version_identification.rb +113 -0
- data/lib/fig/grammar/version_identification.treetop +27 -0
- data/lib/fig/log4r_config_error.rb +1 -1
- data/lib/fig/no_such_package_config_error.rb +1 -1
- data/lib/fig/not_found_error.rb +7 -0
- data/lib/fig/operating_system.rb +31 -20
- data/lib/fig/package.rb +8 -3
- data/lib/fig/package_definition_text_assembler.rb +88 -0
- data/lib/fig/package_descriptor_parse_error.rb +1 -1
- data/lib/fig/parser.rb +115 -29
- data/lib/fig/parser_package_build_state.rb +38 -11
- data/lib/fig/repository.rb +5 -8
- data/lib/fig/repository_package_publisher.rb +114 -96
- data/lib/fig/runtime_environment.rb +42 -14
- data/lib/fig/statement.rb +133 -0
- data/lib/fig/statement/archive.rb +6 -4
- data/lib/fig/statement/asset.rb +28 -34
- data/lib/fig/statement/command.rb +6 -2
- data/lib/fig/statement/configuration.rb +4 -12
- data/lib/fig/statement/grammar_version.rb +22 -0
- data/lib/fig/statement/include.rb +5 -6
- data/lib/fig/statement/override.rb +6 -3
- data/lib/fig/statement/path.rb +12 -2
- data/lib/fig/statement/resource.rb +8 -8
- data/lib/fig/statement/retrieve.rb +11 -3
- data/lib/fig/statement/set.rb +12 -2
- data/lib/fig/unparser.rb +127 -0
- data/lib/fig/unparser/v0.rb +84 -0
- data/lib/fig/unparser/v1.rb +77 -0
- data/lib/fig/url.rb +7 -0
- metadata +139 -25
- 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,
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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.
|
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
|
-
|
95
|
-
|statement|
|
96
|
-
statement.to_config_statement(self)
|
97
|
-
end
|
124
|
+
statement_objects
|
98
125
|
)
|
99
126
|
end
|
100
127
|
|
data/lib/fig/repository.rb
CHANGED
@@ -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
|
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::
|
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::
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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 = @
|
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
|
-
|
111
|
+
add_output_statements_and_create_resource_archive()
|
101
112
|
add_unparsed_text()
|
102
113
|
|
103
|
-
@
|
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
|
-
@
|
132
|
+
@text_assembler.add_header(
|
127
133
|
%Q<# Publishing information for #{@descriptor.to_string()}:>
|
128
|
-
|
134
|
+
)
|
135
|
+
@text_assembler.add_header %q<#>
|
129
136
|
|
130
|
-
@
|
137
|
+
@text_assembler.add_header(
|
131
138
|
%Q<# Time: #{@publish_time} (epoch: #{@publish_time.to_i()})>
|
139
|
+
)
|
132
140
|
|
133
|
-
@
|
134
|
-
@
|
135
|
-
@
|
136
|
-
@
|
137
|
-
@
|
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
|
163
|
-
|
154
|
+
def add_output_statements_and_create_resource_archive()
|
155
|
+
assemble_output_statements()
|
164
156
|
create_resource_archive()
|
165
157
|
|
166
|
-
|
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
|
-
|
171
|
-
statement.class.new(nil, nil, statement.asset_name).unparse('')
|
179
|
+
add_asset_to_output_statements(statement)
|
172
180
|
else
|
173
|
-
@
|
181
|
+
@text_assembler.add_output statement
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
177
185
|
return
|
178
186
|
end
|
179
187
|
|
180
|
-
def
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
if
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
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
|
-
|
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,
|
222
|
+
@operating_system.create_archive(file, @resource_paths)
|
205
223
|
Fig::AtExit.add { File.delete(file) }
|
206
224
|
|
207
|
-
@
|
208
|
-
Fig::Statement::Archive.new(
|
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
|
-
@
|
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
|
252
|
+
asset_remote = "#{@remote_dir_for_package}/#{asset_name}"
|
230
253
|
|
231
|
-
if Fig::
|
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
|
-
@
|
268
|
-
@
|
269
|
-
@
|
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
|
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
|
-
# '
|
349
|
+
# 'paths' is an Array of fileglob patterns: ['tmp/foo/file1',
|
332
350
|
# 'tmp/foo/*.jar']
|
333
|
-
def expand_globs_from(
|
351
|
+
def expand_globs_from(paths)
|
334
352
|
expanded_files = []
|
335
353
|
|
336
|
-
|
354
|
+
paths.each do
|
337
355
|
|path|
|
338
356
|
|
339
357
|
globbed_files = Dir.glob(path)
|