Skip to content

Commit

Permalink
Support :bootclasspath in :java-agents.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed May 16, 2013
1 parent 0d817f5 commit c5767cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions leiningen-core/src/leiningen/core/eval.clj
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ leiningen.core.utils/platform-nullsink instead."
(pr-str form)))

(defn- agent-arg [coords file]
(format "-javaagent:%s%s" file (if-let [o (:options (apply hash-map coords))]
(str "=" o) "")))
(let [{:keys [options bootclasspath]} (apply hash-map coords)]
(concat [(str "-javaagent:" file (and options (str "=" options)))]
(if bootclasspath [(str "-Xbootclasspath/a:" file)]))))

(defn ^:internal classpath-arg [project]
(let [classpath-string (string/join java.io.File/pathSeparatorChar
Expand All @@ -194,7 +195,7 @@ leiningen.core.utils/platform-nullsink instead."
;; here, but it doesn't, which is what we want. but maybe a bug?
agent-jars (aether/dependency-files (aether/dependency-hierarchy
(:java-agents project) agent-tree))]
`(~@(map agent-arg (:java-agents project) agent-jars)
`(~@(mapcat agent-arg (:java-agents project) agent-jars)
~@(if (:bootclasspath project)
[(str "-Xbootclasspath/a:" classpath-string)]
["-classpath" classpath-string]))))
Expand Down
8 changes: 5 additions & 3 deletions leiningen-core/test/leiningen/core/test/eval.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
(contains? args "-Dhttps.proxyPort=443"))))))

(deftest test-java-agent
(let [p {:java-agents '[[com.newrelic.agent.java/newrelic-agent "2.18.0"]
(let [p {:java-agents '[[com.newrelic.agent.java/newrelic-agent "2.18.0"
:bootclasspath true]
[nodisassemble "0.1.1" :options "hello"]]
:dependencies '[[slamhound "1.3.0"]]
:repositories project/default-repositories}
[newrelic nodisassemble] (classpath-arg p)]
(is (.endsWith newrelic (lthelper/fix-path-delimiters
[newrelic newrelic-bootcp nodisassemble] (classpath-arg p)]
(is (.endsWith newrelic (lthelper/fix-path-delimiters
(str "/com/newrelic/agent/java/newrelic-agent"
"/2.18.0/newrelic-agent-2.18.0.jar"))))
(is (re-find #"bootclasspath.*newrelic.*jar" newrelic-bootcp))
(is (re-find #"-javaagent:.*nodisassemble-0.1.1.jar=hello" nodisassemble))))
3 changes: 2 additions & 1 deletion sample.project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@
#"clojars" {:name "Internal nexus"
:url "http://mvn.local/nexus/releases"
:repo-manager true}}
;; Java agents can instrument and intercept certain VM features.
;; Java agents can instrument and intercept certain VM features. Include
;; :bootclasspath true to place the agent jar on the bootstrap classpath.
:java-agents [[nodisassemble "0.1.1" :options "extra"]]
;; Defaults for signing options. Defers to per-repository settings.
:signing {:gpg-key "[email protected]"}
Expand Down

0 comments on commit c5767cd

Please sign in to comment.