Skip to content

Commit 00ba32a

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <[email protected]>
1 parent 3865f0e commit 00ba32a

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ def find_java_packages(self):
183183
def map_java_to_class(self):
184184
"""Map a .class compiled file to its .java source."""
185185
d2d.map_jvm_to_class(
186-
project=self.project, logger=self.log, jvm_lang=jvm.JavaLanguage
186+
project=self.project, jvm_lang=jvm.JavaLanguage, logger=self.log
187187
)
188188

189189
@optional_step("Java")
190190
def map_jar_to_java_source(self):
191191
"""Map .jar files to their related source directory."""
192192
d2d.map_jar_to_jvm_source(
193-
project=self.project, logger=self.log, jvm_lang=jvm.JavaLanguage
193+
project=self.project, jvm_lang=jvm.JavaLanguage, logger=self.log
194194
)
195195

196196
@optional_step("Scala")
@@ -204,14 +204,14 @@ def find_scala_packages(self):
204204
def map_scala_to_class(self):
205205
"""Map a .class compiled file to its .java source."""
206206
d2d.map_jvm_to_class(
207-
project=self.project, logger=self.log, jvm_lang=jvm.ScalaLanguage
207+
project=self.project, jvm_lang=jvm.ScalaLanguage, logger=self.log
208208
)
209209

210210
@optional_step("Scala")
211211
def map_jar_to_scala_source(self):
212212
"""Map .jar files to their related source directory."""
213213
d2d.map_jar_to_jvm_source(
214-
project=self.project, logger=self.log, jvm_lang=jvm.ScalaLanguage
214+
project=self.project, jvm_lang=jvm.ScalaLanguage, logger=self.log
215215
)
216216

217217
@optional_step("Kotlin")
@@ -225,14 +225,14 @@ def find_kotlin_packages(self):
225225
def map_kotlin_to_class(self):
226226
"""Map a .class compiled file to its .java source."""
227227
d2d.map_jvm_to_class(
228-
project=self.project, logger=self.log, jvm_lang=jvm.KotlinLanguage
228+
project=self.project, jvm_lang=jvm.KotlinLanguage, logger=self.log
229229
)
230230

231231
@optional_step("Kotlin")
232232
def map_jar_to_kotlin_source(self):
233233
"""Map .jar files to their related source directory."""
234234
d2d.map_jar_to_jvm_source(
235-
project=self.project, logger=self.log, jvm_lang=jvm.KotlinLanguage
235+
project=self.project, jvm_lang=jvm.KotlinLanguage, logger=self.log
236236
)
237237

238238
@optional_step("JavaScript")

scanpipe/pipes/d2d.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def _map_jvm_to_class_resource(
166166
):
167167
"""
168168
Map the ``to_resource`` .class file Resource with a Resource in
169-
``from_resources`` .java files, using the ``from_classes_index`` index of
170-
from/ fully qualified Java class names.
169+
``from_resources`` source files, using the ``from_classes_index`` index of
170+
from/ fully qualified binary files.
171171
"""
172172
for extension in jvm_lang.source_extensions:
173173
normalized_path = jvm_lang.get_normalized_path(
@@ -194,23 +194,26 @@ def _map_jvm_to_class_resource(
194194

195195
def map_jvm_to_class(project, jvm_lang: jvm.JvmLanguage, logger=None):
196196
"""
197-
Map to/ compiled Java .class(es) to from/ .java source using Java fully
198-
qualified paths and indexing from/ .java files.
197+
Map to/ compiled Jvm's binary files to from/ using Jvm language's fully
198+
qualified paths and indexing from/ Jvm lang's source files.
199199
"""
200200
project_files = project.codebaseresources.files().no_status()
201201
from_resources = project_files.from_codebase()
202202
to_resources = project_files.to_codebase().has_no_relation()
203203

204-
filter = {f"extra_data__{jvm_lang.source_package_attribute_name}__isnull": False}
204+
has_source_pkg_attr_name = {
205+
f"extra_data__{jvm_lang.source_package_attribute_name}__isnull": False
206+
}
205207

206208
to_resources_binary_extension = to_resources.filter(
207209
extension__in=jvm_lang.binary_extensions
208210
)
209211
from_resources_source_extension = (
210212
from_resources.filter(extension__in=jvm_lang.source_extensions)
211-
# The "java_package" extra_data value is set during the `find_java_packages`,
213+
# The source_package_attribute_name extra_data value
214+
# is set during the `find_jvm_package`,
212215
# it is required to build the index.
213-
.filter(**filter)
216+
.filter(**has_source_pkg_attr_name)
214217
)
215218
to_resource_count = to_resources_binary_extension.count()
216219
from_resource_count = from_resources_source_extension.count()
@@ -225,8 +228,8 @@ def map_jvm_to_class(project, jvm_lang: jvm.JvmLanguage, logger=None):
225228
f"{from_resource_count:,d} {jvm_lang.source_extensions}"
226229
)
227230

228-
# build an index using from-side Java fully qualified class file names
229-
# built from the "java_package" and file name
231+
# build an index using from-side fully qualified class file names
232+
# built from the source_package_attribute_name and file name
230233
indexables = jvm_lang.get_indexable_qualified_paths(from_resources_source_extension)
231234

232235
# we do not index subpath since we want to match only fully qualified names
@@ -237,13 +240,16 @@ def map_jvm_to_class(project, jvm_lang: jvm.JvmLanguage, logger=None):
237240

238241
for to_resource in progress.iter(resource_iterator):
239242
_map_jvm_to_class_resource(
240-
to_resource, from_resources, from_classes_index, jvm_lang
243+
to_resource=to_resource,
244+
from_resources=from_resources,
245+
from_classes_index=from_classes_index,
246+
jvm_lang=jvm_lang,
241247
)
242248

243249

244250
def find_jvm_packages(project, jvm_lang: jvm.JvmLanguage, logger=None):
245251
"""
246-
Collect the JVM packages of Java source files for a ``project``.
252+
Collect the JVM packages of source files for a ``project``.
247253
248254
Multiprocessing is enabled by default on this pipe, the number of processes
249255
can be controlled through the SCANCODEIO_PROCESSES setting.
@@ -272,7 +278,7 @@ def find_jvm_packages(project, jvm_lang: jvm.JvmLanguage, logger=None):
272278

273279
def save_jvm_package_scan_results(codebase_resource, scan_results, scan_errors):
274280
"""
275-
Save the resource Java package scan results in the database as Resource.extra_data.
281+
Save the resource Jvm package scan results in the database as Resource.extra_data.
276282
Create project errors if any occurred during the scan.
277283
"""
278284
# The status is only updated in case of errors.
@@ -309,16 +315,16 @@ def _map_jar_to_jvm_source_resource(
309315
dot_class_file_ids = [
310316
dot_class_file.get("id") for dot_class_file in jar_extracted_dot_class_files
311317
]
312-
java_to_class_extra_data_list = CodebaseRelation.objects.filter(
318+
jvm_binary_map_type_extra_data_list = CodebaseRelation.objects.filter(
313319
to_resource__in=dot_class_file_ids, map_type=jvm_lang.binary_map_type
314320
).values_list("extra_data", flat=True)
315321

316322
from_source_roots = [
317323
extra_data.get("from_source_root", "")
318-
for extra_data in java_to_class_extra_data_list
324+
for extra_data in jvm_binary_map_type_extra_data_list
319325
]
320326
if len(set(from_source_roots)) != 1:
321-
# Could not determine a common root directory for the java_to_class files
327+
# Could not determine a common root directory for the binary_map_type files
322328
return
323329

324330
common_source_root = from_source_roots[0].rstrip("/")

scanpipe/pipes/jvm.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23-
"""Support for JVM-specific file formats such as .class and .java files."""
23+
"""
24+
Support for JVM-specific file formats such as
25+
.class and .java, .scala and .kotlin files.
26+
"""
2427

2528
import re
2629
from pathlib import Path
@@ -91,7 +94,7 @@ def scan_for_source_package(cls, location, with_threading=True):
9194
@classmethod
9295
def get_indexable_qualified_paths(cls, from_resources_dot_java):
9396
"""
94-
Yield tuples of (resource id, fully-qualified Java class name) for indexable
97+
Yield tuples of (resource id, fully-qualified class name) for indexable
9598
classes from the "from/" side of the project codebase using the
9699
"java_package" Resource.extra_data.
97100
"""
@@ -103,7 +106,7 @@ def get_indexable_qualified_paths(cls, from_resources_dot_java):
103106
@classmethod
104107
def get_indexable_qualified_paths_from_values(cls, resource_values):
105108
"""
106-
Yield tuples of (resource id, fully-qualified Java path) for indexable
109+
Yield tuples of (resource id, fully-qualified path) for indexable
107110
classes from a list of ``resource_data`` tuples of "from/" side of the
108111
project codebase.
109112
@@ -207,8 +210,8 @@ def get_normalized_path(cls, path, extension):
207210

208211
def get_fully_qualified_path(jvm_package, filename):
209212
"""
210-
Return a fully qualified java path of a .java ``filename`` in a
211-
``java_package`` string.
213+
Return a fully qualified path of a ``filename`` in a
214+
string.
212215
Note that we use "/" as path separators.
213216
214217
For example::

0 commit comments

Comments
 (0)