本文整理汇总了Python中pants.java.distribution.distribution.Distribution.cached方法的典型用法代码示例。如果您正苦于以下问题:Python Distribution.cached方法的具体用法?Python Distribution.cached怎么用?Python Distribution.cached使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.java.distribution.distribution.Distribution
的用法示例。
在下文中一共展示了Distribution.cached方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requirements
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def requirements(cls, tools):
sdk_home = os.environ.get('ANDROID_HOME')
android_sdk = os.path.abspath(sdk_home) if sdk_home else None
if android_sdk:
for tool in tools:
if not os.path.isfile(os.path.join(android_sdk, tool)):
return False
else:
return False
try:
Distribution.cached(minimum_version=cls.JAVA_MIN, maximum_version=cls.JAVA_MAX)
except:
return False
return True
示例2: _run_tests
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def _run_tests(self, tests_to_targets, main, extra_jvm_options=None, classpath_prepend=(),
classpath_append=()):
extra_jvm_options = extra_jvm_options or []
tests_by_properties = self._tests_by_properties(tests_to_targets,
self._infer_workdir,
lambda target: target.test_platform)
result = 0
for (workdir, platform), tests in tests_by_properties.items():
for batch in self._partition(tests):
# Batches of test classes will likely exist within the same targets: dedupe them.
relevant_targets = set(map(tests_to_targets.get, batch))
classpath = self._task_exports.classpath(relevant_targets,
cp=self._task_exports.tool_classpath('junit'))
complete_classpath = OrderedSet()
complete_classpath.update(classpath_prepend)
complete_classpath.update(classpath)
complete_classpath.update(classpath_append)
if self._strict_jvm_version:
max_version = Revision(*(platform.target_level.components + [9999]))
distribution = Distribution.cached(minimum_version=platform.target_level,
maximum_version=max_version)
else:
distribution = Distribution.cached(minimum_version=platform.target_level)
with binary_util.safe_args(batch, self._task_exports.task_options) as batch_tests:
self._context.log.debug('CWD = {}'.format(workdir))
self._context.log.debug('platform = {}'.format(platform))
result += abs(execute_java(
classpath=complete_classpath,
main=main,
jvm_options=self._task_exports.jvm_options + extra_jvm_options,
args=self._args + batch_tests + [u'-xmlreport'],
workunit_factory=self._context.new_workunit,
workunit_name='run',
workunit_labels=[WorkUnitLabel.TEST],
cwd=workdir,
distribution=distribution,
))
if result != 0 and self._fail_fast:
break
if result != 0:
failed_targets = self._get_failed_targets(tests_to_targets)
raise TestFailedTaskError(
'java {0} ... exited non-zero ({1}); {2} failed targets.'
.format(main, result, len(failed_targets)),
failed_targets=failed_targets
)
示例3: distribution
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def distribution(self):
if self._dist is None:
# Currently no Java 8 for Android. I considered max=1.7.0_50. See comment in _render_args().
self._dist = Distribution.cached(minimum_version='1.6.0_00',
maximum_version='1.7.0_99',
jdk=True)
return self._dist
示例4: locate_tools_jar
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def locate_tools_jar():
try:
return Distribution.cached(jdk=True).find_libs(['tools.jar'])
except Distribution.Error:
self.context.log.info('Failed to locate tools.jar. '
'Install a JDK to increase performance of Zinc.')
return []
示例5: execute_junit_runner
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def execute_junit_runner(self, content):
# Create the temporary base test directory
test_rel_path = 'tests/java/org/pantsbuild/foo'
test_abs_path = os.path.join(self.build_root, test_rel_path)
self.create_dir(test_rel_path)
# Generate the temporary java test source code.
test_java_file_rel_path = os.path.join(test_rel_path, 'FooTest.java')
test_java_file_abs_path = os.path.join(self.build_root, test_java_file_rel_path)
self.create_file(test_java_file_rel_path, content)
# Invoke ivy to resolve classpath for junit.
distribution = Distribution.cached(jdk=True)
executor = SubprocessExecutor(distribution=distribution)
classpath_file_abs_path = os.path.join(test_abs_path, 'junit.classpath')
ivy = Bootstrapper.default_ivy()
ivy.execute(args=['-cachepath', classpath_file_abs_path,
'-dependency', 'junit', 'junit-dep', '4.10'], executor=executor)
with open(classpath_file_abs_path) as fp:
classpath = fp.read()
# Now directly invoking javac to compile the test java code into java class
# so later we can inject the class into products mapping for JUnitRun to execute
# the test on.
javac = distribution.binary('javac')
subprocess.check_call(
[javac, '-d', test_abs_path, '-cp', classpath, test_java_file_abs_path])
# Create a java_tests target and a synthetic resource target.
java_tests = self.create_library(test_rel_path, 'java_tests', 'foo_test', ['FooTest.java'])
resources = self.make_target('some_resources', Resources)
# Set the context with the two targets, one java_tests target and
# one synthetic resources target.
# The synthetic resources target is to make sure we won't regress
# in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
# in that bug, the resources target must be the first one in the list.
context = self.context(target_roots=[resources, java_tests])
# Before we run the task, we need to inject the "classes_by_target" with
# the compiled test java classes that JUnitRun will know which test
# classes to execute. In a normal run, this "classes_by_target" will be
# populated by java compiling step.
class_products = context.products.get_data(
'classes_by_target', lambda: defaultdict(MultipleRootedProducts))
java_tests_products = MultipleRootedProducts()
java_tests_products.add_rel_paths(test_abs_path, ['FooTest.class'])
class_products[java_tests] = java_tests_products
# Also we need to add the FooTest.class's classpath to the compile_classpath
# products data mapping so JUnitRun will be able to add that into the final
# classpath under which the junit will be executed.
self.populate_compile_classpath(
context=context,
classpath=[test_abs_path])
# Finally execute the task.
self.execute(context)
示例6: java_sysprops
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def java_sysprops(self):
"""The system properties of the JVM we use."""
# TODO: In the future we can use these to hermeticize the Java enivronment rather than relying
# on whatever's on the shell's PATH. E.g., you either specify a path to the Java home via a
# cmd-line flag or .pantsrc, or we infer one from java.home but verify that the java.version
# is a supported version.
if self._java_sysprops is None:
# TODO(John Sirois): Plumb a sane default distribution through 1 point of control
self._java_sysprops = Distribution.cached().system_properties
return self._java_sysprops
示例7: __init__
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def __init__(self, *args, **kwargs):
"""
:param context: inherited parameter from Task
:param workdir: inherited parameter from Task
"""
super(JaxbGen, self).__init__(*args, **kwargs)
self.gen_langs = set()
lang = 'java'
if self.context.products.isrequired(lang):
self.gen_langs.add(lang)
self.jar_location = os.path.join(Distribution.cached().home, '..', 'lib', 'tools.jar')
示例8: __init__
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def __init__(self, distribution=None):
"""Constructs an Executor that can be used to launch java programs.
:param distribution: an optional validated java distribution to use when launching java
programs
"""
if distribution:
if not isinstance(distribution, Distribution):
raise ValueError('A valid distribution is required, given: %s' % distribution)
distribution.validate()
else:
distribution = Distribution.cached()
self._distribution = distribution
示例9: __init__
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def __init__(self, context, workdir, minimum_version=None,
maximum_version=None, jdk=False, nailgun_name=None):
super(NailgunTaskBase, self).__init__(context, workdir)
self._executor_workdir = os.path.join(context.config.getdefault('pants_workdir'), 'ng',
nailgun_name or self.__class__.__name__)
self._nailgun_bootstrap_key = 'nailgun'
self.register_jvm_tool(self._nailgun_bootstrap_key, [':nailgun-server'])
with self.context.new_workunit(name='jvm-locate'):
try:
self._dist = Distribution.cached(minimum_version=minimum_version,
maximum_version=maximum_version, jdk=jdk)
except Distribution.Error as e:
raise TaskError(e)
示例10: create_javadoc_command
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def create_javadoc_command(self, classpath, gendir, *targets):
sources = []
for target in targets:
sources.extend(target.sources_relative_to_buildroot())
if not sources:
return None
# Without a JDK/tools.jar we have no javadoc tool and cannot proceed, so check/acquire early.
jdk = Distribution.cached(jdk=True)
tool_classpath = jdk.find_libs(["tools.jar"])
args = ["-quiet", "-encoding", "UTF-8", "-notimestamp", "-use", "-classpath", ":".join(classpath), "-d", gendir]
# Always provide external linking for java API
offlinelinks = {"http://download.oracle.com/javase/6/docs/api/"}
def link(target):
for jar in target.jar_dependencies:
if jar.apidocs:
offlinelinks.add(jar.apidocs)
for target in targets:
target.walk(link, lambda t: t.is_jvm)
for link in offlinelinks:
args.extend(["-linkoffline", link, link])
args.extend(self.args)
args.extend(sources)
java_executor = SubprocessExecutor(jdk)
runner = java_executor.runner(
jvm_options=self.jvm_options, classpath=tool_classpath, main="com.sun.tools.javadoc.Main", args=args
)
return runner.command
示例11: __init__
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def __init__(self, *args, **kwargs):
super(JarsignerTask, self).__init__(*args, **kwargs)
self._distdir = self.context.config.getdefault('pants_distdir')
self._build_type = self.get_options().build_type
# No Java 8 for Android. I am considering max=1.7.0_50. See comment in render_args().
self._dist = Distribution.cached(maximum_version="1.7.0_99")
示例12: test_cached_bad_input
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def test_cached_bad_input(self):
with self.assertRaises(ValueError):
with self.distribution(executables=self.exe('java', '1.7.0_33')) as jdk:
with self.env(PATH=jdk):
Distribution.cached(minimum_version=1.7, maximum_version=1.8)
示例13: test_cached_conflicting
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def test_cached_conflicting(self):
with self.distribution(executables=self.exe('java', '1.7.0_33')) as jdk:
with self.env(PATH=jdk):
with self.assertRaises(Distribution.Error):
Distribution.cached(minimum_version='1.7.0_00', maximum_version='1.6.0_50')
示例14: test_cached_low_fault
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def test_cached_low_fault(self):
with self.distribution(executables=self.exe('java', '1.7.0_33')) as jdk:
with self.env(PATH=jdk):
with self.assertRaises(Distribution.Error):
Distribution.cached(minimum_version='1.7.0_35', maximum_version='1.7.0_55')
示例15: test_cached_too_high
# 需要导入模块: from pants.java.distribution.distribution import Distribution [as 别名]
# 或者: from pants.java.distribution.distribution.Distribution import cached [as 别名]
def test_cached_too_high(self):
with self.distribution(executables=self.exe('java', '1.7.0_83')) as jdk:
with self.env(PATH=jdk):
with self.assertRaises(Distribution.Error):
Distribution.cached(maximum_version='1.7.0_55')