36511
|
1 |
/*
|
|
2 |
* Copyright (c) 2015 SAP SE. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 8132475
|
|
27 |
* @summary Check that jlink creates executables in the bin directory
|
|
28 |
* that are are executable by all users
|
|
29 |
* @run main CheckExecutable
|
|
30 |
* @author Volker Simonis
|
|
31 |
*/
|
|
32 |
|
|
33 |
import java.io.IOException;
|
|
34 |
import java.nio.file.*;
|
|
35 |
import java.nio.file.attribute.PosixFilePermission;
|
|
36 |
import static java.nio.file.attribute.PosixFilePermission.*;
|
|
37 |
import java.util.EnumSet;
|
|
38 |
import java.util.Set;
|
|
39 |
|
|
40 |
public class CheckExecutable {
|
|
41 |
|
|
42 |
// The bin directory may contain non-executable files (see 8132704)
|
|
43 |
private static final String IGNORE = "glob:{*.diz,jmc.ini}";
|
|
44 |
|
|
45 |
public static void main(String args[]) throws IOException {
|
|
46 |
String JAVA_HOME = System.getProperty("java.home");
|
|
47 |
Path bin = Paths.get(JAVA_HOME, "bin");
|
|
48 |
|
|
49 |
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(IGNORE);
|
|
50 |
|
|
51 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(bin)) {
|
|
52 |
EnumSet<PosixFilePermission> execPerms
|
|
53 |
= EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);
|
|
54 |
|
|
55 |
for (Path entry : stream) {
|
|
56 |
Path file = entry.getFileName();
|
|
57 |
if (!Files.isRegularFile(entry) || matcher.matches(file)) {
|
|
58 |
continue;
|
|
59 |
}
|
|
60 |
|
|
61 |
if (!Files.isExecutable(entry))
|
|
62 |
throw new RuntimeException(entry + " is not executable!");
|
|
63 |
|
|
64 |
try {
|
|
65 |
Set<PosixFilePermission> perm
|
|
66 |
= Files.getPosixFilePermissions(entry);
|
|
67 |
if (!perm.containsAll(execPerms)) {
|
|
68 |
throw new RuntimeException(entry
|
|
69 |
+ " has not all executable permissions!\n"
|
|
70 |
+ "Should have: " + execPerms + "\nbut has: " + perm);
|
|
71 |
}
|
|
72 |
} catch (UnsupportedOperationException uoe) { }
|
|
73 |
|
|
74 |
}
|
|
75 |
|
|
76 |
}
|
|
77 |
}
|
|
78 |
}
|