Skip to content

Commit 855c257

Browse files
committed
add android dependency scanning
1 parent 58b5ce2 commit 855c257

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

src/fosslight_dependency/_help.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Optional
2323
-h\t\t\t\t Print help message.
2424
-v\t\t\t\t Print the version of the script.
25-
-m <package_manager>\t Enther the package manager(npm, maven, gradle, pip, pub, cocoapods).
25+
-m <package_manager>\t Enther the package manager(npm, maven, gradle, pip, pub, cocoapods, android).
2626
-p <input_path>\t\t Enter the path where the script will be run.
2727
-o <output_path>\t\t Enter the path where the result file will be generated.
2828
@@ -32,6 +32,9 @@
3232
3333
Optional only for gradle, maven
3434
-c <dir_name>\t\t Enter the customized build output directory name(default: target)
35+
36+
Optional only for android
37+
-n <app_name>\t\t Enter the application directory name where the plugin output file is located(default: app)
3538
"""
3639

3740

src/fosslight_dependency/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5-
__version__ = "3.1.0"
5+
__version__ = "3.2.0"

src/fosslight_dependency/analyze_dependency.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
# Check the manifest file
2828
manifest_array = [["pip", "requirements.txt"], ["npm", "package.json"], ["maven", "pom.xml"],
29-
["gradle", "build.gradle"], ["pub", "pubspec.yaml"], ["cocoapods", "Podfile.lock"]]
29+
["gradle", "build.gradle"], ["pub", "pubspec.yaml"], ["cocoapods", "Podfile.lock"],
30+
["android", "gradlew"]]
3031

3132
# binary url to check license text
3233
license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -59,7 +60,7 @@ def check_valid_manifest_file():
5960

6061

6162
def parse_option():
62-
global MANUAL_DETECT, PIP_ACTIVATE, PIP_DEACTIVATE, PACKAGE, OUTPUT_CUSTOM_DIR, CUR_PATH, OUTPUT_RESULT_DIR
63+
global MANUAL_DETECT, PIP_ACTIVATE, PIP_DEACTIVATE, PACKAGE, OUTPUT_CUSTOM_DIR, CUR_PATH, OUTPUT_RESULT_DIR, APPNAME
6364

6465
default_unspecified = "UNSPECIFIED"
6566

@@ -72,6 +73,7 @@ def parse_option():
7273
parser.add_argument('-p', '--path', nargs=1, type=str, required=False)
7374
parser.add_argument('-v', '--version', action='store_true', required=False)
7475
parser.add_argument('-o', '--output', nargs=1, type=str, required=False)
76+
parser.add_argument('-n', '--appname', nargs=1, type=str, required=False)
7577

7678
args = parser.parse_args()
7779

@@ -133,6 +135,11 @@ def parse_option():
133135
CUR_PATH = os.getcwd()
134136
os.chdir(CUR_PATH)
135137

138+
if args.appname:
139+
APPNAME = "".join(args.appname)
140+
else:
141+
APPNAME = "app"
142+
136143

137144
def configure_package():
138145
if MANUAL_DETECT == 0:
@@ -876,10 +883,29 @@ def parse_and_generate_output_cocoapods(input_fp):
876883
return sheet_list
877884

878885

886+
def parse_and_generate_output_android(input_fp):
887+
sheet_list = {}
888+
sheet_list["SRC"] = []
889+
890+
for i, line in enumerate(input_fp.readlines()):
891+
split_str = line.strip().split("\t")
892+
if i < 2:
893+
continue
894+
895+
if len(split_str) == 9:
896+
idx, manifest_file, oss_name, oss_version, license_name, dn_loc, homepage, NA, NA = split_str
897+
elif len(split_str) == 7:
898+
idx, manifest_file, oss_name, oss_version, license_name, dn_loc, homepage = split_str
899+
else:
900+
continue
901+
sheet_list["SRC"].append([manifest_file, oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
902+
903+
return sheet_list
904+
905+
879906
###########################################
880907
# Main functions for each package manager #
881908
###########################################
882-
883909
def main_pip():
884910
# It needs the virtualenv path that pip packages are installed.
885911
check_virtualenv_arg()
@@ -968,10 +994,21 @@ def main_cocoapods():
968994
return sheet_list
969995

970996

997+
def main_android():
998+
999+
input_fp = open_input_file()
1000+
1001+
sheet_list = parse_and_generate_output_android(input_fp)
1002+
1003+
close_input_file(input_fp)
1004+
1005+
return sheet_list
1006+
1007+
9711008
def main():
9721009

9731010
global PACKAGE, output_file_name, input_file_name, CUR_PATH, OUTPUT_RESULT_DIR, \
974-
MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE
1011+
MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE, APPNAME
9751012
global license_scanner_url, license_scanner_bin, venv_tmp_dir, pom_backup, \
9761013
is_maven_first_try, tmp_license_txt_file_name, source_type, logger
9771014

@@ -1027,6 +1064,10 @@ def main():
10271064
output_file_name = "cocoapods_dependency_output"
10281065
source_type = ['git', 'http', 'svn', 'hg']
10291066

1067+
elif PACKAGE == "android":
1068+
input_file_name = os.path.join(APPNAME, "android_dependency_output.txt")
1069+
output_file_name = "android_dependency_output"
1070+
10301071
else:
10311072
logger.error("### Error Message ###")
10321073
logger.error("You enter the wrong first argument.")
@@ -1045,6 +1086,8 @@ def main():
10451086
sheet_list = main_pub()
10461087
elif PACKAGE == "cocoapods":
10471088
sheet_list = main_cocoapods()
1089+
elif PACKAGE == "android":
1090+
sheet_list = main_android()
10481091
else:
10491092
logger.error("### Error Message ###")
10501093
logger.error("Please enter the supported package manager. (Check the help message with (-h) option.)")

0 commit comments

Comments
 (0)