def __init__(self, context, workdir, confs=None): super(IvyResolve, self).__init__(context, workdir) self._ivy_bootstrapper = Bootstrapper.instance() self._cachedir = self._ivy_bootstrapper.ivy_cache_dir self._confs = confs or context.config.getlist( 'ivy-resolve', 'confs', default=['default']) self._classpath_dir = os.path.join(self.workdir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self.workdir, '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.register_jvm_tool(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. self.setup_artifact_cache_from_config(config_section='ivy-resolve')
def __init__(self, *args, **kwargs): super(IvyResolve, self).__init__(*args, **kwargs) self._ivy_bootstrapper = Bootstrapper.instance() self._cachedir = self._ivy_bootstrapper.ivy_cache_dir self._confs = self.context.config.getlist(self._CONFIG_SECTION, 'confs', default=['default']) self._classpath_dir = os.path.join(self.workdir, 'mapped') self._outdir = self.get_options().outdir or os.path.join( self.workdir, 'reports') self._open = self.get_options().open self._report = self._open or self.get_options().report self._ivy_bootstrap_key = 'ivy' self.register_jvm_tool_from_config(self._ivy_bootstrap_key, self.context.config, ini_section=self._CONFIG_SECTION, ini_key='bootstrap-tools', default=['//:xalan']) self._ivy_utils = IvyUtils(config=self.context.config, log=self.context.log) # Typically this should be a local cache only, since classpaths aren't portable. self.setup_artifact_cache_from_config( config_section=self._CONFIG_SECTION)
def __init__(self, *args, **kwargs): super(Provides, self).__init__(*args, **kwargs) self.ivy_utils = IvyUtils(config=self.context.config, options=self.context.options, log=self.context.log) self.confs = self.context.config.getlist('ivy', 'confs', default=['default']) self.target_roots = self.context.target_roots self.transitive = self.context.options.provides_transitive self.also_write_to_stdout = self.context.options.provides_also_write_to_stdout or False
def setUp(self): super(IvyUtilsGenerateIvyTest, self).setUp() self.add_to_build_file( 'src/java/targets', dedent(''' jar_library( name='simple', jars=[ jar('org1', 'name1', 'rev1'), jar('org2', 'name2', 'rev2', force=True), ] ) ''')) self.simple = self.target('src/java/targets:simple') self.ivy_utils = IvyUtils(create_config(), self.create_options(), logging.Logger('test'))
def setUp(self): super(IvyUtilsGenerateIvyTest, self).setUp() self.add_to_build_file( 'src/java/targets', dedent(""" jar_library( name='simple', jars=[ jar('org1', 'name1', 'rev1'), jar('org2', 'name2', 'rev2', force=True), ] ) """)) self.simple = self.target('src/java/targets:simple') context = self.context() self.ivy_utils = IvyUtils(context.config, logging.Logger('test'))
def ivy_resolve(self, targets, executor=None, symlink_ivyxml=False, silent=False, workunit_name=None, workunit_labels=None): # NOTE: Always pass all the targets to exec_ivy, as they're used to calculate the name of # the generated module, which in turn determines the location of the XML report file # ivy generates. We recompute this name from targets later in order to find that file. # TODO: This is fragile. Refactor so that we're not computing the name twice. if executor and not isinstance(executor, Executor): raise ValueError( 'The executor must be an Executor instance, given %s of type %s' % (executor, type(executor))) ivy = Bootstrapper.default_ivy( java_executor=executor, bootstrap_workunit_factory=self.context.new_workunit) if not targets: return [] ivy_workdir = os.path.join( self.context.config.getdefault('pants_workdir'), 'ivy') ivy_utils = IvyUtils(config=self.context.config, options=self.context.options, log=self.context.log) fingerprint_strategy = IvyResolveFingerprintStrategy() with self.invalidated(targets, invalidate_dependents=True, silent=silent, fingerprint_strategy=fingerprint_strategy ) as invalidation_check: global_vts = VersionedTargetSet.from_versioned_targets( invalidation_check.all_vts) target_workdir = os.path.join(ivy_workdir, global_vts.cache_key.hash) target_classpath_file = os.path.join(target_workdir, 'classpath') raw_target_classpath_file = target_classpath_file + '.raw' raw_target_classpath_file_tmp = raw_target_classpath_file + '.tmp' # A common dir for symlinks into the ivy2 cache. This ensures that paths to jars # in artifact-cached analysis files are consistent across systems. # Note that we have one global, well-known symlink dir, again so that paths are # consistent across builds. symlink_dir = os.path.join(ivy_workdir, 'jars') # 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( raw_target_classpath_file): args = ['-cachepath', raw_target_classpath_file_tmp] def exec_ivy(): ivy_utils.exec_ivy( target_workdir=target_workdir, targets=targets, args=args, ivy=ivy, 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(raw_target_classpath_file_tmp): raise TaskError( 'Ivy failed to create classpath file at %s' % raw_target_classpath_file_tmp) shutil.move(raw_target_classpath_file_tmp, raw_target_classpath_file) logger.debug('Copied ivy classfile file to {dest}'.format( dest=raw_target_classpath_file)) if self.artifact_cache_writes_enabled(): self.update_artifact_cache([(global_vts, [raw_target_classpath_file])]) # Make our actual classpath be symlinks, so that the paths are uniform across systems. # Note that we must do this even if we read the raw_target_classpath_file from the artifact # cache. If we cache the target_classpath_file we won't know how to create the symlinks. symlink_map = IvyUtils.symlink_cachepath(self.context.ivy_home, raw_target_classpath_file, symlink_dir, target_classpath_file) with IvyTaskMixin.symlink_map_lock: all_symlinks_map = self.context.products.get_data( 'symlink_map') or defaultdict(list) for path, symlink in symlink_map.items(): all_symlinks_map[os.path.realpath(path)].append(symlink) self.context.products.safe_create_data('symlink_map', lambda: all_symlinks_map) with IvyUtils.cachepath(target_classpath_file) as classpath: stripped_classpath = [path.strip() for path in classpath] return [ path for path in stripped_classpath if ivy_utils.is_classpath_artifact(path) ]