Skip to content

Instantly share code, notes, and snippets.

@jdlich
Created February 6, 2012 22:18
Show Gist options
  • Save jdlich/1755349 to your computer and use it in GitHub Desktop.
Save jdlich/1755349 to your computer and use it in GitHub Desktop.
desc "Configures dev environment"
task :config => [ "config:build_properties", "config:catalina_properties", "config:server_xml", "config:disable_cache"] do
puts ""
puts "Run initportal while running hsql to get started."
end
namespace :config do
desc "Configures build.properties"
task :build_properties do
system "cp #{UPORTAL}/build.properties.sample #{UPORTAL}/build.properties"
file = "#{UPORTAL}/build.properties"
config = "server.home=#{File.expand_path(TOMCAT)}\n"
changes = File.read(file).gsub(/^(server\.home.+\n)/, config)
File.open(file,"w+") { |f| f.write changes }
puts "Configured #{UPORTAL}/build.properties.sample"
end
desc "Configures catalina.properties"
task :catalina_properties do
file = "#{TOMCAT}/conf/catalina.properties"
config = "shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar\n"
changes = File.read(file).gsub(/^(shared\.loader.+\n)/, config)
File.open(file,"w+") { |f| f.write changes }
puts "Configured #{TOMCAT}/conf/catalina.properties"
end
desc "Configures server.xml"
task :server_xml do
file = "#{TOMCAT}/conf/server.xml"
xml = Nokogiri::XML(File.read(file))
xml.css("Connector[port='8080']").first['emptySessionPath'] = 'true'
File.open(file,'w+') { |f| f.write xml }
puts "Configured #{TOMCAT}/conf/server.xml"
end
desc "Disable cache in web.xml"
task :disable_cache do
# TODO: don't disable cache if already disabled
pattern = %{<filter-mapping>
<filter-name>pageCachingFilter</filter-name>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CacheExpiresFilter</filter-name>
<url-pattern>/media/*</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
</filter-mapping>}
replace = "<!-- " + pattern + " -->"
web_xml = "#{UPORTAL}/uportal-war/src/main/webapp/WEB-INF/web.xml"
disable_cache = File.read(web_xml).gsub(pattern,replace)
File.open(web_xml, "w+") { |f| f.write disable_cache }
puts "Configured #{UPORTAL}/uportal-war/src/main/webapp/WEB-INF/web.xml"
end
# desc "Enable SSL (for CAS)"
# task :enable_ssl do
# # TODO
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment