Class: Motion::Project::Gradle
- Inherits:
-
Object
- Object
- Motion::Project::Gradle
- Defined in:
- lib/motion/project/version.rb,
lib/motion/project/gradle.rb
Constant Summary collapse
- VERSION =
'1.5.0'
- GRADLE_ROOT =
'vendor/Gradle'
Instance Attribute Summary collapse
-
#aidls ⇒ Object
readonly
Returns the value of attribute aidls.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#libraries ⇒ Object
readonly
Returns the value of attribute libraries.
Instance Method Summary collapse
- #aidl(package, aidl_file_path) ⇒ Object
- #android_gui_path ⇒ Object
- #android_repository ⇒ Object
- #classpath(classpath) ⇒ Object
- #configure_project ⇒ Object
- #dependency(name, options = {}) ⇒ Object
- #extract_aars ⇒ Object
- #generate_gradle_build_file ⇒ Object
- #generate_gradle_settings_file ⇒ Object
- #google_repository ⇒ Object
- #gradle_build_file ⇒ Object
- #gradle_command ⇒ Object
- #gradle_settings_file ⇒ Object
-
#initialize(config) ⇒ Gradle
constructor
A new instance of Gradle.
- #install!(update) ⇒ Object
- #library(library_name, options = {}) ⇒ Object
- #path=(path) ⇒ Object
- #plugin(plugin) ⇒ Object
- #repository(url) ⇒ Object
- #vendor_aars ⇒ Object
-
#vendor_aidl_files ⇒ Object
Helpers.
- #vendor_jars ⇒ Object
Constructor Details
#initialize(config) ⇒ Gradle
Returns a new instance of Gradle.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/motion/project/gradle.rb', line 28 def initialize(config) @gradle_path = '/usr/bin/env gradle' @config = config @classpaths = [] @plugins = [] @dependencies = [] @repositories = [] @aidl_files = [] @libraries = [] configure_project end |
Instance Attribute Details
#aidls ⇒ Object (readonly)
Returns the value of attribute aidls.
26 27 28 |
# File 'lib/motion/project/gradle.rb', line 26 def aidls @aidls end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
24 25 26 |
# File 'lib/motion/project/gradle.rb', line 24 def dependencies @dependencies end |
#libraries ⇒ Object (readonly)
Returns the value of attribute libraries.
25 26 27 |
# File 'lib/motion/project/gradle.rb', line 25 def libraries @libraries end |
Instance Method Details
#aidl(package, aidl_file_path) ⇒ Object
69 70 71 |
# File 'lib/motion/project/gradle.rb', line 69 def aidl(package, aidl_file_path) @aidl_files << Aidl.new(package, aidl_file_path) end |
#android_gui_path ⇒ Object
167 168 169 |
# File 'lib/motion/project/gradle.rb', line 167 def android_gui_path @android_gui_path ||= File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'tools', 'android') end |
#android_repository ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/motion/project/gradle.rb', line 96 def android_repository android_repository = File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'extras', 'android', 'm2repository') unless exist = File.exist?(android_repository) App.info('[warning]', "To avoid issues you should install `Extras/Android Support Repository`. Open the gui to install it : #{android_gui_path}") end exist end |
#classpath(classpath) ⇒ Object
73 74 75 |
# File 'lib/motion/project/gradle.rb', line 73 def classpath(classpath) @classpaths << classpath end |
#configure_project ⇒ Object
40 41 42 43 |
# File 'lib/motion/project/gradle.rb', line 40 def configure_project vendor_aars vendor_jars end |
#dependency(name, options = {}) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/motion/project/gradle.rb', line 49 def dependency(name, = {}) if name.include?(':') @dependencies << name else @dependencies << LegacyDependency.new(name, ) end end |
#extract_aars ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/motion/project/gradle.rb', line 171 def extract_aars aars = Dir[File.join(GRADLE_ROOT, "dependencies/**/*.aar")] aar_dir = File.join(GRADLE_ROOT, 'aar') FileUtils.mkdir_p(aar_dir) aars.each do |aar| filename = File.basename(aar, '.aar') system("/usr/bin/unzip -o -qq #{aar} -d #{ File.join(aar_dir, filename)}") end end |
#generate_gradle_build_file ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/motion/project/gradle.rb', line 189 def generate_gradle_build_file template_path = File.("../gradle.erb", __FILE__) template = ERB.new(File.new(template_path).read, nil, "%") File.open(gradle_build_file, 'w') do |io| io.puts(template.result(binding)) end end |
#generate_gradle_settings_file ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/motion/project/gradle.rb', line 181 def generate_gradle_settings_file template_path = File.("../settings.erb", __FILE__) template = ERB.new(File.new(template_path).read, nil, "%") File.open(gradle_settings_file, 'w') do |io| io.puts(template.result(binding)) end end |
#google_repository ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/motion/project/gradle.rb', line 104 def google_repository google_repository = File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'extras', 'google', 'm2repository') unless exist = File.exist?(google_repository) App.info('[warning]', "To avoid issues you should install `Extras/Google Repository`. Open the gui to install it : #{android_gui_path}") end exist end |
#gradle_build_file ⇒ Object
197 198 199 |
# File 'lib/motion/project/gradle.rb', line 197 def gradle_build_file File.join(GRADLE_ROOT, 'build.gradle') end |
#gradle_command ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/motion/project/gradle.rb', line 205 def gradle_command unless system("command -v #{@gradle_path} >/dev/null") $stderr.puts("[!] #{@gradle_path} command doesn’t exist. Verify your gradle installation. Or set a different one with `app.gradle.path=(path)`") exit(1) end if ENV['MOTION_GRADLE_DEBUG'] "#{@gradle_path} --info" else "#{@gradle_path}" end end |
#gradle_settings_file ⇒ Object
201 202 203 |
# File 'lib/motion/project/gradle.rb', line 201 def gradle_settings_file File.join(GRADLE_ROOT, 'settings.gradle') end |
#install!(update) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/motion/project/gradle.rb', line 85 def install!(update) vendor_aidl_files generate_gradle_settings_file generate_gradle_build_file system("#{gradle_command} --build-file #{gradle_build_file} generateDependencies") # this might be uneeded in the future # if RM does support .aar out of the box extract_aars end |
#library(library_name, options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/motion/project/gradle.rb', line 57 def library(library_name, = {}) path = .fetch(:path, library_name) unless Pathname.new(path).absolute? path = File.join('../..', path) end @libraries << { name: library_name, path: path } end |
#path=(path) ⇒ Object
45 46 47 |
# File 'lib/motion/project/gradle.rb', line 45 def path=(path) @gradle_path = path end |
#plugin(plugin) ⇒ Object
77 78 79 |
# File 'lib/motion/project/gradle.rb', line 77 def plugin(plugin) @plugins << plugin end |
#repository(url) ⇒ Object
81 82 83 |
# File 'lib/motion/project/gradle.rb', line 81 def repository(url) @repositories << url end |
#vendor_aars ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/motion/project/gradle.rb', line 120 def vendor_aars aars_dependendies = Dir[File.join(GRADLE_ROOT, 'aar/*')] aars_dependendies.each do |dependency| main_jar = File.join(dependency, 'classes.jar') if File.exist?(main_jar) jar_path = File.join(dependency, "#{File.basename(dependency)}.jar") FileUtils.mv(main_jar, jar_path) = {:jar => jar_path} else next end # libs/*.jar may contain dependencies, let's vendor them Dir[File.join(dependency, 'libs/*.jar')].each do |internal_dependancy| @config.vendor_project({:jar => internal_dependancy}) end res = File.join(dependency, 'res') if File.exist?(res) [:resources] = res [:manifest] = File.join(dependency, 'AndroidManifest.xml') end native = File.join(dependency, 'jni') if File.exist?(native) archs = @config.archs.uniq.map do |arch| @config.armeabi_directory_name(arch) end libs = Dir[File.join(native, "{#{archs.join(',')}}", "*.so")] if libs.count != archs.count App.info('[warning]', "Found only #{libs.count} lib(s) -> #{libs.join(',')} for #{archs.count} arch(s) : #{archs.join(',')}") end [:native] = libs end @config.vendor_project() end end |
#vendor_aidl_files ⇒ Object
Helpers
113 114 115 116 117 118 |
# File 'lib/motion/project/gradle.rb', line 113 def vendor_aidl_files @aidl_files.each do |aidl_file| aidl_file.create_lib library(aidl_file.name, path: aidl_file.path) end end |
#vendor_jars ⇒ Object
160 161 162 163 164 165 |
# File 'lib/motion/project/gradle.rb', line 160 def vendor_jars jars = Dir[File.join(GRADLE_ROOT, 'dependencies/*.jar')] jars.each do |jar| @config.vendor_project(:jar => jar) end end |