From 4513e599c2a00d46129c67d94cfd13865c38ff5a Mon Sep 17 00:00:00 2001 From: Kai Inkinen Date: Tue, 5 Nov 2013 13:59:36 +0200 Subject: [PATCH] [#1744] Added parameter parsing for the command line option --jpda.port= Use the framework id when parsing the jpda.port so that we can specify a separate fixed port to use for debugging per mode Fixed bug where adding the option '-f' would actually always randomise the jpda_port Add documentation for the following command line options: http.port, https.port, jpda.port and pid_file --- documentation/commands/cmd-run.txt | 10 +++++++++- documentation/commands/cmd-start.txt | 18 ++++++++++++++++-- framework/pym/play/application.py | 22 +++++++++++++++++----- play | 9 +++++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/documentation/commands/cmd-run.txt b/documentation/commands/cmd-run.txt index acd9934b0e..4bd5e9af5b 100644 --- a/documentation/commands/cmd-run.txt +++ b/documentation/commands/cmd-run.txt @@ -4,7 +4,7 @@ ~ ~ Synopsis: ~ ~~~~~~~~~ -~ play run [app_path] [--deps] [--%fwk_id] [-f] [--java_options] +~ play run [app_path] [-f] [--deps] [--%fwk_id] [--http[s].port=] [--jpda.port=] [--java_options] ~ ~ Description: ~ ~~~~~~~~~~~~ @@ -37,3 +37,11 @@ ~ --silent: ~ Suppress output of the Play ASCII art logo and framework version information. ~ +~ --http.port=: +~ Override the http.port and %fwk_id.http.port variables in application.conf, and listen to the specified http port +~ +~ --https.port=: +~ Override the https.port and %fwk_id.https.port variables in application.conf, and listen to the specified https port +~ +~ --jpda.port=: +~ Override the jpda.port and %fwk_id.jpda.port variables in application.conf. Use the specified port () as the remote debugging port for the application. Can be combined with the option -f diff --git a/documentation/commands/cmd-start.txt b/documentation/commands/cmd-start.txt index ef3e672794..4d319c339c 100644 --- a/documentation/commands/cmd-start.txt +++ b/documentation/commands/cmd-start.txt @@ -4,7 +4,7 @@ ~ ~ Synopsis: ~ ~~~~~~~~~ -~ play start [app_path] [--deps] [--%fwk_id] [--java_options] +~ play start [app_path] ] [-f] [--deps] [--%fwk_id] [--http[s].port=] [--jpda.port=] [--pid_file=] [--java_options] ~ ~ Description: ~ ~~~~~~~~~~~~ @@ -25,9 +25,23 @@ ~ ~ Options: ~ ~~~~~~~~~ +~ -f: +~ Disable the JPDA port checking and force the jpda.port value. +~ ~ --%fwk_id: ~ Use this ID to run the application (override the default framework ID) ~ ~ --deps: ~ Resolve and install dependencies before running the command. -~ \ No newline at end of file +~ +~ --pid_file=: +~ Specify where to write the process id (pid) of the background server process. +~ +~ --http.port=: +~ Override the http.port and %fwk_id.http.port variables in application.conf, and listen to the specified http port +~ +~ --https.port=: +~ Override the https.port and %fwk_id.https.port variables in application.conf, and listen to the specified https port +~ +~ --jpda.port=: +~ Override the jpda.port and %fwk_id.jpda.port variables in application.conf. Use the specified port () as the remote debugging port for the application. Can be combined with the option -f diff --git a/framework/pym/play/application.py b/framework/pym/play/application.py index 52a2405d09..88db535dba 100644 --- a/framework/pym/play/application.py +++ b/framework/pym/play/application.py @@ -33,7 +33,12 @@ def __init__(self, application_path, env, ignoreMissingModules = False): else: self.conf = None self.play_env = env - self.jpda_port = self.readConf('jpda.port') + + if env.has_key('jpda.port'): + self.jpda_port = env['jpda.port'] + else: + self.jpda_port = self.readConf('jpda.port') + self.ignoreMissingModules = ignoreMissingModules # ~~~~~~~~~~~~~~~~~~~~~~ Configuration File @@ -223,8 +228,12 @@ def check_jpda(self): s.bind(('', int(self.jpda_port))) s.close() except socket.error, e: - print 'JPDA port %s is already used. Will try to use any free port for debugging' % self.jpda_port - self.jpda_port = 0 + if self.play_env["disable_random_jpda"]: + print 'JPDA port %s is already used, and command line option "-f" was specified. Cannot start server\n' % self.jpda_port + sys.exit(-1) + else: + print 'JPDA port %s is already used. Will try to use any free port for debugging' % self.jpda_port + self.jpda_port = 0 def java_args_memory(self, java_args): args_memory = [] @@ -257,7 +266,8 @@ def java_cmd(self, java_args, cp_args=None, className='play.server.Server', args if cp_args is None: cp_args = self.cp_args() - self.jpda_port = self.readConf('jpda.port') + if self.play_env.has_key('jpda.port'): + self.jpda_port = self.play_env['jpda.port'] application_mode = self.readConf('application.mode').lower() @@ -281,7 +291,7 @@ def java_cmd(self, java_args, cp_args=None, className='play.server.Server', args java_args.append('-Dfile.encoding=utf-8') if self.readConf('application.mode').lower() == 'dev': - if not self.play_env["disable_check_jpda"]: self.check_jpda() + self.check_jpda() java_args.append('-Xdebug') java_args.append('-Xrunjdwp:transport=dt_socket,address=%s,server=y,suspend=n' % self.jpda_port) java_args.append('-Dplay.debug=yes') @@ -318,6 +328,8 @@ class PlayConfParser: def __init__(self, confFolder, env): self.id = env["id"] self.entries = self.readFile(confFolder, "application.conf") + if env.has_key('jpda.port'): + self.entries['jpda.port'] = env['jpda.port'] if env.has_key('http.port'): self.entries['http.port'] = env['http.port'] diff --git a/play b/play index 0ed2e604e3..e798fd5296 100755 --- a/play +++ b/play @@ -101,6 +101,7 @@ try: # ~~~~~~~~~~~~~~~~~ Override port get_opt(remaining_args, "http.port", play_env) get_opt(remaining_args, "https.port", play_env) + get_opt(remaining_args, "jpda.port", play_env) # ~~~~~~~~~~~~~~~~~ Override id for a in remaining_args: @@ -119,12 +120,12 @@ try: print "~ framework ID is %s" % play_env["id"] print "~" - # ~~~~~~~~~~~~~~~~~ Checking for disable_check_jpda - disable_check_jpda = False + # ~~~~~~~~~~~~~~~~~ Checking for disable_random_jpda + disable_random_jpda = False if remaining_args.count('-f') == 1: - disable_check_jpda = True + disable_random_jpda = True remaining_args.remove('-f') - play_env["disable_check_jpda"] = disable_check_jpda + play_env["disable_random_jpda"] = disable_random_jpda play_app = PlayApplication(application_path, play_env, ignoreMissing)