"""Support for app specific modules for Java apps hosted by javaw.exe.\r
"""\r
\r
-import re\r
+import os\r
+import shlex\r
import appModuleHandler\r
from appModuleHandler import AppModule\r
\r
-RE_CMDLINE_CLASS = re.compile(r'(?:"[^"]+"|[^ ]+)(?: +-[^ "]+(?:"[^"]+")?)* +([^ ]+)')\r
+def _getEntryPoint(cmd):\r
+ cmd = iter(shlex.split(cmd))\r
+ # First argument is the executable.\r
+ next(cmd)\r
+ for arg in cmd:\r
+ if arg in ("-cp", "-classpath"):\r
+ # This option consuems the next argument.\r
+ next(cmd)\r
+ continue\r
+ if arg.startswith("-jar"):\r
+ # Next argument is the jar. Remove the extension.\r
+ return os.path.splitext(next(cmd))[0]\r
+ if arg.startswith("-"):\r
+ continue\r
+ if not arg:\r
+ continue\r
+ # Class.\r
+ return arg\r
+ raise LookupError\r
+\r
def getAppNameFromHost(processId):\r
# Some apps have launcher executables which launch javaw.exe to run the app.\r
# In this case, the parent process will usually be the launcher.\r
# The parent isn't a shell, so it's probably a launcher.\r
return name\r
\r
- # Try getting the class from the command line.\r
+ # Try getting the class/jar from the command line.\r
cmd = proc.CommandLine\r
if not cmd:\r
raise LookupError\r
- m = RE_CMDLINE_CLASS.match(cmd)\r
- if not m:\r
+ try:\r
+ return "javaw_" + _getEntryPoint(cmd).replace(".", "_")\r
+ except:\r
raise LookupError\r
- return "javaw_" + m.group(1).replace(".", "_")\r