motion-gradle 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50c2e48c77d0f368ee44667ae5d574c85ceb2c25
4
- data.tar.gz: 577d8d409dd2fd063f9ca2d1e224561353279bfd
3
+ metadata.gz: 617e05877b988ee1f537b0adaff8e9cfdade69c3
4
+ data.tar.gz: d7228639f466ed173c28e5bdd02945f4501ec01f
5
5
  SHA512:
6
- metadata.gz: 98c82bdc75995ee8bfbe97bf5dda498089bf64b25350751aed15768ba5f8cb94727c698d1861dd7291b212ff6c3c66a822902618b71b0fe76081aa2f0646d600
7
- data.tar.gz: 1492d7d43990043f70e0613af41ee12218a4a4be77308672902ac8ee9683d3ed36f39f40ee57366daaf840e7428c35ad3ec1fa7e10bb663c7ccff0bf221b69cc
6
+ metadata.gz: 5de72870a3a9c756edb92f19f90ca098e60521bbb29f9cef1f3df7d28668b2c12ad47dceeed6ebb0fc425a10e2da2f1ba3fe456db0ed101e029c8d1c202933f9
7
+ data.tar.gz: 400569c31a723e7faafd65e521919c1df6bb6abe205e0ae7ef5d231c127e1c98945935bd9bc3bd3859d01e87e9506a7399103beab9afea2b83ebb0ed12846fa8
@@ -1,6 +1,10 @@
1
1
  require 'pathname'
2
2
  require 'shellwords'
3
- require 'motion/project/legacy_dependency'
3
+ require 'motion_gradle/legacy_dependency'
4
+ require 'motion_gradle/aidl'
5
+ require 'motion_gradle/template'
6
+ require 'motion_gradle/version'
4
7
  require 'motion/project/gradle'
5
- require 'motion/project/aidl'
6
- require 'motion/project/version'
8
+
9
+ module MotionGradle
10
+ end
@@ -1,9 +1,9 @@
1
1
  unless defined?(Motion::Project::Config)
2
- raise("This file must be required within a RubyMotion project Rakefile.")
2
+ fail('This file must be required within a RubyMotion project Rakefile.')
3
3
  end
4
4
 
5
5
  if Motion::Project::App.template != :android
6
- raise("This file must be required within a RubyMotion Android project.")
6
+ fail('This file must be required within a RubyMotion Android project.')
7
7
  end
8
8
 
9
9
  module Motion::Project
@@ -50,7 +50,7 @@ module Motion::Project
50
50
  if name.include?(':')
51
51
  @dependencies << name
52
52
  else
53
- @dependencies << LegacyDependency.new(name, options)
53
+ @dependencies << MotionGradle::LegacyDependency.new(name, options)
54
54
  end
55
55
  end
56
56
 
@@ -59,15 +59,11 @@ module Motion::Project
59
59
  unless Pathname.new(path).absolute?
60
60
  path = File.join('../..', path)
61
61
  end
62
-
63
- @libraries << {
64
- name: library_name,
65
- path: path
66
- }
62
+ @libraries << { name: library_name, path: path }
67
63
  end
68
64
 
69
65
  def aidl(package, aidl_file_path)
70
- @aidl_files << Aidl.new(package, aidl_file_path)
66
+ @aidl_files << MotionGradle::Aidl.new(package, aidl_file_path)
71
67
  end
72
68
 
73
69
  def classpath(classpath)
@@ -82,11 +78,11 @@ module Motion::Project
82
78
  @repositories << url
83
79
  end
84
80
 
85
- def install!(update)
81
+ def install!
86
82
  vendor_aidl_files
87
- generate_gradle_settings_file
88
- generate_gradle_build_file
89
- system("#{gradle_command} --build-file #{gradle_build_file} generateDependencies")
83
+ generate_settings_file
84
+ generate_build_file
85
+ system("#{gradle_command} --build-file #{build_file} generateDependencies")
90
86
 
91
87
  # this might be uneeded in the future
92
88
  # if RM does support .aar out of the box
@@ -124,14 +120,14 @@ module Motion::Project
124
120
  if File.exist?(main_jar)
125
121
  jar_path = File.join(dependency, "#{File.basename(dependency)}.jar")
126
122
  FileUtils.mv(main_jar, jar_path)
127
- vendor_options = {:jar => jar_path}
123
+ vendor_options = { jar: jar_path }
128
124
  else
129
125
  next
130
126
  end
131
127
 
132
128
  # libs/*.jar may contain dependencies, let's vendor them
133
129
  Dir[File.join(dependency, 'libs/*.jar')].each do |internal_dependancy|
134
- @config.vendor_project({:jar => internal_dependancy})
130
+ @config.vendor_project(jar: internal_dependancy)
135
131
  end
136
132
 
137
133
  res = File.join(dependency, 'res')
@@ -146,7 +142,7 @@ module Motion::Project
146
142
  @config.armeabi_directory_name(arch)
147
143
  end
148
144
 
149
- libs = Dir[File.join(native, "{#{archs.join(',')}}", "*.so")]
145
+ libs = Dir[File.join(native, "{#{archs.join(',')}}", '*.so')]
150
146
  if libs.count != archs.count
151
147
  App.info('[warning]', "Found only #{libs.count} lib(s) -> #{libs.join(',')} for #{archs.count} arch(s) : #{archs.join(',')}")
152
148
  end
@@ -160,7 +156,7 @@ module Motion::Project
160
156
  def vendor_jars
161
157
  jars = Dir[File.join(GRADLE_ROOT, 'dependencies/*.jar')]
162
158
  jars.each do |jar|
163
- @config.vendor_project(:jar => jar)
159
+ @config.vendor_project(jar: jar)
164
160
  end
165
161
  end
166
162
 
@@ -169,36 +165,40 @@ module Motion::Project
169
165
  end
170
166
 
171
167
  def extract_aars
172
- aars = Dir[File.join(GRADLE_ROOT, "dependencies/**/*.aar")]
168
+ aars = Dir[File.join(GRADLE_ROOT, 'dependencies/**/*.aar')]
173
169
  aar_dir = File.join(GRADLE_ROOT, 'aar')
174
170
  FileUtils.mkdir_p(aar_dir)
175
171
  aars.each do |aar|
176
172
  filename = File.basename(aar, '.aar')
177
- system("/usr/bin/unzip -o -qq #{aar} -d #{ File.join(aar_dir, filename)}")
173
+ system("/usr/bin/unzip -o -qq #{aar} -d #{File.join(aar_dir, filename)}")
178
174
  end
179
175
  end
180
176
 
181
- def generate_gradle_settings_file
182
- template_path = File.expand_path("../settings.erb", __FILE__)
183
- template = ERB.new(File.new(template_path).read, nil, "%")
184
- File.open(gradle_settings_file, 'w') do |io|
185
- io.puts(template.result(binding))
186
- end
177
+ def generate_settings_file
178
+ template = MotionGradle::Template.new('settings.gradle')
179
+ template.destination = settings_file
180
+ template.write({libraries: @libraries})
187
181
  end
188
182
 
189
- def generate_gradle_build_file
190
- template_path = File.expand_path("../gradle.erb", __FILE__)
191
- template = ERB.new(File.new(template_path).read, nil, "%")
192
- File.open(gradle_build_file, 'w') do |io|
193
- io.puts(template.result(binding))
194
- end
183
+ def generate_build_file
184
+ template = MotionGradle::Template.new('build.gradle')
185
+ template.destination = build_file
186
+ template.write({
187
+ classpaths: @classpaths,
188
+ plugins: @plugins,
189
+ libraries: @libraries,
190
+ repositories: @repositories,
191
+ dependencies: @dependencies,
192
+ android_repository: android_repository,
193
+ google_repository: google_repository
194
+ })
195
195
  end
196
196
 
197
- def gradle_build_file
197
+ def build_file
198
198
  File.join(GRADLE_ROOT, 'build.gradle')
199
199
  end
200
200
 
201
- def gradle_settings_file
201
+ def settings_file
202
202
  File.join(GRADLE_ROOT, 'settings.gradle')
203
203
  end
204
204
 
@@ -218,14 +218,14 @@ module Motion::Project
218
218
  end
219
219
 
220
220
  namespace :gradle do
221
- desc "Download and build dependencies"
221
+ desc 'Download and build dependencies'
222
222
  task :install do
223
223
  root = Motion::Project::Gradle::GRADLE_ROOT
224
224
  FileUtils.mkdir_p(root)
225
225
  rm_rf(File.join(root, 'dependencies'))
226
226
  rm_rf(File.join(root, 'aar'))
227
227
  dependencies = App.config.gradle
228
- dependencies.install!(true)
228
+ dependencies.install!
229
229
  end
230
230
  end
231
231
 
@@ -0,0 +1,51 @@
1
+ module MotionGradle
2
+ class Aidl
3
+ def initialize(package, aidl_file_path)
4
+ @package = package
5
+ @aidl_file_path = File.expand_path(aidl_file_path)
6
+ end
7
+
8
+ def create_lib
9
+ create_structure
10
+ create_gradle_build_file
11
+ create_manifest
12
+ end
13
+
14
+ def name
15
+ @name ||= File.basename(@aidl_file_path, '.aidl').downcase
16
+ end
17
+
18
+ def path
19
+ @path ||= File.join(Motion::Project::Gradle::GRADLE_ROOT, name)
20
+ end
21
+
22
+ protected
23
+
24
+ def create_manifest
25
+ template = MotionGradle::Template.new('android_manifest.xml')
26
+ template.destination = File.join(path, 'src', 'main', 'AndroidManifest.xml')
27
+ template.write({ package: @package })
28
+ end
29
+
30
+ def create_gradle_build_file
31
+ template = MotionGradle::Template.new('aidl_build.gradle')
32
+ template.destination = File.join(path, 'build.gradle')
33
+ template.write({ last_build_tools_version: last_build_tools_version })
34
+ end
35
+
36
+ def create_structure
37
+ aidl_file_dir = File.join(path, 'src', 'main', 'aidl', *@package.split('.'))
38
+ FileUtils.mkdir_p(aidl_file_dir)
39
+ FileUtils.cp(@aidl_file_path, aidl_file_dir)
40
+ end
41
+
42
+ def last_build_tools_version
43
+ build_tools = File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'build-tools')
44
+ glob_pattern = File.join(build_tools, '*')
45
+ builds_tools_directories = Dir.glob(glob_pattern).select do |file|
46
+ File.directory?(file)
47
+ end
48
+ File.basename(builds_tools_directories.last)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ module MotionGradle
2
+ class LegacyDependency
3
+ def initialize(name, params)
4
+ @options = normalized_dependency(name, params)
5
+ end
6
+
7
+ def parse
8
+ options = @options.delete_if { |_, v| v.nil? }.map { |k, v| "#{k}: '#{v}'" }
9
+ "compile #{options.join(', ')}"
10
+ end
11
+
12
+ protected
13
+
14
+ def normalized_dependency(name, params)
15
+ {
16
+ group: name,
17
+ version: params.fetch(:version, '+'),
18
+ name: params.fetch(:artifact, name),
19
+ ext: params.fetch(:extension, nil)
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module MotionGradle
2
+ class Template
3
+ attr_accessor :destination
4
+
5
+ def initialize(name)
6
+ template_path = File.expand_path("../templates/#{name}.erb", __FILE__)
7
+ @template = ERB.new(File.new(template_path).read)
8
+ end
9
+
10
+ def write(locals = {})
11
+ File.open(self.destination, 'w') do |io|
12
+ struct = OpenStruct.new(locals)
13
+ io.puts(@template.result(struct.instance_eval { binding }))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -10,12 +10,12 @@ buildscript {
10
10
  }
11
11
 
12
12
  android {
13
- compileSdkVersion <%= App.config.api_version %>
13
+ compileSdkVersion <%= App.config.api_version.to_i %>
14
14
  buildToolsVersion "<%= last_build_tools_version %>"
15
15
 
16
16
  defaultConfig {
17
- minSdkVersion <%= App.config.api_version %>
18
- targetSdkVersion <%= App.config.api_version %>
17
+ minSdkVersion <%= App.config.api_version.to_i %>
18
+ targetSdkVersion <%= App.config.api_version.to_i %>
19
19
  versionCode 1
20
20
  versionName "1.0"
21
21
  }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<%= package %>">
2
+ </manifest>
@@ -4,7 +4,7 @@ buildscript {
4
4
  mavenCentral()
5
5
  }
6
6
  dependencies {
7
- <% @classpaths.each do |classpath| %>
7
+ <% classpaths.each do |classpath| %>
8
8
  classpath '<%= classpath %>'
9
9
  <% end %>
10
10
  }
@@ -19,7 +19,7 @@ allprojects {
19
19
 
20
20
  apply plugin: 'java'
21
21
  apply plugin: 'eclipse'
22
- <% @plugins.each do |plugin| %>
22
+ <% plugins.each do |plugin| %>
23
23
  apply plugin: '<%= plugin %>'
24
24
  <% end %>
25
25
 
@@ -39,7 +39,7 @@ repositories {
39
39
  url "<%= ENV['RUBYMOTION_ANDROID_SDK'].shellescape %>/extras/google/m2repository/"
40
40
  }
41
41
  <% end %>
42
- <% @repositories.each do |url| %>
42
+ <% repositories.each do |url| %>
43
43
  maven {
44
44
  url "<%= url %>"
45
45
  }
@@ -47,11 +47,11 @@ repositories {
47
47
  }
48
48
 
49
49
  dependencies {
50
- <% @libraries.each do |library| %>
50
+ <% libraries.each do |library| %>
51
51
  compile project(':<%= library[:name] %>')
52
52
  <% end %>
53
- <% @dependencies.each do |dependency| %>
54
- <% if dependency.is_a?(LegacyDependency) %>
53
+ <% dependencies.each do |dependency| %>
54
+ <% if dependency.is_a?(MotionGradle::LegacyDependency) %>
55
55
  <%= dependency.parse %>
56
56
  <% else %>
57
57
  compile '<%= dependency %>'
@@ -1,4 +1,4 @@
1
- <% @libraries.each do |library| %>
1
+ <% libraries.each do |library| %>
2
2
  include '<%= library[:name] %>'
3
3
  project(':<%= library[:name] %>').projectDir = new File('<%= library[:path].shellescape %>')
4
4
  <% end %>
@@ -0,0 +1,3 @@
1
+ module MotionGradle
2
+ VERSION = '1.6.0'
3
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-gradle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joffrey Jaffeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: motion-gradle allows RubyMotion Android projects to have access to the
14
28
  Gradle dependency manager.
15
29
  email: j.jaffeux@gmail.com
@@ -20,13 +34,15 @@ files:
20
34
  - LICENSE
21
35
  - README.md
22
36
  - lib/motion-gradle.rb
23
- - lib/motion/project/aidl.rb
24
- - lib/motion/project/aidl_build_gradle.erb
25
- - lib/motion/project/gradle.erb
26
37
  - lib/motion/project/gradle.rb
27
- - lib/motion/project/legacy_dependency.rb
28
- - lib/motion/project/settings.erb
29
- - lib/motion/project/version.rb
38
+ - lib/motion_gradle/aidl.rb
39
+ - lib/motion_gradle/legacy_dependency.rb
40
+ - lib/motion_gradle/template.rb
41
+ - lib/motion_gradle/templates/aidl_build.gradle.erb
42
+ - lib/motion_gradle/templates/android_manifest.xml.erb
43
+ - lib/motion_gradle/templates/build.gradle.erb
44
+ - lib/motion_gradle/templates/settings.gradle.erb
45
+ - lib/motion_gradle/version.rb
30
46
  homepage: http://www.rubymotion.com
31
47
  licenses:
32
48
  - MIT
@@ -1,54 +0,0 @@
1
- class Aidl
2
- def initialize(package, aidl_file_path)
3
- @package = package
4
- @aidl_file_path = File.expand_path(aidl_file_path)
5
- end
6
-
7
- def create_lib
8
- create_lib_structure
9
- create_gradle_build_file
10
- create_manifest
11
- end
12
-
13
- def name
14
- @name ||= File.basename(@aidl_file_path, '.aidl').downcase
15
- end
16
-
17
- def path
18
- @path ||= File.join(Motion::Project::Gradle::GRADLE_ROOT, name)
19
- end
20
-
21
- protected
22
-
23
- def create_manifest
24
- io = File.new(File.join(path, 'src', 'main', 'AndroidManifest.xml'), "w")
25
- io.puts("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"#{@package}\"></manifest>")
26
- io.close
27
- end
28
-
29
- def create_gradle_build_file
30
- locals = {last_build_tools_version: last_build_tools_version}
31
- erb_template = generate_erb_template(File.expand_path("../aidl_build_gradle.erb", __FILE__), locals)
32
- io = File.new(File.join(path, 'build.gradle',), "w")
33
- io.puts(erb_template)
34
- io.close
35
- end
36
-
37
- def create_lib_structure
38
- aidl_file_dir = File.join(path, 'src', 'main', 'aidl', *@package.split('.'))
39
- FileUtils.mkdir_p(aidl_file_dir)
40
- FileUtils.cp(@aidl_file_path, aidl_file_dir)
41
- end
42
-
43
- def generate_erb_template(path, locals)
44
- template_path = File.expand_path(path, __FILE__)
45
- template = File.new(template_path).read
46
- ERB.new(template).result(OpenStruct.new(locals).instance_eval { binding })
47
- end
48
-
49
- def last_build_tools_version
50
- build_tools = File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'build-tools')
51
- builds_tools_directories = Dir.glob(File.join(build_tools, '*')).select {|f| File.directory? f}
52
- File.basename(builds_tools_directories.last)
53
- end
54
- end
@@ -1,21 +0,0 @@
1
- class LegacyDependency
2
- def initialize(name, params)
3
- @options = normalized_dependency(name, params)
4
- end
5
-
6
- def parse
7
- options = @options.delete_if { |_, v| v.nil? }.map {|k, v| "#{k}: '#{v}'"}
8
- "compile #{options.join(', ')}"
9
- end
10
-
11
- protected
12
-
13
- def normalized_dependency(name, params)
14
- {
15
- group: name,
16
- version: params.fetch(:version, '+'),
17
- name: params.fetch(:artifact, name),
18
- ext: params.fetch(:extension, nil),
19
- }
20
- end
21
- end
@@ -1,5 +0,0 @@
1
- module Motion::Project
2
- class Gradle
3
- VERSION = '1.5.0'
4
- end
5
- end