def package_summarizer(resource, children, keep_details=False): """ Populate a packages summary list of packages mappings. Note: `keep_details` is never used, as we are not keeping details of packages as this has no value. """ packages = [] # Collect current data current_packages = getattr(resource, 'packages') or [] if TRACE_LIGHT and current_packages: from packagedcode.models import Package packs = [Package.create(**p) for p in current_packages] logger_debug('package_summarizer: for:', resource, 'current_packages are:', packs) current_packages = add_files(current_packages, resource) packages.extend(current_packages) if TRACE_LIGHT and packages: logger_debug() from packagedcode.models import Package # NOQA packs = [Package.create(**p) for p in packages] logger_debug('package_summarizer: for:', resource, 'packages are:', packs) # Collect direct children packages summary for child in children: child_summaries = get_resource_summary( child, key='packages', as_attribute=False) or [] packages.extend(child_summaries) # summarize proper set_resource_summary(resource, key='packages', value=packages, as_attribute=False) return packages
def get_package_root(cls, manifest_resource, codebase): if manifest_resource.name.endswith(('pom.xml', '.pom',)): # the root is either the parent or further up for poms stored under # a META-INF dir package_data = manifest_resource.packages if not package_data: return manifest_resource package_data = package_data[0] package = Package.create(**package_data) ns = package.namespace name = package.name path = 'META-INF/maven/{ns}/{name}/pom.xml'.format(**locals()) if manifest_resource.path.endswith(path): for ancestor in manifest_resource.ancestors(codebase): if ancestor.name == 'META-INF': jar_root_dir = ancestor.parent(codebase) return jar_root_dir return manifest_resource.parent(codebase) return manifest_resource