A ScanCode post-scan plugin to return consolidated components and consolidated packages for different types of codebase summarization. A consolidated component is a group of Resources that have the same origin. Currently, a ConsolidatedComponent is created for each detected copyrig
| 115 | |
| 116 | @post_scan_impl |
| 117 | class Consolidator(PostScanPlugin): |
| 118 | """ |
| 119 | A ScanCode post-scan plugin to return consolidated components and consolidated |
| 120 | packages for different types of codebase summarization. |
| 121 | |
| 122 | A consolidated component is a group of Resources that have the same origin. |
| 123 | Currently, a ConsolidatedComponent is created for each detected copyright holder |
| 124 | in a codebase and contains resources that have that particular copyright holder. |
| 125 | |
| 126 | A consolidated package is a detected package in the scanned codebase that has |
| 127 | been enhanced with data about other licenses and holders found within it. |
| 128 | |
| 129 | If a Resource is part of a consolidated component or consolidated package, then |
| 130 | the identifier of the consolidated component or consolidated package it is part |
| 131 | of is in the Resource's ``consolidated_to`` field. |
| 132 | """ |
| 133 | codebase_attributes = dict( |
| 134 | consolidated_components=attr.ib(default=attr.Factory(list)), |
| 135 | consolidated_packages=attr.ib(default=attr.Factory(list)) |
| 136 | ) |
| 137 | |
| 138 | resource_attributes = dict( |
| 139 | consolidated_to=attr.ib(default=attr.Factory(list)) |
| 140 | ) |
| 141 | |
| 142 | run_order = 10 |
| 143 | sort_order = 10 |
| 144 | |
| 145 | options = [ |
| 146 | PluggableCommandLineOption(('--consolidate',), |
| 147 | is_flag=True, default=False, |
| 148 | help='Group resources by Packages or license and copyright holder and ' |
| 149 | 'return those groupings as a list of consolidated packages and ' |
| 150 | 'a list of consolidated components. ' |
| 151 | 'This requires the scan to have/be run with the copyright, license, and package options active', |
| 152 | help_group=POST_SCAN_GROUP |
| 153 | ) |
| 154 | ] |
| 155 | |
| 156 | def is_enabled(self, consolidate, **kwargs): |
| 157 | return consolidate |
| 158 | |
| 159 | def process_codebase(self, codebase, **kwargs): |
| 160 | deprecation_message = "The --consolidate option will be deprecated in a future version of scancode-toolkit." |
| 161 | warnings.simplefilter('always', ConsolidatorPluginDeprecationWarning) |
| 162 | warnings.warn( |
| 163 | deprecation_message, |
| 164 | ConsolidatorPluginDeprecationWarning, |
| 165 | stacklevel=2, |
| 166 | ) |
| 167 | codebase_header = codebase.get_or_create_current_header() |
| 168 | codebase_header.warnings.append(deprecation_message) |
| 169 | |
| 170 | # Collect ConsolidatedPackages and ConsolidatedComponents |
| 171 | # TODO: Have a "catch-all" Component for the things that we haven't grouped |
| 172 | consolidations = [] |
| 173 | root = codebase.root |
| 174 | if hasattr(root, 'packages') and hasattr(root, 'copyrights') and hasattr(root, 'license_detections'): |
nothing calls this directly
no test coverage detected