More weird merge bs.

This commit is contained in:
filmaj 2010-02-24 15:42:23 -08:00
parent de8dc4af2a
commit fcce200701

View File

@ -3,12 +3,12 @@ require 'fileutils'
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
class Build
attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir
attr_reader :android_sdk_path, :name, :pkg, :www, :path
def initialize(*a)
@android_sdk_path, @name, @pkg, @www, @path = a
@s = File::SEPARATOR
@dir = Dir.pwd + @s
@android_dir = File.expand_path(File.dirname(__FILE__))
@framework_dir = File.join(@android_dir, "framework")
end
# runs the build script
@ -35,7 +35,7 @@ class Build
end
Dir.chdir(@framework_dir)
`ant jar`
Dir.chdir(@dir)
Dir.chdir(@android_dir)
end
# runs android create project
@ -49,6 +49,7 @@ class Build
def include_www
puts "Adding www folder to project..."
FileUtils.mkdir_p File.join(@path, "assets", "www")
FileUtils.cp_r File.join(@www, "."), File.join(@path, "assets", "www")
end
@ -57,27 +58,40 @@ class Build
def generate_manifest
puts "Generating manifest..."
manifest = ""
open(@dir + 'framework/AndroidManifest.xml', 'r') do |old|
open(File.join(@framework_dir, "AndroidManifest.xml"), 'r') do |old|
manifest = old.read
manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"'
manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\""
manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\""
manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"'
end
open("#{ @path }#{@s}AndroidManifest.xml", 'w') { |x| x.puts manifest }
open(File.join(@path, "AndroidManifest.xml"), 'w') { |x| x.puts manifest }
end
# copies stuff from framework into the project
# TODO need to allow for www import inc icon
def copy_libs
puts "Copying over libraries and assets and creating phonegap.js..."
FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs"
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml"
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.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|
FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png"
framework_res_dir = File.join(@framework_dir, "res")
app_res_dir = File.join(@path, "res")
FileUtils.mkdir_p File.join(@path, "libs")
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
FileUtils.mkdir_p File.join(app_res_dir, "values")
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
FileUtils.mkdir_p File.join(app_res_dir, "layout")
%w(main.xml preview.xml).each do |f|
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
end
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
FileUtils.mkdir_p File.join(app_res_dir, e)
FileUtils.cp File.join(framework_res_dir, "drawable", "icon.png"), File.join(app_res_dir, e, "icon.png")
end
# concat JS and put into www folder.
js_dir = File.join(@framework_dir, "assets", "js")
@ -101,7 +115,7 @@ class Build
<string name=\"go\">Snap</string>
</resources>
"
open("#{ @path }#{@s}res#{@s}values#{@s}strings.xml", 'w') do |f|
open(File.join(@path, "res", "values", "strings.xml"), 'w') do |f|
f.puts x.gsub(' ','')
end
end
@ -127,10 +141,11 @@ class Build
}
}
"
dir = "#{ @path }#{@s}src#{@s}#{ @pkg.gsub '.', '/' }";
cls = "#{ @name }.java"
pth = File.join(dir,cls)
open(pth,'w') { |f| f.puts j.gsub(' ','') }
code_dir = File.join(@path, "src", @pkg.gsub('.', File::SEPARATOR))
FileUtils.mkdir_p(code_dir)
open(File.join(code_dir, "#{@name}.java"),'w') { |f| f.puts j.gsub(' ','') }
end
#
end