Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scanpipe/pipelines/deploy_to_develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def steps(cls):
cls.perform_house_keeping_tasks,
cls.match_purldb_resources_post_process,
cls.remove_packages_without_resources,
cls.scan_ignored_to_files,
cls.scan_unmapped_to_files,
cls.scan_mapped_from_for_files,
cls.collect_and_create_license_detections,
Expand Down Expand Up @@ -387,6 +388,16 @@ def remove_packages_without_resources(self):
)
package_without_resources.delete()

def scan_ignored_to_files(self):
"""
Scan status="ignored-from-config" ``to/`` files for copyrights,
licenses, emails, and urls. These files are ignored based on
ecosystem specific configurations. These files are not used for the
D2D purpose, but scanning them may provide useful information about
the deployed codebase.
"""
d2d.scan_ignored_to_files(project=self.project, logger=self.log)

def scan_unmapped_to_files(self):
"""
Scan unmapped/matched ``to/`` files for copyrights, licenses,
Expand Down
17 changes: 17 additions & 0 deletions scanpipe/pipes/d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,23 @@ def flag_undeployed_resources(project):
from_unmapped.update(status=flag.NOT_DEPLOYED)


def scan_ignored_to_files(project, logger=None):
"""
Scan status="ignored-from-config" ``to/`` files for copyrights, licenses,
emails, and urls.
"""
scan_files = (
project.codebaseresources.files()
.to_codebase()
.filter(status=flag.IGNORED_FROM_CONFIG)
)
scancode.scan_for_files(project, scan_files, progress_logger=logger)

project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
status=flag.IGNORED_FROM_CONFIG
)


def scan_unmapped_to_files(project, logger=None):
"""
Scan unmapped/matched ``to/`` files for copyrights, licenses,
Expand Down
1 change: 1 addition & 0 deletions scanpipe/pipes/d2d_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class EcosystemConfig:
ecosystem_option="Java",
matchable_package_extensions=[".jar", ".war"],
matchable_resource_extensions=[".class"],
deployed_resource_path_exclusions=["*META-INF/*", "*/module-info.class"],
),
"Scala": EcosystemConfig(
ecosystem_option="Scala",
Expand Down
4 changes: 2 additions & 2 deletions scanpipe/tests/data/d2d/config/ecosystem_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"matchable_package_extensions": [".jar", ".war", ".gem", ".zip", ".tar.gz", ".tar.xz"],
"matchable_resource_extensions": [".map", ".js", ".mjs", ".ts", ".d.ts", ".jsx", ".tsx", ".css", ".scss", ".less", ".sass", ".soy",".class", ".rb"],
"doc_extensions": [".pdf", ".doc", ".docx", ".ppt", ".pptx", ".tex", ".odt", ".odp"],
"deployed_resource_path_exclusions": ["*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig"],
"deployed_resource_path_exclusions": ["*META-INF/*", "*/module-info.class", "*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig"],
"devel_resource_path_exclusions": ["*/tests/*"],
"standard_symbols_to_exclude": [],
"source_symbol_extensions": []
}
}
6 changes: 3 additions & 3 deletions scanpipe/tests/data/d2d/flume-ng-node-d2d.json
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@
"path": "to/flume-ng-node-1.9.0.jar-extract/META-INF/DEPENDENCIES",
"type": "file",
"name": "DEPENDENCIES",
"status": "requires-review",
"status": "ignored-from-config",
"for_packages": [],
"tag": "to",
"extension": "",
Expand Down Expand Up @@ -2885,7 +2885,7 @@
"path": "to/flume-ng-node-1.9.0.jar-extract/META-INF/MANIFEST.MF",
"type": "file",
"name": "MANIFEST.MF",
"status": "requires-review",
"status": "ignored-from-config",
"for_packages": [],
"tag": "to",
"extension": ".MF",
Expand Down Expand Up @@ -4014,4 +4014,4 @@
"from_resource": "from/flume-ng-node-1.9.0-sources.jar-extract/org/apache/flume/node/StaticZooKeeperConfigurationProvider.java"
}
]
}
}
40 changes: 40 additions & 0 deletions scanpipe/tests/pipes/test_d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,22 @@ def test_scanpipe_pipes_d2d_map_java_to_class_no_java(self):
expected = "No ('.java',) resources to map."
self.assertIn(expected, buffer.getvalue())

def test_scanpipe_pipes_d2d_java_ignore_pattern(self):
make_resource_file(self.project1, path="to/module-info.class")
make_resource_file(self.project1, path="to/META-INF/MANIFEST.MF")
make_resource_file(self.project1, path="to/test.class")
make_resource_file(self.project1, path="to/META-INF/others.txt")
buffer = io.StringIO()

java_config = d2d_config.get_ecosystem_config(ecosystem="Java")
d2d.ignore_unmapped_resources_from_config(
project=self.project1,
patterns_to_ignore=java_config.deployed_resource_path_exclusions,
logger=buffer.write,
)
expected = "Ignoring 3 to/ resources with ecosystem specific configurations."
self.assertIn(expected, buffer.getvalue())

def test_scanpipe_pipes_d2d_map_jar_to_java_source(self):
from1 = make_resource_file(
self.project1,
Expand Down Expand Up @@ -1289,6 +1305,30 @@ def test_flag_undeployed_resources(self):

self.assertEqual(1, expected)

def test_scan_ignored_to_files(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name is not consistent with the existing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdruez what do you mean by "The test name is not consistent with the existing.". It is used to test the d2d.scan_ignored_to_files()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to follow the existing naming conventions. See all the tests function start with test_scanpipe_pipes_d2d_
Note that the other test you added in the PR respects the convention: test_scanpipe_pipes_d2d_java_ignore_pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thank. Updated.

to_dir = (
self.project1.codebase_path / "to/project.tar.zst-extract/META-INF/foo-bar"
)
to_input_location = self.data / "d2d/find_java_packages/Foo.java"
to_dir.mkdir(parents=True)
copy_input(to_input_location, to_dir)

pipes.collect_and_create_codebase_resources(self.project1)

foo_java = self.project1.codebaseresources.get(
path=("to/project.tar.zst-extract/META-INF/foo-bar/Foo.java")
)
foo_java.update(status=flag.IGNORED_FROM_CONFIG)

d2d.scan_ignored_to_files(self.project1)
foo_java.refresh_from_db()

expected = self.project1.codebaseresources.filter(
status=flag.IGNORED_FROM_CONFIG
).count()

self.assertEqual(1, expected)

def test_scan_unmapped_to_files(self):
to_dir = (
self.project1.codebase_path / "to/project.tar.zst-extract/osgi/marketplace/"
Expand Down
3 changes: 1 addition & 2 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,8 @@ def assertPipelineResultEqual(
expected_json = self._normalize_package_uids(expected_json)
expected_data = self._without_keys(expected_json, self.exclude_from_diff)
if sort_dependencies:
result_data = self._sort_dependencies(result_data)
expected_data = self._sort_dependencies(expected_data)
expected_data = sort_for_os_compatibility(expected_data)

self.assertEqual(expected_data, result_data)

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