Skip to content

Commit f784e6c

Browse files
authored
Update "find_jvm_packages" to include all resources (#1921)
* Update "find_jvm_packages" to include all resources - Ensure extra_data is populated in "find_jvm_packages()" for all resources for mapping purposes - Adjust test logic to update extra_data after map_checksum, matching d2d pipeline sequence Signed-off-by: Chin Yeung Li <tli@nexb.com> * Reformat code with `make valid` #1854 Signed-off-by: Chin Yeung Li <tli@nexb.com> * Rewrite the test to simulate the D2D steps. #1854 Signed-off-by: Chin Yeung Li <tli@nexb.com> --------- Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 010692d commit f784e6c

4 files changed

Lines changed: 31 additions & 37 deletions

File tree

scanpipe/pipes/d2d.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ def find_jvm_packages(project, jvm_lang: jvm.JvmLanguage, logger=None):
262262
263263
Note: we use the same API as the ScanCode scans by design
264264
"""
265-
resources = (
266-
project.codebaseresources.files().no_status().from_codebase().has_no_relation()
267-
)
265+
resources = project.codebaseresources.files().no_status().from_codebase()
268266

269267
from_jvm_resources = resources.filter(extension__in=jvm_lang.source_extensions)
270268

187 Bytes
Binary file not shown.
552 Bytes
Binary file not shown.

scanpipe/tests/pipes/test_d2d.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -394,50 +394,46 @@ def test_scanpipe_pipes_d2d_map_java_to_class(self):
394394
self.assertEqual("", to3.status)
395395

396396
def test_scanpipe_pipes_d2d_map_java_to_class_with_java_in_deploy(self):
397-
sha1 = "abcde"
398-
from1 = make_resource_file(
399-
self.project1,
400-
path="from/flume-ng-node-1.9.0-sources.jar-extract/org/apache/flume/node/"
401-
"AbstractConfigurationProvider.java",
402-
extra_data={"java_package": "org.apache.flume.node"},
403-
sha1=sha1,
404-
)
405-
to1 = make_resource_file(
406-
self.project1,
407-
path="to/flume-ng-node-1.9.0.jar-extract/org/apache/flume/node/"
408-
"AbstractConfigurationProvider.java",
409-
sha1=sha1,
410-
)
411-
to2 = make_resource_file(
412-
self.project1,
413-
path="to/flume-ng-node-1.9.0.jar-extract/org/apache/flume/node/"
414-
"AbstractConfigurationProvider.class",
415-
)
397+
input_dir = self.project1.input_path
398+
# "from-Baz.zip" contains Baz.java
399+
# "to-Baz.jar" contains Baz.java and Baz.class
400+
input_resources = [
401+
self.data / "d2d" / "find_java_packages" / "from-Baz.zip",
402+
self.data / "d2d" / "find_java_packages" / "to-Baz.jar",
403+
]
404+
405+
copy_inputs(input_resources, input_dir)
406+
self.from_files, self.to_files = d2d.get_inputs(self.project1)
407+
inputs_with_codebase_path_destination = [
408+
(self.from_files, self.project1.codebase_path / d2d.FROM),
409+
(self.to_files, self.project1.codebase_path / d2d.TO),
410+
]
411+
for input_files, codebase_path in inputs_with_codebase_path_destination:
412+
for input_file_path in input_files:
413+
scancode.extract_archive(input_file_path, codebase_path)
416414

415+
scancode.extract_archives(
416+
self.project1.codebase_path,
417+
recurse=True,
418+
)
419+
pipes.collect_and_create_codebase_resources(self.project1)
417420
buffer = io.StringIO()
418421

419-
# The pipeline will run map_checksum first
420-
d2d.map_checksum(self.project1, "sha1", logger=buffer.write)
421-
expected = "Mapping 1 to/ resources using sha1 against from/ codebase"
422-
self.assertEqual(expected, buffer.getvalue())
423-
self.assertEqual(1, to1.related_from.count())
424-
relation1 = to1.related_from.get()
425-
self.assertEqual("sha1", relation1.map_type)
426-
self.assertEqual(from1, relation1.from_resource)
422+
d2d.map_checksum(
423+
project=self.project1, checksum_field="sha1", logger=buffer.write
424+
)
427425

426+
d2d.find_jvm_packages(
427+
self.project1, jvm_lang=jvm.JavaLanguage, logger=buffer.write
428+
)
429+
expected = "Finding java packages for 1 ('.java',) resources."
430+
self.assertIn(expected, buffer.getvalue())
428431
# Now run map_java_to_class
429432
d2d.map_jvm_to_class(
430433
self.project1, logger=buffer.write, jvm_lang=jvm.JavaLanguage
431434
)
432435
expected = "Mapping 1 .class resources to 1 ('.java',)"
433436
self.assertIn(expected, buffer.getvalue())
434-
self.assertEqual(2, self.project1.codebaserelations.count())
435-
relation2 = self.project1.codebaserelations.get(
436-
to_resource=to2, from_resource=from1
437-
)
438-
self.assertEqual("java_to_class", relation2.map_type)
439-
expected = {"from_source_root": "from/flume-ng-node-1.9.0-sources.jar-extract/"}
440-
self.assertEqual(expected, relation2.extra_data)
441437

442438
def test_scanpipe_pipes_d2d_map_java_to_class_no_java(self):
443439
make_resource_file(self.project1, path="to/Abstract.class")

0 commit comments

Comments
 (0)