|
|
||
Stanley Ho's BlogVersioning in the Java Module System (Part 2)Posted by stanleyh on May 29, 2008 at 04:13 PM | Comments (5)This is the second of two articles about versioning in the Java Module System. The first article was about version format and policies.
Version rangesIn the Java Module System, modules describe their dependencies on other modules, and on particular versions of those other modules. Versions and version ranges, like all syntactic elements, are fundamentally matters of taste, but we have tried in the Java Module System to make common versioning tasks easy and advanced versioning tasks possible.
First, the Java Module System (in the forthcoming JSR 277 EDR2) adopts the OSGi syntax for version range intervals. [ and ] mean the bound is inclusive and ( and ) mean the bound is exclusive: [1.2.3, 4.5.6) ~ 1.2.3 <= x < 4.5.6
(1.2.3, 4.5.6] ~ 1.2.3 < x <= 4.5.6
(1.2.3, 4.5.6) ~ 1.2.3 < x < 4.5.6
[1.2.3, 4.5.6] ~ 1.2.3 <= x <= 4.5.6
All these intervals have the same meaning in the Java Module System as they do in OSGi.
Where the Java Module System differs from OSGi is in the interpretation of a single version. OSGi interprets a single version like 1.2.3 as "1.2.3 or greater" (OSGi R4.1 3.2.5). To get precisely version 1.2.3, you must write [1.2.3,1.2.3]. Adopting an implicit range is certainly concise, and use of exact versions is sufficiently rare that their [...,...] overhead is not too bad. But millions of programmers will first encounter versions via the Java Module System and it is best to adopt the simplest possible interpretation of any term. There is no doubt that someone seeing 1.2.3 for the first time thinks "exactly 1.2.3", so that is how the Java Module System interprets it. Ranges are denoted with explicit symbols. '+' means "or greater": 1+ ~ [1, infinity) ~ 1 <= x < infinity
1.2+ ~ [1.2, infinity) ~ 1.2 <= x < infinity
1.2.3+ ~ [1.2.3, infinity) ~ 1.2.3 <= x < infinity
1.2.3.4+ ~ [1.2.3.4, infinity) ~ 1.2.3.4 <= x < infinity
'*' means any version in a particular release family:
1.* ~ [1, 2) ~ 1 <= x < 2
1.2.* ~ [1.2, 1.3) ~ 1.2 <= x < 1.3
1.2.3.* ~ [1.2.3, 1.2.4) ~ 1.2.3 <= x < 1.2.4
Clearly, + and * in the Java Module System can express the same versions as intervals in OSGi, but without writing an ",infinity)" interval or adopting unintuitive "open versions" (1.2.3 == "1.2.3 or greater") to avoid the infinity interval.
The Java Module System also allows groups of ranges to be expressed, separated by ';'. These "union ranges" are separated by ';' because it works in command line expressions, unlike ',' and '&' ! 1.* ; [2.0, 2.7.3) ~ 1.0.0 <= x < 2.7.3
[1.2.3.4, 2.0) ; 2.* ; 3+ ~ 1.2.3.4 <= x < infinity
One feature you might expect are exclusive ranges, e.g. to express that the 2.5 product family was a disaster and should not be used. You might want to write:
[1, 3) - 2.5.*The Java Module System does not directly support exclusive ranges because it is easy to express them with union ranges: [1, 2.5) ; [2.6, 3)Or if you prefer to use a closed interval (this lets you avoid writing down the dreaded version 2.5): [1, 2.4.*] ; [2.6, 3)Now suppose the problem is narrowed down from 2.5 to 2.5.1: [1, 3) - 2.5.1.*You can express this with: [1, 2.5.1) ; [2.5.2, 3)or [1, 2.5.0.*] ; [2.5.2, 3)Happily, the precision of the exclusion does not affect the length of the union.
The cardinality of the exclusion does affect the length of the union, so excluding two version ranges: [1, 3) - 2.5.1.* - 2.6.8.*is expressible with: [1, 2.5.1) ; [2.5.2, 2.6.8) ; [2.6.9, 3)or [1, 2.5.0.*] ; [2.5.2, 2.6.7.*] ; [2.6.9, 3)The number of exclusive ranges, i.e. 2.5.1.* and 2.6.8.*, is the same as the number of ranges in the union. All the Java Module System really needs is unions (;) not exclusive ranges per se. Just as well, because taking the union of normal ranges and exclusive ranges could get pretty complicated.
In summary, we think it is reasonable for the Java Module System to let version numbers be version numbers, and introduce simple syntax (+, *) to denote ranges. Intervals work as they do in OSGi. Complex scenarios can use ; to group ranges and intervals. Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| ||
|
|