Skip to content

Commit

Permalink
Changed SSH to use Net::SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Feb 25, 2013
1 parent d050c75 commit 310c800
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -9,6 +9,8 @@ gem 'plist'
gem 'rest-client'
gem 'yard'
gem 'net/ftp'
gem 'net/ssh'
gem 'net/scp'

group :test do
gem 'rspec'
Expand Down
2 changes: 1 addition & 1 deletion lib/xcode/builder/base_builder.rb
Expand Up @@ -108,7 +108,7 @@ def web(protocol)

web = Xcode::Deploy::Web.new(protocol)
yield(web) if block_given?
web.prepare(ipa_name, app_path, configuration_build_path, product_name)
web.prepare(ipa_name, app_path, configuration_build_path, @config.product_name, @config.info_plist, ipa_path)
web.deploy
end

Expand Down
39 changes: 29 additions & 10 deletions lib/xcode/deploy/web.rb
@@ -1,9 +1,11 @@
require 'net/ftp'
require 'net/ssh'
require 'net/scp'

module Xcode
module Deploy
class Web
attr_accessor :protocol, :remote_host, :deploy_to, :username, :password, :remote_directory, :product_name, :ipa_name, :dist_path
attr_accessor :protocol, :remote_host, :deploy_to, :username, :password, :remote_directory, :product_name, :ipa_name, :dist_path, :ipa_path

def initialize(protocol)
@protocol = protocol
Expand All @@ -21,13 +23,14 @@ def remote_installation_path
File.join(@remote_directory, @product_name.downcase)
end

def prepare(ipa_name, app_path, configuration_build_path, product_name)
def prepare(ipa_name, app_path, configuration_build_path, product_name, info_plist, ipa_path)
@product_name = product_name
@ipa_name = ipa_name
@dist_path = "#{configuration_build_path}/dist"
File.mkdir(@dist_path)
plist = CFPropertyList::List.new(:file => "#{app_path}/Info.plist")
plist_data = CFPropertyList.native_types(plist.value)
@ipa_path = ipa_path
Dir.mkdir(@dist_path) unless File.exists?(@dist_path)
#plist = CFPropertyList::List.new(:file => "#{app_path}/Info.plist")
#plist_data = CFPropertyList.native_types(plist.value)
File.open("#{@dist_path}/manifest.plist", "w") do |io|
io << %{
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -49,13 +52,13 @@ def prepare(ipa_name, app_path, configuration_build_path, product_name)
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>#{plist_data['CFBundleIdentifier']}</string>
<string>#{info_plist.identifier}</string>
<key>bundle-version</key>
<string>#{plist_data['CFBundleVersion']}</string>
<string>#{info_plist.version}</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>#{plist_data['CFBundleDisplayName']}</string>
<string>#{product_name}</string>
</dict>
</dict>
</array>
Expand Down Expand Up @@ -93,7 +96,20 @@ def prepare(ipa_name, app_path, configuration_build_path, product_name)

def deploy
if @protocol == "ssh" then
system("scp #{@dist_path}/* #{@remote_host}:#{remote_installation_path}")
puts "Copying files to #{@remote_host}:#{remote_installation_path}"
#system("scp #{@dist_path}/* #{@remote_host}:#{remote_installation_path}")
Net::SSH.start(@remote_host, @username, :password => @password) do |ssh|
puts "Creating folder with mkdir #{remote_installation_path}"
ssh.exec!("mkdir #{remote_installation_path}")
end
Net::SCP.start(@remote_host, @username, :password => @password) do |scp|
puts "Copying files from folder #{@dist_path}"
Dir["#{@dist_path}/*"].each do |f|
puts "Copying #{f} to remote host in folder #{remote_installation_path}"
scp.upload! "#{f}", "#{remote_installation_path}"
end
scp.upload! "#{@ipa_path}", "#{remote_installation_path}"
end
elsif @protocol == "ftp" then
puts "Connecting to #{@remote_host} with username #{@username}"
Net::FTP.open(@remote_host, @username, @password) do |ftp|
Expand All @@ -105,11 +121,14 @@ def deploy
end
puts "Changing to remote folder #{remote_installation_path}"
files = ftp.chdir(remote_installation_path)
Dir['#{@dist_path}/*'].each do |f|
Dir["#{@dist_path}/*"].each do |f|
filename = File.basename(f)
puts "Uploading #{filename}"
ftp.putbinaryfile(f, filename, 1024)
end
filename = File.basename("#{@ipa_path}")
puts "Uploading #{filename}"
ftp.putbinaryfile("#{@ipa_path}", filename, 1024)
end

else
Expand Down
16 changes: 16 additions & 0 deletions lib/xcode/info_plist.rb
Expand Up @@ -34,6 +34,22 @@ def version=(version)
@plist['CFBundleVersion'] = version.to_s
end

def identifier
@plist['CFBundleIdentifier']
end

def identifier=(identifier)
@plist['CFBundleIdentifier'] = identifier
end

def display_name
@plist['CFBundleDisplayName']
end

def display_name=(name)
@plist['CFBundleDisplayName'] = name
end

def save
File.open(@plist_location, 'w') {|f| f << @plist.to_plist}
end
Expand Down

0 comments on commit 310c800

Please sign in to comment.