Skip to content

Commit b2ec8a5

Browse files
committed
Merge branch 'main' into python-d2d
2 parents 2b24f4f + f557411 commit b2ec8a5

25 files changed

Lines changed: 3214 additions & 49 deletions

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ v35.1.0 (unreleased)
1010
Requires the ``find_vulnerabilities`` pipeline to be executed beforehand.
1111
https://github.com/aboutcode-org/scancode.io/pull/1702
1212

13+
- Enable ``--license-references`` scan option in the ``scan_single_package`` pipeline.
14+
The ``license_references`` and ``license_rule_references`` attributes will now be
15+
available in the scan results, including the details about detected licenses and
16+
license rules used during the scan.
17+
https://github.com/aboutcode-org/scancode.io/issues/1657
18+
1319
- Add a new step to the ``DeployToDevelop`` pipeline, ``match_python``, to match
1420
Cython source files (.pyx) to their compiled binaries.
1521
https://github.com/aboutcode-org/scancode.io/pull/1703

scancodeio/static/add-inputs.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,41 @@
2121
// Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

2323
const fileInput = document.querySelector("#id_input_files");
24+
let selectedFiles = []; // Store selected files
2425
fileInput.onchange = updateFiles;
2526

2627
// Update the list of files to be uploaded in the UI
2728
function updateFiles() {
2829
if (fileInput.files.length > 0) {
2930
const fileName = document.querySelector("#inputs_file_name");
3031
fileName.innerHTML = "";
31-
for (let file of fileInput.files) {
32-
fileName.innerHTML += `<span class="is-block">${file.name}</span>`;
32+
33+
// Update the selectedFiles array
34+
const newFiles = Array.from(fileInput.files);
35+
// Create a Set to track unique file names
36+
const uniqueFileNames = new Set(selectedFiles.map(file => file.name));
37+
// Filter out files with the same name
38+
const filteredNewFiles = newFiles.filter(file => !uniqueFileNames.has(file.name));
39+
// Concatenate the unique files to the existing selectedFiles array
40+
selectedFiles = selectedFiles.concat(filteredNewFiles);
41+
42+
for (let file of selectedFiles) {
43+
const fileNameWithoutSpaces = file.name.replace(/\s/g, '');
44+
fileName.innerHTML += `
45+
<span class="is-flex is-justify-content-space-between is-block" id="file-name-${fileNameWithoutSpaces}">
46+
<span class="is-block">${file.name}</span>
47+
<a href="#" onclick="removeFile('${fileNameWithoutSpaces}')" class="model-button" id="file-delete-btn-${fileNameWithoutSpaces}">
48+
<i class="fa-solid fa-trash-can"></i>
49+
</a>
50+
</span>
51+
`;
52+
document.getElementById("file-delete-btn-"+ fileNameWithoutSpaces).addEventListener("click", function(event){
53+
disableEvent(event);
54+
removeFile(fileNameWithoutSpaces);
55+
if(selectedFiles.length == 0){
56+
fileName.innerHTML ="<i>No files selected</i>"
57+
}
58+
});
3359
}
3460
}
3561
}
@@ -40,15 +66,37 @@ function disableEvent(event) {
4066
event.preventDefault();
4167
}
4268

69+
function removeFile(fileName) {
70+
selectedFiles = selectedFiles.filter(file => {
71+
const fileNameWithoutSpaces = file.name.replace(/\s/g, '');
72+
return fileNameWithoutSpaces !== fileName;
73+
});
74+
75+
const fileNameElement = document.getElementById(`file-name-${fileName}`);
76+
if (fileNameElement) {
77+
fileNameElement.remove();
78+
}
79+
80+
const dataTransfer = new DataTransfer();
81+
for (let file of selectedFiles) {
82+
dataTransfer.items.add(file);
83+
}
84+
85+
fileInput.files = dataTransfer.files;
86+
}
87+
4388
function dropHandler(event) {
4489
disableEvent(event);
4590
const droppedFiles = event.dataTransfer.files;
46-
const updatedFiles = Array.from(fileInput.files);
91+
const updatedFilesSet = new Set(Array.from(fileInput.files));
4792

4893
for (let file of droppedFiles) {
49-
updatedFiles.push(file);
94+
updatedFilesSet.add(file);
5095
}
5196

97+
// Convert the Set back to an array if needed
98+
const updatedFiles = Array.from(updatedFilesSet);
99+
52100
const dataTransfer = new DataTransfer();
53101
for (let file of updatedFiles) {
54102
dataTransfer.items.add(file);

scanpipe/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ def filter(self, qs, value):
483483
("about_file", "about file"),
484484
("java_to_class", "java to class"),
485485
("jar_to_source", "jar to source"),
486+
("javascript_strings", "js strings"),
486487
("javascript_symbols", "js symbols"),
487488
("js_compiled", "js compiled"),
488489
("js_colocation", "js colocation"),

scanpipe/pipelines/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ def flag_ignored_resources(self):
7878
ignored_patterns = ignored_patterns.splitlines()
7979
ignored_patterns.extend(flag.DEFAULT_IGNORED_PATTERNS)
8080

81-
flag.flag_ignored_patterns(self.project, patterns=ignored_patterns)
81+
flag.flag_ignored_patterns(
82+
codebaseresources=self.project.codebaseresources.no_status(),
83+
patterns=ignored_patterns,
84+
)
8285

8386
def extract_archive(self, location, target):
8487
"""Extract archive at `location` to `target`. Save errors as messages."""
@@ -179,6 +182,8 @@ def __init__(self, run_instance):
179182
self.selected_groups = run_instance.selected_groups
180183
self.selected_steps = run_instance.selected_steps
181184

185+
self.ecosystem_config = None
186+
182187
@classmethod
183188
def get_initial_steps(cls):
184189
"""Add the ``download_inputs`` step as an initial step if enabled."""

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from scanpipe import pipes
2525
from scanpipe.pipelines import Pipeline
2626
from scanpipe.pipes import d2d
27+
from scanpipe.pipes import d2d_config
2728
from scanpipe.pipes import flag
2829
from scanpipe.pipes import input
2930
from scanpipe.pipes import matchcode
@@ -64,6 +65,8 @@ def steps(cls):
6465
cls.flag_empty_files,
6566
cls.flag_whitespace_files,
6667
cls.flag_ignored_resources,
68+
cls.load_ecosystem_config,
69+
cls.map_ruby,
6770
cls.map_about_files,
6871
cls.map_checksum,
6972
cls.match_archives_to_purldb,
@@ -72,6 +75,7 @@ def steps(cls):
7275
cls.map_jar_to_source,
7376
cls.map_javascript,
7477
cls.map_javascript_symbols,
78+
cls.map_javascript_strings,
7579
cls.map_elf,
7680
cls.map_macho,
7781
cls.map_winpe,
@@ -95,33 +99,6 @@ def steps(cls):
9599
cls.create_local_files_packages,
96100
)
97101

98-
purldb_package_extensions = [".jar", ".war", ".zip"]
99-
purldb_resource_extensions = [
100-
".map",
101-
".js",
102-
".mjs",
103-
".ts",
104-
".d.ts",
105-
".jsx",
106-
".tsx",
107-
".css",
108-
".scss",
109-
".less",
110-
".sass",
111-
".soy",
112-
".class",
113-
]
114-
doc_extensions = [
115-
".pdf",
116-
".doc",
117-
".docx",
118-
".ppt",
119-
".pptx",
120-
".tex",
121-
".odt",
122-
".odp",
123-
]
124-
125102
def get_inputs(self):
126103
"""Locate the ``from`` and ``to`` input files."""
127104
self.from_files, self.to_files = d2d.get_inputs(self.project)
@@ -156,6 +133,15 @@ def flag_whitespace_files(self):
156133
"""Flag whitespace files with size less than or equal to 100 byte as ignored."""
157134
d2d.flag_whitespace_files(project=self.project)
158135

136+
def load_ecosystem_config(self):
137+
"""Load ecosystem specific configurations for d2d steps for selected options."""
138+
d2d_config.load_ecosystem_config(pipeline=self, options=self.selected_groups)
139+
140+
@optional_step("Ruby")
141+
def map_ruby(self):
142+
"""Load Ruby specific configurations for d2d steps."""
143+
pass
144+
159145
def map_about_files(self):
160146
"""Map ``from/`` .ABOUT files to their related ``to/`` resources."""
161147
d2d.map_about_files(project=self.project, logger=self.log)
@@ -172,7 +158,7 @@ def match_archives_to_purldb(self):
172158

173159
d2d.match_purldb_resources(
174160
project=self.project,
175-
extensions=self.purldb_package_extensions,
161+
extensions=self.matchable_package_extensions,
176162
matcher_func=d2d.match_purldb_package,
177163
logger=self.log,
178164
)
@@ -205,6 +191,11 @@ def map_javascript_symbols(self):
205191
"""Map deployed JavaScript, TypeScript to its sources using symbols."""
206192
d2d.map_javascript_symbols(project=self.project, logger=self.log)
207193

194+
@optional_step("JavaScript")
195+
def map_javascript_strings(self):
196+
"""Map deployed JavaScript, TypeScript to its sources using string literals."""
197+
d2d.map_javascript_strings(project=self.project, logger=self.log)
198+
208199
@optional_step("Elf")
209200
def map_elf(self):
210201
"""Map ELF binaries to their sources using dwarf paths and symbols."""
@@ -258,7 +249,7 @@ def match_resources_to_purldb(self):
258249

259250
d2d.match_purldb_resources(
260251
project=self.project,
261-
extensions=self.purldb_resource_extensions,
252+
extensions=self.matchable_resource_extensions,
262253
matcher_func=d2d.match_purldb_resource,
263254
logger=self.log,
264255
)
@@ -296,6 +287,7 @@ def flag_mapped_resources_archives_and_ignored_directories(self):
296287
def perform_house_keeping_tasks(self):
297288
"""
298289
On deployed side
290+
- Ignore specific files based on ecosystem based configurations.
299291
- PurlDB match files with ``no-java-source`` and empty status,
300292
if no match is found update status to ``requires-review``.
301293
- Update status for uninteresting files.
@@ -306,9 +298,14 @@ def perform_house_keeping_tasks(self):
306298
"""
307299
d2d.match_resources_with_no_java_source(project=self.project, logger=self.log)
308300
d2d.handle_dangling_deployed_legal_files(project=self.project, logger=self.log)
301+
d2d.ignore_unmapped_resources_from_config(
302+
project=self.project,
303+
patterns_to_ignore=self.ecosystem_config.deployed_resource_path_exclusions,
304+
logger=self.log,
305+
)
309306
d2d.match_unmapped_resources(
310307
project=self.project,
311-
matched_extensions=self.purldb_resource_extensions,
308+
matched_extensions=self.ecosystem_config.matchable_resource_extensions,
312309
logger=self.log,
313310
)
314311
d2d.flag_undeployed_resources(project=self.project)
@@ -344,5 +341,5 @@ def flag_deployed_from_resources_with_missing_license(self):
344341
"""Update the status for deployed from files with missing license."""
345342
d2d.flag_deployed_from_resources_with_missing_license(
346343
self.project,
347-
doc_extensions=self.doc_extensions,
344+
doc_extensions=self.ecosystem_config.doc_extensions,
348345
)

scanpipe/pipelines/scan_single_package.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def steps(cls):
6161
"info": True,
6262
"license": True,
6363
"license_text": True,
64+
"license_references": True,
6465
"package": True,
6566
"url": True,
6667
"classify": True,

0 commit comments

Comments
 (0)