3333from scanpipe .models import Project
3434from scanpipe .pipes import d2d
3535from scanpipe .pipes import flag
36+ from scanpipe .pipes import scancode
3637from scanpipe .pipes .input import copy_input
3738from scanpipe .pipes .input import copy_inputs
3839from scanpipe .tests import make_resource_directory
@@ -47,6 +48,7 @@ class ScanPipeD2DPipesTest(TestCase):
4748
4849 def setUp (self ):
4950 self .project1 = Project .objects .create (name = "Analysis" )
51+ self .maxDiff = 200
5052
5153 def test_scanpipe_pipes_d2d_get_inputs (self ):
5254 with self .assertRaises (FileNotFoundError ) as error :
@@ -1258,6 +1260,126 @@ def test_scanpipe_pipes_flag_whitespace_files(self):
12581260 flag .IGNORED_WHITESPACE_FILE , non_whitespace_resource .status
12591261 )
12601262
1263+ def test_scanpipe_pipes_create_about_file_indexes (self ):
1264+ input_dir = self .project1 .input_path
1265+ input_resources = [
1266+ self .data_location / "d2d/about_files/to-with-jar.zip" ,
1267+ self .data_location / "d2d/about_files/from-with-about-file.zip" ,
1268+ ]
1269+ copy_inputs (input_resources , input_dir )
1270+ self .from_files , self .to_files = d2d .get_inputs (self .project1 )
1271+
1272+ inputs_with_codebase_path_destination = [
1273+ (self .from_files , self .project1 .codebase_path / d2d .FROM ),
1274+ (self .to_files , self .project1 .codebase_path / d2d .TO ),
1275+ ]
1276+
1277+ for input_files , codebase_path in inputs_with_codebase_path_destination :
1278+ for input_file_path in input_files :
1279+ scancode .extract_archive (input_file_path , codebase_path )
1280+
1281+ scancode .extract_archives (
1282+ self .project1 .codebase_path ,
1283+ recurse = True ,
1284+ )
1285+
1286+ pipes .collect_and_create_codebase_resources (self .project1 )
1287+
1288+ from_about_files = (
1289+ self .project1 .codebaseresources .files ()
1290+ .from_codebase ()
1291+ .filter (extension = ".ABOUT" )
1292+ )
1293+ about_file_indexes = d2d .AboutFileIndexes .create_indexes (
1294+ project = self .project1 ,
1295+ from_about_files = from_about_files ,
1296+ )
1297+
1298+ about_path = "from/flume-ng-node-1.9.0-sources.ABOUT"
1299+ about_notice_path = "from/flume-ng-node-1.9.0-sources.NOTICE"
1300+
1301+ about_notice_file = self .project1 .codebaseresources .get (path = about_notice_path )
1302+
1303+ self .assertIn (
1304+ about_path , list (about_file_indexes .about_resources_by_path .keys ())
1305+ )
1306+ about_regex = d2d .convert_glob_to_django_regex (
1307+ glob_pattern = "*flume-ng-node-*.jar*"
1308+ )
1309+ self .assertEqual (
1310+ about_file_indexes .regex_by_about_path .get (about_path ), about_regex
1311+ )
1312+ self .assertEqual (
1313+ about_file_indexes .about_pkgdata_by_path .get (about_path ).get ("name" ),
1314+ "log4j" ,
1315+ )
1316+ self .assertIn (
1317+ about_notice_file , about_file_indexes .get_about_file_companions (about_path )
1318+ )
1319+ to_resource = self .project1 .codebaseresources .get (
1320+ path = (
1321+ "to/flume-ng-node-1.9.0.jar-extract/org/apache/"
1322+ "flume/node/AbstractZooKeeperConfigurationProvider.class"
1323+ )
1324+ )
1325+ self .assertEqual (
1326+ about_file_indexes .get_matched_about_path (to_resource ), about_path
1327+ )
1328+
1329+ def test_scanpipe_pipes_map_d2d_using_about (self ):
1330+ input_dir = self .project1 .input_path
1331+ input_resources = [
1332+ self .data_location / "d2d/about_files/to-with-jar.zip" ,
1333+ self .data_location / "d2d/about_files/from-with-about-file.zip" ,
1334+ ]
1335+ copy_inputs (input_resources , input_dir )
1336+ self .from_files , self .to_files = d2d .get_inputs (self .project1 )
1337+
1338+ inputs_with_codebase_path_destination = [
1339+ (self .from_files , self .project1 .codebase_path / d2d .FROM ),
1340+ (self .to_files , self .project1 .codebase_path / d2d .TO ),
1341+ ]
1342+
1343+ for input_files , codebase_path in inputs_with_codebase_path_destination :
1344+ for input_file_path in input_files :
1345+ scancode .extract_archive (input_file_path , codebase_path )
1346+
1347+ scancode .extract_archives (
1348+ self .project1 .codebase_path ,
1349+ recurse = True ,
1350+ )
1351+
1352+ pipes .collect_and_create_codebase_resources (self .project1 )
1353+
1354+ from_about_files = (
1355+ self .project1 .codebaseresources .files ()
1356+ .from_codebase ()
1357+ .filter (extension = ".ABOUT" )
1358+ )
1359+ about_file_indexes = d2d .AboutFileIndexes .create_indexes (
1360+ project = self .project1 ,
1361+ from_about_files = from_about_files ,
1362+ )
1363+
1364+ to_resources = self .project1 .codebaseresources .to_codebase ()
1365+ about_file_indexes .map_deployed_to_devel_using_about (
1366+ to_resources = to_resources ,
1367+ )
1368+
1369+ about_path = "from/flume-ng-node-1.9.0-sources.ABOUT"
1370+ to_resource = self .project1 .codebaseresources .get (
1371+ path = (
1372+ "to/flume-ng-node-1.9.0.jar-extract/org/apache/"
1373+ "flume/node/AbstractZooKeeperConfigurationProvider.class"
1374+ )
1375+ )
1376+ self .assertIn (
1377+ to_resource ,
1378+ about_file_indexes .mapped_resources_by_aboutpath .get (about_path ),
1379+ )
1380+
1381+ about_file_indexes .create_about_packages_relations (self .project1 )
1382+
12611383 def test_scanpipe_pipes_d2d_match_purldb_resources_post_process (self ):
12621384 to_map = self .data_location / "d2d-javascript" / "to" / "main.js.map"
12631385 to_mini = self .data_location / "d2d-javascript" / "to" / "main.js"
0 commit comments