Skip to content

Commit

Permalink
added javac and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhansen committed Aug 1, 2009
1 parent 6b215a5 commit e5899e1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
49 changes: 49 additions & 0 deletions javac-test.rb
@@ -0,0 +1,49 @@
#!/bin/ruby
require 'test/unit'
require 'javac.rb'

class
Javac < Test::Unit::TestCase
def test_windows_javac_cmd_one_input
expected = "c:\\\\test.java"
actual = windows_javac_args("/cygdrive/c/test.java".split)
assert_equal(expected.split, actual)
end

def test_windows_javac_cmd_two_inputs
expected = "c:\\\\test.java c:\\\\test2.java"
actual = windows_javac_args("/cygdrive/c/test.java /cygdrive/c/test2.java".split)
assert_equal(expected.split, actual)
end

def test_windows_javac_cmd_options
expected = "-classpath c:\\\\classpath"
actual = windows_javac_args("-classpath /cygdrive/c/classpath".split)
assert_equal(expected.split, actual)
end

def test_windows_javac_cmd_slash
expected = "wrappers\\\\hello.java"
actual = windows_javac_args("./wrappers/hello.java")
assert_equal(expected.split, actual)
end

def test_find_javac
expected = "/cygdrive/c/Program Files/Java/jdk1.6.0_13/bin/javac.exe"
actual = javac_path()
assert_equal(expected, actual)
end

def test_javac_command
expected = '"/cygdrive/c/Program Files/Java/jdk1.6.0_13/bin/javac.exe" 1.java 2.java'
actual = windows_javac_command(["1.java", "2.java"])
assert_equal(expected, actual)
end

def test_to_winPathList
expected="c:\\home;c:\\java"
actual = to_winPathList("/cygdrive/c/home:/cygdrive/c/java")
assert_equal(expected, actual)
end

end
35 changes: 35 additions & 0 deletions javac.rb
@@ -0,0 +1,35 @@
#!/bin/ruby
require 'paths.rb'


def windows_javac_args(unixARGV)
unixARGV.map do | arg |
if arg[0] != '-'[0]
#need to escape slashes or javac swallows them
to_winPath(arg).sub(/\\/,"\\\\\\")
else
#options like '-d' aren't paths, so don't convert them
arg
end
end
end

def javac_path
javacName = "javac.exe"
javaPath = ENV["JAVA_HOME"]
IO.popen("find \"#{javaPath}\" -name #{javacName}").readlines[0].chomp
end

def windows_javac_command(unixARGV)
'"' << javac_path << '" ' << windows_javac_args(unixARGV).join(" ")
end

if __FILE__ == $0
ENV["CLASSPATH"] = to_winPathList(ENV["CLASSPATH"])

javac = IO.popen(windows_javac_command(ARGV))

#wait for javac to finish before exitting
#and echo the input
puts javac.readlines
end

0 comments on commit e5899e1

Please sign in to comment.