Skip to content

Commit

Permalink
Improve Java command line parser
Browse files Browse the repository at this point in the history
This change adds support for -noverify, -agentlib: and -javaagent:.
From a real-world commandline.

Fixes #40
  • Loading branch information
walles committed Feb 12, 2018
1 parent 5651490 commit 61b68ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions px/px_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ def get_java_command(commandline):
continue
if component.startswith('-da'):
continue
if component.startswith('-agentlib:'):
continue
if component.startswith('-javaagent:'):
continue
if component == "-server":
continue
if component == "-noverify":
continue
if component == "-cp" or component == "-classpath":
state = "skip next"
continue
Expand Down
29 changes: 29 additions & 0 deletions tests/px_commandline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ def test_get_command_java_logstash():
assert px_commandline.get_command(commandline) == "jruby.Main"


def test_get_command_java_gradleworkermain():
commandline = (
"/some/path/bin/java "
"-Djava.awt.headless=true "
"-Djava.security.manager="
+ "worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager "
"-Dorg.gradle.native=false "
"-Drobolectric.accessibility.enablechecks=true "
"-Drobolectric.logging=stderr "
"-Drobolectric.logging.enabled=true "
"-agentlib:jdwp=transport=dt_socket,server=y,address=,suspend=n "
"-noverify "
"-javaagent:gen_build/.../jacocoagent.jar="
+ "destfile=gen_build/jacoco/testDebugUnitTest.exec,"
+ "append=true,dumponexit=true,output=file,jmx=false "
"-Xmx2400m "
"-Dfile.encoding=UTF-8 "
"-Duser.country=SE "
"-Duser.language=sv "
"-Duser.variant "
"-ea "
"-cp "
"/Users/walles/.gradle/caches/4.2.1/workerMain/gradle-worker.jar "
"worker.org.gradle.process.internal.worker.GradleWorkerMain "
"'Gradle Test Executor 16'"
)
assert px_commandline.get_command(commandline) == "GradleWorkerMain"


def test_get_command_resque():
# These command names are from a real-world system
assert px_commandline.get_command("resque-1.20.0: x y z") == "resque-1.20.0:"
Expand Down

0 comments on commit 61b68ae

Please sign in to comment.