Skip to content
This repository has been archived by the owner on Nov 24, 2017. It is now read-only.

Commit

Permalink
Merge pull request #77 from danielegozzi/master
Browse files Browse the repository at this point in the history
Passing options to the JVM
  • Loading branch information
cjohansen committed Aug 15, 2014
2 parents 09d4bc4 + 8239149 commit 8786f2f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/juicer/binary.rb
Expand Up @@ -29,8 +29,8 @@ def path

# Run command
#
def execute(params = nil)
cmd = IO.popen("#{self.command} #{params}", "r")
def execute(*params)
cmd = IO.popen(([self.command] + params).flatten, "r")
results = cmd.gets(nil)
cmd.close
results
Expand Down Expand Up @@ -107,7 +107,7 @@ def set_opts(options)
def command
return @command if !@opt_set && @command
@opt_set = false
@command = "#{@binary} #{options}"
@command = [@binary, options]
end

# Locate the binary to execute. The binary is searched for in the
Expand Down
14 changes: 13 additions & 1 deletion lib/juicer/jslint.rb
Expand Up @@ -18,6 +18,18 @@ def initialize(options = {})
path << options[:bin_path] if options[:bin_path]
end

# Constructs the command to use
#
def command
java_opts = []
if ENV['JAVA_OPTS'].nil?
java_opts = []
else
java_opts = ENV['JAVA_OPTS'].split(" ")
end
@command = ([@binary] + java_opts).flatten
end

#
# Checks if a files has problems. Also includes experimental support for CSS
# files. CSS files should begin with the line @charset "UTF-8";
Expand All @@ -32,7 +44,7 @@ def check(file)
raise FileNotFoundError.new("Unable to locate JsLint '#{js_file}'") if !js_file || !File.exists?(js_file)
raise FileNotFoundError.new("Unable to locate input file '#{file}'") unless File.exists?(file)

lines = execute(%Q{-jar "#{rhino}" "#{locate_lib}" "#{file}"}).split("\n")
lines = execute("-jar", rhino, locate_lib, file).split("\n")
return Report.new if lines.length == 1 && lines[0] =~ /jslint: No problems/

report = Report.new
Expand Down
2 changes: 1 addition & 1 deletion lib/juicer/minifyer/closure_compiler.rb
Expand Up @@ -62,7 +62,7 @@ def save(file, output = nil, type = nil)

out_dir = File.dirname(output)
FileUtils.mkdir_p(out_dir) unless File.exists?(out_dir)
execute(%Q{-jar "#{locate_jar}"#{jar_args} --js_output_file "#{output}" --js "#{file}"})
execute("-jar", "#{locate_jar}#{jar_args}", "--js_output_file", output, "--js", file)

File.delete(file) if use_tmp
end
Expand Down
12 changes: 12 additions & 0 deletions lib/juicer/minifyer/java_base.rb
Expand Up @@ -55,6 +55,18 @@ def set_opts(args)
@jar_args = " #{args}"
end

# Constructs the command to use
#
def command
java_opts = []
if ENV['JAVA_OPTS'].nil?
java_opts = []
else
java_opts = ENV['JAVA_OPTS'].split(" ")
end
@command = ([@binary] + java_opts).flatten
end

def jar_args
@jar_args
end
Expand Down
2 changes: 1 addition & 1 deletion lib/juicer/minifyer/yui_compressor.rb
Expand Up @@ -57,7 +57,7 @@ def save(file, output = nil, type = nil)
output = File.join(Dir::tmpdir, File.basename(file) + '.min.tmp.' + type.to_s) if use_tmp
FileUtils.mkdir_p(File.dirname(output))

result = execute(%Q{-jar "#{locate_jar}"#{jar_args} -o "#{output}" "#{file}"})
result = execute("-jar", "#{locate_jar}#{jar_args}", "-o", output, file)

if use_tmp # If no output file is provided, YUI compressor will
output.puts IO.read(output) # compress to a temp file. This file should be cleared
Expand Down
2 changes: 1 addition & 1 deletion test/unit/juicer/css_cache_buster_test.rb
Expand Up @@ -80,7 +80,7 @@ def teardown
buster = Juicer::CssCacheBuster.new :document_root => path("")
buster.save file, output

buster.urls(output).each { |url| assert url !~ /(jcb=\d+).*(jcb=\d+)/, url }
buster.urls(output).each { |url| assert url !~ /(jcb=\d+).*(jcb=\d+)/, url.to_s }
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/juicer/jslint_test.rb
Expand Up @@ -19,7 +19,7 @@ def teardown
context "verifying file with jslint" do
should "shell out to rhino/jslint" do
jslint = Juicer::JsLint.new(:bin_path => @path)
jslint.expects(:execute).with("-jar \"#{@path}/rhino1_7R3.jar\" \"#{@path}/jslint-1.0.js\" \"#{@file}\"").returns("jslint: No problems")
jslint.expects(:execute).with("-jar", "#{@path}/rhino1_7R3.jar", "#{@path}/jslint-1.0.js", @file).returns("jslint: No problems")

assert jslint.check(@file).ok?
end
Expand Down
8 changes: 4 additions & 4 deletions test/unit/juicer/minifyer/closure_compressor_test.rb
Expand Up @@ -6,25 +6,25 @@ def setup
@jar = "compiler.jar"
@input = "in-file.css"
@output = "out-file.css"
@cmd = %Q{-jar "#@jar"}
@cmd = "-jar", @jar
@closure = Juicer::Minifyer::ClosureCompiler.new
@closure.stubs(:locate_jar).returns(@jar)
end

context "#save" do
should "overwrite existing file" do
@closure.expects(:execute).with(%Q{#@cmd --js_output_file "#@output" --js "#@output"})
@closure.expects(:execute).with(*@cmd, "--js_output_file", @output, "--js", @output)
@closure.save(@output, @output)
end

should "write compressed input to output" do
@closure.expects(:execute).with(%Q{#@cmd --js_output_file "#@output" --js "#@input"})
@closure.expects(:execute).with(*@cmd , "--js_output_file", @output, "--js", @input)
@closure.save(@input, @output)
end

should "create non-existant path" do
output = "some/nested/directory"
@closure.expects(:execute).with(%Q{#@cmd --js_output_file "#{output}/file.css" --js "#@input"})
@closure.expects(:execute).with(*@cmd, "--js_output_file", "#{output}/file.css", "--js", @input)
FileUtils.expects(:mkdir_p).with(output)
@closure.save(@input, "#{output}/file.css")
end
Expand Down
12 changes: 6 additions & 6 deletions test/unit/juicer/minifyer/yui_compressor_test.rb
Expand Up @@ -5,35 +5,35 @@ def setup
@jar = "yuicompressor-2.4.2.jar"
@input = "in-file.css"
@output = "out-file.css"
@cmd = %Q{-jar "#@jar"}
@cmd = "-jar", @jar
@yui_compressor = Juicer::Minifyer::YuiCompressor.new
@yui_compressor.stubs(:locate_jar).returns(@jar)
end

context "#save" do
should "overwrite existing file" do
@yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@output"})
@yui_compressor.expects(:execute).with(*@cmd, "-o", @output, @output)
@yui_compressor.save(@output)
end

should "use provided symbol type" do
@yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
@yui_compressor.expects(:execute).with(*@cmd, "-o", @output, @input)
@yui_compressor.save(@input, @output, :css)
end

should "use provided string type" do
@yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
@yui_compressor.expects(:execute).with(*@cmd, "-o", @output, @input)
@yui_compressor.save(@input, @output, "css")
end

should "write compressed input to output" do
@yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
@yui_compressor.expects(:execute).with(*@cmd, "-o", @output, @input)
@yui_compressor.save(@input, @output)
end

should "create non-existant path" do
output = "some/nested/directory"
@yui_compressor.expects(:execute).with(%Q{#@cmd -o "#{output}/file.css" "#@input"})
@yui_compressor.expects(:execute).with(*@cmd, "-o", "#{output}/file.css", @input)
FileUtils.expects(:mkdir_p).with(output)
@yui_compressor.save(@input, "#{output}/file.css")
end
Expand Down

0 comments on commit 8786f2f

Please sign in to comment.