MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _inherit_from_parent

Method _inherit_from_parent

src/packagedcode/maven.py:681–734  ·  view source on GitHub ↗

Update attributes using inheritance from parent attributes. For instance, the parent group_id is used if group_id is not defined.

(self)

Source from the content-addressed store, hash-verified

679 # nest list: 'mailing_lists',
680
681 def _inherit_from_parent(self):
682 """
683 Update attributes using inheritance from parent attributes. For
684 instance, the parent group_id is used if group_id is not defined.
685 """
686 # TODO: there are more attributes (all) that can be inherited
687 if not self.parent:
688 return
689 if self.group_id is None and self.parent.group_id:
690 self.group_id = self.parent.group_id
691 if TRACE: logger.debug('_inherit_from_parent: group_id: {}'.format(self.parent.group_id))
692 if self.version is None and self.parent.version:
693 self.version = str(self.parent.version)
694 if TRACE: logger.debug('_inherit_from_parent: version: {}'.format(self.parent.version))
695 if not self.classifier is None and self.parent.classifier:
696 self.classifier = self.parent.classifier
697 if TRACE: logger.debug('_inherit_from_parent: classifier: {}'.format(self.parent.classifier))
698
699 # FIXME: the parent may need to be resolved too?
700 # special handling for URLs: see
701 # http://maven.apache.org/ref/3.5.0/maven-model-builder/index.html#Inheritance_Assembly
702 # Notice that the 5 URLs from the model:
703 # project.url,
704 # project.scm.connection, project.scm.developerConnection, project.scm.url
705 # project.distributionManagement.site.url)
706 # ... have a special inheritance handling: if not configured in
707 # current model, the inherited value is the parent's one with
708 # current artifact id appended.
709 if (self.url is None
710 and hasattr(self.parent, 'url')
711 and getattr(self.parent, 'url', None)
712 and self.artifact_id):
713 # FIXME: this is not the way to join URLs parts!
714 self.url = self.parent.url + self.artifact_id
715
716 # FIXME: this is not the way to join URLs parts!
717 parent_scm = getattr(self.parent, 'scm', None)
718 if self.scm and parent_scm and self.artifact_id:
719 ps_url = parent_scm.get('url')
720 if not self.scm.get('url') and ps_url:
721 # FIXME: this is not the way to join URLs parts!
722 self.scm['url'] = ps_url + self.artifact_id
723
724 ps_connection = parent_scm.get('connection')
725 if not self.scm.get('connection') and ps_connection:
726 # FIXME: this is not the way to join URLs parts!
727 self.scm['connection'] = ps_connection + self.artifact_id
728
729 ps_devconnection = parent_scm.get('developer_connection')
730 if not self.scm.get('developer_connection') and ps_devconnection:
731 # FIXME: this is not the way to join URLs parts!
732 self.scm['developer_connection'] = ps_devconnection + self.artifact_id
733
734 # TODO: distribution_management.site.url
735
736 def _pom_factory(self, group_id, artifact_id, version):
737 return ParentPom('%s:%s:pom:%s' % (group_id, artifact_id, version))

Callers 1

resolveMethod · 0.95

Calls 3

getMethod · 0.65
debugMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected