26
26
_PKG_NAME = "fosslight_dependency"
27
27
28
28
# 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 " ]]
32
32
33
33
# binary url to check license text
34
34
license_scanner_url_linux = "third_party/nomos/nomossa"
@@ -93,7 +93,12 @@ def parse_option():
93
93
MANUAL_DETECT = 0 # It will be detected the package manager automatically with manifest file.
94
94
else :
95
95
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 )
97
102
98
103
# -a option
99
104
if args .activate :
@@ -327,6 +332,9 @@ def open_input_file():
327
332
if os .path .isfile (input_file_name ) != 1 :
328
333
logger .warning (input_file_name + " doesn't exist in this directory." )
329
334
335
+ if PACKAGE == "gradle" and MANUAL_DETECT == 0 :
336
+ return False
337
+
330
338
if PACKAGE == "maven" :
331
339
global is_maven_first_try
332
340
@@ -340,11 +348,11 @@ def open_input_file():
340
348
else :
341
349
clean_run_maven_plugin_output ()
342
350
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" )
348
356
sys .exit (1 )
349
357
350
358
input_fp = open (input_file_name , 'r' , encoding = 'utf8' )
@@ -966,13 +974,28 @@ def main_maven():
966
974
967
975
968
976
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
970
978
979
+ # Before running this script, first you should add the com.github.hierynomus.license in build.gradle and run it.
971
980
# open dependency-license.json
972
981
input_fp = open_input_file ()
973
982
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 )
976
999
977
1000
# close dependency-license.json
978
1001
close_input_file (input_fp )
@@ -1013,27 +1036,11 @@ def main_android():
1013
1036
return sheet_list
1014
1037
1015
1038
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
1017
1042
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
1037
1044
1038
1045
if PACKAGE == "pip" :
1039
1046
dn_url = "https://pypi.org/project/"
@@ -1078,6 +1085,31 @@ def main():
1078
1085
logger .error ("Please enter the supported package manager. (Check the help message with (-h) option.)" )
1079
1086
sys .exit (1 )
1080
1087
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
+
1081
1113
if PACKAGE == "pip" :
1082
1114
sheet_list = main_pip ()
1083
1115
elif PACKAGE == "npm" :
0 commit comments