-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring : tests and extract templating logic
- Loading branch information
Showing
18 changed files
with
315 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.*.sw? | ||
app | ||
AppRakefile | ||
pkg | ||
tmp | ||
vendor/Gradle | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
desc "Build the gem" | ||
desc 'Build the gem' | ||
task :gem do | ||
sh "bundle exec gem build motion-gradle.gemspec" | ||
sh "mkdir -p pkg" | ||
sh "mv *.gem pkg/" | ||
sh 'bundle exec gem build motion-gradle.gemspec' | ||
sh 'mkdir -p pkg' | ||
sh 'mv *.gem pkg/' | ||
end | ||
|
||
task :clean do | ||
FileUtils.rm_rf 'pkg' | ||
end | ||
|
||
desc "Run all the specs" | ||
desc 'Run all the specs' | ||
task :spec do | ||
sh "bundle exec bacon #{FileList['spec/*_spec.rb'].join(' ')}" | ||
end | ||
|
||
task :default => :spec | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
require 'pathname' | ||
require 'shellwords' | ||
require 'motion/project/legacy_dependency' | ||
require 'motion_gradle/legacy_dependency' | ||
require 'motion_gradle/aidl' | ||
require 'motion_gradle/template' | ||
require 'motion_gradle/version' | ||
require 'motion/project/gradle' | ||
require 'motion/project/aidl' | ||
require 'motion/project/version' | ||
|
||
module MotionGradle | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module MotionGradle | ||
class Aidl | ||
def initialize(package, aidl_file_path) | ||
@package = package | ||
@aidl_file_path = File.expand_path(aidl_file_path) | ||
end | ||
|
||
def create_lib | ||
create_structure | ||
create_gradle_build_file | ||
create_manifest | ||
end | ||
|
||
def name | ||
@name ||= File.basename(@aidl_file_path, '.aidl').downcase | ||
end | ||
|
||
def path | ||
@path ||= File.join(Motion::Project::Gradle::GRADLE_ROOT, name) | ||
end | ||
|
||
protected | ||
|
||
def create_manifest | ||
template = MotionGradle::Template.new('android_manifest.xml') | ||
template.destination = File.join(path, 'src', 'main', 'AndroidManifest.xml') | ||
template.write({ package: @package }) | ||
end | ||
|
||
def create_gradle_build_file | ||
template = MotionGradle::Template.new('aidl_build.gradle') | ||
template.destination = File.join(path, 'build.gradle') | ||
template.write({ last_build_tools_version: last_build_tools_version }) | ||
end | ||
|
||
def create_structure | ||
aidl_file_dir = File.join(path, 'src', 'main', 'aidl', *@package.split('.')) | ||
FileUtils.mkdir_p(aidl_file_dir) | ||
FileUtils.cp(@aidl_file_path, aidl_file_dir) | ||
end | ||
|
||
def last_build_tools_version | ||
build_tools = File.join(ENV['RUBYMOTION_ANDROID_SDK'], 'build-tools') | ||
glob_pattern = File.join(build_tools, '*') | ||
builds_tools_directories = Dir.glob(glob_pattern).select do |file| | ||
File.directory?(file) | ||
end | ||
File.basename(builds_tools_directories.last) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module MotionGradle | ||
class LegacyDependency | ||
def initialize(name, params) | ||
@options = normalized_dependency(name, params) | ||
end | ||
|
||
def parse | ||
options = @options.delete_if { |_, v| v.nil? }.map { |k, v| "#{k}: '#{v}'" } | ||
"compile #{options.join(', ')}" | ||
end | ||
|
||
protected | ||
|
||
def normalized_dependency(name, params) | ||
{ | ||
group: name, | ||
version: params.fetch(:version, '+'), | ||
name: params.fetch(:artifact, name), | ||
ext: params.fetch(:extension, nil) | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module MotionGradle | ||
class Template | ||
attr_accessor :destination | ||
|
||
def initialize(name) | ||
template_path = File.expand_path("../templates/#{name}.erb", __FILE__) | ||
@template = ERB.new(File.new(template_path).read) | ||
end | ||
|
||
def write(locals = {}) | ||
File.open(self.destination, 'w') do |io| | ||
struct = OpenStruct.new(locals) | ||
io.puts(@template.result(struct.instance_eval { binding })) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<%= package %>"> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/motion/project/settings.erb → ...tion_gradle/templates/settings.gradle.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<% @libraries.each do |library| %> | ||
<% libraries.each do |library| %> | ||
include '<%= library[:name] %>' | ||
project(':<%= library[:name] %>').projectDir = new File('<%= library[:path].shellescape %>') | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module MotionGradle | ||
VERSION = '1.6.0' | ||
end |
Oops, something went wrong.