Skip to content

Commit

Permalink
Added ability to set the environment for all grails commands and have…
Browse files Browse the repository at this point in the history
… it persist across command invocations.
  • Loading branch information
ldaley committed Nov 20, 2010
1 parent 0119bd2 commit a0c13ab
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 9 deletions.
24 changes: 24 additions & 0 deletions Commands/Set Environment….tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>autoScrollOutput</key>
<true/>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>grailsmate_bootstrap.sh set_env</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>^@G</string>
<key>name</key>
<string>Set Environment…</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.groovy, source.java, source.java-props, text.xml, text.html.grails</string>
<key>uuid</key>
<string>A085D123-3C2B-4960-AC5B-0D576FE55F49</string>
</dict>
</plist>
79 changes: 70 additions & 9 deletions Support/GrailsMate/GrailsMate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,71 @@
class GrailsCommand

attr_reader :colorisations

@@location = ENV['TM_PROJECT_DIRECTORY'] || ENV['TM_DIRECTORY']
@@prefs = PStore.new(File.expand_path( "~/Library/Preferences/com.macromates.textmate.grailsmate"))

def self.prefs(&t)
@@prefs.transaction do |p|
t.call(p)
end
end

def self.location_prefs(&t)
prefs do |p|
p[@@location] = {} if p[@@location].nil?
t.call(p[@@location])
end
end

def self.get_location_pref(key)
location_prefs do |p|
p[key]
end
end

def self.set_location_pref(key, value)
location_prefs do |p|
p[key] = value
end
end

def self.last_option_prefs(&t)
location_prefs do |p|
p["task"] = {} if p["task"].nil?
t.call(p["task"])
end
end

def self.set_last_option_pref(task, option)
last_option_prefs do |p|
p[task] = option
end
end

def self.get_last_option_pref(task)
last_option_prefs do |p|
p[task]
end
end

def self.select_env
env = TextMate::UI.request_string(
:title => "Grails Environment",
:prompt => 'Enter the full name of the environment you wish to set (leave blank for default)',
:default => get_env(),
:button2 => "Clear"
)
set_location_pref("env", env)
env
end

def self.get_env
get_location_pref("env")
end

def initialize(task, &option_getter)
@grails = ENV['TM_GRAILS']
@location = ENV['TM_PROJECT_DIRECTORY'] || ENV['TM_DIRECTORY']
@task = task
@option_getter = option_getter
@command = nil
Expand All @@ -27,19 +88,19 @@ def command
if @command.nil?
option = nil
unless @option_getter.nil?
prefs = PStore.new(File.expand_path( "~/Library/Preferences/com.macromates.textmate.grailsmate"))
pref_key = "#{@location}::#{@task}"
last_value = prefs.transaction(true) { prefs[pref_key] }
last_value = self.class.get_last_option_pref(@task)
option = @option_getter[last_value]
prefs.transaction { prefs[pref_key] = option }
self.class.set_last_option_pref(@task, option)
end
@command = construct_command(@task, option)
end
@command
end

def construct_command(task, option)
def construct_command(task, option)
env = self.class.get_env
command = []
command << "-Dgrails.env=#{env}" if env
command << task unless task.nil? or task.empty?
unless option.nil? or option.empty?
(Shellwords.shellwords(option).each { |option| command << option })
Expand All @@ -48,9 +109,9 @@ def construct_command(task, option)
end

def run
Dir.chdir(@location) do
Dir.chdir(@@location) do
cmd = command
TextMate::HTMLOutput.show(:window_title => "GrailsMate", :page_title => "GrailsMate", :sub_title => "#{@location}") do |io|
TextMate::HTMLOutput.show(:window_title => "GrailsMate", :page_title => "GrailsMate", :sub_title => "#{@@location}") do |io|
if cmd.nil?
io << "Command cancelled."
else
Expand All @@ -65,7 +126,7 @@ def run
end
end
line = (match ? match : "#{htmlize line}<br/>")
line.sub!(/(Running test )(\S+)(\.\.\.)/, "\\1<a href='txmt://open?url=file://#{@location}/test/reports/plain/TEST-\\2.txt'>\\2</a>\\3")
line.sub!(/(Running test )(\S+)(\.\.\.)/, "\\1<a href='txmt://open?url=file://#{@@location}/test/reports/plain/TEST-\\2.txt'>\\2</a>\\3")
line.sub!(/(Browse to )([^\<]+)/, "\\1<a href=\"javascript:TextMate.system('open \\\\'\\2\\\\'')\">\\2</a>")
line.sub!(/(view reports in )(.+)(\.)/, "\\0 <br /><br /><input type='submit' name='open_test_report' value='Open HTML Report' onclick=\"TextMate.system('open \\\\'\\2/html/index.html\\\\'')\"/>")
io << line
Expand Down
1 change: 1 addition & 0 deletions Support/GrailsMate/set_env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GrailsCommand.select_env
2 changes: 2 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
<string>9B67E226-4E45-4DDD-99FC-31545A67B7B9</string>
<string>90AF1D77-BD5E-454C-A5E0-D8B19DA4089A</string>
<string>DEFDA7D4-BB3B-47D4-9408-C63C7A901A97</string>
<string>A085D123-3C2B-4960-AC5B-0D576FE55F49</string>
<string>69E74F74-6AEC-43A3-9F82-580CD17DE40B</string>
</array>
<key>uuid</key>
<string>2536CAAD-FADB-4C08-B950-A7FAAD24A738</string>
Expand Down

0 comments on commit a0c13ab

Please sign in to comment.