< prev index next >

test/jdk/internal/jimage/ExecutableTest.java

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


  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 }


  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.Arrays;
  31 import java.util.EnumSet;
  32 import java.util.HashSet;
  33 import java.util.Set;
  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  * @run main ExecutableTest
  41  * @author Volker Simonis
  42  */
  43 
  44 public class ExecutableTest {
  45 
  46     // The bin/ directory may contain non-executable files (see 8132704)
  47     private static final String[] exclude = { "jmc.ini" };
  48     private static final Set<String> excludeSet =
  49         new HashSet<String>(Arrays.asList(exclude));
  50 
  51     public static void main(String args[]) throws Throwable {
  52         String JAVA_HOME = System.getProperty("java.home");
  53         Path binPath = Paths.get(JAVA_HOME, "bin");
  54         DirectoryStream<Path> stream = Files.newDirectoryStream(binPath);
  55         EnumSet<PosixFilePermission> execPerms =
  56             EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);
  57         for (Path entry : stream) {
  58             if (excludeSet.contains(entry.getFileName().toString())) continue;
  59             if (Files.isRegularFile(entry)) {
  60                 if (!Files.isExecutable(entry)) {
  61                     throw new Error(entry + " is not executable!");
  62                 }
  63                 try {
  64                     Set<PosixFilePermission> perm = Files.getPosixFilePermissions(entry);
  65                     if (!perm.containsAll(execPerms)) {
  66                         throw new Error(entry + " has not all executable permissions!\n" +
  67                                         "Should have: " + execPerms + "\nbut has: " + perm);
  68                     }
  69                 } catch (UnsupportedOperationException e) {}
  70             }
  71         }
  72     }
  73 }
< prev index next >