Exemple #1
0
  def test_force_override(self):
    jars = list(self.simple.dependencies)
    with temporary_file_path() as ivyxml:
      self.ivy_utils._generate_ivy([self.simple], jars=jars, excludes=[], ivyxml=ivyxml,
                                   confs=['default'])

      doc = ET.parse(ivyxml).getroot()

      conf = self.find_single(doc, 'configurations/conf')
      self.assert_attributes(conf, name='default')

      dependencies = list(doc.findall('dependencies/dependency'))
      self.assertEqual(2, len(dependencies))

      dep1 = dependencies[0]
      self.assert_attributes(dep1, org='org1', name='name1', rev='rev1')
      conf = self.find_single(dep1, 'conf')
      self.assert_attributes(conf, name='default', mapped='default')

      dep2 = dependencies[1]
      self.assert_attributes(dep2, org='org2', name='name2', rev='rev2', force='true')
      conf = self.find_single(dep1, 'conf')
      self.assert_attributes(conf, name='default', mapped='default')

      override = self.find_single(doc, 'dependencies/override')
      self.assert_attributes(override, org='org2', module='name2', rev='rev2')
Exemple #2
0
  def try_insert(self, cache_key, paths):
    with temporary_file_path() as tarfile:
      artifact = TarballArtifact(self.artifact_root, tarfile, self.compress)
      artifact.collect(paths)

      with open(tarfile, 'rb') as infile:
        remote_path = self._remote_path_for_key(cache_key)
        if not self._request('PUT', remote_path, body=infile):
          raise self.CacheError('Failed to PUT to %s. Error: 404' % self._url_string(remote_path))
  def try_insert(self, cache_key, paths):
    with temporary_file_path() as tarfile:
      artifact = TarballArtifact(self.artifact_root, tarfile, self.compress)
      artifact.collect(paths)

      with open(tarfile, 'rb') as infile:
        remote_path = self._remote_path_for_key(cache_key)
        if not self._request('PUT', remote_path, body=infile):
          raise self.CacheError('Failed to PUT to %s. Error: 404' % self._url_string(remote_path))
Exemple #4
0
  def test_write_run_info(self):
    with temporary_file_path() as tmppath:
      ri = RunInfo(tmppath)
      ri.add_info('key1', 'val1')
      ri.add_infos(('key2', ' val2'), (' key3 ', 'val3 '))
      self.assertEquals({'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}, ri.get_as_dict())

      with open(tmppath, 'r') as tmpfile:
        contents = tmpfile.read()
      self.assertEquals('key1: val1\nkey2: val2\nkey3: val3\n', contents)
Exemple #5
0
 def localize_analysis_cache(self, src, dst):
   with temporary_file_path() as tmp_analysis_cache:
     shutil.copy(src, tmp_analysis_cache)
     rebasings = [
       (ZincUtils.IVY_HOME_PLACEHOLDER, self._ivy_home),
       (ZincUtils.PANTS_HOME_PLACEHOLDER, self._pants_home),
     ]
     exit_code = self.run_zinc_rebase(cache=tmp_analysis_cache, rebasings=rebasings)
     if not exit_code:
       shutil.copy(tmp_analysis_cache, dst)
     return exit_code
  def try_insert(self, cache_key, build_artifacts):
    with temporary_file_path() as tarfile:
      mode = 'w:bz2' if self.compress else 'w'
      with open_tar(tarfile, mode, dereference=True) as tarout:
        for artifact in build_artifacts:
          # Adds dirs recursively.
          tarout.add(artifact, os.path.relpath(artifact, self.artifact_root))

      with open(tarfile, 'rb') as infile:
        path = self._path_for_key(cache_key)
        if not self._request('PUT', path, body=infile):
          raise self.CacheError('Failed to PUT to %s. Error: 404' % self._url_string(path))
Exemple #7
0
    def test_write_run_info(self):
        with temporary_file_path() as tmppath:
            ri = RunInfo(tmppath)
            ri.add_info('key1', 'val1')
            ri.add_infos(('key2', ' val2'), (' key3 ', 'val3 '))
            self.assertEquals({
                'key1': 'val1',
                'key2': 'val2',
                'key3': 'val3'
            }, ri.get_as_dict())

            with open(tmppath, 'r') as tmpfile:
                contents = tmpfile.read()
            self.assertEquals('key1: val1\nkey2: val2\nkey3: val3\n', contents)
    def try_insert(self, cache_key, build_artifacts):
        with temporary_file_path() as tarfile:
            mode = 'w:bz2' if self.compress else 'w'
            with open_tar(tarfile, mode, dereference=True) as tarout:
                for artifact in build_artifacts:
                    # Adds dirs recursively.
                    tarout.add(artifact,
                               os.path.relpath(artifact, self.artifact_root))

            with open(tarfile, 'rb') as infile:
                path = self._path_for_key(cache_key)
                if not self._request('PUT', path, body=infile):
                    raise self.CacheError('Failed to PUT to %s. Error: 404' %
                                          self._url_string(path))
  def try_insert(self, cache_key, build_artifacts):
    with temporary_file_path() as tarfile:
      # In our tests, gzip is slightly less compressive than bzip2 on .class files,
      # but decompression times are much faster.
      mode = 'w:gz' if self.compress else 'w'
      with open_tar(tarfile, mode, dereference=True) as tarout:
        for artifact in build_artifacts:
          # Adds dirs recursively.
          tarout.add(artifact, os.path.relpath(artifact, self.artifact_root))

      with open(tarfile, 'rb') as infile:
        path = self._path_for_key(cache_key)
        if not self._request('PUT', path, body=infile):
          raise self.CacheError('Failed to PUT to %s. Error: 404' % self._url_string(path))
Exemple #10
0
 def localize_analysis_file(self, src, dst):
     with temporary_file_path() as tmp_analysis_file:
         shutil.copy(src, tmp_analysis_file)
         rebasings = [
             (ZincUtils.IVY_HOME_PLACEHOLDER, self._ivy_home),
             (ZincUtils.PANTS_HOME_PLACEHOLDER, self._pants_home),
         ]
         exit_code = self.run_zinc_rebase(tmp_analysis_file, rebasings)
         if not exit_code:
             shutil.copy(tmp_analysis_file, dst)
             tmp_relations_file = tmp_analysis_file + '.relations'
             dst_relations_file = dst + '.relations'
             if os.path.exists(tmp_relations_file):
                 shutil.copy(tmp_relations_file, dst_relations_file)
         return exit_code
Exemple #11
0
 def localize_analysis_file(self, src, dst):
   with temporary_file_path() as tmp_analysis_file:
     shutil.copy(src, tmp_analysis_file)
     rebasings = [
       (ZincUtils.IVY_HOME_PLACEHOLDER, self._ivy_home),
       (ZincUtils.PANTS_HOME_PLACEHOLDER, self._pants_home),
     ]
     exit_code = self.run_zinc_rebase(tmp_analysis_file, rebasings)
     if not exit_code:
       shutil.copy(tmp_analysis_file, dst)
       tmp_relations_file = tmp_analysis_file + '.relations'
       dst_relations_file = dst + '.relations'
       if os.path.exists(tmp_relations_file):
         shutil.copy(tmp_relations_file, dst_relations_file)
     return exit_code
Exemple #12
0
    def test_run_info_read(self):
        with temporary_file_path() as tmppath:
            with open(tmppath, 'w') as tmpfile:
                tmpfile.write('foo:bar\n baz :qux quux')
            ri = RunInfo(tmppath)
            self.assertEquals(ri.path(), tmppath)

            # Test get_info access.
            self.assertEquals(ri.get_info('foo'), 'bar')
            self.assertEquals(ri.get_info('baz'), 'qux quux')
            self.assertIsNone(ri.get_info('nonexistent'))

            # Test dict-like access.
            self.assertEquals(ri['foo'], 'bar')
            self.assertEquals(ri['baz'], 'qux quux')
Exemple #13
0
  def test_run_info_read(self):
    with temporary_file_path() as tmppath:
      with open(tmppath, 'w') as tmpfile:
        tmpfile.write('foo:bar\n baz :qux quux')
      ri = RunInfo(tmppath)
      self.assertEquals(ri.path(), tmppath)

      # Test get_info access.
      self.assertEquals(ri.get_info('foo'), 'bar')
      self.assertEquals(ri.get_info('baz'), 'qux quux')
      self.assertIsNone(ri.get_info('nonexistent'))

      # Test dict-like access.
      self.assertEquals(ri['foo'], 'bar')
      self.assertEquals(ri['baz'], 'qux quux')
    def try_insert(self, cache_key, build_artifacts):
        with temporary_file_path() as tarfile:
            # In our tests, gzip is slightly less compressive than bzip2 on .class files,
            # but decompression times are much faster.
            mode = 'w:gz' if self.compress else 'w'
            with open_tar(tarfile, mode, dereference=True) as tarout:
                for artifact in build_artifacts:
                    # Adds dirs recursively.
                    tarout.add(artifact,
                               os.path.relpath(artifact, self.artifact_root))

            with open(tarfile, 'rb') as infile:
                path = self._path_for_key(cache_key)
                if not self._request('PUT', path, body=infile):
                    raise self.CacheError('Failed to PUT to %s. Error: 404' %
                                          self._url_string(path))
Exemple #15
0
 def relativize_analysis_file(self, src, dst):
     # Make an analysis cache portable. Work on a tmpfile, for safety.
     #
     # NOTE: We can't port references to deps on the Java home. This is because different JVM
     # implementations on different systems have different structures, and there's not
     # necessarily a 1-1 mapping between Java jars on different systems. Instead we simply
     # drop those references from the analysis cache.
     #
     # In practice the JVM changes rarely, and it should be fine to require a full rebuild
     # in those rare cases.
     with temporary_file_path() as tmp_analysis_file:
         shutil.copy(src, tmp_analysis_file)
         rebasings = [
             (self._java_home, ''),  # Erase java deps.
             (self._ivy_home, ZincUtils.IVY_HOME_PLACEHOLDER),
             (self._pants_home, ZincUtils.PANTS_HOME_PLACEHOLDER),
         ]
         exit_code = self.run_zinc_rebase(tmp_analysis_file, rebasings)
         if not exit_code:
             shutil.copy(tmp_analysis_file, dst)
         return exit_code
Exemple #16
0
 def relativize_analysis_file(self, src, dst):
   # Make an analysis cache portable. Work on a tmpfile, for safety.
   #
   # NOTE: We can't port references to deps on the Java home. This is because different JVM
   # implementations on different systems have different structures, and there's not
   # necessarily a 1-1 mapping between Java jars on different systems. Instead we simply
   # drop those references from the analysis cache.
   #
   # In practice the JVM changes rarely, and it should be fine to require a full rebuild
   # in those rare cases.
   with temporary_file_path() as tmp_analysis_file:
     shutil.copy(src, tmp_analysis_file)
     rebasings = [
       (self._java_home, ''),  # Erase java deps.
       (self._ivy_home, ZincUtils.IVY_HOME_PLACEHOLDER),
       (self._pants_home, ZincUtils.PANTS_HOME_PLACEHOLDER),
     ]
     exit_code = self.run_zinc_rebase(tmp_analysis_file, rebasings)
     if not exit_code:
       shutil.copy(tmp_analysis_file, dst)
     return exit_code
Exemple #17
0
    def test_force_override(self):
        jars = list(self.simple.payload.jars)
        with temporary_file_path() as ivyxml:
            self.ivy_utils._generate_ivy([self.simple],
                                         jars=jars,
                                         excludes=[],
                                         ivyxml=ivyxml,
                                         confs=['default'])

            doc = ET.parse(ivyxml).getroot()

            conf = self.find_single(doc, 'configurations/conf')
            self.assert_attributes(conf, name='default')

            dependencies = list(doc.findall('dependencies/dependency'))
            self.assertEqual(2, len(dependencies))

            dep1 = dependencies[0]
            self.assert_attributes(dep1, org='org1', name='name1', rev='rev1')
            conf = self.find_single(dep1, 'conf')
            self.assert_attributes(conf, name='default', mapped='default')

            dep2 = dependencies[1]
            self.assert_attributes(dep2,
                                   org='org2',
                                   name='name2',
                                   rev='rev2',
                                   force='true')
            conf = self.find_single(dep1, 'conf')
            self.assert_attributes(conf, name='default', mapped='default')

            override = self.find_single(doc, 'dependencies/override')
            self.assert_attributes(override,
                                   org='org2',
                                   module='name2',
                                   rev='rev2')