tofi86/universalJavaApplicationStub

Support for a new syntax in JVMVersion field to specify both min and max Java version

tofi86 opened this issue · 3 comments

to specifiy minimal 1.7 and max 1.8 but not Java 9

e.g.

  • 1.7+ for Java 7, 8, 9
  • 1.7;1.8* for Java 7, 8
  • 1.8;9.0 for Java 8* up to exactly 9.0 (but not 9.0.*)
  • 1.8;9.0* for Java 8* and 9.0.* but not 9.1.*

It's not as easy to implement as I thought...

Splitting the JVMVersion is easy:

	# read the Java version we want to find
	JVMVersion=$(plist_get_java ':JVMVersion' | xargs)
	if [[ ${JVMVersion} == *";"* ]]; then
		minMaxArray=(${JVMVersion//;/ })
		JVMVersion=$(echo ${minMaxArray[0]} | sed 's/+//')
		JVMMaxVersion=$(echo ${minMaxArray[1]} | sed 's/+//')
		stub_logger "[JavaRequirement] JVM minimum version: ${JVMVersion}"
		stub_logger "[JavaRequirement] JVM maximum version: ${JVMMaxVersion}"
	fi

I already removed a trailing + as it would conflict with the min/max system.

But then finding an installed Java version which is between min and max is hard.
Also because the system tool /usr/libexec/java_home does not support a max version parameter.

So I wrote this new piece of code over the past couple of days:
https://gist.github.com/tofi86/3d5973f8cb259f07207451d051a52ae1

Given a $min and (optionally) a $max version requirement it finds all the JVMs on the system (JDK and JRE, no preference) and compares its version number to the min/max requirement.

Look at the gist comments for examples. Should work quite well :)

Integration on development is still missing and to come in the next couple of days.

Solved with commit 02c2c24.

Supported syntax is

  • 1.7;1.8* for Java 7, 8
  • 1.8;9.0 for Java 8* up to exactly 9.0 (but not 9.0.*)
  • 1.8;9.0* for Java 8* and 9.0.* but not 9.1.*