Exemplo n.º 1
0
  def _filter_unpacked_dir(self, target, unpacked_dir, class_files):
    # The Dx tool returns failure if more than one copy of a class is packed into the dex file and
    # it is easy to fetch duplicate libraries (as well as conflicting versions) from the SDK repos.
    # This filters the contents of the unpacked_dir against the include/exclude patterns of the
    # target, then compares the filtered files against previously gathered class_files to
    # dedupe and detect version conflicts.

    file_filter = UnpackJars.get_unpack_filter(target)
    for root, _, file_names in os.walk(unpacked_dir):
      for filename in file_names:
        # Calculate the filename relative to the unpacked_dir and then filter.
        relative_dir = os.path.relpath(root, unpacked_dir)
        class_file = os.path.join(relative_dir, filename)
        if file_filter(class_file):
          class_location = os.path.join(root, filename)

          # If the class_file (e.g. 'a/b/c/Hello.class') has already been added, then compare the
          # full path. If the full path is identical then we can ignore it as a duplicate. If
          # the path is different, that means that there is probably conflicting version
          # numbers amongst the library deps and so we raise an exception.
          if class_file in class_files:
            if class_files[class_file] != class_location:
              raise TaskError("Dependency:\n{}\n\nConflicts\n1: {} "
                              "\n2: {}".format(target, class_location, class_files[class_file]))
          class_files[class_file] = class_location
    return class_files.values()
Exemplo n.º 2
0
 def _run_filter(self, filename, include_patterns=None, exclude_patterns=None):
   return UnpackJars._file_filter(
     filename,
     UnpackJars._compile_patterns(include_patterns or []),
     UnpackJars._compile_patterns(exclude_patterns or []))
Exemplo n.º 3
0
 def test_invalid_pattern(self):
   with self.assertRaises(UnpackJars.InvalidPatternError):
     UnpackJars._compile_patterns([45])
Exemplo n.º 4
0
 def run_filter(filename, include_patterns=[], exclude_patterns=[]):
   return UnpackJars._unpack_filter(
     filename,
     UnpackJars._compile_patterns(include_patterns),
     UnpackJars._compile_patterns(exclude_patterns))
Exemplo n.º 5
0
 def run_filter(filename, include_patterns=[], exclude_patterns=[]):
     return UnpackJars._unpack_filter(
         filename, UnpackJars._compile_patterns(include_patterns),
         UnpackJars._compile_patterns(exclude_patterns))