|
47 | 47 | from summarycode.classify import LEGAL_STARTS_ENDS
|
48 | 48 |
|
49 | 49 | from aboutcode.pipeline import LoopProgress
|
| 50 | +from scanpipe import config |
50 | 51 | from scanpipe import pipes
|
51 | 52 | from scanpipe.models import CodebaseRelation
|
52 | 53 | from scanpipe.models import CodebaseResource
|
|
66 | 67 | TO = "to/"
|
67 | 68 |
|
68 | 69 |
|
| 70 | +ECOSYSTEM_CONFIGS = [ |
| 71 | + config.DefaultEcosystemConfig, |
| 72 | + config.JavaEcosystemConfig, |
| 73 | + config.JavaScriptEcosystemConfig, |
| 74 | + config.RubyEcosystemConfig, |
| 75 | + config.RustEcosystemConfig, |
| 76 | + config.GoEcosystemConfig, |
| 77 | +] |
| 78 | + |
| 79 | + |
69 | 80 | def get_inputs(project):
|
70 | 81 | """
|
71 | 82 | Locate the ``from`` and ``to`` input files in project inputs/ directory.
|
@@ -114,6 +125,55 @@ def get_best_path_matches(to_resource, matches):
|
114 | 125 | return matches
|
115 | 126 |
|
116 | 127 |
|
| 128 | +def load_ecosystem_config(pipeline, options): |
| 129 | + """ |
| 130 | + Add ecosystem specific configurations for each ecosystem selected |
| 131 | + as `options` to the `pipeline`. |
| 132 | + """ |
| 133 | + configs_by_ecosystem = { |
| 134 | + ecosystem.ecosystem_option: ecosystem for ecosystem in ECOSYSTEM_CONFIGS |
| 135 | + } |
| 136 | + |
| 137 | + # Add default configurations which are common accross ecosystems |
| 138 | + add_ecosystem_config( |
| 139 | + pipeline=pipeline, |
| 140 | + configs_by_ecosystem=configs_by_ecosystem, |
| 141 | + selected_option="Default", |
| 142 | + ) |
| 143 | + |
| 144 | + # Add configurations for each selected ecosystem |
| 145 | + for selected_option in options: |
| 146 | + if selected_option not in configs_by_ecosystem: |
| 147 | + continue |
| 148 | + |
| 149 | + add_ecosystem_config( |
| 150 | + pipeline=pipeline, |
| 151 | + configs_by_ecosystem=configs_by_ecosystem, |
| 152 | + selected_option=selected_option, |
| 153 | + ) |
| 154 | + |
| 155 | + |
| 156 | +def add_ecosystem_config(pipeline, configs_by_ecosystem, selected_option): |
| 157 | + d2d_pipeline_configs = [ |
| 158 | + "purldb_package_extensions", |
| 159 | + "purldb_resource_extensions", |
| 160 | + "deployed_resource_path_exclusions", |
| 161 | + ] |
| 162 | + |
| 163 | + ecosystem_config = configs_by_ecosystem.get(selected_option) |
| 164 | + |
| 165 | + for pipeline_config in d2d_pipeline_configs: |
| 166 | + config_value = getattr(ecosystem_config, pipeline_config) |
| 167 | + pipeline_config_value = getattr(pipeline, pipeline_config) |
| 168 | + if config_value: |
| 169 | + if not pipeline_config_value: |
| 170 | + new_config_value = config_value |
| 171 | + else: |
| 172 | + new_config_value = pipeline_config_value.extend(config_value) |
| 173 | + |
| 174 | + setattr(pipeline, pipeline_config, new_config_value) |
| 175 | + |
| 176 | + |
117 | 177 | def get_from_files_for_scanning(resources):
|
118 | 178 | """
|
119 | 179 | Return resources in the "from/" side which has been mapped to the "to/"
|
@@ -1453,6 +1513,20 @@ def match_resources_with_no_java_source(project, logger=None):
|
1453 | 1513 | )
|
1454 | 1514 |
|
1455 | 1515 |
|
| 1516 | +def ignore_unmapped_resources_from_config(project, patterns_to_ignore, logger=None): |
| 1517 | + """Ignore unmapped resources for a project using `patterns_to_ignore`.""" |
| 1518 | + ignored_resources_count = flag.flag_ignored_patterns( |
| 1519 | + codebaseresources=project.codebaseresources.to_codebase().no_status(), |
| 1520 | + patterns=patterns_to_ignore, |
| 1521 | + status=flag.IGNORED_FROM_CONFIG, |
| 1522 | + ) |
| 1523 | + if logger: |
| 1524 | + logger( |
| 1525 | + f"Ignoring {ignored_resources_count:,d} to/ resources with " |
| 1526 | + "from ecosystem specific configurations." |
| 1527 | + ) |
| 1528 | + |
| 1529 | + |
1456 | 1530 | def match_unmapped_resources(project, matched_extensions=None, logger=None):
|
1457 | 1531 | """
|
1458 | 1532 | Match resources with empty status to PurlDB, if unmatched
|
|
0 commit comments