/
requireJavaVersion.apt.vm
95 lines (77 loc) · 3.21 KB
/
requireJavaVersion.apt.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
------
Require Java Version
------
Brian Fox
------
June 2007
------
Require Java Version
This rule enforces certain Java JDK versions. The rule uses the {{{./versionRanges.html}Enforcer version range syntax}} to define allowed versions.
The following parameters are supported by this rule:
* message - an optional message to the user if the rule fails.
* {{{../apidocs/org/apache/maven/plugins/enforcer/AbstractVersionEnforcer.html#version}version}} - {{{./versionRanges.html}range}} of allowed JDKs.
[]
The JDK version is retrieved and the following processing occurs before being checked:
[[1]] Drop all non-numeric characters preceding the first number. (build 1.5.0_07-b03 becomes 1.5.0_07-b03)
[[2]] Replace all '_' and '-' with '.' (1.5.0_07-b03 becomes 1.5.0.07.b03)
[[3]] Remove all non digit characters "[^0-9] and convert each section using Integer.parseInt() (1.5.0_07-b03 becomes 1.5.0.7.3)
[[3]] Split the string on '.' and take the first 3 sections, separated by '.' and add '-' followed by the fourth section (1.5.0.7.3 becomes 1.5.0-7)
[]
This preprocessing normalizes various JDK version strings into a standard x.y.z-b version number. Your required range should therefore use the x.y.z-b format for comparison.
There is an easy way to see how your current JDK string will be normalized:
+---+
mvn enforcer:display-info
...
[enforcer:display-info]
Maven Version: 2.0.8
JDK Version: 1.5.0_11 normalized as: 1.5.0-11
OS Info: Arch: x86 Family: windows Name: windows xp Version: 5.1
+---+
Sample Plugin Configuration:
+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>1.6.0</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
+---+
If you would like to enforce a certain vendor string for the JDK, you would use the {{{./requireJavaVendor.html}RequireJavaVendor}} rule