ruboto 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,136 @@
1
+ ############################################################################
2
+ #
3
+ # Use to build dependencies within stdlib.
4
+ #
5
+
6
+ class StdlibDependencies
7
+ attr_reader :dependencies, :version
8
+
9
+ REQUIRE = %r{^\s*require[ (]['"]([a-zA-Z0-9/-_]+)["'][)]?\s*$}
10
+ REQUIRE_RELATIVE = %r{^\s*require_relative[ (]['"]([a-zA-Z0-9/-_]+)["'][)]?\s*$}
11
+
12
+ def self.[](key)
13
+ versions[key]
14
+ end
15
+
16
+ def self.versions
17
+ @@versions ||= {}
18
+ end
19
+
20
+ def self.collect(dir=".")
21
+ local = new("app")
22
+ Dir.chdir(dir) do
23
+ local.check_dir(["ruboto"])
24
+ end
25
+ local
26
+ end
27
+
28
+ def self.generate(dir=".")
29
+ versions
30
+
31
+ Dir.chdir(dir) do
32
+ raise("Can't find shared directory") unless File.directory?("shared")
33
+ Dir["*"].select{|d| File.directory?(d) && d != "shared"}.each do |d|
34
+ @@versions[d] = new(d).generate
35
+ end
36
+ end
37
+
38
+ versions
39
+ end
40
+
41
+ def self.dump(file)
42
+ require 'yaml'
43
+
44
+ all_dependencies = {}
45
+ versions.each{|k, v| all_dependencies[k] = v.dependencies}
46
+
47
+ File.open( file, 'w' ) do |out|
48
+ YAML.dump( all_dependencies, out )
49
+ end
50
+
51
+ versions
52
+ end
53
+
54
+ def self.load(file)
55
+ require 'yaml'
56
+
57
+ @@versions = {}
58
+ raise("Can't find #{file}") unless File.exists?(file)
59
+
60
+ File.open(file) do |versions|
61
+ YAML.load(versions).each{|k,v| @@versions[k] = new(k, v)}
62
+ end
63
+
64
+ versions
65
+ end
66
+
67
+ def initialize(version, dependencies={})
68
+ @version = version
69
+ @dependencies = dependencies
70
+ end
71
+
72
+ def [](key)
73
+ @dependencies[key]
74
+ end
75
+
76
+ def generate
77
+ raise("Can't find shared directory") unless File.directory?("shared")
78
+ raise("Can't find #{@version} directory") unless File.directory?(@version)
79
+
80
+ Dir.chdir("shared"){check_dir}
81
+ Dir.chdir(@version){check_dir}
82
+
83
+ # Clean up dependencies
84
+ @dependencies.keys.sort.each do |i|
85
+ # remove duplicates
86
+ @dependencies[i] = @dependencies[i].uniq
87
+
88
+ # remove references to self
89
+ @dependencies[i] = @dependencies[i] - [i]
90
+
91
+ # sort
92
+ @dependencies[i] = @dependencies[i].sort
93
+ end
94
+
95
+ self
96
+ end
97
+
98
+ def depends_on(name, on=nil)
99
+ base = name[0..-4]
100
+ @dependencies[base] = (@dependencies[base] || [])
101
+ @dependencies[base] << on
102
+ end
103
+
104
+ def gather_dependencies(file)
105
+ f = IO.read(file)
106
+
107
+ ##################################
108
+ #
109
+ # Handle encoding problems under different rubies
110
+ #
111
+ if String.method_defined?(:encode)
112
+ f.encode!('UTF-8', 'UTF-8', :invalid => :replace)
113
+ else
114
+ require 'iconv'
115
+ f = Iconv.new('UTF-8', 'UTF-8//IGNORE').iconv(f)
116
+ end
117
+ #
118
+ #################################
119
+
120
+ f.scan(REQUIRE) do |j|
121
+ depends_on(file, j[0])
122
+ end
123
+
124
+ f.scan(REQUIRE_RELATIVE) do |j|
125
+ on = file.split('/')[0..-2] << j[0]
126
+ depends_on(file, on.join('/'))
127
+ end
128
+ end
129
+
130
+ def check_dir(exclude=[])
131
+ Dir["**/*.rb"].select{|rb| not exclude.include?(rb.split('/')[0])}.each do |i|
132
+ gather_dependencies(i)
133
+ end
134
+ end
135
+ end
136
+
@@ -0,0 +1,62 @@
1
+ ###################################
2
+ #
3
+ # heap_alloc
4
+ #
5
+ # Forces the heap to grow by a number of megabytes.
6
+ # Can result in improved start-up performance because
7
+ # it prevents the heap from growing through smaller
8
+ # increments.
9
+ #
10
+ # heap_alloc: 13
11
+
12
+ ###################################
13
+ #
14
+ # ruby_version
15
+ #
16
+ # Sets the jruby.compat.version property of JRuby
17
+ # If you include the jruby jars, this is used to
18
+ # trim away unused versions of the stdlib.
19
+ #
20
+ #ruby_version: 1.9
21
+
22
+ ###################################
23
+ #
24
+ # included_stdlibs
25
+ #
26
+ # Specify parts of the stdlib that are needed.
27
+ # If you specify a list, all other components
28
+ # will be removed. If you specify "auto,"
29
+ # dependencies will be determined from
30
+ # auto_dependencies.yml. Running
31
+ # "rake libs:check_dependencies' will build
32
+ # auto_dependencies.yml.
33
+ #
34
+ # included_stdlibs: auto
35
+ #
36
+ # included_stdlibs:
37
+ # - fileutils
38
+
39
+ ###################################
40
+ #
41
+ # excluded_stdlibs
42
+ #
43
+ # Remove unneeded files from stdlib.
44
+ # Note: If you specify included_stdlibs above,
45
+ # this information will be ingnored.
46
+ #
47
+ #excluded_stdlibs:
48
+ #- ant
49
+ #- cgi
50
+ #- drb
51
+ #- erb
52
+ #- gauntlet_rdoc
53
+ #- minitest
54
+ #- profiler
55
+ #- rake
56
+ #- rdoc
57
+ #- shell
58
+ #- test
59
+ #- webrick
60
+ #- win32
61
+ #- Win32API
62
+
@@ -134,7 +134,9 @@ public class JRubyAdapter {
134
134
  Log.d("Setting up JRuby runtime (" + (isDebugBuild ? "DEBUG" : "RELEASE") + ")");
135
135
  System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri
136
136
  System.setProperty("jruby.bytecode.version", "1.6");
137
- // System.setProperty("jruby.compat.version", "RUBY2_0"); // RUBY1_9 is the default in JRuby 1.7
137
+ // BEGIN Ruboto RubyVersion
138
+ // System.setProperty("jruby.compat.version", "RUBY1_9"); // RUBY1_9 is the default in JRuby 1.7
139
+ // END Ruboto RubyVersion
138
140
  // System.setProperty("jruby.compile.backend", "DALVIK");
139
141
  System.setProperty("jruby.compile.mode", "OFF"); // OFF OFFIR JITIR? FORCE FORCEIR
140
142
  System.setProperty("jruby.interfaces.useProxy", "true");
@@ -377,14 +379,19 @@ public class JRubyAdapter {
377
379
  File storageDir = null;
378
380
  if (isDebugBuild()) {
379
381
  storageDir = context.getExternalFilesDir(null);
380
- if (storageDir == null || (!storageDir.exists() && !storageDir.mkdirs())) {
382
+ if (storageDir == null) {
381
383
  Log.e("Development mode active, but sdcard is not available. Make sure you have added\n<uses-permission android:name='android.permission.WRITE_EXTERNAL_STORAGE' />\nto your AndroidManifest.xml file.");
382
384
  storageDir = context.getFilesDir();
383
385
  }
384
386
  } else {
385
387
  storageDir = context.getFilesDir();
386
388
  }
387
- return storageDir.getAbsolutePath() + "/scripts";
389
+ File scriptsDir = new File(storageDir, "scripts");
390
+ if ((!scriptsDir.exists() && !scriptsDir.mkdirs())) {
391
+ Log.e("Unable to create the scripts dir.");
392
+ scriptsDir = new File(context.getFilesDir(), "scripts");
393
+ }
394
+ return scriptsDir.getAbsolutePath();
388
395
  }
389
396
 
390
397
  private static void setDebugBuild(Context context) {
@@ -140,13 +140,21 @@ public class SplashActivity extends Activity {
140
140
  }).start();
141
141
  }
142
142
  return;
143
+ } else {
144
+ Log.e("Permission missing for direct download: Internet: " +
145
+ hasInternetPermission() + ", non-market install: " +
146
+ canInstallFromUnknownSources());
143
147
  }
144
148
  } catch (Exception e) {
145
149
  Log.e("Exception in direct RubotoCore download: " + e);
150
+ e.printStackTrace();
146
151
  }
147
152
  try {
153
+ Log.i("Download RubotoCore using the market");
148
154
  startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://details?id=org.ruboto.core")));
149
155
  } catch (android.content.ActivityNotFoundException anfe) {
156
+ Log.e("Exception in market RubotoCore download: " + anfe);
157
+ Log.i("Download RubotoCore using the download manager");
150
158
  Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(RUBOTO_URL));
151
159
  startActivity(intent);
152
160
  }
@@ -347,18 +355,11 @@ public class SplashActivity extends Activity {
347
355
  }
348
356
 
349
357
  private boolean canInstallFromUnknownSources() {
350
- Uri settingsUri = Settings.Secure.CONTENT_URI;
351
- String[] projection = new String[]{Settings.System.VALUE};
352
- String selection = Settings.Secure.NAME + " = ? AND " + Settings.Secure.VALUE + " = ?";
353
-
354
- // FIXME(uwe): Use android.provider.Settings.Global.INSTALL_NON_MARKET_APPS
355
- // when we stop supporting Android api level < 17
356
- String[] selectionArgs = {Settings.Secure.INSTALL_NON_MARKET_APPS, String.valueOf(1)};
358
+ // FIXME(uwe): Use Settings.Global when we stop supporting Android api level < 17
359
+ // return Settings.Global.getInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
357
360
  // EMXIF
358
361
 
359
- Cursor query = getContentResolver().query(settingsUri, projection,
360
- selection, selectionArgs, null);
361
- return query.getCount() == 1;
362
+ return Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0) == 1;
362
363
  }
363
364
 
364
365
  // Get the downloaded percent
@@ -42,10 +42,10 @@ module Ruboto::Activity::Reload
42
42
  Log.d "Got reload intent: #{reload_intent.inspect}"
43
43
  file_string = reload_intent.get_string_extra('reload')
44
44
  if file_string
45
- files = file_string.split(/(?<!&);/).map { |f| f.gsub(/&(.)/) { |m| m[1] } }
45
+ scripts_dir = @activity.getExternalFilesDir(nil).absolute_path + '/scripts'
46
46
  files.each do |file|
47
- Log.d "load file: #{file.inspect}"
48
- load file
47
+ Log.d "load file: #{scripts_dir}/#{file}"
48
+ load "#{scripts_dir}/#{file}"
49
49
  end
50
50
  Log.d 'restart activity'
51
51
  if @activity.intent.action == android.content.Intent::ACTION_MAIN ||
@@ -55,8 +55,8 @@ module Ruboto::Activity::Reload
55
55
  else
56
56
  restart_intent = @activity.intent
57
57
  end
58
- @activity.startActivity(restart_intent)
59
58
  @activity.finish
59
+ @activity.startActivity(restart_intent)
60
60
  Log.d 'activity restarted'
61
61
  end
62
62
  Log.d 'reload complete.'
@@ -76,7 +76,10 @@ View.class_eval do
76
76
  end
77
77
 
78
78
  params.each do |k, v|
79
- method_name = self.respond_to?("#{k}=") ? "#{k}=" : k
79
+ setter_method = "set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}"
80
+ assign_method = "#{k}="
81
+ method_name = self.respond_to?(assign_method) ? assign_method :
82
+ (self.respond_to?(setter_method) ? setter_method : k)
80
83
  invoke_with_converted_arguments(self, method_name, v)
81
84
  end
82
85
  end
@@ -61,6 +61,12 @@ module Ruboto
61
61
  description 'Generate the JRuby jars jar'
62
62
  cast :boolean
63
63
  }
64
+ option('ruby-version') {
65
+ description 'Using what version of Ruby? (e.g., 1.8, 1.9, 2.0)'
66
+ argument :required
67
+ cast :float
68
+ validate {|rv| [1.8, 1.9, 2.0].include?(rv)}
69
+ }
64
70
  option('force') {
65
71
  description 'Force creation of project even if the path exists'
66
72
  cast :boolean
@@ -75,6 +81,7 @@ module Ruboto
75
81
  target = params['target'].value
76
82
  min_sdk = params['min-sdk'].value || target
77
83
  with_jruby = params['with-jruby'].value
84
+ ruby_version = params['ruby-version'].value
78
85
  force = params['force'].value
79
86
 
80
87
  abort "Path (#{path}) must be to a directory that does not yet exist. It will be created." if !force && File.exists?(path)
@@ -103,6 +110,13 @@ module Ruboto
103
110
  update_manifest min_sdk[/\d+/], target[/\d+/], true
104
111
  update_test true
105
112
  update_assets
113
+
114
+ if ruby_version
115
+ source = File.read('ruboto.yml')
116
+ pattern = %r{^#? ?ruby_version: 1.9$}
117
+ File.open('ruboto.yml', 'w') { |f| f << source.sub(pattern, "ruby_version: #{ruby_version}") }
118
+ end
119
+
106
120
  update_ruboto true
107
121
  update_icons true
108
122
  update_classes nil, 'exclude'
@@ -394,7 +408,7 @@ module Ruboto
394
408
  option('target', 't') {
395
409
  extend Ruboto::Util::Emulator
396
410
  description 'sets the target Android API level for the emulator'
397
- examples Ruboto::Util::Emulator::API_LEVEL_TO_VERSION.keys.join(', ')
411
+ examples Ruboto::SdkVersions::API_LEVEL_TO_VERSION.keys.join(', ')
398
412
  required unless api_level
399
413
  argument :required
400
414
  default(api_level) if api_level
@@ -3,16 +3,19 @@ require 'pathname'
3
3
  module Ruboto
4
4
  module SdkVersions
5
5
  VERSION_TO_API_LEVEL = {
6
- '2.3' => 'android-9', '2.3.1' => 'android-9', '2.3.2' => 'android-9',
7
- '2.3.3' => 'android-10', '2.3.4' => 'android-10',
8
- '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
9
- '4.0.1' => 'android-14', '4.0.3' => 'android-15', '4.0.4' => 'android-15',
10
- '4.1' => 'android-16', '4.1.1' => 'android-16', '4.1.2' => 'android-16',
11
- '4.2' => 'android-17', '4.2.2' => 'android-17',
6
+ '2.3' => 9, '2.3.1' => 9, '2.3.2' => 9, '2.3.3' => 10, '2.3.4' => 10,
7
+ '3.0' => 11, '3.1' => 12, '3.2' => 13, '4.0.1' => 14, '4.0.3' => 15,
8
+ '4.0.4' => 15, '4.1' => 16, '4.1.1' => 16, '4.1.2' => 16, '4.2' => 17,
9
+ '4.2.2' => 17, '4.3' => 18, '4.4.2' => 19,
12
10
  }
11
+ API_LEVEL_TO_VERSION = {
12
+ 10 => '2.3.3', 11 => '3.0', 12 => '3.1', 13 => '3.2', 14 => '4.0',
13
+ 15 => '4.0.3', 16 => '4.1.2', 17 => '4.2.2', 18 => '4.3', 19 => '4.4.2',
14
+ }
15
+
13
16
  MINIMUM_SUPPORTED_SDK_LEVEL = 10
14
17
  MINIMUM_SUPPORTED_SDK = "android-#{MINIMUM_SUPPORTED_SDK_LEVEL}"
15
- DEFAULT_TARGET_SDK_LEVEL = 10
18
+ DEFAULT_TARGET_SDK_LEVEL = 15
16
19
  DEFAULT_TARGET_SDK = "android-#{DEFAULT_TARGET_SDK_LEVEL}"
17
20
  end
18
21
  end
@@ -1,4 +1,5 @@
1
1
  require 'net/telnet'
2
+ require 'ruboto/sdk_versions'
2
3
 
3
4
  module Ruboto
4
5
  module Util
@@ -6,13 +7,8 @@ module Ruboto
6
7
  ON_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i)
7
8
  ON_MAC_OS_X = RbConfig::CONFIG['host_os'] =~ /^darwin(.*)/
8
9
 
9
- API_LEVEL_TO_VERSION = {
10
- 10 => '2.3.3', 11 => '3.0', 12 => '3.1', 13 => '3.2', 14 => '4.0',
11
- 15 => '4.0.3', 16 => '4.1.2', 17 => '4.2.2', 18 => '4.3', 19 => '4.4',
12
- }
13
-
14
10
  def sdk_level_name(sdk_level)
15
- API_LEVEL_TO_VERSION[sdk_level] || "api_#{sdk_level}"
11
+ Ruboto::SdkVersions::API_LEVEL_TO_VERSION[sdk_level] || "api_#{sdk_level}"
16
12
  end
17
13
 
18
14
  def start_emulator(sdk_level)
@@ -123,21 +119,10 @@ module Ruboto
123
119
  manifest_file = 'AndroidManifest.xml'
124
120
  heap_size = (File.exists?(manifest_file) && File.read(manifest_file) =~ /largeHeap/) ? 256 : 48
125
121
  new_avd_config = old_avd_config.gsub(/vm.heapSize=([0-9]*)/) { |m| $1.to_i < heap_size ? "vm.heapSize=#{heap_size}" : m }
126
- unless new_avd_config =~ /^hw.device.manufacturer=/
127
- device_manufacturer_prop = 'hw.device.manufacturer=Generic'
128
- new_avd_config << "#{device_manufacturer_prop}\n"
129
- puts "Added #{device_manufacturer_prop} property"
130
- end
131
- unless new_avd_config =~ /^hw.device.name=/
132
- device_name_prop = 'hw.device.name=3.2in HVGA slider (ADP1)'
133
- new_avd_config << "#{device_name_prop}\n"
134
- puts "Added #{device_name_prop} property"
135
- end
136
- unless new_avd_config =~ /^hw.mainKeys=/
137
- main_keys_prop = 'hw.mainKeys=yes'
138
- new_avd_config << "#{main_keys_prop}\n"
139
- puts "Added #{main_keys_prop} property"
140
- end
122
+ add_property(new_avd_config, 'hw.device.manufacturer', 'Generic')
123
+ add_property(new_avd_config, 'hw.device.name', '3.2" HVGA slider (ADP1)')
124
+ add_property(new_avd_config, 'hw.mainKeys', 'yes')
125
+ add_property(new_avd_config, 'hw.sdCard', 'yes')
141
126
 
142
127
  File.write(avd_config_file_name, new_avd_config) if new_avd_config != old_avd_config
143
128
  new_snapshot = true
@@ -183,16 +168,12 @@ module Ruboto
183
168
  if $? == 0
184
169
  print 'Emulator started: '
185
170
  50.times do
186
- if `adb get-state`.chomp == 'device'
187
- break
188
- end
171
+ break if device_ready?
189
172
  print '.'
190
173
  sleep 1
191
174
  end
192
175
  puts
193
- if `adb get-state`.chomp == 'device'
194
- break
195
- end
176
+ break if device_ready?
196
177
  end
197
178
  puts 'Unable to start the emulator.'
198
179
  end
@@ -224,6 +205,22 @@ EOF
224
205
 
225
206
  puts "Emulator #{avd_name} started OK."
226
207
  end
208
+
209
+ def device_ready?
210
+ `adb get-state`.gsub(/^WARNING:.*$/, '').chomp == 'device'
211
+ end
212
+
213
+ def add_property(new_avd_config, property_name, value)
214
+ pattern = /^#{property_name}=.*$/
215
+ property = "#{property_name}=#{value}"
216
+ if new_avd_config =~ pattern
217
+ new_avd_config.gsub! pattern, property
218
+ puts "Changed property: #{property}"
219
+ else
220
+ new_avd_config << "#{property}\n"
221
+ puts "Added property: #{property}"
222
+ end
223
+ end
227
224
  end
228
225
  end
229
226
  end