From 685cd47c6bd04fceab9a4b75db37d83a3410bb19 Mon Sep 17 00:00:00 2001 From: Geert Josten Date: Tue, 30 Jun 2015 20:30:16 +0200 Subject: [PATCH] Fixed #467: allowed multiple prop replace syntax --- deploy/lib/server_config.rb | 46 +++++++---- deploy/sample/ml-config.sample.xml | 100 +++++++++++------------ deploy/sample/pipeline-config.sample.xml | 6 +- 3 files changed, 82 insertions(+), 70 deletions(-) diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index 61391cc4..e92669a7 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -112,7 +112,7 @@ def info logger.info "" logger.info "\s\s#{@@is_jar}" logger.info "\s\s" - @properties.sort {|x,y| y <=> x}.each do |k, v| + @properties.sort {|x,y| x <=> y}.each do |k, v| logger.info "\s\s\s\s#{v}" end logger.info "\s\s" @@ -120,7 +120,7 @@ def info else logger.info "IS_JAR: #{@@is_jar}" logger.info "Properties:" - @properties.sort {|x,y| y <=> x}.each do |k, v| + @properties.sort {|x,y| x <=> y}.each do |k, v| logger.info k + ": " + v end end @@ -1104,9 +1104,7 @@ def mlcp options = File.read option_file # substitute properties - @properties.sort {|x,y| y <=> x}.each do |k, v| - options.gsub!("@#{k}", v) - end + replace_properties(options, File.basename(option_file)) logger.debug "Options after resolving properties:" lines = options.split(/[\n\r]+/).reject { |line| line.empty? || line.match("^#") } @@ -1486,9 +1484,7 @@ def deploy_src if File.exist? app_config_file buffer = File.read app_config_file - @properties.sort {|x,y| y <=> x}.each do |k, v| - buffer.gsub!("@#{k}", v) - end + replace_properties(buffer, File.basename(app_config_file)) total_count += xcc.load_buffer "/config.xqy", buffer, @@ -1499,9 +1495,7 @@ def deploy_src if deploy_tests?(dest_db) && File.exist?(test_config_file) buffer = File.read test_config_file - @properties.sort {|x,y| y <=> x}.each do |k, v| - buffer.gsub!("@#{k}", v) - end + replace_properties(buffer, File.basename(test_config_file)) total_count += xcc.load_buffer "/test-config.xqy", buffer, @@ -1670,9 +1664,7 @@ def deploy_cpf ERR else cpf_config = File.read ServerConfig.expand_path("#{@@path}/pipeline-config.xml") - @properties.sort {|x,y| y <=> x}.each do |k, v| - cpf_config.gsub!("@#{k}", v) - end + replace_properties(cpf_config, "pipeline-config.xml") cpf_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/cpf.xqy") query = %Q{#{cpf_code} cpf:load-from-config(#{cpf_config})} logger.debug(query) @@ -2172,12 +2164,32 @@ def build_config(config_file) else config.gsub!("@ml.rewrite-resolves-globally", "") end - @properties.sort {|x,y| y <=> x}.each do |k, v| - config.gsub!("@#{k}", v) - end + + replace_properties(config, File.basename(config_file)) + + # escape unresolved braces, they have special meaning in XQuery + config.gsub!("{", "{{") + config.gsub!("}", "}}") config end + + def replace_properties(contents, name) + @properties.sort {|x,y| y <=> x}.each do |k, v| + # new property syntax + n = k.sub("ml.", "") + contents.gsub!("@{#{n}}", v) + contents.gsub!("${#{n}}", v) + + # backwards compat + contents.gsub!("@#{k}", v) + end + + # warn for unresolved properties + contents.scan(/[@$]\{[^}]+\}/).each do |match| + logger.warn("Unresolved property #{match} in #{name}") + end + end def ServerConfig.properties(prop_file_location = @@path) default_properties_file = ServerConfig.expand_path("#{prop_file_location}/default.properties") diff --git a/deploy/sample/ml-config.sample.xml b/deploy/sample/ml-config.sample.xml index 2c75cac7..e705df47 100644 --- a/deploy/sample/ml-config.sample.xml +++ b/deploy/sample/ml-config.sample.xml @@ -1,13 +1,13 @@ - + - @ml.group + ${group} - @ml.app-name - @ml.app-port - - - @ml.modules-root - @ml.authentication-method - - @ml.url-rewriter - @ml.error-handler + ${app-name} + ${app-port} + + + ${modules-root} + ${authentication-method} + + ${url-rewriter} + ${error-handler} @ml.rewrite-resolves-globally @@ -138,14 +138,14 @@ - @ml.content-db + ${content-db} @ml.forest-data-dir-xml @ml.test-content-db-assignment @ml.test-modules-db-assignment @ml.rest-modules-db-assignment - @ml.modules-db + ${modules-db} @ml.schemas-assignment @ml.triggers-assignment @@ -161,12 +161,12 @@ @ml.test-content-db-xml @ml.rest-modules-db-xml - @ml.content-db - @ml.content-forests-per-host + ${content-db} + ${content-forests-per-host} @ml.schemas-mapping @ml.triggers-mapping - + @ml.forest-data-dir-xml true @@ -388,9 +388,9 @@ - @ml.modules-db + ${modules-db} - + off false @@ -437,26 +437,26 @@ - @ml.app-role - A role for users of the @ml.app-name application + ${app-role} + A role for users of the ${app-name} application execute - @ml.app-role + ${app-role} update - @ml.app-role + ${app-role} insert - @ml.app-role + ${app-role} read - @ml.app-role + ${app-role} @@ -479,11 +479,11 @@ - @ml.app-name-user - A user for the @ml.app-name application - @ml.appuser-password + ${app-name}-user + A user for the ${app-name} application + ${appuser-password} - @ml.app-role + ${app-role} @@ -498,7 +498,7 @@ http://marklogic.com/roxy sample /app/models/sample.xqy - @ml.app-modules-db + ${app-modules-db} a-privileged-role --> diff --git a/deploy/sample/pipeline-config.sample.xml b/deploy/sample/pipeline-config.sample.xml index 1d64e642..648398fe 100644 --- a/deploy/sample/pipeline-config.sample.xml +++ b/deploy/sample/pipeline-config.sample.xml @@ -31,15 +31,15 @@ --> - @ml.modules-db + ${modules-db} / - @ml.app-name-user + ${app-name}-user execute - @ml.app-role + ${app-role}