Permalink
Browse files

Add apk distribution.

  • Loading branch information...
1 parent 6862dba commit 2e0bfd04ae227ce66231206e4e956933b046794a @yuya-takeyama committed Jun 3, 2012
Showing with 41 additions and 22 deletions.
  1. +32 −19 lib/andy/app.rb
  2. +9 −3 views/projects/branch.haml
View
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'andy'
require 'yaml'
require 'digest/sha1'
@@ -7,6 +8,10 @@ def initialize(url)
@url = url
end
+ def checkout(path, to)
+ `svn co #{@url+path} #{to}`
+ end
+
def branches
`svn ls #{@url}/branches`.split("\n").grep(%r{/$}).map{|r| r.sub(%r{/$}, '') }
end
@@ -21,7 +26,7 @@ def android_project_root?(path)
end
class Andy::App < ::Sinatra::Base
- set :haml, {:format => :html5}
+ set :haml, {:format => :html5, :encoding => 'utf-8'}
set :root, Andy::ROOT_DIR
set :views, File.expand_path('views', settings.root)
set :config, YAML::load(open(File.expand_path('config/config.yml', settings.root)))
@@ -35,13 +40,20 @@ class Andy::App < ::Sinatra::Base
end
end
- get '/:repo/*.apk' do
- branch = params[:splat].join('/')
- setup_worktree(params[:repo], branch)
+ get '/projects/:project_id/*/:file.apk' do
+ @path = "/" + params['splat'].join('/')
+ repo_hash = ::Digest::SHA1.hexdigest(@project['repo']['url'])
+ dir = ::File.expand_path("tmp/repos/#{@project_id}/#{repo_hash}#{@path}/bin", settings.root)
+ send_file "#{dir}/#{params[:file]}.apk", :type => 'application/vnd.android.package-archive'
end
get '/projects/:project_id/*' do
@path = "/" + params['splat'].join('/')
+ if params['build']
+ build_apk(@project_id, @project, @path)
+ redirect "/projects/#{@project_id}#{@path}"
+ end
+ @apks = apks(@project_id, @project, @path)
haml :'projects/branch', :locals => {:title => @project['name'] + " - " + @path}
end
@@ -54,30 +66,31 @@ class Andy::App < ::Sinatra::Base
haml :index
end
- def repo_config
- settings.repos[params[:repo]]
- end
-
- def repo(project)
- ::Grit::Repo.new(project['repo']['url'])
- end
-
- def setup_worktree(repo_name, branch)
- repo_hash = ::Digest::SHA1.hexdigest(repo_config['url'])
- dir = ::File.expand_path("tmp/repos/#{repo_name}/#{repo_hash}/#{branch}", settings.root)
+ def build_apk(project_id, project, path)
+ repo_hash = ::Digest::SHA1.hexdigest(project['repo']['url'])
+ dir = ::File.expand_path("tmp/repos/#{project_id}/#{repo_hash}#{path}", settings.root)
::FileUtils.rm_rf(dir) if File.exist? dir
::FileUtils.mkdir_p(dir)
- grit = ::Grit::Git.new('/tmp')
- clone_option = {:quiet => true, :verbose => false, :progress => false, :branch => branch}
- grit.clone(clone_option, repo_config['url'], dir)
+ @repo.checkout(@path, dir)
put_local_properties(dir)
orig_dir = Dir.pwd
Dir.chdir(dir)
- result = `ant release`
+ java_opt = "_JAVA_OPTIONS='-Dfile.encoding=UTF-8'"
+ result = `#{java_opt} ant debug && #{java_opt} ant release`
Dir.chdir(orig_dir)
result
end
+ def apks(project_id, project, path)
+ repo_hash = ::Digest::SHA1.hexdigest(project['repo']['url'])
+ dir = ::File.expand_path("tmp/repos/#{project_id}/#{repo_hash}#{path}/bin", settings.root)
+ Dir.glob(dir + "/*.apk").map {|f| f.gsub(%r{^.*/}, '') }
+ end
+
+ def repo(project)
+ ::Grit::Repo.new(project['repo']['url'])
+ end
+
def put_local_properties(dir)
open("#{dir}/local.properties", 'w') do |file|
file.puts "sdk.dir=#{settings.config['android']['sdk_dir']}"
@@ -1,6 +1,12 @@
%a(href="/") ../
-- if @repo.android_project_root? @path
- %p This is Android project root.
-- else
+%div
+ %a(href="/projects/#{@project_id}#{@path}?build=on") Build this branch
+
+- unless @repo.android_project_root? @path
%p This is not Android project root.
+
+%ul
+ - @apks.each do |file|
+ %li
+ %a(href="/projects/#{@project_id}#{@path}/#{file}") #{file}

0 comments on commit 2e0bfd0

Please sign in to comment.