def __init__(self, *args, **kwargs): super(JarPublish, self).__init__(*args, **kwargs) ScmPublish.__init__(self, get_scm(), self.get_options().restrict_push_branches) self.cachedir = os.path.join(self.workdir, 'cache') self._jvm_options = self.get_options().jvm_options if self.get_options().local: local_repo = dict( resolver='publish_local', path=os.path.abspath(os.path.expanduser(self.get_options().local)), confs=['default'], auth=None ) self.repos = defaultdict(lambda: local_repo) self.commit = False self.local_snapshot = self.get_options().local_snapshot else: self.repos = self.get_options().repos if not self.repos: raise TaskError("This repo is not configured to publish externally! Please configure per\n" "http://pantsbuild.github.io/publish.html#authenticating-to-the-artifact-repository,\n" "or re-run with the '--publish-local' flag.") for repo, data in self.repos.items(): auth = data.get('auth') if auth: credentials = next(iter(self.context.resolve(auth))) user = credentials.username(data['resolver']) password = credentials.password(data['resolver']) self.context.log.debug('Found auth for repo=%s user=%s' % (repo, user)) self.repos[repo]['username'] = user self.repos[repo]['password'] = password self.commit = self.get_options().commit self.local_snapshot = False self.named_snapshot = self.get_options().named_snapshot if self.named_snapshot: self.named_snapshot = Namedver.parse(self.named_snapshot) self.dryrun = self.get_options().dryrun self.transitive = self.get_options().transitive self.force = self.get_options().force def parse_jarcoordinate(coordinate): components = coordinate.split('#', 1) if len(components) == 2: org, name = components return org, name else: try: # TODO(Eric Ayers) This code is suspect. Target.get() is a very old method and almost certainly broken. # Refactor to use methods from BuildGraph or BuildFileAddressMapper address = Address.parse(get_buildroot(), coordinate) target = Target.get(address) if not target: siblings = Target.get_all_addresses(address.build_file) prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these' raise TaskError('%s => %s?:\n %s' % (address, prompt, '\n '.join(str(a) for a in siblings))) if not target.is_exported: raise TaskError('%s is not an exported target' % coordinate) return target.provides.org, target.provides.name except (BuildFile.BuildFileError, BuildFileParser.BuildFileParserError, AddressLookupError) as e: raise TaskError('{message}\n Problem with BUILD file at {coordinate}' .format(message=e, coordinate=coordinate)) self.overrides = {} if self.get_options().override: if self.named_snapshot: raise TaskError('Options --named-snapshot and --override are mutually exclusive!') def parse_override(override): try: coordinate, rev = override.split('=', 1) try: # overrides imply semantic versioning rev = Semver.parse(rev) except ValueError as e: raise TaskError('Invalid version %s: %s' % (rev, e)) return parse_jarcoordinate(coordinate), rev except ValueError: raise TaskError('Invalid override: %s' % override) self.overrides.update(parse_override(o) for o in self.get_options().override) self.restart_at = None if self.get_options().restart_at: self.restart_at = parse_jarcoordinate(self.get_options().restart_at)
def __init__(self, context, workdir, scm=None): super(JarPublish, self).__init__(context, workdir) ScmPublish.__init__(self, scm or get_scm(), self.context.config.getlist( JarPublish._CONFIG_SECTION, 'restrict_push_branches')) self.cachedir = os.path.join(self.workdir, 'cache') self._jvmargs = context.config.getlist(JarPublish._CONFIG_SECTION, 'ivy_jvmargs', default=[]) if context.options.jar_publish_local: local_repo = dict( resolver='publish_local', path=os.path.abspath(os.path.expanduser(context.options.jar_publish_local)), confs=['default'], auth=None ) self.repos = defaultdict(lambda: local_repo) self.commit = False self.snapshot = context.options.jar_publish_local_snapshot else: self.repos = context.config.getdict(JarPublish._CONFIG_SECTION, 'repos') if not self.repos: raise TaskError("This repo is not yet set for publishing to the world!" "Please re-run with --publish-local") for repo, data in self.repos.items(): auth = data.get('auth') if auth: credentials = context.resolve(auth).next() user = credentials.username(data['resolver']) password = credentials.password(data['resolver']) self.context.log.debug('Found auth for repo=%s user=%s' % (repo, user)) self.repos[repo]['username'] = user self.repos[repo]['password'] = password self.commit = context.options.jar_publish_commit self.snapshot = False self.ivycp = context.config.getlist('ivy', 'classpath') self.ivysettings = context.config.get('jar-publish', 'ivy_settings') self.dryrun = context.options.jar_publish_dryrun self.transitive = context.options.jar_publish_transitive self.force = context.options.jar_publish_force def parse_jarcoordinate(coordinate): components = coordinate.split('#', 1) if len(components) == 2: org, name = components return org, name else: try: address = Address.parse(get_buildroot(), coordinate) # TODO: This is broken. try: target = Target.get(address) if not target: siblings = Target.get_all_addresses(address.buildfile) prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these' raise TaskError('%s => %s?:\n %s' % (address, prompt, '\n '.join(str(a) for a in siblings))) if not target.is_exported: raise TaskError('%s is not an exported target' % coordinate) return target.provides.org, target.provides.name except (ImportError, SyntaxError, TypeError): raise TaskError('Failed to parse %s' % address.buildfile.relpath) except IOError: raise TaskError('No BUILD file could be found at %s' % coordinate) self.overrides = {} if context.options.jar_publish_override: def parse_override(override): try: coordinate, rev = override.split('=', 1) try: rev = Semver.parse(rev) except ValueError as e: raise TaskError('Invalid version %s: %s' % (rev, e)) return parse_jarcoordinate(coordinate), rev except ValueError: raise TaskError('Invalid override: %s' % override) self.overrides.update(parse_override(o) for o in context.options.jar_publish_override) self.restart_at = None if context.options.jar_publish_restart_at: self.restart_at = parse_jarcoordinate(context.options.jar_publish_restart_at) context.products.require('jars') context.products.require('source_jars')
def __init__(self, *args, **kwargs): super(JarPublish, self).__init__(*args, **kwargs) ScmPublish.__init__(self, get_scm(), self.context.config.getlist(self._CONFIG_SECTION, 'restrict_push_branches')) self.cachedir = os.path.join(self.workdir, 'cache') self._jvmargs = self.context.config.getlist(self._CONFIG_SECTION, 'ivy_jvmargs', default=[]) if self.context.options.jar_publish_local: local_repo = dict( resolver='publish_local', path=os.path.abspath(os.path.expanduser(self.context.options.jar_publish_local)), confs=['default'], auth=None ) self.repos = defaultdict(lambda: local_repo) self.commit = False self.snapshot = self.context.options.jar_publish_local_snapshot else: self.repos = self.context.config.getdict(self._CONFIG_SECTION, 'repos') if not self.repos: raise TaskError("This repo is not configured to publish externally! Please configure per\n" "http://pantsbuild.github.io/publish.html#authenticating-to-the-artifact-repository,\n" "or re-run with the '--publish-local' flag.") for repo, data in self.repos.items(): auth = data.get('auth') if auth: credentials = next(iter(context.resolve(auth))) user = credentials.username(data['resolver']) password = credentials.password(data['resolver']) self.context.log.debug('Found auth for repo=%s user=%s' % (repo, user)) self.repos[repo]['username'] = user self.repos[repo]['password'] = password self.commit = self.context.options.jar_publish_commit self.snapshot = False self.ivycp = self.context.config.getlist('ivy', 'classpath') self.dryrun = self.context.options.jar_publish_dryrun self.transitive = self.context.options.jar_publish_transitive self.force = self.context.options.jar_publish_force def parse_jarcoordinate(coordinate): components = coordinate.split('#', 1) if len(components) == 2: org, name = components return org, name else: try: address = Address.parse(get_buildroot(), coordinate) # TODO: This is broken. try: target = Target.get(address) if not target: siblings = Target.get_all_addresses(address.build_file) prompt = 'did you mean' if len(siblings) == 1 else 'maybe you meant one of these' raise TaskError('%s => %s?:\n %s' % (address, prompt, '\n '.join(str(a) for a in siblings))) if not target.is_exported: raise TaskError('%s is not an exported target' % coordinate) return target.provides.org, target.provides.name except (ImportError, SyntaxError, TypeError): raise TaskError('Failed to parse %s' % address.build_file.relpath) except (IOError, AddressLookupError) as e: raise TaskError('{message}\n No BUILD file could be found at {coordinate}' .format(message=e, coordinate=coordinate)) self.overrides = {} if self.context.options.jar_publish_override: def parse_override(override): try: coordinate, rev = override.split('=', 1) try: rev = Semver.parse(rev) except ValueError as e: raise TaskError('Invalid version %s: %s' % (rev, e)) return parse_jarcoordinate(coordinate), rev except ValueError: raise TaskError('Invalid override: %s' % override) self.overrides.update(parse_override(o) for o in self.context.options.jar_publish_override) self.restart_at = None if self.context.options.jar_publish_restart_at: self.restart_at = parse_jarcoordinate(self.context.options.jar_publish_restart_at)
def __init__(self, *args, **kwargs): super(JarPublish, self).__init__(*args, **kwargs) ScmPublish.__init__( self, get_scm(), self.context.config.getlist(self._CONFIG_SECTION, 'restrict_push_branches')) self.cachedir = os.path.join(self.workdir, 'cache') self._jvmargs = self.context.config.getlist(self._CONFIG_SECTION, 'ivy_jvmargs', default=[]) if self.context.options.jar_publish_local: local_repo = dict(resolver='publish_local', path=os.path.abspath( os.path.expanduser( self.context.options.jar_publish_local)), confs=['default'], auth=None) self.repos = defaultdict(lambda: local_repo) self.commit = False self.local_snapshot = self.context.options.jar_publish_local_snapshot else: self.repos = self.context.config.getdict(self._CONFIG_SECTION, 'repos') if not self.repos: raise TaskError( "This repo is not configured to publish externally! Please configure per\n" "http://pantsbuild.github.io/publish.html#authenticating-to-the-artifact-repository,\n" "or re-run with the '--publish-local' flag.") for repo, data in self.repos.items(): auth = data.get('auth') if auth: credentials = next(iter(self.context.resolve(auth))) user = credentials.username(data['resolver']) password = credentials.password(data['resolver']) self.context.log.debug('Found auth for repo=%s user=%s' % (repo, user)) self.repos[repo]['username'] = user self.repos[repo]['password'] = password self.commit = self.context.options.jar_publish_commit self.local_snapshot = False self.named_snapshot = self.context.options.jar_publish_named_snapshot if self.named_snapshot: self.named_snapshot = Namedver.parse(self.named_snapshot) self.ivycp = self.context.config.getlist('ivy', 'classpath') self.dryrun = self.context.options.jar_publish_dryrun self.transitive = self.context.options.jar_publish_transitive self.force = self.context.options.jar_publish_force def parse_jarcoordinate(coordinate): components = coordinate.split('#', 1) if len(components) == 2: org, name = components return org, name else: try: # TODO(Eric Ayers) This code is suspect. Target.get() is a very old method and almost certainly broken. # Refactor to use methods from BuildGraph or BuildFileAddressMapper address = Address.parse(get_buildroot(), coordinate) target = Target.get(address) if not target: siblings = Target.get_all_addresses(address.build_file) prompt = 'did you mean' if len( siblings) == 1 else 'maybe you meant one of these' raise TaskError('%s => %s?:\n %s' % (address, prompt, '\n '.join( str(a) for a in siblings))) if not target.is_exported: raise TaskError('%s is not an exported target' % coordinate) return target.provides.org, target.provides.name except (BuildFile.BuildFileError, BuildFileParser.BuildFileParserError, AddressLookupError) as e: raise TaskError( '{message}\n Problem with BUILD file at {coordinate}' .format(message=e, coordinate=coordinate)) self.overrides = {} if self.context.options.jar_publish_override: if self.named_snapshot: raise TaskError( 'Flags {0} and {1} are mutually exclusive!'.format( named_snapshot_flag, override_flag)) def parse_override(override): try: coordinate, rev = override.split('=', 1) try: # overrides imply semantic versioning rev = Semver.parse(rev) except ValueError as e: raise TaskError('Invalid version %s: %s' % (rev, e)) return parse_jarcoordinate(coordinate), rev except ValueError: raise TaskError('Invalid override: %s' % override) self.overrides.update( parse_override(o) for o in self.context.options.jar_publish_override) self.restart_at = None if self.context.options.jar_publish_restart_at: self.restart_at = parse_jarcoordinate( self.context.options.jar_publish_restart_at)