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 import java.nio.file.DirectoryStream;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.nio.file.attribute.PosixFilePermission;
29 import static java.nio.file.attribute.PosixFilePermission.*;
30 import java.util.EnumSet;
31 import java.util.Set;
32
33 /*
34 * @test
35 * @bug 8132475
36 * @summary Check that the executables in the current JDK image
37 * are executable by all users.
38 * @run main ExecutableTest
39 * @author Volker Simonis
40 */
41
42 public class ExecutableTest {
43
44 public static void main(String args[]) throws Throwable {
45 String JAVA_HOME = System.getProperty("java.home");
46 Path binPath = Paths.get(JAVA_HOME, "bin");
47 DirectoryStream<Path> stream = Files.newDirectoryStream(binPath);
48 EnumSet<PosixFilePermission> execPerms =
49 EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);
50 for (Path entry : stream) {
51 if (Files.isRegularFile(entry)) {
52 if (!Files.isExecutable(entry)) {
53 throw new Error(entry + " is not executable!");
54 }
55 try {
56 Set<PosixFilePermission> perm = Files.getPosixFilePermissions(entry);
57 if (!perm.containsAll(execPerms)) {
58 throw new Error(entry + " has not all executable permissions!\n" +
59 "Should have: " + execPerms + "\nbut has: " + perm);
60 }
61 } catch (UnsupportedOperationException e) {}
62 }
63 }
64 }
65 }
|
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 import java.nio.file.DirectoryStream;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.nio.file.attribute.PosixFilePermission;
29 import static java.nio.file.attribute.PosixFilePermission.*;
30 import java.util.EnumSet;
31 import java.util.Set;
32
33 import jdk.testlibrary.Platform;
34
35 /*
36 * @test
37 * @bug 8132475
38 * @summary Check that the executables in the current JDK image
39 * are executable by all users.
40 * @library /lib/testlibrary
41 * @run main ExecutableTest
42 * @author Volker Simonis
43 */
44
45 public class ExecutableTest {
46
47 // We use a fixed list of binaries because not all the files in the
48 // bin/ directory are necessarily exectuables (see 8132704)
49 private static final String[] executables = {
50 "appletviewer", "idlj", "jar", "jarsigner", "java", "java-rmi.cgi", "javac",
51 "javadoc", "javah", "javap", "jcmd", "jconsole", "jdb", "jdeps", "jimage",
52 "jinfo", "jjs", "jmap", "jps", "jrunscript", "jsadebugd", "jstack", "jstat",
53 "jstatd", "keytool", "orbd", "pack200", "policytool", "rmic", "rmid",
54 "rmiregistry", "schemagen", "serialver", "servertool", "tnameserv",
55 "unpack200", "wsgen", "wsimport", "xjc" };
56
57 public static void main(String args[]) throws Throwable {
58 String JAVA_HOME = System.getProperty("java.home");
59 String exeSuffix = Platform.isWindows() ? ".exe" : "";
60
61 EnumSet<PosixFilePermission> execPerms =
62 EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);
63
64 for (String exe : executables) {
65 Path path = Paths.get(JAVA_HOME, "bin", exe + exeSuffix);
66 if (Files.isRegularFile(path)) {
67 if (!Files.isExecutable(path)) {
68 throw new Error(path + " is not executable!");
69 }
70 try {
71 Set<PosixFilePermission> perm = Files.getPosixFilePermissions(path);
72 if (!perm.containsAll(execPerms)) {
73 throw new Error(path + " has not all executable permissions!\n" +
74 "Should have: " + execPerms + "\nbut has: " + perm);
75 }
76 } catch (UnsupportedOperationException e) {}
77 }
78 }
79 }
80 }
|