cegredev / josi

A Java library designed to make making decisions based on the current operating system easier.
MIT License
36 stars 4 forks source link

Handle Mac OS version 11.x #4

Closed RohanNagar closed 3 years ago

RohanNagar commented 3 years ago

As a follow up to #2, @dbwiddis pointed out that os.version on macOS Big Sur could return 11.x.

My machine doesn't do this so I can't completely verify, but this should work.

dbwiddis commented 3 years ago

See this article. The result depends on the system environment variable SYSTEM_VERSION_COMPAT. If set with a value of 1 (the default) you get 10.16, to be backwards compatible with (poorly written) version checking code. If unset (or set to 0) you'll get 11.x (or possibly 12.x this fall?)

In my IDE (Eclipse) I can go into Run Configurations and add a new environment variable: image

With that setting I'm currently getting 11.3 for System.getProperty("os.version").

I'm sure IntelliJ IDEA has something similar.

cegredev commented 3 years ago

Thanks @dbwiddis for the advice and thanks @RohanNagar for implementing it. Really like the way you did it.

You might want to keep track of major/minor versions inside your OS object

I have thought about this and something like it is definitely planned. I just want it to fit in nicely with the rest of the library and be as easy to use as possible, so I don't want to rush anything.

String.split() uses regex and is less efficient than using indexOf() and substring(). Since you're trying to be lightweight/fast

Since this, as the init method, will only be called once I'm not too worried about micro-optimisations like this but there also is no reason not to implement it, so thanks!

Makes sense to me. I can address this in a follow-up change after this is merged

Great timing. I was just writing this comment. Merging now.

dbwiddis commented 3 years ago

not too worried about micro-optimisations like this

Agreed it's not a big deal (a few hundred nanoseconds) particularly for a one-time call. Just a habit for me to avoid split() unless it's necessary. If we do Regex it'd be even cleaner to define one that only allows digits between the delimiters. So many options! :)