Skip to content

Commit 35c8e60

Browse files
authored
fix: exclude certain file patterns from map_deploy_to_develop (Java) (#1995)
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 193da09 commit 35c8e60

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

scanpipe/pipes/d2d_config.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,37 @@ class EcosystemConfig:
8080
".odt",
8181
".odp",
8282
],
83+
deployed_resource_path_exclusions=["*.properties", "*.html"],
8384
),
8485
"Java": EcosystemConfig(
8586
ecosystem_option="Java",
8687
matchable_package_extensions=[".jar", ".war"],
8788
matchable_resource_extensions=[".class"],
88-
deployed_resource_path_exclusions=["*META-INF/*", "*/module-info.class"],
89+
deployed_resource_path_exclusions=[
90+
"*META-INF/*",
91+
"*/module-info.class",
92+
"*/OSGI-INF/*.xml",
93+
"*/OSGI-INF/*.json",
94+
"*spring-configuration-metadata.json",
95+
],
8996
),
9097
"Scala": EcosystemConfig(
9198
ecosystem_option="Scala",
9299
matchable_package_extensions=[".jar", ".war"],
93100
matchable_resource_extensions=[".class"],
101+
deployed_resource_path_exclusions=[
102+
"*META-INF/*",
103+
],
94104
),
95105
"Kotlin": EcosystemConfig(
96106
ecosystem_option="Kotlin",
97107
matchable_package_extensions=[".jar", ".war"],
98108
matchable_resource_extensions=[".class"],
109+
deployed_resource_path_exclusions=[
110+
"*META-INF/*",
111+
"*.knm",
112+
"*kotlin-project-structure-metadata.json",
113+
],
99114
),
100115
"JavaScript": EcosystemConfig(
101116
ecosystem_option="JavaScript",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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": ["*META-INF/*", "*/module-info.class", "*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig"],
6+
"deployed_resource_path_exclusions": ["*META-INF/*", "*/module-info.class", "*/OSGI-INF/*.xml", "*/OSGI-INF/*.json", "*spring-configuration-metadata.json", "*checksums.yaml.gz*", "*metadata.gz*", "*data.tar.gz.sig", "*.properties", "*.html"],
77
"devel_resource_path_exclusions": ["*/tests/*"],
88
"standard_symbols_to_exclude": [],
99
"source_symbol_extensions": []

scanpipe/tests/pipes/test_d2d.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ def test_scanpipe_pipes_d2d_java_ignore_pattern(self):
503503
make_resource_file(self.project1, path="to/META-INF/MANIFEST.MF")
504504
make_resource_file(self.project1, path="to/test.class")
505505
make_resource_file(self.project1, path="to/META-INF/others.txt")
506+
make_resource_file(
507+
self.project1, path="to/META-INF/spring-configuration-metadata.json"
508+
)
509+
make_resource_file(self.project1, path="to/OSGI-INF/test.xml")
510+
make_resource_file(self.project1, path="to/OSGI-INF/test.json")
511+
make_resource_file(self.project1, path="to/OSGI-INF/test.class")
506512
buffer = io.StringIO()
507513

508514
java_config = d2d_config.get_ecosystem_config(ecosystem="Java")
@@ -511,7 +517,7 @@ def test_scanpipe_pipes_d2d_java_ignore_pattern(self):
511517
patterns_to_ignore=java_config.deployed_resource_path_exclusions,
512518
logger=buffer.write,
513519
)
514-
expected = "Ignoring 3 to/ resources with ecosystem specific configurations."
520+
expected = "Ignoring 6 to/ resources with ecosystem specific configurations."
515521
self.assertIn(expected, buffer.getvalue())
516522

517523
def test_scanpipe_pipes_d2d_map_jar_to_java_source(self):
@@ -612,6 +618,21 @@ def test_scanpipe_pipes_d2d_map_jar_to_scala_source(self):
612618
self.assertEqual(from2, relation.from_resource)
613619
self.assertEqual(to_jar, relation.to_resource)
614620

621+
def test_scanpipe_pipes_d2d_scala_ignore_pattern(self):
622+
make_resource_file(self.project1, path="to/META-INF/MANIFEST.MF")
623+
make_resource_file(self.project1, path="to/test.class")
624+
make_resource_file(self.project1, path="to/META-INF/others.txt")
625+
buffer = io.StringIO()
626+
627+
scala_config = d2d_config.get_ecosystem_config(ecosystem="Scala")
628+
d2d.ignore_unmapped_resources_from_config(
629+
project=self.project1,
630+
patterns_to_ignore=scala_config.deployed_resource_path_exclusions,
631+
logger=buffer.write,
632+
)
633+
expected = "Ignoring 2 to/ resources with ecosystem specific configurations."
634+
self.assertIn(expected, buffer.getvalue())
635+
615636
def test_scanpipe_pipes_d2d_map_jar_to_kotlin_source(self):
616637
from1 = make_resource_file(
617638
self.project1,
@@ -661,6 +682,23 @@ def test_scanpipe_pipes_d2d_map_jar_to_kotlin_source(self):
661682
self.assertEqual(from2, relation.from_resource)
662683
self.assertEqual(to_jar, relation.to_resource)
663684

685+
def test_scanpipe_pipes_d2d_kotlin_ignore_pattern(self):
686+
make_resource_file(self.project1, path="to/META-INF/test.knm")
687+
make_resource_file(self.project1, path="to/test.class")
688+
make_resource_file(
689+
self.project1, path="to/META-INF/kotlin-project-structure-metadata.json"
690+
)
691+
buffer = io.StringIO()
692+
693+
kotlin_config = d2d_config.get_ecosystem_config(ecosystem="Kotlin")
694+
d2d.ignore_unmapped_resources_from_config(
695+
project=self.project1,
696+
patterns_to_ignore=kotlin_config.deployed_resource_path_exclusions,
697+
logger=buffer.write,
698+
)
699+
expected = "Ignoring 2 to/ resources with ecosystem specific configurations."
700+
self.assertIn(expected, buffer.getvalue())
701+
664702
def test_scanpipe_pipes_d2d_map_jar_to_source_works_for_jar(self):
665703
from1 = make_resource_file(
666704
self.project1,

0 commit comments

Comments
 (0)