Updated the Ruby build script so that this shiat works on Windows!

This commit is contained in:
unknown 2010-02-03 16:41:39 -08:00
parent 4c0da8e241
commit c023c3d8cc

View File

@ -1,31 +1,44 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'fileutils'
class Build class Build
attr_reader :android_sdk_path, :name, :pkg, :www, :path attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir
def initialize(*a) def initialize(*a)
@android_sdk_path, @name, @pkg, @www, @path = a @android_sdk_path, @name, @pkg, @www, @path = a
@s = File::SEPARATOR
@dir = Dir.pwd + @s
end end
# runs the build script # runs the build script
def run def run
puts "Building the JAR..."
build_jar build_jar
puts "Creating Android project..."
create_android create_android
puts "Generating manifest..."
generate_manifest generate_manifest
puts "Copying over libraries and assets..."
copy_libs copy_libs
puts "Adding some application name to strings.xml..."
add_name_to_strings add_name_to_strings
puts "Writing application Java code..."
write_java write_java
puts "Complete!"
end end
# removes local.properties and recreates based on android_sdk_path # removes local.properties and recreates based on android_sdk_path
# then generates framework/phonegap.jar # then generates framework/phonegap.jar
def build_jar def build_jar
`rm framework/local.properties` if File.exists? 'framework/local.properties' FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties"
`rm framework/phonegap.jar` if File.exists? 'framework/phonegap.jar' FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js"
`rm framework/phonegap.js` if File.exists? 'framework/phonegap.js' FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar"
`ECHO 'sdk-location=#{ @android_sdk_path }' > framework/local.properties` open("#{ @dir }framework#{@s}local.properties", 'w') do |f|
`cd framework; ant jar` f.puts "sdk.dir=#{ @android_sdk_path }"
end end
Dir.chdir(@dir + "framework")
`ant jar`
Dir.chdir(@dir)
end
# runs android create project # runs android create project
# TODO need to allow more flexible SDK targetting # TODO need to allow more flexible SDK targetting
@ -37,29 +50,29 @@ class Build
# creates an AndroidManifest.xml for the project # creates an AndroidManifest.xml for the project
def generate_manifest def generate_manifest
manifest = "" manifest = ""
open('framework/AndroidManifest.xml', 'r') do |old| open(@dir + 'framework/AndroidManifest.xml', 'r') do |old|
manifest = old.read manifest = old.read
manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"' manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"'
manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\"" manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\""
manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\"" manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\""
manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"' manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"'
end end
open("#{ @path }/AndroidManifest.xml", 'w') { |x| x.puts manifest } open("#{ @path }#{@s}AndroidManifest.xml", 'w') { |x| x.puts manifest }
end end
# copies stuff from framework into the project # copies stuff from framework into the project
# TODO need to allow for www import inc icon # TODO need to allow for www import inc icon
def copy_libs def copy_libs
`mkdir -p #{ @path }/assets/wwww` FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www"
`cp framework/phonegap.jar #{ @path }/libs` FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs"
`cp framework/res/values/strings.xml #{ @path }/res/values/strings.xml` FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml"
`cp framework/res/layout/main.xml #{ @path }/res/layout/main.xml` FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml"
`cp framework/res/layout/preview.xml #{ @path }/res/layout/preview.xml` FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}preview.xml", "#{ @path }#{@s}res#{@s}layout#{@s}preview.xml"
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e| %w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
`cp framework/res/drawable/icon.png #{ @path }/res/#{ e }/icon.png` FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
end end
`cp -R example #{ @path }/assets` FileUtils.cp_r "#{ @www }#{ @s }", "#{ @path }#{ @s }assets#{ @s }"
`mv #{ @path }/assets/example #{ @path }/assets/www` FileUtils.mv "#{ @path }#{ @s }assets#{ @s }#{ @www }", "#{ @path }#{ @s }assets#{ @s }www"
end end
# puts app name in strings # puts app name in strings
@ -70,7 +83,7 @@ class Build
<string name=\"go\">Snap</string> <string name=\"go\">Snap</string>
</resources> </resources>
" "
open("#{ @path }/res/values/strings.xml", 'w') do |f| open("#{ @path }#{@s}res#{@s}values#{@s}strings.xml", 'w') do |f|
f.puts x.gsub(' ','') f.puts x.gsub(' ','')
end end
end end
@ -95,7 +108,7 @@ class Build
} }
} }
" "
dir = "#{ @path }/src/#{ @pkg.gsub '.', '/' }"; dir = "#{ @path }#{@s}src#{@s}#{ @pkg.gsub '.', '/' }";
cls = "#{ @name }.java" cls = "#{ @name }.java"
pth = File.join(dir,cls) pth = File.join(dir,cls)
open(pth,'w') { |f| f.puts j.gsub(' ','') } open(pth,'w') { |f| f.puts j.gsub(' ','') }