Skip to content

Commit

Permalink
Merge pull request #26 from jmatsu/infer_apkanalyzer_path
Browse files Browse the repository at this point in the history
Infer the path of apkanalyzer via ANDROID_HOME or ANDROID_SDK_ROOT but show warnings if inferred
  • Loading branch information
jmatsu authored Sep 1, 2020
2 parents 9e19129 + 8b8ab13 commit dc6df05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 59 deletions.
26 changes: 17 additions & 9 deletions lib/apkstats/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,25 @@ def run_command(command, name)
def apkanalyzer_command
return @apkanalyzer_command if defined?(@apkanalyzer_command)

command_path = apkanalyzer_path || begin
android_home = ENV["ANDROID_HOME"]
command_path = apkanalyzer_path || `which apkanalyzer`.chomp

if android_home
warn("apkstats will not use ANDROID_HOME in further versions because ANDROID_HOME has been officially deprecated.")
else
raise Error, "Please specify apkanalyzer_path to execute apkstats"
end
if command_path.empty?
sdk_path = ENV["ANDROID_HOME"] || ENV["ANDROID_SDK_ROOT"]

"#{android_home}/tools/bin/apkanalyzer"
end
if sdk_path
tmp_path = File.join(sdk_path, "cmdline-tools/tools/bin/apkanalyzer")
tmp_path = File.join(sdk_path, "tools/bin/apkanalyzer") unless File.executable?(tmp_path)

command_path = tmp_path if File.executable?(tmp_path)
else
warn("apkstats will not infer the apkanalyzer path in further versions so please include apkanalyer in your PATH or specify it explicitly.")
end
end

command_path = command_path.chomp

raise Error, "Please include apkanalyer in your PATH or specify it explicitly." if command_path.empty?
raise Error, "#{command_path} is not executable." unless File.executable?(command_path)

@apkanalyzer_command = Apkstats::Command::ApkAnalyzer.new(command_path: command_path)
end
Expand Down
50 changes: 0 additions & 50 deletions spec/apkstats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

module Danger
describe Danger::DangerApkstats do
before do
ENV.delete("ANDROID_HOME")
ENV.delete("ANDROID_SDK_ROOT")
end

it "should be a plugin" do
expect(Danger::DangerApkstats.new(nil)).to be_a Danger::Plugin
end
Expand All @@ -22,51 +17,6 @@ module Danger
allow(apkstats.github).to receive(:pr_json).and_return(json)
end

# compatibility
describe "#command_path=" do
context "unless command_path is given" do
it { expect { apkstats.send(:apkanalyzer_command) }.to raise_error(Danger::DangerApkstats::Error) }

context "with ANDROID_HOME" do
before do
ENV["ANDROID_HOME"] = "dummy"
end

it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
end
end

context "if command_path is given" do
before do
apkstats.command_path = "dummy"
end

it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
end
end

describe "#apkanalyzer_path=" do
context "unless analyzer_path is given" do
it { expect { apkstats.send(:apkanalyzer_command) }.to raise_error(Danger::DangerApkstats::Error) }

context "with ANDROID_HOME" do
before do
ENV["ANDROID_HOME"] = "dummy"
end

it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
end
end

context "if analyzer_path is given" do
before do
apkstats.apkanalyzer_path = "dummy"
end

it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
end
end

describe "#compare_with" do
let(:apk_base) { fixture_path + "app-base.apk" }
let(:apk_other1) { fixture_path + "app-other1.apk" }
Expand Down

0 comments on commit dc6df05

Please sign in to comment.