vj-player-sdk 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ *.esproj
3
+ *.gemspec
4
+ bin/
5
+ tmp/
6
+ pkg/
data/README.textile ADDED
@@ -0,0 +1,35 @@
1
+ h1. Videojuicer Player SDK
2
+
3
+ h2. Configuration
4
+
5
+ You must create a `config.yml` to define the build tasks for the `playersdk` to use, the configuration file uses standard "YAML":http://en.wikipedia.org/wiki/YAML syntaxs.
6
+
7
+ ---
8
+ # Flex SDK location
9
+ flex_sdk: "/Applications/Adobe\ Flex\ Builder\ 3/sdks/3.3.0"
10
+
11
+ # Flex framework version, the bundled RSLs are specific
12
+ flex_framework_version: "framework_3.3.0.4852"
13
+
14
+ # List of tasks the SDK will complete
15
+ tasks:
16
+ # Copies the Flex framework RSLs into the build folder
17
+ "framework": {
18
+ type: framework,
19
+ framework_rsl: 'framework_3.3.0.4852'
20
+ }
21
+ # Compiles an Addon for use with the Videojuicer Player
22
+ "player-addon": {
23
+ type: addon,
24
+ src: vj-player-ui/src, main: DefaultUI.mxml,
25
+ sdk: true,
26
+ engine: "builds/vj-player-engine",
27
+ libs: false,
28
+ target: player-addon
29
+ }
30
+
31
+ h2. TODO
32
+
33
+ # Tests
34
+ # Expand README
35
+ License
data/Rakefile ADDED
@@ -0,0 +1,71 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ gem 'jeweler', '>= 1.0.1'
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |s|
9
+ s.name = "vj-player-sdk"
10
+ s.summary = %Q{Videojuicer Player SDK runtime and compiler to create and build Player Addons.}
11
+ s.homepage = "http://videojuicer.com/"
12
+ s.email = "adam@videojuicer.com"
13
+ s.description = "Videojuicer Player SDK runtime and compiler to create and build Player Addons."
14
+ s.authors = ["sixones", "danski"]
15
+ s.files.exclude 'test/dest'
16
+ s.test_files.exclude 'test/dest'
17
+
18
+ # Dependencies
19
+ s.add_dependency('open4', '>= 0.9.6')
20
+ s.add_dependency('rubyzip', '>= 0.9.1')
21
+ end
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: sudo gem install jeweler --version '>= 1.0.1'"
24
+ exit(1)
25
+ end
26
+
27
+ Rake::TestTask.new do |t|
28
+ t.libs << 'lib'
29
+ t.pattern = 'test/**/test_*.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+ Rake::RDocTask.new do |rdoc|
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = 'playersdk'
36
+ rdoc.options << '--line-numbers' << '--inline-source'
37
+ rdoc.rdoc_files.include('README*')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
40
+
41
+ begin
42
+ require 'rcov/rcovtask'
43
+ Rcov::RcovTask.new do |t|
44
+ t.libs << 'test'
45
+ t.test_files = FileList['test/**/test_*.rb']
46
+ t.verbose = true
47
+ end
48
+ rescue LoadError
49
+ end
50
+
51
+ task :default => [:test, :features]
52
+
53
+ # console
54
+
55
+ desc "Open an irb session preloaded with this library"
56
+ task :console do
57
+ sh "irb -rubygems -I lib -r player-sdk.rb"
58
+ end
59
+
60
+ begin
61
+ require 'cucumber/rake/task'
62
+
63
+ Cucumber::Rake::Task.new(:features) do |t|
64
+ t.cucumber_opts = "--format progress"
65
+ end
66
+ rescue LoadError
67
+ desc 'Cucumber rake task not available'
68
+ task :features do
69
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
70
+ end
71
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 4
4
+ :patch: 5
data/lib/playersdk.rb ADDED
@@ -0,0 +1,60 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+
3
+ # rubygems
4
+ require 'rubygems'
5
+
6
+ # core
7
+ require 'fileutils'
8
+ require 'yaml'
9
+ require 'zip/zip'
10
+
11
+ # internal requires
12
+ require 'playersdk/core_ext/hash.rb'
13
+ require 'playersdk/compiler.rb'
14
+ require 'playersdk/compilers/flex.rb'
15
+
16
+ module PlayerSDK
17
+ # Default options. Overriden by values in config.yml or command-line opts.
18
+ # (Strings rather symbols used for compatability with YAML)
19
+ DEFAULTS = {
20
+ 'build_dir' => '.',
21
+ 'temp_dir' => 'tmp',
22
+ 'config_path' => './config.yml',
23
+ 'flex_sdk' => '',
24
+ 'flex_framework_swc' => 'frameworks/libs/framework.swc',
25
+ 'flex_framework_version' => '',
26
+ 'tasks' => '',
27
+ 'verbose' => false,
28
+ 'deployment_url' => ''
29
+ }
30
+
31
+ # Generate a Player SDK configuration Hash by merging the default options
32
+ # with anything in config.yml, and adding the given options on top
33
+ # +override+ is a Hash of config directives
34
+ #
35
+ # Returns Hash
36
+ def self.configuration(override)
37
+ # _config.yml may override default source location, but until
38
+ # then, we need to know where to look for _config.yml
39
+ config_path = override['config_path'] || PlayerSDK::DEFAULTS['config_path']
40
+
41
+ # Get configuration from <source>/config.yml
42
+ config = {}
43
+
44
+ begin
45
+ config = YAML.load_file(config_path)
46
+ puts "Configuration from #{config_path}"
47
+ rescue => err
48
+ puts "WARNING: Could not read configuration. Using defaults (and options)."
49
+ puts "\t" + err
50
+ end
51
+
52
+ # Merge DEFAULTS < config.yml < override
53
+ PlayerSDK::DEFAULTS.deep_merge(config).deep_merge(override)
54
+ end
55
+
56
+ def self.version
57
+ yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
58
+ "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
59
+ end
60
+ end
@@ -0,0 +1,122 @@
1
+ module PlayerSDK
2
+ class Compiler
3
+ attr_accessor :config, :compiler, :version
4
+
5
+ def initialize(config)
6
+ self.config = config.clone
7
+
8
+ self.compiler = PlayerSDK::Compilers::Flex.new(self.config);
9
+ end
10
+
11
+ def process
12
+ tasks = self.config['tasks']
13
+
14
+ puts "Found #{tasks.length} task(s) to process"
15
+
16
+ if tasks.length != 0
17
+ # find the copy tasks
18
+ tasks.each do |key,value|
19
+ if value['type'] == 'copy'
20
+ self.run_task(key, value)
21
+ end
22
+ end
23
+
24
+ find_version
25
+
26
+ if self.version != nil
27
+ self.config['deployment_url'] = self.config['deployment_url'].gsub("%V", self.version)
28
+
29
+ puts "Deployment url set to: #{self.config['deployment_url']}"
30
+
31
+ tasks.each do |key,value|
32
+ if value['type'] != 'copy'
33
+ self.run_task(key, value)
34
+ end
35
+ end
36
+
37
+ puts "\n\n"
38
+ end
39
+
40
+ puts "Completed #{tasks.length} tasks(s)"
41
+ end
42
+ end
43
+
44
+ def find_version
45
+ if File.exists?("#{self.config['build_dir']}/version.properties")
46
+ file = File.read("#{self.config['build_dir']}/version.properties")
47
+
48
+ if (file == nil)
49
+ puts "Something went wrong reading the file"
50
+ return
51
+ end
52
+
53
+ version_s = ""
54
+ file.scan(/version.([a-z]+) = ('?)([\w]+)('?)/i).each { |key, q1, value, q2|
55
+ if value != ''
56
+ if key == 'text'
57
+ version_s = version_s.slice(0, version_s.length - 1)
58
+ end
59
+
60
+ version_s += "#{value}."
61
+ end
62
+ }
63
+
64
+ version_s = version_s.slice(0, version_s.length - 1)
65
+
66
+ self.version = version_s
67
+
68
+ puts "Using version #{self.version}"
69
+ else
70
+ puts "No version file found at #{self.config['build_dir']}/version.properties"
71
+ end
72
+ end
73
+
74
+ def run_task(key, value)
75
+ if value['src'] != nil && value['src'] != ''
76
+ puts "\nRunning task #{key} in #{value['src']}"
77
+ else
78
+ puts "\nRunning task #{key}"
79
+ end
80
+
81
+ case value['type']
82
+ when "player"
83
+ self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
84
+ when "engine"
85
+ self.compiler.compile_compc(value['src'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
86
+
87
+ puts "Optimizing engine swf .."
88
+
89
+ optimize_target = value['optimize_target'] != '' ? value['optimize_target'] : value['target']
90
+
91
+ self.compiler.optimize_swc(value['target'], optimize_target, self.config['build_dir'])
92
+ when "addon"
93
+ self.compiler.compile_mxmlc(value['src'], value['main'], value['sdk'], value['engine'], value['libs'], value['target'], self.config['build_dir'], self.config['deployment_url'])
94
+ when "framework"
95
+ if value['target'] == nil || value['target'] == ""
96
+ value['target'] = 'framework'
97
+ end
98
+
99
+ puts "Moving Flex framework RSLs to #{value['target']}"
100
+
101
+ self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swz #{config['build_dir']}/#{value['target']}.swz")
102
+ self.compiler.run_command("cp #{config['flex_sdk']}/frameworks/rsls/#{value['framework_rsl']}.swf #{config['build_dir']}/#{value['target']}.swf")
103
+
104
+ #self.compiler.run_command("chmod 644 #{config['build_dir']}/#{config['target']}.sw*")
105
+ when "clean"
106
+ puts "Cleaning directories ..."
107
+
108
+ self.compiler.run_command("rm -rf #{config['build_dir']}/* #{config['tmp_dir']}/*")
109
+ when "copy"
110
+ puts "Copying over #{value['src']}"
111
+
112
+ self.compiler.run_command("cp #{value['src']} #{config['build_dir']}/#{value['target']}")
113
+ when ""
114
+ puts "Unknown task type, skipping task ..\n"
115
+ return
116
+ end
117
+
118
+ puts "\n"
119
+ puts "Successfully compiled #{key} to target #{value['target']}.\n"
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,102 @@
1
+ module PlayerSDK
2
+ module Compilers
3
+ class Flex
4
+ attr_accessor :config
5
+
6
+ def initialize(config)
7
+ self.config = config.clone
8
+ end
9
+
10
+ def executable(name)
11
+ excutable = "#{config['flex_sdk']}/bin/#{name}"
12
+
13
+ if false
14
+ excutable += ".exe"
15
+ end
16
+
17
+ excutable
18
+ end
19
+
20
+ def run_command(command)
21
+ if config['verbose']
22
+ system command
23
+ else
24
+ `#{command}`
25
+ end
26
+ end
27
+
28
+ def compile_mxmlc(source_path, main_file, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
29
+ command ="#{executable('mxmlc')} -compiler.source-path #{source_path} -file-specs #{source_path}/#{main_file} -static-link-runtime-shared-libraries=false"
30
+
31
+ if include_sdk
32
+ command += " -runtime-shared-library-path=#{config['flex_sdk']}/frameworks/libs/framework.swc,#{deployment_url}/framework.swz,#{config['crossdomain_url']}/crossdomain.xml,#{deployment_url}/framework.swf"
33
+ end
34
+
35
+ if include_engine
36
+ command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}/vj-player-engine.swf"
37
+ end
38
+
39
+ if include_libs
40
+ command += " -compiler.include-libraries #{include_libs}"
41
+ end
42
+
43
+ command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
44
+ command += " -output #{output_dir}/#{output_file}"
45
+
46
+ run_command(command)
47
+ end
48
+
49
+ def compile_compc(source_path, include_sdk, include_engine, include_libs, output_file, output_dir, deployment_url)
50
+ command = "#{executable('compc')} -source-path #{source_path} -include-sources #{source_path}"
51
+
52
+ if include_sdk
53
+ command += " -runtime-shared-library-path=#{config['flex_sdk']}/#{config['flex_framework_swc']},#{deployment_url}/framework.swz,#{config['crossdomain_url']}/crossdomain.xml,#{deployment_url}/framework.swf"
54
+ end
55
+
56
+ if include_engine
57
+ command += " -runtime-shared-library-path=#{include_engine}.swc,#{deployment_url}/vj-player-engine.swf"
58
+ end
59
+
60
+ if include_libs
61
+ command += " -compiler.include-libraries #{include_libs}"
62
+ end
63
+
64
+ command += " -use-network -benchmark -compiler.strict --show-actionscript-warnings=true -compiler.optimize -compiler.as3"
65
+ command += " -output #{output_dir}/#{output_file}"
66
+
67
+ run_command(command)
68
+ end
69
+
70
+ def optimize_swc(input_swc, output_file, output_dir)
71
+ # extract
72
+ self.unzip("#{output_dir}/#{input_swc}", "#{config['temp_dir']}")
73
+
74
+ # optimize
75
+ command = "#{executable('optimizer')} -input #{config['temp_dir']}/library.swf -output #{output_dir}/#{output_file} --keep-as3-metadata='Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient'"
76
+
77
+ run_command(command)
78
+
79
+ # update digest information
80
+ command = "#{executable('digest')} --digest.swc-path #{output_dir}/#{input_swc} --digest.rsl-file #{output_dir}/#{output_file}"
81
+
82
+ run_command(command)
83
+ end
84
+
85
+ def unzip(file, destination)
86
+ Zip::ZipFile.open(file) { |zip_file|
87
+ zip_file.each { |f|
88
+ f_path = File.join(destination, f.name)
89
+
90
+ if File.exist?(f_path) then
91
+ FileUtils.rm_rf f_path
92
+ end
93
+
94
+ FileUtils.mkdir_p(File.dirname(f_path))
95
+
96
+ zip_file.extract(f, f_path) # unless File.exist?(f_path)
97
+ }
98
+ }
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,63 @@
1
+ class Hash
2
+
3
+ # Returns a new hash just like this one, but with all the string keys expressed as symbols.
4
+ # Also applies to hashes within self.
5
+ # Based on an implementation within Rails 2.x, thanks Rails!
6
+ def deep_symbolize
7
+ target = dup
8
+ target.inject({}) do |memo, (key, value)|
9
+ value = value.deep_symbolize if value.is_a?(Hash)
10
+ memo[(key.to_sym rescue key) || key] = value
11
+ memo
12
+ end
13
+ end
14
+
15
+ # Subtracts one hash from another by removing keys from the actor and recursing on any hash values.
16
+ # Returns a new Hash without affecting the actors.
17
+ # Example 1:
18
+ # {:foo=>"bar"} - {:foo=>"bar"} == {}
19
+ # Example 2 of deep nesting:
20
+ # {:foo=>{:bar=>"baz", :car=>"naz"}, :bar=>"baz"} - {:foo=>{:car=>"naz"}} == {:foo=>{:bar=>"baz"}, :bar=>"baz"}
21
+ def -(arg)
22
+ target = dup; actor = arg.dup
23
+ actor.each do |key, value|
24
+ if value.is_a?(Hash)
25
+ target[key] = target[key] - value
26
+ else
27
+ target.delete(key)
28
+ end
29
+ end
30
+ return target
31
+ end
32
+
33
+ # Returns a new hash just like this one, but with all STRING keys and values evaluated
34
+ # and rendered as liquid templates using the provided payload hash.
35
+ def deep_liquify(payload={})
36
+ target = dup
37
+ target.inject({}) do |memo, (key, value)|
38
+ value = value.deep_liquify(payload) if value.is_a?(Hash)
39
+ value = value.liquify(payload) if value.is_a?(String)
40
+ key = key.liquify(payload) if key.is_a?(String)
41
+ memo[(key.to_sym rescue key) || key] = value
42
+ memo
43
+ end
44
+ end
45
+
46
+ # Merges self with another hash, recursively.
47
+ #
48
+ # This code was lovingly stolen from some random gem:
49
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
50
+ #
51
+ # Thanks to whoever made it.
52
+ def deep_merge(hash)
53
+ target = dup
54
+ hash.keys.each do |key|
55
+ if hash[key].is_a? Hash and self[key].is_a? Hash
56
+ target[key] = target[key].deep_merge(hash[key])
57
+ next
58
+ end
59
+ target[key] = hash[key]
60
+ end
61
+ target
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vj-player-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
5
+ platform: ruby
6
+ authors:
7
+ - sixones
8
+ - danski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-30 00:00:00 +00:00
14
+ default_executable: playersdk
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: open4
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.9.6
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rubyzip
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.1
35
+ version:
36
+ description: Videojuicer Player SDK runtime and compiler to create and build Player Addons.
37
+ email: adam@videojuicer.com
38
+ executables:
39
+ - playersdk
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.textile
44
+ files:
45
+ - .gitignore
46
+ - README.textile
47
+ - Rakefile
48
+ - VERSION.yml
49
+ - bin/playersdk
50
+ - lib/playersdk.rb
51
+ - lib/playersdk/compiler.rb
52
+ - lib/playersdk/compilers/flex.rb
53
+ - lib/playersdk/core_ext/hash.rb
54
+ has_rdoc: true
55
+ homepage: http://videojuicer.com/
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Videojuicer Player SDK runtime and compiler to create and build Player Addons.
82
+ test_files: []
83
+