示例#1
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)
示例#2
0
    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=[
                                                           WorkUnit.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 execute(self):
    targets = self.context.targets(self.is_signtarget)
    # Check for Android keystore config file (where the default keystore definition is kept).
    config_file = os.path.join(self.context.config.getdefault('pants_bootstrapdir'),
                               self._DEFAULT_KEYSTORE_CONFIG)
    if not os.path.isfile(config_file):
      try:
        AndroidConfigUtil.setup_keystore_config(config_file)
      except OSError as e:
        raise TaskError('Failed to setup keystore config: {0}'.format(e))

    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=[WorkUnit.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.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)
示例#4
0
文件: sign_apk.py 项目: areitz/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)
示例#5
0
 def test_bad_config_location(self):
     with self.assertRaises(KeystoreResolver.Error):
         KeystoreResolver.resolve(os.path.join('no', 'config_file', 'here'))
示例#6
0
 def test_a_missing_field(self):
     with self.assertRaises(KeystoreResolver.Error):
         with self.config_file(keystore_alias="") as config:
             KeystoreResolver.resolve(config)
 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')
示例#8
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'))
示例#9
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')
示例#10
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
示例#11
0
 def test_resolve(self):
   with self.config_file() as config:
     keystores = KeystoreResolver.resolve(config)
     self.assertEquals(keystores['default-debug'].build_type, 'debug')
示例#12
0
 def test_resolve(self):
     with self.config_file() as config:
         keystores = KeystoreResolver.resolve(config)
         self.assertEquals(keystores['default-debug'].build_type, 'debug')
示例#13
0
 def test_a_missing_field(self):
   with self.assertRaises(KeystoreResolver.Error):
     with self.config_file(keystore_alias="") as config:
       KeystoreResolver.resolve(config)
示例#14
0
 def test_bad_config_location(self):
   with self.assertRaises(KeystoreResolver.Error):
     KeystoreResolver.resolve(os.path.join('no', 'config_file', 'here'))
示例#15
0
 def test_expanding_path(self):
   with self.config_file(keystore_location='~/dir') as config:
     keystores = KeystoreResolver.resolve(config)
     self.assertEqual(keystores['default-debug'].keystore_location, os.path.expandvars('~/dir'))
示例#16
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)
示例#17
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