fig 0.1.41-java → 0.1.42-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +10 -0
- data/VERSION +1 -1
- data/lib/fig.rb +15 -7
- data/lib/fig/environment.rb +8 -4
- data/lib/fig/grammar.treetop +57 -17
- data/lib/fig/options.rb +10 -5
- data/lib/fig/os.rb +33 -12
- data/lib/fig/package.rb +43 -190
- data/lib/fig/package/archive.rb +24 -0
- data/lib/fig/package/command.rb +20 -0
- data/lib/fig/package/configuration.rb +40 -0
- data/lib/fig/package/include.rb +30 -0
- data/lib/fig/package/install.rb +21 -0
- data/lib/fig/package/override.rb +21 -0
- data/lib/fig/package/path.rb +21 -0
- data/lib/fig/package/publish.rb +21 -0
- data/lib/fig/package/resource.rb +24 -0
- data/lib/fig/package/retrieve.rb +21 -0
- data/lib/fig/package/set.rb +21 -0
- data/lib/fig/package/statement.rb +12 -0
- data/lib/fig/parser.rb +17 -4
- data/lib/fig/repository.rb +18 -23
- data/lib/fig/urlaccesserror.rb +6 -2
- metadata +16 -65
@@ -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::Archive
|
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
|
+
%Q<#{indent}archive "#{url}">
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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::Command
|
9
|
+
include Fig::Package::Statement
|
10
|
+
|
11
|
+
attr_reader :command
|
12
|
+
|
13
|
+
def initialize(command)
|
14
|
+
@command = command
|
15
|
+
end
|
16
|
+
|
17
|
+
def unparse(indent)
|
18
|
+
%Q<#{indent}command "#{@command}">
|
19
|
+
end
|
20
|
+
end
|
@@ -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
|
data/lib/fig/parser.rb
CHANGED
@@ -4,21 +4,34 @@ require 'treetop'
|
|
4
4
|
require 'fig/grammar'
|
5
5
|
require 'fig/logging'
|
6
6
|
require 'fig/packageerror'
|
7
|
+
require 'fig/repository'
|
8
|
+
require 'fig/urlaccesserror'
|
7
9
|
|
8
10
|
module Fig
|
9
11
|
class Parser
|
10
|
-
def initialize
|
12
|
+
def initialize(application_config)
|
11
13
|
@parser = FigParser.new
|
14
|
+
@application_config = application_config
|
12
15
|
end
|
13
16
|
|
14
17
|
def parse_package(package_name, version_name, directory, input)
|
15
18
|
input = input.gsub(/#.*$/, '')
|
16
19
|
result = @parser.parse(" #{input} ")
|
17
20
|
if result.nil?
|
18
|
-
|
19
|
-
raise PackageError.new
|
21
|
+
Logging.fatal "#{directory}: #{@parser.failure_reason}"
|
22
|
+
raise PackageError.new("#{directory}: #{@parser.failure_reason}")
|
20
23
|
end
|
21
|
-
result.to_package(package_name, version_name, directory)
|
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
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
data/lib/fig/repository.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'fig/logging'
|
2
2
|
require 'fig/notfounderror'
|
3
|
+
require 'fig/package/archive'
|
4
|
+
require 'fig/package/resource'
|
3
5
|
require 'fig/parser'
|
4
6
|
require 'fig/repositoryerror'
|
5
7
|
require 'fig/urlaccesserror'
|
6
8
|
|
7
9
|
module Fig
|
8
10
|
class Repository
|
11
|
+
def self.is_url?(url)
|
12
|
+
not (/ftp:\/\/|http:\/\/|file:\/\/|ssh:\/\// =~ url).nil?
|
13
|
+
end
|
14
|
+
|
9
15
|
def initialize(os, local_repository_dir, remote_repository_url, application_config, remote_repository_user=nil, update=false, update_if_missing=true)
|
10
16
|
@os = os
|
11
17
|
@local_repository_dir = local_repository_dir
|
@@ -14,7 +20,7 @@ module Fig
|
|
14
20
|
@application_config = application_config
|
15
21
|
@update = update
|
16
22
|
@update_if_missing = update_if_missing
|
17
|
-
@parser = Parser.new
|
23
|
+
@parser = Parser.new(@application_config)
|
18
24
|
|
19
25
|
@overrides = {}
|
20
26
|
if File.exist?('fig.properties')
|
@@ -54,17 +60,17 @@ module Fig
|
|
54
60
|
@os.clear_directory(local_dir)
|
55
61
|
fig_file = File.join(temp_dir, '.fig')
|
56
62
|
content = bundle_resources(package_statements).map do |statement|
|
57
|
-
if statement.is_a?(Publish)
|
63
|
+
if statement.is_a?(Package::Publish)
|
58
64
|
nil
|
59
|
-
elsif statement.is_a?(Archive) || statement.is_a?(Resource)
|
60
|
-
if statement.is_a?(Resource) && !is_url?(statement.url)
|
65
|
+
elsif statement.is_a?(Package::Archive) || statement.is_a?(Package::Resource)
|
66
|
+
if statement.is_a?(Package::Resource) && !Repository.is_url?(statement.url)
|
61
67
|
archive_name = statement.url
|
62
68
|
archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{statement.url}"
|
63
69
|
else
|
64
70
|
archive_name = statement.url.split('/').last
|
65
71
|
archive_remote = "#{remote_dir_for_package(package_name, version_name)}/#{archive_name}"
|
66
72
|
end
|
67
|
-
if
|
73
|
+
if Repository.is_url?(statement.url)
|
68
74
|
archive_local = File.join(temp_dir, archive_name)
|
69
75
|
@os.download(statement.url, archive_local)
|
70
76
|
else
|
@@ -72,7 +78,7 @@ module Fig
|
|
72
78
|
end
|
73
79
|
@os.upload(archive_local, archive_remote, @remote_repository_user) unless local_only
|
74
80
|
@os.copy(archive_local, local_dir + '/' + archive_name)
|
75
|
-
if statement.is_a?(Archive)
|
81
|
+
if statement.is_a?(Package::Archive)
|
76
82
|
@os.unpack_archive(local_dir, archive_name)
|
77
83
|
end
|
78
84
|
statement.class.new(archive_name).unparse('')
|
@@ -88,7 +94,7 @@ module Fig
|
|
88
94
|
def bundle_resources(package_statements)
|
89
95
|
resources = []
|
90
96
|
new_package_statements = package_statements.reject do |statement|
|
91
|
-
if statement.is_a?(Resource) && !is_url?(statement.url)
|
97
|
+
if statement.is_a?(Package::Resource) && !Repository.is_url?(statement.url)
|
92
98
|
resources << statement.url
|
93
99
|
true
|
94
100
|
else
|
@@ -99,7 +105,7 @@ module Fig
|
|
99
105
|
resources = expand_globs_from(resources)
|
100
106
|
file = 'resources.tar.gz'
|
101
107
|
@os.create_archive(file, resources)
|
102
|
-
new_package_statements.unshift(Archive.new(file))
|
108
|
+
new_package_statements.unshift(Package::Archive.new(file))
|
103
109
|
at_exit { File.delete(file) }
|
104
110
|
end
|
105
111
|
new_package_statements
|
@@ -139,7 +145,7 @@ module Fig
|
|
139
145
|
def read_remote_package(package_name, version_name)
|
140
146
|
url = remote_fig_file_for_package(package_name, version_name)
|
141
147
|
content = @os.read_url(url)
|
142
|
-
@parser.parse_package(package_name, version_name, nil, content)
|
148
|
+
return @parser.parse_package(package_name, version_name, nil, content)
|
143
149
|
end
|
144
150
|
|
145
151
|
def read_package_from_directory(dir, package_name, version_name)
|
@@ -159,9 +165,8 @@ module Fig
|
|
159
165
|
Logging.fatal "Package not found: #{package_name}/#{version_name}"
|
160
166
|
raise RepositoryError.new
|
161
167
|
end
|
162
|
-
modified_time = @os.mtime(file_name)
|
163
168
|
content = @os.read(file_name)
|
164
|
-
@parser.parse_package(package_name, version_name, File.dirname(file_name), content)
|
169
|
+
return @parser.parse_package(package_name, version_name, File.dirname(file_name), content)
|
165
170
|
end
|
166
171
|
|
167
172
|
def local_dir_for_package(package_name, version_name)
|
@@ -183,13 +188,13 @@ module Fig
|
|
183
188
|
temp_dir = temp_dir_for_package(package_name, version_name)
|
184
189
|
@os.clear_directory(temp_dir)
|
185
190
|
package.archive_urls.each do |archive_url|
|
186
|
-
if not is_url?(archive_url)
|
191
|
+
if not Repository.is_url?(archive_url)
|
187
192
|
archive_url = remote_dir_for_package(package_name, version_name) + '/' + archive_url
|
188
193
|
end
|
189
194
|
@os.download_archive(archive_url, File.join(temp_dir))
|
190
195
|
end
|
191
196
|
package.resource_urls.each do |resource_url|
|
192
|
-
if not is_url?(resource_url)
|
197
|
+
if not Repository.is_url?(resource_url)
|
193
198
|
resource_url = remote_dir_for_package(package_name, version_name) + '/' + resource_url
|
194
199
|
end
|
195
200
|
@os.download_resource(resource_url, File.join(temp_dir))
|
@@ -215,16 +220,6 @@ module Fig
|
|
215
220
|
expanded_files
|
216
221
|
end
|
217
222
|
|
218
|
-
def is_url?(url)
|
219
|
-
not (/ftp:\/\/|http:\/\/|file:\/\/|ssh:\/\// =~ url).nil?
|
220
|
-
end
|
221
|
-
|
222
|
-
def is_url_with_access?(url)
|
223
|
-
return false if not is_url?(url)
|
224
|
-
raise URLAccessError.new(url) if not @application_config.url_access_allowed?(url)
|
225
|
-
return true
|
226
|
-
end
|
227
|
-
|
228
223
|
def delete_local_package(package_name, version_name)
|
229
224
|
FileUtils.rm_rf(local_dir_for_package(package_name, version_name))
|
230
225
|
end
|