def missing_jvm(version): with subsystem_instance(DistributionLocator): try: DistributionLocator.locate(minimum_version=version, maximum_version="{}.9999".format(version)) return False except DistributionLocator.Error: return True
def missing_jvm(version): with subsystem_instance(DistributionLocator): try: DistributionLocator.locate(minimum_version=version, maximum_version='{}.9999'.format(version)) return False except DistributionLocator.Error: return True
def get_two_distributions(): with subsystem_instance(DistributionLocator): try: java7 = DistributionLocator.locate(minimum_version='1.7', maximum_version='1.7.9999') java8 = DistributionLocator.locate(minimum_version='1.8', maximum_version='1.8.9999') return java7, java8 except DistributionLocator.Error: return None
def test_default_to_path(self): with self.java_home_exe() as (jdk1_home, jdk2_home): with distribution(executables=EXE('bin/java', version='3')) as path_jdk: with env(PATH=os.path.join(path_jdk, 'bin')): dist = DistributionLocator.locate(minimum_version='2') self.assertEqual(path_jdk, dist.home) dist = DistributionLocator.locate(maximum_version='2') self.assertEqual(jdk1_home, dist.home)
def test_locate_trumps_path(self): with self.java_home_exe() as (jdk1_home, jdk2_home): with distribution( executables=exe('bin/java', version='3')) as path_jdk: with env(PATH=os.path.join(path_jdk, 'bin')): dist = DistributionLocator.locate() self.assertEqual(jdk1_home, dist.home) dist = DistributionLocator.locate(minimum_version='3') self.assertEqual(path_jdk, dist.home)
def test_locate_java_home_trumps(self): with self.java_home_exe() as (jdk1_home, jdk2_home): with distribution(executables=EXE('bin/java', version='3')) as java_home: with env(JAVA_HOME=java_home): dist = DistributionLocator.locate() self.assertEqual(java_home, dist.home) dist = DistributionLocator.locate(maximum_version='1.1') self.assertEqual(jdk1_home, dist.home) dist = DistributionLocator.locate(minimum_version='1.1', maximum_version='2') self.assertEqual(jdk2_home, dist.home)
def test_locate_java_home_trumps(self): with self.java_home_exe() as (jdk1_home, jdk2_home): with distribution( executables=exe('bin/java', version='3')) as java_home: with env(JAVA_HOME=java_home): dist = DistributionLocator.locate() self.assertEqual(java_home, dist.home) dist = DistributionLocator.locate(maximum_version='1.1') self.assertEqual(jdk1_home, dist.home) dist = DistributionLocator.locate(minimum_version='1.1', maximum_version='2') self.assertEqual(jdk2_home, dist.home)
def test_validate_live(self): with self.assertRaises(Distribution.Error): Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='999.9.9').validate() with self.assertRaises(Distribution.Error): Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='0.0.1').validate() Distribution(bin_path=os.path.dirname(self.JAVA)).validate() Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1').validate() Distribution(bin_path=os.path.dirname(self.JAVA), maximum_version='999.999.999').validate() Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='1.3.1', maximum_version='999.999.999').validate() with subsystem_instance(DistributionLocator): DistributionLocator.locate(jdk=False)
def test_no_jvm_restriction(self): with subsystem_instance(DistributionLocator): distribution = DistributionLocator.locate() target_spec = 'testprojects/src/java/org/pantsbuild/testproject/printversion' run = self.run_pants(['run', target_spec]) self.assert_success(run) self.assertIn('java.home:{}'.format(distribution.home), run.stdout_data)
def test_jvm_meets_min_and_max_distribution(self): with subsystem_instance(DistributionLocator): distribution = DistributionLocator.locate() target_spec = 'testprojects/src/java/org/pantsbuild/testproject/printversion' run = self.run_pants(['run', target_spec], config={ 'jvm-distributions': { 'minimum_version': str(distribution.version), 'maximum_version': str(distribution.version) } }) self.assert_success(run) self.assertIn('java.home:{}'.format(distribution.home), run.stdout_data)
def test_jvm_meets_min_and_max_distribution(self): with subsystem_instance(DistributionLocator): distribution = DistributionLocator.locate() target_spec = 'testprojects/src/java/org/pantsbuild/testproject/printversion' run = self.run_pants( ['run', target_spec], config={ 'jvm-distributions': { 'minimum_version': str(distribution.version), 'maximum_version': str(distribution.version) } }) self.assert_success(run) self.assertIn('java.home:{}'.format(distribution.home), run.stdout_data)
def test_locate_java_not_executable(self): with distribution(files='bin/java') as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): with self.assertRaises(Distribution.Error): DistributionLocator.locate()
def test_locate_version_to_high(self): with distribution(executables=exe('bin/java', '1.8.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): with self.assertRaises(Distribution.Error): DistributionLocator.locate(maximum_version='1.7.999')
def test_locate_jdk1(self): with env(): with self.java_home_exe() as (jdk1_home, _): dist = DistributionLocator.locate() self.assertEqual(jdk1_home, dist.home)
def test_locate_via_java_home(self): with distribution(executables=EXE('bin/java')) as dist_root: with env(JAVA_HOME=dist_root): DistributionLocator.locate()
def test_locate_version_less_then_or_equal(self): with distribution(executables=EXE('bin/java', '1.7.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(maximum_version='1.7.999')
def test_locate_jdk_by_path(self): with distribution(executables=[EXE('bin/java'), EXE('bin/javac')]) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(jdk=True)
def test_locate_invalid_java_home(self): with distribution(executables=EXE('java')) as dist_root: with env(JAVA_HOME=dist_root): with self.assertRaises(Distribution.Error): DistributionLocator.locate()
def test_locate_jdk_by_path(self): with distribution(executables=[exe('bin/java'), exe('bin/javac')]) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(jdk=True)
def test_locate_jdk_via_jre_path(self): with distribution(executables=[exe('jre/bin/java'), exe('bin/javac')], java_home='jre') as dist_root: with env(PATH=os.path.join(dist_root, 'jre', 'bin')): DistributionLocator.locate(jdk=True)
def test_locate_version_less_then_or_equal(self): with distribution(executables=exe('bin/java', '1.7.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(maximum_version='1.7.999')
def test_validate_live_jdk(self): Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).validate() Distribution(bin_path=os.path.dirname(self.JAVAC), jdk=True).binary('javap') with subsystem_instance(DistributionLocator): DistributionLocator.locate(jdk=True)
def test_locate_version_within_range(self): with distribution(executables=exe('bin/java', '1.7.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(minimum_version='1.6.0', maximum_version='1.7.999')
def test_locate_via_java_home(self): with distribution(executables=exe('bin/java')) as dist_root: with env(JAVA_HOME=dist_root): DistributionLocator.locate()
def test_locate_jdk1(self): with env(): with self.java_dist_dir() as (jdk1_home, _): dist = DistributionLocator.locate(maximum_version='1') self.assertEqual(jdk1_home, dist.home)
def test_locate_jdk2(self): with env(): with self.java_home_exe() as (_, jdk2_home): dist = DistributionLocator.locate(minimum_version='2') self.assertEqual(jdk2_home, dist.home)
def test_locate_version_to_high(self): with distribution(executables=EXE('bin/java', '1.8.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): with self.assertRaises(Distribution.Error): DistributionLocator.locate(maximum_version='1.7.999')
def test_locate_none(self): with env(): with self.assertRaises(Distribution.Error): with subsystem_instance(DistributionLocator): DistributionLocator.locate()
def test_locate_jre_by_path(self): with distribution(executables=EXE('bin/java')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate()
def test_locate_jre_by_path(self): with distribution(executables=exe('bin/java')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate()
def test_locate_jdk_via_jre_path(self): with distribution(executables=[EXE('jre/bin/java'), EXE('bin/javac')], java_home='jre') as dist_root: with env(PATH=os.path.join(dist_root, 'jre', 'bin')): DistributionLocator.locate(jdk=True)
def test_locate_version_greater_then_or_equal(self): with distribution(executables=exe('bin/java', '1.7.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(minimum_version='1.6.0')
def test_locate_version_within_range(self): with distribution(executables=EXE('bin/java', '1.7.0')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): DistributionLocator.locate(minimum_version='1.6.0', maximum_version='1.7.999')
def test_locate_invalid_java_home(self): with distribution(executables=exe('java')) as dist_root: with env(JAVA_HOME=dist_root): with self.assertRaises(Distribution.Error): DistributionLocator.locate()
def test_locate_jdk_is_jre(self): with distribution(executables=exe('bin/java')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): with self.assertRaises(Distribution.Error): DistributionLocator.locate(jdk=True)
def test_locate_jdk_is_jre(self): with distribution(executables=EXE('bin/java')) as dist_root: with env(PATH=os.path.join(dist_root, 'bin')): with self.assertRaises(Distribution.Error): DistributionLocator.locate(jdk=True)