forked from sgithens/OAE-Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cle.rake
205 lines (181 loc) · 7.18 KB
/
cle.rake
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
namespace :cle do
desc "Checkout CLE from SVN"
task :clone do
if @cle.has_key? "path"
if File.directory? @cle["path"]
@logger.info "#{@cle["path"]} already exists."
elsif @cle.has_key? "repository"
system("svn -q checkout #{@cle["repository"]} #{@cle["path"]}")
if @hybrid.has_key? "path" and @hybrid.has_key? "repository"
system("svn -q checkout #{@hybrid["repository"]} #{@hybrid["path"]}")
end
end
end
end
desc "Update the SVN checkout of CLE"
task :update do
if @cle.has_key? "path" and File.directory? @cle["path"]
@logger.info "Updating #{@cle["path"]}"
system("svn -q update #{@cle["path"]}")
if @hybrid.has_key? "path" and File.directory? @hybrid["path"]
@logger.info "Updating #{@hybrid["path"]}"
system("svn -q update #{@hybrid["path"]}")
end
end
end
desc "Rebuild the CLE and its hybrid module"
task :rebuild => 'cle:config' do
deploydir = "#{Dir.pwd}/sakai2-demo"
Dir.chdir(@cle["path"]) do
system("#{@mvn_cmd} -Dmaven.tomcat.home=#{deploydir} clean install sakai:deploy")
end
Dir.chdir(@hybrid["path"]) do
system("#{@mvn_cmd} -Dmaven.tomcat.home=#{deploydir} clean install sakai:deploy")
end
end
desc "Start a CLE server. Will kill the previously started server if still running."
task :run => 'cle:kill' do
ENV['CATALINA_PID'] = "[email protected]"
process = ChildProcess.build("./sakai2-demo/bin/startup.sh")
process.detach = true
process.io.inherit!
process.start
end
desc "Kill the CLE server."
task :kill do
kill("[email protected]")
end
desc "Configure the CLE server"
task :config => 'tomcat:unpack' do
class SakaiProperties < Mustache
end
sakaiprops = SakaiProperties.new
sakaiprops[:s2_tag] = @cle["repository"].split('/')[-1]
sakaiprops[:hybrid_tag] = @hybrid["repository"].split('/')[-1]
Dir.chdir(@cle["path"]) do
sakaiprops[:repo_rev] = /Revision.*$/.match(`svn info`).to_s
end
sakaiprops[:server] = @hostname
sakaiprops[:build_date] = Time.now
sakaiprops[:k2_http_port] = @nakamura["port"]
# don't worry, no data gets sent to this google ip
# Since UDP is a stateless protocol connect() merely makes a system call
# which figures out how to route the packets
ip = UDPSocket.open {|s| s.connect('64.233.187.99', 1); s.addr.last }
sakaiprops[:external_ip] = ip
unless Dir.exists? "./sakai2-demo/sakai"
Dir.mkdir("./sakai2-demo/sakai")
end
File.open("./sakai2-demo/sakai/sakai.properties", 'w') do |f|
f.write(sakaiprops.render())
end
sXML = ""
# Read the default server.xml into memory replacing the default ports with the configured ones
File.open("./sakai2-demo/conf/server.xml") do |f|
sXML = REXML::Document.new f
sXML.elements.each("Server/Service/Connector") do |el|
if el.attributes["port"] == "8080"
el.attributes["port"] = @cle["port"]
elsif el.attributes["port"] == "8009"
el.attributes["port"] = @cle["ajp_port"]
end
end
end
# Write the new server.xml
File.open("./sakai2-demo/conf/server.xml", "w+") do |f|
sXML.write f
end
File.open("./sakai2-demo/bin/setenv.sh", "w+") do |f|
f.write("export JAVA_OPTS='-server -Xms512m -Xmx1028m -XX:NewSize=192m -XX:MaxNewSize=384m -XX:PermSize=96m -XX:MaxPermSize=512m'")
end
end
desc "Update and rebuild the CLE"
task :build => ['cle:update', 'cle:rebuild']
namespace :hybrid do
desc "Enable Hybrid Widgets and Config"
task :enable do
enableInPortal("devwidgets/mysakai2/config.json")
enableInSakaiDoc("devwidgets/basiclti/config.json")
enableInSakaiDoc("devwidgets/sakai2tools/config.json")
setFsResource("/dev/configuration/config_custom.js", "#{@oaebuilder_dir}/ui-conf/[email protected]")
end
desc "Build a hybrid server"
task :build => ['bld:build', 'ctl:run', 'cle:build', 'cle:config:directoryprovider', 'cle:run', 'conf:fsresource:uiconf', 'cle:hybrid:enable']
desc "Build a hybrid server from scratch, including checking out all the source."
task :scratch => ['bld:clean', 'bld:clone', 'cle:clone', 'cle:hybrid:build']
end
namespace :tomcat do
desc "Unpack Tomcat tarball"
task :unpack => 'cle:tomcat:dl' do
@logger.info "Unpacking #{@tomcat["filename"]}"
Dir.chdir(File.dirname(@tomcat["filename"])) do
tgz = Zlib::GzipReader.new(File.open(@tomcat["filename"], 'rb'))
Archive::Tar::Minitar.unpack(tgz, './tmp')
FileUtils.mv("./tmp/apache-tomcat-#{@tomcat["version"]}", "./sakai2-demo")
end
end
desc "Download Tomcat tarball"
task :dl do
@tomcat["filename"] = "apache-tomcat-#{@tomcat["version"]}.tar.gz"
unless File.exists? @tomcat["filename"]
@logger.info "Downloading #{@tomcat["filename"]} from #{@tomcat["mirror"]}"
Net::HTTP.start(@tomcat["mirror"]) do |http|
resp = http.get("/#{@tomcat["prefix"]}/tomcat/tomcat-5/v#{@tomcat["version"]}/bin/#{@tomcat["filename"]}")
open("#{@tomcat["filename"]}", "wb") do |file|
file.write(resp.body)
end
end
end
end
end
def enableInPortal(path)
widgetname = File.basename(File.dirname(path))
@logger.info("Enabling #{widgetname} Widget in Portal")
resp = @sling.execute_get(@sling.url_for(path))
json = JSON.parse(resp.body)
json["personalportal"] = true
postJsonAsFile(path, JSON.generate(json))
end
def enableInSakaiDoc(path)
widgetname = File.basename(File.dirname(path))
@logger.info("Enabling #{widgetname} Widget in SakaiDoc")
resp = @sling.execute_get(@sling.url_for(path))
json = JSON.parse(resp.body)
json["sakaidocs"] = true
postJsonAsFile(path, JSON.generate(json))
end
def postJsonAsFile(path, json)
filename = File.basename(path)
@logger.info @sling.execute_file_post(@sling.url_for(File.dirname(path)), "file", filename, json, "application/json")
end
namespace :config do
desc "Configure the CLE to use NakamuraUserDirectoryProvider"
task :directoryprovider do #=> 'cle:build' do
components = 'sakai2-demo/components/sakai-provider-pack/WEB-INF/components.xml'
cXML = nil
File.open(components) do |f|
cXML = REXML::Document.new(f)
beans = REXML::XPath.first(cXML, '//beans')
bean = beans.add_element("bean", {
"id" => "org.sakaiproject.user.api.UserDirectoryProvider",
"class" => "org.sakaiproject.provider.user.NakamuraUserDirectoryProvider",
"init-method" => "init"
})
prop1 = bean.add_element("property", {"name" => "threadLocalManager"})
prop1.add_element("ref", {
"bean" => "org.sakaiproject.thread_local.api.ThreadLocalManager"
})
prop2 = bean.add_element("property", {
"name" => "serverConfigurationService"
})
prop2.add_element("ref", {
"bean" => "org.sakaiproject.component.api.ServerConfigurationService"
})
end
File.open(components, "w+") do |f|
cXML.write f
end
FileUtils.rm("sakai2-demo/components/sakai-provider-pack/WEB-INF/components-demo.xml")
end
end
end