Skip to content

Commit 3f54d50

Browse files
authored
Merge pull request #35 from fosslight/develop
Fix the android scanning issues
2 parents 8a68844 + 99a8141 commit 3f54d50

File tree

9 files changed

+381
-37
lines changed

9 files changed

+381
-37
lines changed

.reuse/dep5

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Files: tests/test_pypi/*
6262
Copyright: 2021 LG Electronics
6363
License: Apache-2.0
6464

65-
Files: tests/test_cocoapods/cocoapods-tips*
65+
Files: tests/test_cocoapods/cocoapods-tips/*
6666
Copyright: 2017 ClintJang
6767
License: MIT
68+
69+
Files: tests/test_android/*
70+
Copyright: 2018 Google, Inc
71+
License: Apache-2.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Each package manager uses the results of the following software:
3131
- Gradle : [License Gradle Plugin](https://github.com/hierynomus/license-gradle-plugin)
3232
- Maven : [license-maven-plugin](https://github.com/mojohaus/license-maven-plugin)
3333
- Pub : [flutter_oss_licenses](https://github.com/espresso3389/flutter_oss_licenses)
34+
- Android(gradle) : [android-dependency-scanning](https://github.com/fosslight/android-dependency-scanning)
3435

3536
Because we utilizes the different open source software to analyze the dependencies of each package manager, you need to set up the **Prerequisite** steps in [User guide](https://fosslight.org/fosslight-guide-en/scanner/2_dependency.html) according to package manager to analyze.
3637

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
if __name__ == "__main__":
1818
setup(
1919
name='fosslight_dependency',
20-
version='3.4.0',
20+
version='3.5.0',
2121
package_dir={"": "src"},
2222
packages=find_packages(where='src'),
2323
description='FOSSLight Dependency Scanner',

src/fosslight_dependency/_help.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
Gradle : License Gradle Plugin
1818
Maven : License-maven-plugin
1919
Pub : Flutter_oss_licenses
20+
Android : android-dependency-scanning
2021
2122
Options:
2223
Optional
2324
-h\t\t\t\t Print help message.
2425
-v\t\t\t\t Print the version of the script.
25-
-m <package_manager>\t Enter the package manager(npm, maven, gradle, pip, pub, cocoapods).
26+
-m <package_manager>\t Enter the package manager(npm, maven, gradle, pip, pub, cocoapods, android).
2627
-p <input_path>\t\t Enter the path where the script will be run.
2728
-o <output_path>\t\t Enter the path where the result file will be generated.
2829

src/fosslight_dependency/analyze_dependency.py

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
_PKG_NAME = "fosslight_dependency"
2727

2828
# Check the manifest file
29-
manifest_array = [["pip", "requirements.txt"], ["npm", "package.json"], ["maven", "pom.xml"],
30-
["gradle", "build.gradle"], ["pub", "pubspec.yaml"], ["cocoapods", "Podfile.lock"],
31-
["android", "gradlew"]]
29+
SUPPORT_PACKAE = ["pip", "npm", "maven", "gradle", "pub", "cocoapods", "android"]
30+
manifest_array = [[SUPPORT_PACKAE[0], "requirements.txt"], [SUPPORT_PACKAE[1], "package.json"], [SUPPORT_PACKAE[2], "pom.xml"],
31+
[SUPPORT_PACKAE[3], "build.gradle"], [SUPPORT_PACKAE[4], "pubspec.yaml"], [SUPPORT_PACKAE[5], "Podfile.lock"]]
3232

3333
# binary url to check license text
3434
license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -93,7 +93,12 @@ def parse_option():
9393
MANUAL_DETECT = 0 # It will be detected the package manager automatically with manifest file.
9494
else:
9595
MANUAL_DETECT = 1
96-
PACKAGE = "".join(args.manager)
96+
package_name = "".join(args.manager)
97+
if package_name in SUPPORT_PACKAE:
98+
PACKAGE = package_name
99+
else:
100+
print("Please enter the supported package manager({0}) with 'm' option.".format(", ".join(SUPPORT_PACKAE)))
101+
sys.exit(1)
97102

98103
# -a option
99104
if args.activate:
@@ -327,6 +332,9 @@ def open_input_file():
327332
if os.path.isfile(input_file_name) != 1:
328333
logger.warning(input_file_name + " doesn't exist in this directory.")
329334

335+
if PACKAGE == "gradle" and MANUAL_DETECT == 0:
336+
return False
337+
330338
if PACKAGE == "maven":
331339
global is_maven_first_try
332340

@@ -340,11 +348,11 @@ def open_input_file():
340348
else:
341349
clean_run_maven_plugin_output()
342350

343-
logger.error("Please check the below thing first.")
344-
logger.error(" 1.Did you run the license-maven-plugin?")
345-
logger.error(" 2.Or if your project has the customized build output directory, \
346-
then use '-c' option with your customized build output directory name")
347-
logger.error(" $ fosslight_dependency -c output")
351+
logger.error("Please check the below thing first.")
352+
logger.error(" 1.Did you run the license-maven-plugin?")
353+
logger.error(" 2.Or if your project has the customized build output directory, \
354+
then use '-c' option with your customized build output directory name")
355+
logger.error(" $ fosslight_dependency -c output")
348356
sys.exit(1)
349357

350358
input_fp = open(input_file_name, 'r', encoding='utf8')
@@ -966,13 +974,28 @@ def main_maven():
966974

967975

968976
def main_gradle():
969-
# Before running this script, first you should add the com.github.hierynomus.license in build.gradle and run it.
977+
global PACKAGE
970978

979+
# Before running this script, first you should add the com.github.hierynomus.license in build.gradle and run it.
971980
# open dependency-license.json
972981
input_fp = open_input_file()
973982

974-
# Make output file for OSS report using temporary output file for License Gradle Plugin.
975-
sheet_list = parse_and_generate_output_gradle(input_fp)
983+
# If the PACKAGE is gradle & MANUAL_DETECT is false, then open_input_file results is false.
984+
# In that case, we re-try the open_input_file for the android package manager.
985+
if not input_fp:
986+
logger.warning("If the PACKAGE is gradle and automatically detcted, it re-tries to find input file for android")
987+
PACKAGE = 'android'
988+
set_package_variables(PACKAGE)
989+
input_fp = open_input_file()
990+
991+
if PACKAGE == "gradle":
992+
# Make output file for OSS report using temporary output file for License Gradle Plugin.
993+
sheet_list = parse_and_generate_output_gradle(input_fp)
994+
elif PACKAGE == "android":
995+
sheet_list = parse_and_generate_output_android(input_fp)
996+
else:
997+
logger.error("Cannot find the PACKAGE name() based on gradle.", PACKAGE)
998+
sys.exit(1)
976999

9771000
# close dependency-license.json
9781001
close_input_file(input_fp)
@@ -1013,27 +1036,11 @@ def main_android():
10131036
return sheet_list
10141037

10151038

1016-
def main():
1039+
def set_package_variables(package):
1040+
global PACKAGE, dn_url, output_file_name, input_file_name, venv_tmp_dir, pom_backup, is_maven_first_try, \
1041+
tmp_license_txt_file_name, source_type
10171042

1018-
global PACKAGE, output_file_name, input_file_name, CUR_PATH, OUTPUT_RESULT_DIR, \
1019-
MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE, APPNAME
1020-
global license_scanner_url, license_scanner_bin, venv_tmp_dir, pom_backup, \
1021-
is_maven_first_try, tmp_license_txt_file_name, source_type, logger
1022-
1023-
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
1024-
1025-
parse_option()
1026-
logger = init_log(os.path.join(OUTPUT_RESULT_DIR, "fosslight_dependency_log_" + start_time + ".txt"), True, 20, 10)
1027-
_result_log = init_log_item(_PKG_NAME)
1028-
1029-
logger.info("Tool Info : " + _result_log["Tool Info"])
1030-
1031-
# Configure global variables according to package manager.
1032-
try:
1033-
configure_package()
1034-
except:
1035-
logger.error("Error : Failed to configure package.")
1036-
sys.exit(1)
1043+
PACKAGE = package
10371044

10381045
if PACKAGE == "pip":
10391046
dn_url = "https://pypi.org/project/"
@@ -1078,6 +1085,31 @@ def main():
10781085
logger.error("Please enter the supported package manager. (Check the help message with (-h) option.)")
10791086
sys.exit(1)
10801087

1088+
1089+
def main():
1090+
1091+
global PACKAGE, output_file_name, input_file_name, CUR_PATH, OUTPUT_RESULT_DIR, \
1092+
MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE, APPNAME
1093+
global license_scanner_url, license_scanner_bin, venv_tmp_dir, pom_backup, \
1094+
is_maven_first_try, tmp_license_txt_file_name, source_type, logger
1095+
1096+
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
1097+
1098+
parse_option()
1099+
logger = init_log(os.path.join(OUTPUT_RESULT_DIR, "fosslight_dependency_log_" + start_time + ".txt"), True, 20, 10)
1100+
_result_log = init_log_item(_PKG_NAME)
1101+
1102+
logger.info("Tool Info : " + _result_log["Tool Info"])
1103+
1104+
# Configure global variables according to package manager.
1105+
try:
1106+
configure_package()
1107+
except:
1108+
logger.error("Error : Failed to configure package.")
1109+
sys.exit(1)
1110+
1111+
set_package_variables(PACKAGE)
1112+
10811113
if PACKAGE == "pip":
10821114
sheet_list = main_pip()
10831115
elif PACKAGE == "npm":

0 commit comments

Comments
 (0)