fig18 0.1.45-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/command'
4
+ require 'fig/package/statement'
5
+
6
+ module Fig; end
7
+ class Fig::Package; end
8
+
9
+ class Fig::Package::Configuration
10
+ include Fig::Package::Statement
11
+
12
+ attr_reader :name, :statements
13
+
14
+ def initialize(name, statements)
15
+ @name = name
16
+ @statements = statements
17
+ end
18
+
19
+ def with_name(name)
20
+ Configuration.new(name, statements)
21
+ end
22
+
23
+ def commands
24
+ result = statements.select do
25
+ |statement| statement.is_a?(Fig::Package::Command)
26
+ end
27
+ result
28
+ end
29
+
30
+ def walk_statements(&block)
31
+ @statements.each do |statement|
32
+ yield statement
33
+ statement.walk_statements &block
34
+ end
35
+ end
36
+
37
+ def unparse(indent)
38
+ unparse_statements(indent, "config #{@name}", @statements, 'end')
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Include
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :package_name, :config_name, :version_name, :overrides
12
+
13
+ def initialize(package_name, config_name, version_name, overrides)
14
+ @package_name = package_name
15
+ @config_name = config_name
16
+ @version_name = version_name
17
+ @overrides = overrides
18
+ end
19
+
20
+ def unparse(indent)
21
+ descriptor = ''
22
+ descriptor += @package_name if @package_name
23
+ descriptor += "/#{@version_name}" if @version_name
24
+ descriptor += ":#{@config_name}" if @config_name
25
+ @overrides.each do |override|
26
+ descriptor += override.unparse
27
+ end
28
+ return "#{indent}include #{descriptor}"
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Install
9
+ include Fig::Package::Statement
10
+
11
+ def initialize(statements)
12
+ @statements = statements
13
+ end
14
+
15
+ def unparse(indent)
16
+ prefix = "\n#{indent}install"
17
+ body = @statements.map { |statement| statement.unparse(indent+' ') }.join("\n")
18
+ suffix = "#{indent}end"
19
+ return [prefix, body, suffix].join("\n")
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Override
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :package_name, :version_name
12
+
13
+ def initialize(package_name, version_name)
14
+ @package_name = package_name
15
+ @version_name = version_name
16
+ end
17
+
18
+ def unparse()
19
+ return ' override ' + @package_name + '/' + @version_name
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Path
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :name, :value
12
+
13
+ def initialize(name, value)
14
+ @name = name
15
+ @value = value
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}append #{name}=#{value}"
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Publish
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :local_name, :remote_name
12
+
13
+ def initialize(local_name, remote_name)
14
+ @local_name = local_name
15
+ @remote_name = remote_name
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}publish #{@local_name}->#{@remote_name}"
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Resource
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :url
12
+
13
+ def initialize(url)
14
+ @url = url
15
+ end
16
+
17
+ def urls
18
+ return [@url]
19
+ end
20
+
21
+ def unparse(indent)
22
+ "#{indent}resource #{url}"
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Retrieve
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :var, :path
12
+
13
+ def initialize(var, path)
14
+ @var = var
15
+ @path = path
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}retrieve #{var}->#{path}"
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/statement'
4
+
5
+ module Fig; end
6
+ class Fig::Package; end
7
+
8
+ class Fig::Package::Set
9
+ include Fig::Package::Statement
10
+
11
+ attr_reader :name, :value
12
+
13
+ def initialize(name, value)
14
+ @name = name
15
+ @value = value
16
+ end
17
+
18
+ def unparse(indent)
19
+ "#{indent}set #{name}=#{value}"
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Fig; end
2
+ class Fig::Package; end
3
+
4
+ module Fig::Package::Statement
5
+ def walk_statements(&block)
6
+ return
7
+ end
8
+
9
+ def urls
10
+ return []
11
+ end
12
+ end
@@ -0,0 +1,73 @@
1
+ require 'fig/logging'
2
+ require 'fig/packageerror'
3
+ require 'fig/package/archive'
4
+ require 'fig/package/configuration'
5
+ require 'fig/package/resource'
6
+ require 'fig/package/retrieve'
7
+
8
+ module Fig; end
9
+
10
+ class Fig::Package
11
+ attr_reader :package_name, :version_name, :directory, :statements
12
+ attr_accessor :backtrace
13
+
14
+ def initialize(package_name, version_name, directory, statements)
15
+ @package_name = package_name
16
+ @version_name = version_name
17
+ @directory = directory
18
+ @statements = statements
19
+ @backtrace = nil
20
+ end
21
+
22
+ def [](config_name)
23
+ @statements.each do |stmt|
24
+ return stmt if stmt.is_a?(Configuration) && stmt.name == config_name
25
+ end
26
+ Fig::Logging.fatal "Configuration not found: #{@package_name}/#{@version_name}:#{config_name}"
27
+ raise PackageError.new
28
+ end
29
+
30
+ def configs
31
+ @statements.select { |statement| statement.is_a?(Configuration) }
32
+ end
33
+
34
+ def retrieves
35
+ retrieves = {}
36
+ statements.each { |statement| retrieves[statement.var] = statement.path if statement.is_a?(Retrieve) }
37
+ retrieves
38
+ end
39
+
40
+ def archive_urls
41
+ @statements.select{|s| s.is_a?(Archive)}.map{|s|s.url}
42
+ end
43
+
44
+ def resource_urls
45
+ @statements.select{|s| s.is_a?(Resource)}.map{|s|s.url}
46
+ end
47
+
48
+ def walk_statements(&block)
49
+ @statements.each do |statement|
50
+ yield statement
51
+ statement.walk_statements &block
52
+ end
53
+ end
54
+
55
+ def unparse
56
+ @statements.map { |statement| statement.unparse('') }.join("\n")
57
+ end
58
+
59
+ def ==(other)
60
+ return false if other.nil?
61
+ @package_name == other.package_name && @version_name == other.version_name && @statements.to_yaml == other.statements.to_yaml
62
+ end
63
+
64
+ def to_s
65
+ @package_name + '/' + @version_name
66
+ end
67
+ end
68
+
69
+ def unparse_statements(indent, prefix, statements, suffix)
70
+ body = @statements.map { |statement| statement.unparse(indent+' ') }.join("\n")
71
+ return ["\n#{indent}#{prefix}", body, "#{indent}#{suffix}"].join("\n")
72
+ end
73
+
@@ -0,0 +1,7 @@
1
+ require 'fig/userinputerror'
2
+
3
+ module Fig
4
+ # An issue with a stored package.
5
+ class PackageError < UserInputError
6
+ end
7
+ end
data/lib/fig/parser.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'polyglot'
2
+ require 'treetop'
3
+
4
+ require 'fig/grammar'
5
+ require 'fig/logging'
6
+ require 'fig/packageerror'
7
+ require 'fig/repository'
8
+ require 'fig/urlaccesserror'
9
+
10
+ module Fig
11
+ class Parser
12
+ def initialize(application_config)
13
+ @parser = FigParser.new
14
+ @application_config = application_config
15
+ end
16
+
17
+ def parse_package(package_name, version_name, directory, input)
18
+ input = input.gsub(/#.*$/, '')
19
+ result = @parser.parse(" #{input} ")
20
+ if result.nil?
21
+ Logging.fatal "#{directory}: #{@parser.failure_reason}"
22
+ raise PackageError.new("#{directory}: #{@parser.failure_reason}")
23
+ end
24
+ package = result.to_package(package_name, version_name, directory)
25
+ bad_urls = []
26
+ package.walk_statements do |statement|
27
+ statement.urls.each do |url|
28
+ # collect all bad urls in bad_urls
29
+ next if not Repository.is_url?(url)
30
+ bad_urls << url if not @application_config.url_access_allowed?(url)
31
+ end
32
+ end
33
+ raise URLAccessError.new(bad_urls, package_name, version_name) if not bad_urls.empty?
34
+ return package
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,252 @@
1
+ require 'fig/logging'
2
+ require 'fig/notfounderror'
3
+ require 'fig/package/archive'
4
+ require 'fig/package/resource'
5
+ require 'fig/parser'
6
+ require 'fig/repositoryerror'
7
+ require 'fig/urlaccesserror'
8
+
9
+ module Fig
10
+ class Repository
11
+ def self.is_url?(url)
12
+ not (/ftp:\/\/|http:\/\/|file:\/\/|ssh:\/\// =~ url).nil?
13
+ end
14
+
15
+ def initialize(os, local_repository_dir, remote_repository_url, application_config, remote_repository_user=nil, update=false, update_if_missing=true)
16
+ @os = os
17
+ @local_repository_dir = local_repository_dir
18
+ @remote_repository_url = remote_repository_url
19
+ @remote_repository_user = remote_repository_user
20
+ @application_config = application_config
21
+ @update = update
22
+ @update_if_missing = update_if_missing
23
+ @parser = Parser.new(@application_config)
24
+
25
+ @overrides = {}
26
+ if File.exist?('fig.properties')
27
+ File.readlines('fig.properties').each do |line|
28
+ descriptor, path = line.strip.split('=')
29
+ @overrides[descriptor] = path
30
+ end
31
+ end
32
+ end
33
+
34
+ def clean(package_name, version_name)
35
+ dir = File.join(@local_repository_dir, package_name)
36
+ dir = File.join(dir, version_name) if version_name
37
+ FileUtils.rm_rf(dir)
38
+ end
39
+
40
+ def list_packages
41
+ results = []
42
+ if File.exist?(@local_repository_dir)
43
+ @os.list(@local_repository_dir).each do |package_name|
44
+ @os.list(File.join(@local_repository_dir, package_name)).each do |version_name|
45
+ results << "#{package_name}/#{version_name}"
46
+ end
47
+ end
48
+ end
49
+ results
50
+ end
51
+
52
+ def list_remote_packages
53
+ @os.download_list(@remote_repository_url)
54
+ end
55
+
56
+ def publish_package(package_statements, package_name, version_name, local_only)
57
+ temp_dir = temp_dir_for_package(package_name, version_name)
58
+ @os.clear_directory(temp_dir)
59
+ local_dir = local_dir_for_package(package_name, version_name)
60
+ @os.clear_directory(local_dir)
61
+ fig_file = File.join(temp_dir, '.fig')
62
+ content = bundle_resources(package_statements).map do |statement|
63
+ if statement.is_a?(Package::Publish)
64
+ nil
65
+ elsif statement.is_a?(Package::Archive) || statement.is_a?(Package::Resource)
66
+ if statement.is_a?(Package::Resource) && !Repository.is_url?(statement.url)
67
+ archive_name = statement.url
68
+ archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{statement.url}"
69
+ else
70
+ archive_name = statement.url.split('/').last
71
+ archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{archive_name}"
72
+ end
73
+ if Repository.is_url?(statement.url)
74
+ archive_local = File.join(temp_dir, archive_name)
75
+ @os.download(statement.url, archive_local)
76
+ else
77
+ archive_local = statement.url
78
+ end
79
+ @os.upload(archive_local, archive_remote, @remote_repository_user) unless local_only
80
+ @os.copy(archive_local, local_dir + '/' + archive_name)
81
+ if statement.is_a?(Package::Archive)
82
+ @os.unpack_archive(local_dir, archive_name)
83
+ end
84
+ statement.class.new(archive_name).unparse('')
85
+ else
86
+ statement.unparse('')
87
+ end
88
+ end.select {|s|not s.nil?}
89
+ @os.write(fig_file, content.join("\n").strip)
90
+ @os.upload(fig_file, remote_fig_file_for_package(package_name, version_name), @remote_repository_user) unless local_only
91
+ @os.copy(fig_file, local_fig_file_for_package(package_name, version_name))
92
+ end
93
+
94
+ def bundle_resources(package_statements)
95
+ resources = []
96
+ new_package_statements = package_statements.reject do |statement|
97
+ if statement.is_a?(Package::Resource) && !Repository.is_url?(statement.url)
98
+ resources << statement.url
99
+ true
100
+ else
101
+ false
102
+ end
103
+ end
104
+ if resources.size > 0
105
+ resources = expand_globs_from(resources)
106
+ file = 'resources.tar.gz'
107
+ @os.create_archive(file, resources)
108
+ new_package_statements.unshift(Package::Archive.new(file))
109
+ at_exit { File.delete(file) }
110
+ end
111
+ new_package_statements
112
+ end
113
+
114
+ def load_package(package_name, version_name)
115
+ Logging.debug "Considering #{package_name}/#{version_name}."
116
+ if @update || (@update_if_missing && package_missing?(package_name, version_name))
117
+ update_package(package_name, version_name)
118
+ end
119
+ read_local_package(package_name, version_name)
120
+ end
121
+
122
+ def updating?
123
+ return @update || @update_if_missing
124
+ end
125
+
126
+ def update_package(package_name, version_name)
127
+ remote_fig_file = remote_fig_file_for_package(package_name, version_name)
128
+ local_fig_file = local_fig_file_for_package(package_name, version_name)
129
+ begin
130
+ if @os.download(remote_fig_file, local_fig_file)
131
+ install_package(package_name, version_name)
132
+ end
133
+ rescue NotFoundError
134
+ Logging.fatal "Package not found in remote repository: #{package_name}/#{version_name}"
135
+ delete_local_package(package_name, version_name)
136
+ raise RepositoryError.new
137
+ end
138
+ end
139
+
140
+ def read_local_package(package_name, version_name)
141
+ dir = local_dir_for_package(package_name, version_name)
142
+ read_package_from_directory(dir, package_name, version_name)
143
+ end
144
+
145
+ def read_remote_package(package_name, version_name)
146
+ url = remote_fig_file_for_package(package_name, version_name)
147
+ content = @os.read_url(url)
148
+ return @parser.parse_package(package_name, version_name, nil, content)
149
+ end
150
+
151
+ def read_package_from_directory(dir, package_name, version_name)
152
+ file = File.join(dir, '.fig')
153
+ if not File.exist?(file)
154
+ file = File.join(dir, 'package.fig')
155
+ end
156
+ if not File.exist?(file)
157
+ Logging.fatal "Fig file not found for package: #{file}"
158
+ raise RepositoryError.new
159
+ end
160
+ read_package_from_file(file, package_name, version_name)
161
+ end
162
+
163
+ def read_package_from_file(file_name, package_name, version_name)
164
+ if not @os.exist?(file_name)
165
+ Logging.fatal "Package not found: #{package_name}/#{version_name}"
166
+ raise RepositoryError.new
167
+ end
168
+ content = @os.read(file_name)
169
+ return @parser.parse_package(package_name, version_name, File.dirname(file_name), content)
170
+ end
171
+
172
+ def local_dir_for_package(package_name, version_name)
173
+ descriptor = "#{package_name}/#{version_name}"
174
+ dir = @overrides[descriptor]
175
+ if dir
176
+ Logging.info "override: #{descriptor}=#{dir}"
177
+ else
178
+ dir = File.join(@local_repository_dir, package_name, version_name)
179
+ end
180
+ dir
181
+ end
182
+
183
+ private
184
+
185
+ def install_package(package_name, version_name)
186
+ begin
187
+ package = read_local_package(package_name, version_name)
188
+ temp_dir = temp_dir_for_package(package_name, version_name)
189
+ @os.clear_directory(temp_dir)
190
+ package.archive_urls.each do |archive_url|
191
+ if not Repository.is_url?(archive_url)
192
+ archive_url = remote_dir_for_package(package_name, version_name) + '/' + archive_url
193
+ end
194
+ @os.download_archive(archive_url, File.join(temp_dir))
195
+ end
196
+ package.resource_urls.each do |resource_url|
197
+ if not Repository.is_url?(resource_url)
198
+ resource_url = remote_dir_for_package(package_name, version_name) + '/' + resource_url
199
+ end
200
+ @os.download_resource(resource_url, File.join(temp_dir))
201
+ end
202
+ local_dir = local_dir_for_package(package_name, version_name)
203
+ @os.clear_directory(local_dir)
204
+ # some packages contain no files, only a fig file.
205
+ if not (package.archive_urls.empty? && package.resource_urls.empty?)
206
+ FileUtils.mv(Dir.glob(File.join(temp_dir, '*')), local_dir)
207
+ end
208
+ write_local_package(package_name, version_name, package)
209
+ rescue
210
+ Logging.fatal 'Install failed, cleaning up.'
211
+ delete_local_package(package_name, version_name)
212
+ raise RepositoryError.new
213
+ end
214
+ end
215
+
216
+ # 'resources' is an Array of filenames: ['tmp/foo/file1', 'tmp/foo/*.jar']
217
+ def expand_globs_from(resources)
218
+ expanded_files = []
219
+ resources.each {|f| expanded_files.concat(Dir.glob(f))}
220
+ expanded_files
221
+ end
222
+
223
+ def delete_local_package(package_name, version_name)
224
+ FileUtils.rm_rf(local_dir_for_package(package_name, version_name))
225
+ end
226
+
227
+ def write_local_package(package_name, version_name, package)
228
+ file = local_fig_file_for_package(package_name, version_name)
229
+ @os.write(file, package.unparse)
230
+ end
231
+
232
+ def remote_fig_file_for_package(package_name, version_name)
233
+ "#{@remote_repository_url}/#{package_name}/#{version_name}/.fig"
234
+ end
235
+
236
+ def local_fig_file_for_package(package_name, version_name)
237
+ File.join(local_dir_for_package(package_name, version_name), '.fig')
238
+ end
239
+
240
+ def remote_dir_for_package(package_name, version_name)
241
+ "#{@remote_repository_url}/#{package_name}/#{version_name}"
242
+ end
243
+
244
+ def temp_dir_for_package(package_name, version_name)
245
+ File.join(@local_repository_dir, 'tmp')
246
+ end
247
+
248
+ def package_missing?(package_name, version_name)
249
+ not File.exist?(local_fig_file_for_package(package_name, version_name))
250
+ end
251
+ end
252
+ end
@@ -0,0 +1,7 @@
1
+ require 'fig/userinputerror'
2
+
3
+ module Fig
4
+ # A problem within/related to a repository.
5
+ class RepositoryError < UserInputError
6
+ end
7
+ end