def test_validate_live(self): with pytest.raises(Distribution.Error): Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='999.9.9').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.locate(jdk=False)
def test_validated_binary(self): with pytest.raises(Distribution.Error): with self.distribution(files='jar', executables=self.exe('java')) as jdk: Distribution(bin_path=jdk).binary('jar') with self.distribution(executables=[self.exe('java'), self.exe('jar')]) as jdk: Distribution(bin_path=jdk).binary('jar')
def test_validate_jdk(self): with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: Distribution(bin_path=jdk, jdk=True).validate() with self.distribution( executables=[self.exe('java'), self.exe('javac')]) as jdk: Distribution(bin_path=jdk, jdk=True).validate()
def test_validate_basic(self): with pytest.raises(Distribution.Error): with self.distribution() as jdk: Distribution(bin_path=jdk).validate() with pytest.raises(Distribution.Error): with self.distribution(files='java') as jdk: Distribution(bin_path=jdk).validate() with self.distribution(executables=self.exe('java')) as jdk: Distribution(bin_path=jdk).validate()
def test_validate_version(self): with pytest.raises(Distribution.Error): with self.distribution( executables=self.exe('java', '1.7.0_25')) as jdk: Distribution(bin_path=jdk, minimum_version='1.7.0_45').validate() with pytest.raises(Distribution.Error): with self.distribution( executables=self.exe('java', '1.8.0_1')) as jdk: Distribution(bin_path=jdk, maximum_version='1.7.9999').validate() with self.distribution( executables=self.exe('java', '1.7.0_25')) as jdk: Distribution(bin_path=jdk, minimum_version='1.7.0_25').validate() Distribution(bin_path=jdk, minimum_version=Revision.semver('1.6.0')).validate() Distribution(bin_path=jdk, minimum_version='1.7.0_25', maximum_version='1.7.999').validate()
def __init__(self, context, workdir): """ :param context: inherited parameter from Task :param workdir: inherited parameter from Task """ super(JaxbGen, self).__init__(context, workdir) 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')
def __init__(self, context, workdir, minimum_version=None, maximum_version=None, jdk=False): super(NailgunTask, self).__init__(context, workdir) self._executor_workdir = os.path.join(context.config.getdefault('pants_workdir'), 'ng', 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)
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
def test_validate_live(self): with pytest.raises(Distribution.Error): Distribution(bin_path=os.path.dirname(self.JAVA), minimum_version='999.9.9').validate() with pytest.raises(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() Distribution.locate(jdk=False)
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
def __init__(self, context, minimum_version=None, jdk=False): super(NailgunTask, self).__init__(context) default_workdir_root = os.path.join(context.config.getdefault('pants_workdir'), 'ng') self._workdir = os.path.join( context.config.get('nailgun', 'workdir', default=default_workdir_root), self.__class__.__name__) self._nailgun_bootstrap_key = 'nailgun' self._jvm_tool_bootstrapper.register_jvm_tool(self._nailgun_bootstrap_key, [':nailgun-server']) start = time.time() try: self._dist = Distribution.cached(minimum_version=minimum_version, jdk=jdk) # TODO(John Sirois): Use a context timer when AWESOME-1265 gets merged. context.log.debug('Located java distribution in %.3fs' % (time.time() - start)) except Distribution.Error as e: raise TaskError(e)
def __init__(self, context, workdir, minimum_version=None, maximum_version=None, jdk=False): super(NailgunTask, self).__init__(context, workdir) self._executor_workdir = os.path.join( context.config.getdefault('pants_workdir'), 'ng', 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)
def test_locate(self): @contextmanager def env(**kwargs): environment = dict(JDK_HOME=None, JAVA_HOME=None, PATH=None) environment.update(**kwargs) with environment_as(**environment): yield with pytest.raises(Distribution.Error): with env(): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(files='java') as jdk: with env(PATH=jdk): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(PATH=jdk): Distribution.locate(jdk=True) with pytest.raises(Distribution.Error): with self.distribution( executables=self.exe('java', '1.6.0')) as jdk: with env(PATH=jdk): Distribution.locate(minimum_version='1.7.0') with self.distribution( executables=self.exe('java', '1.8.0')) as jdk: with env(PATH=jdk): Distribution.locate(maximum_version='1.7.999') with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(JDK_HOME=jdk): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(JAVA_HOME=jdk): Distribution.locate() with self.distribution(executables=self.exe('java')) as jdk: with env(PATH=jdk): Distribution.locate() with self.distribution( executables=[self.exe('java'), self.exe('javac')]) as jdk: with env(PATH=jdk): Distribution.locate(jdk=True) with self.distribution(executables=self.exe('java', '1.7.0')) as jdk: with env(PATH=jdk): Distribution.locate(minimum_version='1.6.0') with env(PATH=jdk): Distribution.locate(maximum_version='1.7.999') with env(PATH=jdk): Distribution.locate(minimum_version='1.6.0', maximum_version='1.7.999') with self.distribution(executables=self.exe('bin/java')) as jdk: with env(JDK_HOME=jdk): Distribution.locate() with self.distribution(executables=self.exe('bin/java')) as jdk: with env(JAVA_HOME=jdk): Distribution.locate()
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') Distribution.locate(jdk=True)
def test_locate(self): @contextmanager def env(**kwargs): environment = dict(JDK_HOME=None, JAVA_HOME=None, PATH=None) environment.update(**kwargs) with environment_as(**environment): yield with pytest.raises(Distribution.Error): with env(): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(files='java') as jdk: with env(PATH=jdk): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(PATH=jdk): Distribution.locate(jdk=True) with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java', '1.6.0')) as jdk: with env(PATH=jdk): Distribution.locate(minimum_version='1.7.0') with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(JDK_HOME=jdk): Distribution.locate() with pytest.raises(Distribution.Error): with self.distribution(executables=self.exe('java')) as jdk: with env(JAVA_HOME=jdk): Distribution.locate() with self.distribution(executables=self.exe('java')) as jdk: with env(PATH=jdk): Distribution.locate() with self.distribution(executables=[self.exe('java'), self.exe('javac')]) as jdk: with env(PATH=jdk): Distribution.locate(jdk=True) with self.distribution(executables=self.exe('java', '1.7.0')) as jdk: with env(PATH=jdk): Distribution.locate(minimum_version='1.6.0') with self.distribution(executables=self.exe('bin/java')) as jdk: with env(JDK_HOME=jdk): Distribution.locate() with self.distribution(executables=self.exe('bin/java')) as jdk: with env(JAVA_HOME=jdk): Distribution.locate()