-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance.rb
78 lines (65 loc) · 1.96 KB
/
instance.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
=begin
--------------------------------------------------------------------------------
Info about this VIVO instance
Create using factory methods:
Instance.from_settings_file(settings_file)
Instance.from_instance_path(instance_path)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
=end
class Instance
attr_reader :path
attr_reader :filename
attr_reader :distro
attr_reader :tomcat
attr_reader :knowledge_base
attr_reader :props
attr_reader :all_props
def file(filename)
File.expand_path(filename, @path)
end
# Get a file from the distro, unless overridden in the instance.
def distro_file(filename)
if File.exist?(file(filename))
file(filename)
else
@distro.file(filename)
end
end
def initialize(path)
@path = path
@filename = File.basename(path)
@props = {
'description' => '(no description)',
'site_home' => @path,
'distro_home' => @path,
'tomcat_home' => file('tomcat'),
'vivo_home' => file('vivo_home')
}
@props.merge!(PropertyFileReader.read(file('instance.properties')))
@site = Site.create(@props.site_home)
@distro = Distro.create(@props.distro_home)
@tomcat = Tomcat.create(@props.tomcat_home)
@knowledge_base = KnowledgeBase.create(@props, self)
@all_props = @distro.props.merge(@tomcat.props).merge(@site.props).merge(@props)
end
def self.from_settings_file(settings_file)
settings = PropertyFileReader.read(settings_file)
self.from_instance_path(settings.instance_path);
end
def self.from_instance_path(instance_path)
if (instance_path)
Instance.new(instance_path)
else
EmptyInstance.new()
end
end
end
class EmptyInstance < Instance
def initialize()
@path = 'no current instance'
@filename = 'no filename'
@description = '(no description)'
@tomcat = EmptyTomcat.new()
end
end