コード例 #1
0
ファイル: sign_apk.py プロジェクト: zhaohaobing/pants
    def execute(self):
        # One time setup of the default keystore config file.
        if not os.path.isfile(self.default_config_location):
            self.setup_default_config(self.default_config_location)

        targets = self.context.targets(self.is_signtarget)
        with self.invalidated(targets) as invalidation_check:
            invalid_targets = []
            for vt in invalidation_check.invalid_vts:
                invalid_targets.extend(vt.targets)
            for target in invalid_targets:

                def get_products_path(target):
                    """Get path of target's unsigned apks as created by AaptBuilder."""
                    unsigned_apks = self.context.products.get('apk')
                    packages = unsigned_apks.get(target)
                    if packages:
                        for tgts, products in packages.items():
                            for prod in products:
                                yield os.path.join(tgts, prod)

                packages = list(get_products_path(target))
                for unsigned_apk in packages:
                    keystores = KeystoreResolver.resolve(self.config_file)

                    for key in keystores:
                        outdir = self.sign_apk_out(target,
                                                   keystores[key].build_type)
                        safe_mkdir(outdir)
                        args = self._render_args(target, keystores[key],
                                                 unsigned_apk, outdir)
                        with self.context.new_workunit(
                                name='sign_apk',
                                labels=[WorkUnitLabel.MULTITOOL]) as workunit:
                            returncode = subprocess.call(
                                args,
                                stdout=workunit.output('stdout'),
                                stderr=workunit.output('stderr'))
                            if returncode:
                                raise TaskError(
                                    'The SignApk jarsigner process exited non-zero: {0}'
                                    .format(returncode))

        for target in targets:
            release_path = self.sign_apk_out(target, 'release')
            release_apk = self.signed_package_name(target, 'release')

            if os.path.isfile(os.path.join(release_path, release_apk)):
                self.context.products.get('release_apk').add(
                    target, release_path).append(release_apk)
コード例 #2
0
ファイル: sign_apk.py プロジェクト: benjyw/pants
  def execute(self):
    # One time setup of the default keystore config file.
    if not os.path.isfile(self.default_config_location):
      self.setup_default_config(self.default_config_location)

    targets = self.context.targets(self.is_signtarget)
    with self.invalidated(targets) as invalidation_check:
      invalid_targets = []
      for vt in invalidation_check.invalid_vts:
        invalid_targets.extend(vt.targets)
      for target in invalid_targets:

        def get_products_path(target):
          """Get path of target's unsigned apks as created by AaptBuilder."""
          unsigned_apks = self.context.products.get('apk')
          packages = unsigned_apks.get(target)
          if packages:
            for tgts, products in packages.items():
              for prod in products:
                yield os.path.join(tgts, prod)

        packages = list(get_products_path(target))
        for unsigned_apk in packages:
          keystores = KeystoreResolver.resolve(self.config_file)

          for key in keystores:
            outdir = self.sign_apk_out(target, keystores[key].build_type)
            safe_mkdir(outdir)
            args = self._render_args(target, keystores[key], unsigned_apk, outdir)
            with self.context.new_workunit(name='sign_apk',
                                           labels=[WorkUnitLabel.MULTITOOL]) as workunit:
              returncode = subprocess.call(args, stdout=workunit.output('stdout'),
                                           stderr=workunit.output('stderr'))
              if returncode:
                raise TaskError('The SignApk jarsigner process exited non-zero: {0}'
                                .format(returncode))

    for target in targets:
      release_path = self.sign_apk_out(target, 'release')
      release_apk = self.signed_package_name(target, 'release')

      if os.path.isfile(os.path.join(release_path, release_apk)):
        self.context.products.get('release_apk').add(target, release_path).append(release_apk)
コード例 #3
0
 def test_a_missing_field(self):
   with self.assertRaises(KeystoreResolver.Error):
     with self.config_file(keystore_alias="") as config:
       KeystoreResolver.resolve(config)
コード例 #4
0
 def test_bad_config_location(self):
   with self.assertRaises(KeystoreResolver.Error):
     KeystoreResolver.resolve(os.path.join('no', 'config_file', 'here'))
コード例 #5
0
 def test_expanding_key_path(self):
   with self.config_file(keystore_location='~/dir') as config:
     keystores = KeystoreResolver.resolve(config)
     self.assertEqual(keystores['default-debug'].keystore_location, os.path.expanduser('~/dir'))
コード例 #6
0
 def test_set_location(self):
   with temporary_file() as temp_location:
     with self.config_file(keystore_location=temp_location.name) as config:
       keystores = KeystoreResolver.resolve(config)
       self.assertEqual(keystores['default-debug'].keystore_location, temp_location.name)
コード例 #7
0
 def test_bad_build_type(self):
   with self.config_file(build_type='bad-build-type') as config:
     keystores = KeystoreResolver.resolve(config)
     with self.assertRaises(ValueError):
       keystores['default-debug'].build_type
コード例 #8
0
 def test_resolve_mixed_case(self):
   with self.config_file(build_type='ReleASE') as config:
     keystores = KeystoreResolver.resolve(config)
     self.assertEquals(keystores['test-release'].build_type, 'release')
コード例 #9
0
 def test_resolve(self):
   with self.config_file() as config:
     keystores = KeystoreResolver.resolve(config)
     self.assertEquals(keystores['default-debug'].build_type, 'debug')