Skip to content

Commit

Permalink
Fixed marklogic-community#467: allowed multiple prop replace syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
grtjn committed Jun 30, 2015
1 parent aefee7f commit 685cd47
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 70 deletions.
46 changes: 29 additions & 17 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ def info
logger.info "<info>"
logger.info "\s\s<isJar>#{@@is_jar}</isJar>"
logger.info "\s\s<properties>"
@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<property name=\"#{k}\">#{v}</property>"
end
logger.info "\s\s</properties>"
logger.info "</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
Expand Down Expand Up @@ -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("^#") }
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
100 changes: 50 additions & 50 deletions deploy/sample/ml-config.sample.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<configuration default-group="@ml.group">
<configuration default-group="${group}">
<!--
default-group applies to databases
@ml.group defaults to "Default", you can override in build.properties or {env}.properties
${group} defaults to "Default", you can override in build.properties or {env}.properties
Note: if you change ml.group, make sure to assign hosts to it! See <hosts> below.
-->
<groups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://marklogic.com/xdmp/group" xsi:schemaLocation="http://marklogic.com/xdmp/group group.xsd">
<group>
<group-name>@ml.group</group-name>
<group-name>${group}</group-name>
<!--
Only enable the task server section if you need to.
<task-server>
Expand All @@ -29,28 +29,28 @@
<task-type>daily</task-type>
<task-period>2</task-period>
<task-start-time>13:00:00-05:00</task-start-time>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
<scheduled-task>
<task-path>/some/hourly-task.xqy</task-path>
<task-root>/</task-root>
<task-type>hourly</task-type>
<task-period>2</task-period>
<task-minute>15</task-minute>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
<scheduled-task>
<task-path>/some/minutely-task.xqy</task-path>
<task-root>/</task-root>
<task-type>minutely</task-type>
<task-period>3</task-period>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
<scheduled-task>
<task-path>/some/monthly-task.xqy</task-path>
Expand All @@ -59,19 +59,19 @@
<task-period>1</task-period>
<task-month-day>15</task-month-day>
<task-start-time>13:00:00-05:00</task-start-time>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
<scheduled-task>
<task-path>/some/once-task.xqy</task-path>
<task-root>/</task-root>
<task-type>once</task-type>
<task-period>1</task-period>
<task-start>2019-01-01T13:00:00-05:00</task-start>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
<scheduled-task>
<task-path>/some/weekly-task.xqy</task-path>
Expand All @@ -84,25 +84,25 @@
<task-day>friday</task-day>
</task-days>
<task-start-time>13:00:00-05:00</task-start-time>
<task-database name="@ml.content-db"/>
<task-modules name="@ml.app-modules-db"/>
<task-user name="@ml.app-name-user"/>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
</scheduled-tasks>
</task-server>
-->
<http-servers>
<!--Default Application Server-->
<http-server>
<http-server-name>@ml.app-name</http-server-name>
<port>@ml.app-port</port>
<database name="@ml.content-db"/>
<modules name="@ml.app-modules-db"/>
<root>@ml.modules-root</root>
<authentication>@ml.authentication-method</authentication>
<default-user name="@ml.default-user"/>
<url-rewriter>@ml.url-rewriter</url-rewriter>
<error-handler>@ml.error-handler</error-handler>
<http-server-name>${app-name}</http-server-name>
<port>${app-port}</port>
<database name="${content-db}"/>
<modules name="${app-modules-db}"/>
<root>${modules-root}</root>
<authentication>${authentication-method}</authentication>
<default-user name="${default-user}"/>
<url-rewriter>${url-rewriter}</url-rewriter>
<error-handler>${error-handler}</error-handler>
@ml.rewrite-resolves-globally
<!-- for external security use:
Expand All @@ -129,23 +129,23 @@
<hosts xsi:schemaLocation="http://marklogic.com/xdmp/hosts hosts.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://marklogic.com/xdmp/hosts">
<host>
<host-name>myhostname</host-name>
<group name="@ml.group"/>
<host-name>@ml.server</host-name>
<group name="${group}"/>
</host>
</hosts>
-->

<!--Assignments-->
<assignments xmlns="http://marklogic.com/xdmp/assignments" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://marklogic.com/xdmp/assignments assignments.xsd">
<assignment>
<forest-name>@ml.content-db</forest-name>
<forest-name>${content-db}</forest-name>
@ml.forest-data-dir-xml
</assignment>
@ml.test-content-db-assignment
@ml.test-modules-db-assignment
@ml.rest-modules-db-assignment
<assignment>
<forest-name>@ml.modules-db</forest-name>
<forest-name>${modules-db}</forest-name>
</assignment>
@ml.schemas-assignment
@ml.triggers-assignment
Expand All @@ -161,12 +161,12 @@
@ml.test-content-db-xml
@ml.rest-modules-db-xml
<database>
<database-name>@ml.content-db</database-name>
<forests-per-host>@ml.content-forests-per-host</forests-per-host>
<database-name>${content-db}</database-name>
<forests-per-host>${content-forests-per-host}</forests-per-host>
@ml.schemas-mapping
@ml.triggers-mapping
<forests>
<forest-id name="@ml.content-db"/>
<forest-id name="${content-db}"/>
@ml.forest-data-dir-xml
</forests>
<uri-lexicon>true</uri-lexicon>
Expand Down Expand Up @@ -388,9 +388,9 @@
</database>
<!--Create Application Modules Database-->
<database>
<database-name>@ml.modules-db</database-name>
<database-name>${modules-db}</database-name>
<forests>
<forest-id name="@ml.modules-db"/>
<forest-id name="${modules-db}"/>
</forests>
<stemmed-searches>off</stemmed-searches>
<word-searches>false</word-searches>
Expand Down Expand Up @@ -437,26 +437,26 @@
</certificates>
<roles xmlns="http://marklogic.com/xdmp/security">
<role>
<role-name>@ml.app-role</role-name>
<description>A role for users of the @ml.app-name application</description>
<role-name>${app-role}</role-name>
<description>A role for users of the ${app-name} application</description>
<role-names>
</role-names>
<permissions>
<permission>
<capability>execute</capability>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</permission>
<permission>
<capability>update</capability>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</permission>
<permission>
<capability>insert</capability>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</permission>
<permission>
<capability>read</capability>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</permission>
</permissions>
<collections>
Expand All @@ -479,11 +479,11 @@
</roles>
<users xmlns="http://marklogic.com/xdmp/security">
<user>
<user-name>@ml.app-name-user</user-name>
<description>A user for the @ml.app-name application</description>
<password>@ml.appuser-password</password>
<user-name>${app-name}-user</user-name>
<description>A user for the ${app-name} application</description>
<password>${appuser-password}</password>
<role-names>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</role-names>
<permissions/>
<collections/>
Expand All @@ -498,7 +498,7 @@
<namespace>http://marklogic.com/roxy</namespace>
<local-name>sample</local-name>
<doc-uri>/app/models/sample.xqy</doc-uri>
<db-name>@ml.app-modules-db</db-name>
<db-name>${app-modules-db}</db-name>
<role-name>a-privileged-role</role-name>
</amp>
-->
Expand Down
6 changes: 3 additions & 3 deletions deploy/sample/pipeline-config.sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
</scope>
-->
<context>
<modules-database>@ml.modules-db</modules-database>
<modules-database>${modules-db}</modules-database>
<root>/</root>
</context>
<restart-user>@ml.app-name-user</restart-user>
<restart-user>${app-name}-user</restart-user>
<!-- Permissions are optional -->
<permissions>
<permission>
<capability>execute</capability>
<role-name>@ml.app-role</role-name>
<role-name>${app-role}</role-name>
</permission>
</permissions>
</domain>
Expand Down

0 comments on commit 685cd47

Please sign in to comment.