Skip to content

Commit

Permalink
(SERVER-297) Check if subcommand exists before loading
Browse files Browse the repository at this point in the history
Without this patch the subcommand string given to the cli-run! command
may not actually exist in the assumed directory of
META-INF/jruby.home/bin/  This patch checks before trying to execute the
given subcommand.
  • Loading branch information
Jeff McCune committed Jun 3, 2015
1 parent d7574cc commit 791ba54
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/clj/puppetlabs/services/jruby/jruby_puppet_core.clj
Expand Up @@ -4,7 +4,8 @@
[puppetlabs.services.jruby.jruby-puppet-schemas :as jruby-schemas]
[puppetlabs.services.jruby.puppet-environments :as puppet-env]
[puppetlabs.services.jruby.jruby-puppet-internal :as jruby-internal]
[puppetlabs.services.jruby.jruby-puppet-agents :as jruby-agents])
[puppetlabs.services.jruby.jruby-puppet-agents :as jruby-agents]
[clojure.java.io :as io])
(:import (puppetlabs.services.jruby.jruby_puppet_schemas JRubyPuppetInstance)
(com.puppetlabs.puppetserver PuppetProfiler)))

Expand Down Expand Up @@ -184,11 +185,11 @@
argv (into-array String (concat ["-rjar-dependencies"] args))]
(.run main argv)))

(schema/defn ^:always-validate cli-run! :- jruby-schemas/JRubyMainStatus
(schema/defn ^:always-validate cli-run! :- jruby-schemas/JRubyMainStatusOrNil
"Run a JRuby CLI command, e.g. gem, irb, etc..."
[config :- {schema/Keyword schema/Any}
command :- schema/Str
args :- [schema/Str]]
(let [load-arg (format "load 'META-INF/jruby.home/bin/%s'" command)
load-args (concat ["-e" load-arg "--"] args)]
(cli-ruby! config load-args)))
(let [load-path (format "META-INF/jruby.home/bin/%s" command)]
(if-let [url (io/resource load-path (.getClassLoader org.jruby.Main))]
(cli-ruby! config (concat ["-e" (format "load '%s'" url) "--"] args)))))
Expand Up @@ -292,6 +292,6 @@
{:keys [ruby-load-path gem-home]} config]
(doto jruby-config
(.setEnvironment (managed-environment (get-system-env) gem-home))
(.setLoadPaths (managed-load-path ruby-load-path jruby-home))
(.setLoadPaths (managed-load-path ruby-load-path))
(.setCompatVersion (CompatVersion/RUBY1_9)))
(Main. jruby-config)))
4 changes: 4 additions & 0 deletions src/clj/puppetlabs/services/jruby/jruby_puppet_schemas.clj
Expand Up @@ -186,3 +186,7 @@

(def JRubyMainStatus
(schema/pred jruby-main-status-instance?))

(def JRubyMainStatusOrNil
(schema/either JRubyMainStatus
(schema/pred nil? 'nil?)))
Expand Up @@ -107,7 +107,9 @@
{:keys [return out]} m
exit-code (.getStatus return)]
(is (= 0 exit-code))
(is (re-find #"VERSION: \d+\.\d+\.\d+" out))))))
(is (re-find #"VERSION: \d+\.\d+\.\d+" out))))
(testing "non existing subcommand returns nil"
(is (nil? (jruby-core/cli-run! min-config "doesnotexist" []))))))

(deftest ^:integration cli-ruby!-test
(testing "jruby cli command output"
Expand Down

0 comments on commit 791ba54

Please sign in to comment.