def __init__(self, context): Task.__init__(self, context) self.ivy_utils = IvyUtils(context, context.config.get('ivy', 'cache_dir')) self.confs = context.config.getlist('ivy', 'confs') self.target_roots = context.target_roots self.transitive = context.options.provides_transitive self.workdir = context.config.get('provides', 'workdir') self.outdir = context.options.provides_outdir or self.workdir self.also_write_to_stdout = context.options.provides_also_write_to_stdout or False # Create a fake target, in case we were run directly on a JarLibrary containing nothing but JarDependencies. # TODO(benjy): Get rid of this special-casing of jar dependencies. context.add_new_target(self.workdir, JvmBinary, name='provides', dependencies=self.target_roots, configurations=self.confs) context.products.require('jars')
def __init__(self, context, confs=None): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._cachedir = context.options.ivy_resolve_cache or context.config.get( 'ivy', 'cache_dir') self._confs = confs or context.config.getlist('ivy-resolve', 'confs') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_bootstrap_key = 'ivy' ivy_bootstrap_tools = context.config.getlist('ivy-resolve', 'bootstrap-tools', ':xalan') self._bootstrap_utils.register_jvm_build_tools(self._ivy_bootstrap_key, ivy_bootstrap_tools) self._ivy_utils = IvyUtils(config=context.config, options=context.options, log=context.log) context.products.require_data('exclusives_groups') # Typically this should be a local cache only, since classpaths aren't portable. artifact_cache_spec = context.config.getlist('ivy-resolve', 'artifact_caches', default=[]) self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._ivy_settings = context.config.get('ivy', 'ivy_settings') self._cachedir = context.config.get('ivy', 'cache_dir') self._confs = context.config.getlist('ivy-resolve', 'confs') self._transitive = context.config.getbool('ivy-resolve', 'transitive') self._args = context.config.getlist('ivy-resolve', 'args') self._profile = context.config.get('ivy-resolve', 'profile') self._template_path = os.path.join('ivy_resolve', 'ivy.mk') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_file = os.path.join(self._work_dir, 'classpath') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_utils = IvyUtils(context, self._cachedir) def parse_override(override): match = re.match(r'^([^#]+)#([^=]+)=([^\s]+)$', override) if not match: raise TaskError('Invalid dependency override: %s' % override) org, name, rev_or_url = match.groups() def fmt_message(message, template): return message % dict( overridden='%s#%s;%s' % (template.org, template.module, template.version), rev=rev_or_url, url=rev_or_url) def replace_rev(template): context.log.info( fmt_message('Overrode %(overridden)s with rev %(rev)s', template)) return template.extend(version=rev_or_url, url=None, force=True) def replace_url(template): context.log.info( fmt_message( 'Overrode %(overridden)s with snapshot at %(url)s', template)) return template.extend(version='SNAPSHOT', url=rev_or_url, force=True) replace = replace_url if re.match(r'^\w+://.+', rev_or_url) else replace_rev return (org, name), replace self._overrides = {} if context.options.ivy_resolve_overrides: self._overrides.update( parse_override(o) for o in context.options.ivy_resolve_overrides)
def __init__(self, context, confs=None): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._ivy_settings = context.config.get('ivy', 'ivy_settings') self._cachedir = context.options.ivy_resolve_cache or context.config.get( 'ivy', 'cache_dir') self._confs = confs or context.config.getlist('ivy-resolve', 'confs') self._transitive = context.config.getbool('ivy-resolve', 'transitive') self._opts = context.config.getlist('ivy-resolve', 'args') self._ivy_args = context.options.ivy_args self._mutable_pattern = (context.options.ivy_mutable_pattern or context.config.get('ivy-resolve', 'mutable_pattern', default=None)) if self._mutable_pattern: try: self._mutable_pattern = re.compile(self._mutable_pattern) except re.error as e: raise TaskError('Invalid mutable pattern specified: %s %s' % (self._mutable_pattern, e)) self._profile = context.config.get('ivy-resolve', 'profile') self._template_path = os.path.join('templates', 'ivy_resolve', 'ivy.mustache') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_utils = IvyUtils(context, self._cachedir) context.products.require_data('exclusives_groups') # Typically this should be a local cache only, since classpaths aren't portable. artifact_cache_spec = context.config.getlist('ivy-resolve', 'artifact_caches2', default=[]) self.setup_artifact_cache(artifact_cache_spec) def parse_override(override): match = re.match(r'^([^#]+)#([^=]+)=([^\s]+)$', override) if not match: raise TaskError('Invalid dependency override: %s' % override) org, name, rev_or_url = match.groups() def fmt_message(message, template): return message % dict( overridden='%s#%s;%s' % (template.org, template.module, template.version), rev=rev_or_url, url=rev_or_url) def replace_rev(template): context.log.info( fmt_message('Overrode %(overridden)s with rev %(rev)s', template)) return template.extend(version=rev_or_url, url=None, force=True) def replace_url(template): context.log.info( fmt_message( 'Overrode %(overridden)s with snapshot at %(url)s', template)) return template.extend(version='SNAPSHOT', url=rev_or_url, force=True) replace = replace_url if re.match(r'^\w+://.+', rev_or_url) else replace_rev return (org, name), replace self._overrides = {} if context.options.ivy_resolve_overrides: self._overrides.update( parse_override(o) for o in context.options.ivy_resolve_overrides)
def ivy_resolve(self, targets, java_runner=None, ivy_args=None, symlink_ivyxml=False, silent=False, workunit_name=None, workunit_labels=None): java_runner = java_runner or runjava_indivisible ivy_args = ivy_args or [] targets = set(targets) if not targets: return [] work_dir = self.context.config.get('ivy-resolve', 'workdir') confs = self.context.config.getlist('ivy-resolve', 'confs') with self.invalidated(targets, only_buildfiles=True, invalidate_dependents=True, silent=silent) as invalidation_check: global_vts = VersionedTargetSet.from_versioned_targets( invalidation_check.all_vts) target_workdir = os.path.join(work_dir, global_vts.cache_key.hash) target_classpath_file = os.path.join(target_workdir, 'classpath') target_classpath_file_tmp = target_classpath_file + '.tmp' # Note that it's possible for all targets to be valid but for no classpath file to exist at # target_classpath_file, e.g., if we previously built a superset of targets. if invalidation_check.invalid_vts or not os.path.exists( target_classpath_file): ivy_utils = IvyUtils(config=self.context.config, options=self.context.options, log=self.context.log) args = (['-cachepath', target_classpath_file_tmp] + ['-confs'] + confs + ivy_args) def exec_ivy(): ivy_utils.exec_ivy( target_workdir=target_workdir, targets=targets, args=args, runjava=java_runner, workunit_name='ivy', workunit_factory=self.context.new_workunit, symlink_ivyxml=symlink_ivyxml, ) if workunit_name: with self.context.new_workunit(name=workunit_name, labels=workunit_labels or []): exec_ivy() else: exec_ivy() if not os.path.exists(target_classpath_file_tmp): raise TaskError( 'Ivy failed to create classpath file at %s' % target_classpath_file_tmp) shutil.move(target_classpath_file_tmp, target_classpath_file) if self.get_artifact_cache( ) and self.context.options.write_to_artifact_cache: self.update_artifact_cache([(global_vts, [target_classpath_file])]) with IvyUtils.cachepath(target_classpath_file) as classpath: stripped_classpath = [path.strip() for path in classpath] return [ path for path in stripped_classpath if IvyUtils.is_mappable_artifact(path) ]