forked from SQLDroid/SQLDroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
69 lines (57 loc) · 2.19 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'fileutils'
require File.expand_path 'lib/sqldroid/version', File.dirname(__FILE__)
require 'rake/clean'
unless ENV['ANDROID_HOME'] && Dir.exist?(ENV['ANDROID_HOME'])
if ENV['ANDROID_SDK']
ENV['ANDROID_HOME'] = ENV['ANDROID_SDK']
else
dx_location = `which dx`
unless $? == 0
raise 'Unable to find ANDROID_HOME environment variable or the "dx" command.'
end
ENV['ANDROID_HOME'] = File.dirname(File.dirname(File.dirname(dx_location)))
end
end
TARGET_DIR = File.expand_path 'target'
JAR = "sqldroid-#{SQLDroid::MAVEN_VERSION}.jar"
JAR_IN_TARGET = "#{TARGET_DIR}/#{JAR}"
LIB_DIR = File.expand_path 'lib/sqldroid'
JAR_IN_GEM = "#{LIB_DIR}/#{JAR}"
GEM_BASE_FILE = "sqldroid-#{SQLDroid::VERSION}-java.gem"
GEM_FILE_TARGET = "#{TARGET_DIR}/#{GEM_BASE_FILE}"
JAVA_SRC_FILES = Dir[File.expand_path 'src/main/java/**/*.java']
CLEAN.include('target')
CLOBBER.include('target', 'lib/sqldroid/sqldroid-*.jar')
desc 'Generate the binary and source jars'
task jar: JAR_IN_TARGET
file JAR_IN_TARGET => JAVA_SRC_FILES do
sh 'mvn install -B'
end
file JAR_IN_GEM => JAR_IN_TARGET do
FileUtils.rm_rf Dir["#{LIB_DIR}/sqldroid-*.jar"]
FileUtils.cp JAR_IN_TARGET, JAR_IN_GEM
end
desc 'Create a RubyGem for SQLDroid'
task gem: GEM_FILE_TARGET
file GEM_FILE_TARGET => JAR_IN_GEM do
pom = File.read(File.expand_path('pom.xml', __dir__))
maven_version = pom[%r{(?<=<version>)([0-9a-zA-Z.-]*)(?=</version>)}]
version_file_name = File.expand_path('lib/sqldroid/version.rb', __dir__)
version_file_content = File.read(version_file_name)
version_file_content.sub!(/^\s*pom = .*$/, '')
version_file_content.sub!(/^\s*MAVEN_VERSION = .*$/, "MAVEN_VERSION = '#{maven_version}'")
sh 'gem build sqldroid.gemspec'
FileUtils.mv GEM_BASE_FILE, GEM_FILE_TARGET
sh "git checkout #{version_file_name}"
end
desc 'Tag the project and push the tag to GitHub'
task :tag do
output = `git status --porcelain`
raise "Workspace not clean!\n#{output}" unless output.empty?
sh "git tag #{SQLDroid::VERSION}"
sh 'git push --tags'
end
desc 'Release SQLDroid as a Ruby gem to rubygems.org'
task release: [:tag, GEM_FILE_TARGET] do
sh "gem push #{GEM_FILE_TARGET}"
end