author | dmarkov |
Mon, 23 Sep 2019 17:18:03 +0100 | |
changeset 58328 | fe46ee1d42ee |
parent 47737 | acfedb75dd51 |
permissions | -rw-r--r-- |
47737
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
1 |
/* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
4 |
* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
8 |
* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
14 |
* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
18 |
* |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
21 |
* questions. |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
22 |
*/ |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
23 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
24 |
import java.lang.module.ModuleDescriptor; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
25 |
import java.lang.module.ModuleFinder; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
26 |
import java.lang.module.ModuleReference; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
27 |
import java.util.Arrays; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
28 |
import java.util.Set; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
29 |
import java.util.stream.Collectors; |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
30 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
31 |
public class CheckRuntimeVersion { |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
32 |
public static void main(String... args) { |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
33 |
int version = Integer.parseInt(args[0]); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
34 |
if (Runtime.version().major() != version) { |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
35 |
throw new RuntimeException(version + " != current runtime version " |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
36 |
+ Runtime.version()); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
37 |
} |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
38 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
39 |
Set<String> expected = Arrays.stream(args, 1, args.length) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
40 |
.collect(Collectors.toSet()); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
41 |
Set<String> modules = ModuleFinder.ofSystem().findAll().stream() |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
42 |
.map(ModuleReference::descriptor) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
43 |
.map(ModuleDescriptor::name) |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
44 |
.collect(Collectors.toSet()); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
45 |
|
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
46 |
if (!modules.equals(expected)) { |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
47 |
throw new RuntimeException("Expected: " + expected + |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
48 |
" observable modules: " + modules); |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
49 |
} |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
50 |
} |
acfedb75dd51
8177471: jlink should use the version from java.base.jmod to find modules
sundar
parents:
diff
changeset
|
51 |
} |