Path: blob/master/test/jdk/tools/jlink/CheckExecutable.java
41144 views
/*1* Copyright (c) 2015 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813247526* @summary Check that jlink creates executables in the bin directory27* that are are executable by all users28* @run main CheckExecutable29* @author Volker Simonis30*/3132import java.io.IOException;33import java.nio.file.*;34import java.nio.file.attribute.PosixFilePermission;35import static java.nio.file.attribute.PosixFilePermission.*;36import java.util.EnumSet;37import java.util.Set;3839public class CheckExecutable {4041// The bin directory may contain non-executable files (see 8132704)42private static final String IGNORE = "glob:{*.diz,jmc.ini}";4344public static void main(String args[]) throws IOException {45String JAVA_HOME = System.getProperty("java.home");46Path bin = Paths.get(JAVA_HOME, "bin");4748PathMatcher matcher = FileSystems.getDefault().getPathMatcher(IGNORE);4950try (DirectoryStream<Path> stream = Files.newDirectoryStream(bin)) {51EnumSet<PosixFilePermission> execPerms52= EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);5354for (Path entry : stream) {55Path file = entry.getFileName();56if (!Files.isRegularFile(entry) || matcher.matches(file)) {57continue;58}5960if (!Files.isExecutable(entry))61throw new RuntimeException(entry + " is not executable!");6263try {64Set<PosixFilePermission> perm65= Files.getPosixFilePermissions(entry);66if (!perm.containsAll(execPerms)) {67throw new RuntimeException(entry68+ " has not all executable permissions!\n"69+ "Should have: " + execPerms + "\nbut has: " + perm);70}71} catch (UnsupportedOperationException uoe) { }7273}7475}76}77}787980