Skip to content

Commit 8840c26

Browse files
committed
Fixed failing tests #1876
- Added scan_ignored_to_files() - Updated tests Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 89cd952 commit 8840c26

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def steps(cls):
101101
cls.perform_house_keeping_tasks,
102102
cls.match_purldb_resources_post_process,
103103
cls.remove_packages_without_resources,
104+
cls.scan_ignored_to_files,
104105
cls.scan_unmapped_to_files,
105106
cls.scan_mapped_from_for_files,
106107
cls.collect_and_create_license_detections,
@@ -387,6 +388,16 @@ def remove_packages_without_resources(self):
387388
)
388389
package_without_resources.delete()
389390

391+
def scan_ignored_to_files(self):
392+
"""
393+
Scan status="ignored-from-config" ``to/`` files for copyrights,
394+
licenses, emails, and urls. These files are ignored based on
395+
ecosystem specific configurations. These files are not used for the
396+
D2D purpose, but scanning them may provide useful information about
397+
the deployed codebase.
398+
"""
399+
d2d.scan_ignored_to_files(project=self.project, logger=self.log)
400+
390401
def scan_unmapped_to_files(self):
391402
"""
392403
Scan unmapped/matched ``to/`` files for copyrights, licenses,

scanpipe/pipes/d2d.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,23 @@ def flag_undeployed_resources(project):
15091509
from_unmapped.update(status=flag.NOT_DEPLOYED)
15101510

15111511

1512+
def scan_ignored_to_files(project, logger=None):
1513+
"""
1514+
Scan status="ignored-from-config" ``to/`` files for copyrights, licenses,
1515+
emails, and urls.
1516+
"""
1517+
scan_files = (
1518+
project.codebaseresources.files()
1519+
.to_codebase()
1520+
.filter(status=flag.IGNORED_FROM_CONFIG)
1521+
)
1522+
scancode.scan_for_files(project, scan_files, progress_logger=logger)
1523+
1524+
project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
1525+
status=flag.IGNORED_FROM_CONFIG
1526+
)
1527+
1528+
15121529
def scan_unmapped_to_files(project, logger=None):
15131530
"""
15141531
Scan unmapped/matched ``to/`` files for copyrights, licenses,

scanpipe/tests/data/d2d/config/ecosystem_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"matchable_package_extensions": [".jar", ".war", ".gem", ".zip", ".tar.gz", ".tar.xz"],
44
"matchable_resource_extensions": [".map", ".js", ".mjs", ".ts", ".d.ts", ".jsx", ".tsx", ".css", ".scss", ".less", ".sass", ".soy",".class", ".rb"],
55
"doc_extensions": [".pdf", ".doc", ".docx", ".ppt", ".pptx", ".tex", ".odt", ".odp"],
6-
"deployed_resource_path_exclusions": ["*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig"],
6+
"deployed_resource_path_exclusions": ["*META-INF/*", "*/module-info.class", "*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig"],
77
"devel_resource_path_exclusions": ["*/tests/*"],
88
"standard_symbols_to_exclude": [],
99
"source_symbol_extensions": []
10-
}
10+
}

scanpipe/tests/data/d2d/flume-ng-node-d2d.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@
15451545
"path": "to/flume-ng-node-1.9.0.jar-extract/META-INF/DEPENDENCIES",
15461546
"type": "file",
15471547
"name": "DEPENDENCIES",
1548-
"status": "requires-review",
1548+
"status": "ignored-from-config",
15491549
"for_packages": [],
15501550
"tag": "to",
15511551
"extension": "",
@@ -2885,7 +2885,7 @@
28852885
"path": "to/flume-ng-node-1.9.0.jar-extract/META-INF/MANIFEST.MF",
28862886
"type": "file",
28872887
"name": "MANIFEST.MF",
2888-
"status": "requires-review",
2888+
"status": "ignored-from-config",
28892889
"for_packages": [],
28902890
"tag": "to",
28912891
"extension": ".MF",
@@ -4014,4 +4014,4 @@
40144014
"from_resource": "from/flume-ng-node-1.9.0-sources.jar-extract/org/apache/flume/node/StaticZooKeeperConfigurationProvider.java"
40154015
}
40164016
]
4017-
}
4017+
}

scanpipe/tests/pipes/test_d2d.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,30 @@ def test_flag_undeployed_resources(self):
13051305

13061306
self.assertEqual(1, expected)
13071307

1308+
def test_scan_ignored_to_files(self):
1309+
to_dir = (
1310+
self.project1.codebase_path / "to/project.tar.zst-extract/META-INF/foo-bar"
1311+
)
1312+
to_input_location = self.data / "d2d/find_java_packages/Foo.java"
1313+
to_dir.mkdir(parents=True)
1314+
copy_input(to_input_location, to_dir)
1315+
1316+
pipes.collect_and_create_codebase_resources(self.project1)
1317+
1318+
foo_java = self.project1.codebaseresources.get(
1319+
path=("to/project.tar.zst-extract/META-INF/foo-bar/Foo.java")
1320+
)
1321+
foo_java.update(status=flag.IGNORED_FROM_CONFIG)
1322+
1323+
d2d.scan_ignored_to_files(self.project1)
1324+
foo_java.refresh_from_db()
1325+
1326+
expected = self.project1.codebaseresources.filter(
1327+
status=flag.IGNORED_FROM_CONFIG
1328+
).count()
1329+
1330+
self.assertEqual(1, expected)
1331+
13081332
def test_scan_unmapped_to_files(self):
13091333
to_dir = (
13101334
self.project1.codebase_path / "to/project.tar.zst-extract/osgi/marketplace/"

scanpipe/tests/test_pipelines.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,8 @@ def assertPipelineResultEqual(
693693
expected_json = self._normalize_package_uids(expected_json)
694694
expected_data = self._without_keys(expected_json, self.exclude_from_diff)
695695
if sort_dependencies:
696-
result_data = self._sort_dependencies(result_data)
696+
expected_data = self._sort_dependencies(expected_data)
697697
expected_data = sort_for_os_compatibility(expected_data)
698-
699698
self.assertEqual(expected_data, result_data)
700699

701700
@skipIf(from_docker_image, "Random failure in the Docker context.")

0 commit comments

Comments
 (0)