Esempio n. 1
0
 def find_dependencies(self, source_file_name):
   """Process a pom.xml file containing the <dependencyManagement> tag.
      Returns an array of dictionaries containing the children of the <dependency> tag.
   """
   if source_file_name in DependencyManagementFinder._cache:
     return DependencyManagementFinder._cache[source_file_name]
   if self._rootdir:
     source_file_name = os.path.join(self._rootdir, source_file_name)
   pomHandler = _DMFPomContentHandler()
   with open(source_file_name) as source:
     xml.sax.parse(source, pomHandler)
   source.close()
   return GenerationUtils.symbol_substitution_on_dicts(pomHandler.properties,
                                                       pomHandler.dependency_management)
Esempio n. 2
0
  def _parse(self, source_file_name, rootdir):
    pomHandler = _DFPomContentHandler()
    if rootdir:
      full_source_path = os.path.join(rootdir, source_file_name)
    else:
      full_source_path = source_file_name

    if os.path.basename(full_source_path) != 'pom.xml':
      full_source_path = os.path.join(full_source_path, 'pom.xml')

    try:
      with open(full_source_path) as source:
        xml.sax.parse(source, pomHandler)
    except IOError:
      # assume this file has been removed for a good reason and just continue normally
      return
    except xml.sax.SAXParseException as e:
      raise MalformattedPOMException(source_file_name, e)

    self._artifactId = pomHandler.artifactId
    self._groupId = pomHandler.groupId
    self._parent = pomHandler.parent

    # Since dependencies are just dicts, we keep track of keys separately.  Maybe in the future
    # it would be good to create a Dependency data structure and return a set or ordered dictionary
    # of those instances instead.
    dep_keys = set()
    for dep in pomHandler.dependencies:
      if 'groupId' in dep and 'artifactId' in dep:
        dep_keys.add('{0} {1}'.format(dep['groupId'], dep['artifactId']))
        self._dependencies.append(dep)

    parent_df = self.parent
    if parent_df:
      for dep in parent_df.dependencies:
        key = '{0} {1}'.format(dep['groupId'], dep['artifactId'])
        # dependencies declared in parent poms can be overridden
        if key not in dep_keys:
          self._dependencies.append(dep)
      self._properties.update(parent_df.properties)

    self._properties.update(pomHandler.properties)
    for key, value in self._properties.items():
      self._properties[key] = GenerationUtils.symbol_substitution(self._properties, value)
    self._dependencies = GenerationUtils.symbol_substitution_on_dicts(self._properties,
                                                                      self._dependencies)