Skip to main content

provenant/scanner/
mod.rs

1// SPDX-FileCopyrightText: Provenant contributors
2// SPDX-License-Identifier: Apache-2.0
3
4mod collect;
5pub(crate) mod process;
6
7use crate::license_detection::LicenseDetectionEngine;
8use crate::models::FileInfo;
9
10pub struct ProcessResult {
11    pub files: Vec<FileInfo>,
12    pub excluded_count: usize,
13}
14
15#[derive(Debug, Clone, Copy)]
16pub struct LicenseScanOptions {
17    pub include_text: bool,
18    pub include_text_diagnostics: bool,
19    pub include_diagnostics: bool,
20    pub unknown_licenses: bool,
21    pub enable_sequence_matching: bool,
22    pub min_score: u8,
23}
24
25impl Default for LicenseScanOptions {
26    fn default() -> Self {
27        Self {
28            include_text: false,
29            include_text_diagnostics: false,
30            include_diagnostics: false,
31            unknown_licenses: false,
32            enable_sequence_matching: true,
33            min_score: 0,
34        }
35    }
36}
37
38#[derive(Debug, Clone)]
39pub struct TextDetectionOptions {
40    pub collect_info: bool,
41    pub detect_packages: bool,
42    pub detect_application_packages: bool,
43    pub detect_system_packages: bool,
44    pub detect_packages_in_compiled: bool,
45    pub detect_copyrights: bool,
46    pub detect_generated: bool,
47    pub detect_emails: bool,
48    pub detect_urls: bool,
49    pub max_emails: usize,
50    pub max_urls: usize,
51    pub timeout_seconds: f64,
52}
53
54impl Default for TextDetectionOptions {
55    fn default() -> Self {
56        Self {
57            collect_info: false,
58            detect_packages: false,
59            detect_application_packages: false,
60            detect_system_packages: false,
61            detect_packages_in_compiled: false,
62            detect_copyrights: true,
63            detect_generated: false,
64            detect_emails: false,
65            detect_urls: false,
66            max_emails: 50,
67            max_urls: 50,
68            timeout_seconds: 120.0,
69        }
70    }
71}
72
73pub fn scan_options_fingerprint(
74    text_options: &TextDetectionOptions,
75    license_options: LicenseScanOptions,
76    license_engine: Option<&LicenseDetectionEngine>,
77) -> String {
78    let (license_enabled, rules_count, first_rule_id, last_rule_id) = match license_engine {
79        Some(engine) => {
80            let rules = &engine.index().rules_by_rid;
81            (
82                true,
83                rules.len(),
84                rules
85                    .first()
86                    .map(|rule| rule.identifier.as_str())
87                    .unwrap_or(""),
88                rules
89                    .last()
90                    .map(|rule| rule.identifier.as_str())
91                    .unwrap_or(""),
92            )
93        }
94        None => (false, 0, "", ""),
95    };
96
97    format!(
98        "tool_version={};info={};packages={};app_packages={};system_packages={};compiled_packages={};copyrights={};generated={};emails={};urls={};max_emails={};max_urls={};timeout={:.6};license_enabled={};rules_count={};first_rule_id={};last_rule_id={};license_text={};license_text_diagnostics={};license_diagnostics={};unknown_licenses={};sequence_matching={};license_score={}",
99        crate::version::BUILD_VERSION,
100        text_options.collect_info,
101        text_options.detect_packages,
102        text_options.detect_application_packages,
103        text_options.detect_system_packages,
104        text_options.detect_packages_in_compiled,
105        text_options.detect_copyrights,
106        text_options.detect_generated,
107        text_options.detect_emails,
108        text_options.detect_urls,
109        text_options.max_emails,
110        text_options.max_urls,
111        text_options.timeout_seconds,
112        license_enabled,
113        rules_count,
114        first_rule_id,
115        last_rule_id,
116        license_options.include_text,
117        license_options.include_text_diagnostics,
118        license_options.include_diagnostics,
119        license_options.unknown_licenses,
120        license_options.enable_sequence_matching,
121        license_options.min_score,
122    )
123}
124
125pub use self::collect::{
126    CollectedPaths, CollectionFrontier, collect_paths, collect_selected_paths,
127};
128#[allow(unused_imports)]
129pub use self::process::{
130    MemoryMode, process_collected, process_collected_sequential,
131    process_collected_with_memory_limit, process_collected_with_memory_limit_sequential,
132};
133
134#[cfg(test)]
135mod tests;