rev 12468 : 8132704: [TESTBUG] jdk/internal/jimage/ExecutableTest.java incorrectly asserts all files to be executable
Reviewed-by: rriggs

   1 /*
   2  * Copyright 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 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 }
--- EOF ---