Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Fix #228
Browse files Browse the repository at this point in the history
- Any properties defined can be overwritten from the command line. For
example ml local info --ml.password=mysecretpassword
- If the property is not defined a warning is displayed and its value
will be ignored.
  • Loading branch information
Richard Louapre committed May 1, 2014
1 parent 03cde56 commit 96c6006
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
4 changes: 3 additions & 1 deletion deploy/lib/ml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def need_help?
if need_help? && Help.respond_to?(command)
Help.doHelp(@logger, command)
break
elsif command.start_with?("--ml.")
break
elsif ServerConfig.instance_methods.include?(command.to_sym) || ServerConfig.instance_methods.include?(command)
raise HelpException.new(command, "Missing environment for #{command}") if @properties["environment"].nil?
raise ExitException.new("Missing ml-config.xml file. Check config.file property") if @properties["ml.config.file"].nil?
Expand Down Expand Up @@ -168,4 +170,4 @@ def need_help?
# Print a flat profile to text
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
end
end
33 changes: 18 additions & 15 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
require 'util'
require 'uri'
require 'net/http'
require 'fileutils'
Expand Down Expand Up @@ -688,65 +689,65 @@ def mlcp
if @properties['ml.mlcp-home'] == nil || ! File.directory?(File.expand_path(mlcp_home)) || ! File.exists?(File.expand_path("#{mlcp_home}/bin/mlcp.sh"))
raise "MLCP not found or mis-configured, please check the mlcp-home setting."
end

# Find all jars required for running MLCP. At least:
jars = Dir.glob(ServerConfig.expand_path("#{mlcp_home}/lib/*.jar"))
classpath = jars.join(path_separator)

ARGV.each do |arg|
if arg == "-option_file"
# remove flag from ARGV
index = ARGV.index(arg)
ARGV.slice!(index)

# capture and remove value from ARGV
option_file = ARGV[index]
ARGV.slice!(index)

# find and read file if exists
option_file = ServerConfig.expand_path("#{@@path}/#{option_file}")
if File.exist? option_file
logger.debug "Reading options file #{option_file}.."
options = File.read option_file

# substitute properties
@properties.sort {|x,y| y <=> x}.each do |k, v|
options.gsub!("@#{k}", v)
end

logger.debug "Options after resolving properties:"
lines = options.split(/[\n\r]+/).reject! { |line| line.empty? || line.match("^#") }

lines.each do |line|
logger.debug line
end

# and insert the properties back into ARGV
ARGV[index,0] = lines
else
raise "Option file #{option_file} not found."
end
end
end

if ARGV.length > 0
password_prompt
connection_string = %Q{ -username #{@properties['ml.user']} -password #{@ml_password} -host #{@properties['ml.server']} -port #{@properties['ml.xcc-port']}}

args = ARGV.join(" ")

runme = %Q{java -cp #{classpath} #{@properties['ml.mlcp-vmargs']} com.marklogic.contentpump.ContentPump #{args} #{connection_string}}
else
runme = %Q{java -cp #{classpath} com.marklogic.contentpump.ContentPump}
end

logger.debug runme
logger.info ""

system runme

logger.info ""

ARGV.clear
end

Expand Down Expand Up @@ -1602,6 +1603,8 @@ def ServerConfig.properties(prop_file_location = @@path)
properties.merge!(ServerConfig.load_properties(env_properties_file, "ml.")) if File.exists? env_properties_file

properties = ServerConfig.substitute_properties(properties, properties, "ml.")

properties = load_prop_from_args(properties)
end

end
18 changes: 17 additions & 1 deletion deploy/lib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def find_arg(args = [])
nil
end

def load_prop_from_args(props)
ARGV.each do |a|
if a.match(/(^--)(ml\..*)(=)(.*)/)
matches = a.match(/(^--)(ml\..*)(=)(.*)/).to_a
ml_key = matches[2]
ml_val = matches[4]
if props.has_key?("#{ml_key}")
props["#{ml_key}"] = ml_val
else
logger.warn "Property #{ml_key} does not exist. It will be skipped."
end
end
end
props
end

def pluralize(count, singular, plural = nil)
count == 1 || count =~ /^1(\.0+)?$/ ? singular : plural
end
Expand Down Expand Up @@ -82,4 +98,4 @@ def present?
def to_b
present? && ['true', 'TRUE', 'yes', 'YES', 'y', 'Y', 't', 'T'].include?(self)
end
end
end

0 comments on commit 96c6006

Please sign in to comment.