changeset 19429:d14d350af115

.DSStore files confuse scanning of exploded modules
author alanb
date Wed, 29 Mar 2017 15:04:40 +0100
parents e6eda998e521
children 13a7d45fdf76
files src/java.base/share/classes/java/lang/module/ModuleFinder.java src/java.base/share/classes/jdk/internal/module/ModulePatcher.java src/java.base/share/classes/jdk/internal/module/ModulePath.java test/java/lang/module/ModuleFinderTest.java
diffstat 4 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/module/ModuleFinder.java	Wed Mar 29 14:12:28 2017 +0100
+++ b/src/java.base/share/classes/java/lang/module/ModuleFinder.java	Wed Mar 29 15:04:40 2017 +0100
@@ -312,7 +312,9 @@
      *
      * <p> As with automatic modules, the contents of a packaged or exploded
      * module may need to be <em>scanned</em> in order to determine the packages
-     * in the module. If a {@code .class} file (other than {@code
+     * in the module. Whether {@linkplain java.nio.file.Files#isHidden(Path)
+     * hidden files} are ignored or not is implementation specific and therefore
+     * not specified. If a {@code .class} file (other than {@code
      * module-info.class}) is found in the top-level directory then it is
      * assumed to be a class in the unnamed package and so {@code FindException}
      * is thrown. </p>
--- a/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java	Wed Mar 29 14:12:28 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java	Wed Mar 29 15:04:40 2017 +0100
@@ -135,8 +135,9 @@
                     Path top = file;
                     Files.find(top, Integer.MAX_VALUE,
                                ((path, attrs) -> attrs.isRegularFile()))
-                            .filter(path -> !isAutomatic
+                            .filter(path -> (!isAutomatic
                                     || path.toString().endsWith(".class"))
+                                    && !isHidden(path))
                             .map(path -> toPackageName(top, path))
                             .filter(Checks::isPackageName)
                             .forEach(packages::add);
@@ -556,7 +557,7 @@
 
 
     /**
-     * Derives a package name from a file path to a .class file.
+     * Derives a package name from the file path of an entry in an exploded patch
      */
     private static String toPackageName(Path top, Path file) {
         Path entry = top.relativize(file);
@@ -569,6 +570,17 @@
     }
 
     /**
+     * Returns true if the given file exists and is a hidden file
+     */
+    private boolean isHidden(Path file) {
+        try {
+            return Files.isHidden(file);
+        } catch (IOException ioe) {
+            return false;
+        }
+    }
+
+    /**
      * Derives a package name from the name of an entry in a JAR file.
      */
     private static String toPackageName(Path file, JarEntry entry) {
--- a/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Wed Mar 29 14:12:28 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Wed Mar 29 15:04:40 2017 +0100
@@ -626,7 +626,7 @@
     private Set<String> explodedPackages(Path dir) {
         try {
             return Files.find(dir, Integer.MAX_VALUE,
-                              ((path, attrs) -> attrs.isRegularFile()))
+                    ((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
                     .map(path -> dir.relativize(path))
                     .map(this::toPackageName)
                     .flatMap(Optional::stream)
@@ -722,6 +722,17 @@
         }
     }
 
+    /**
+     * Returns true if the given file exists and is a hidden file
+     */
+    private boolean isHidden(Path file) {
+        try {
+            return Files.isHidden(file);
+        } catch (IOException ioe) {
+            return false;
+        }
+    }
+
     private static final PerfCounter scanTime
         = PerfCounter.newPerfCounter("jdk.module.finder.modulepath.scanTime");
     private static final PerfCounter moduleCount
--- a/test/java/lang/module/ModuleFinderTest.java	Wed Mar 29 14:12:28 2017 +0100
+++ b/test/java/lang/module/ModuleFinderTest.java	Wed Mar 29 15:04:40 2017 +0100
@@ -529,6 +529,30 @@
 
 
     /**
+     * Test ModuleFinder.of with a directory containing hidden files
+     */
+    public void testOfWithHiddenFiles() throws Exception {
+        Path dir = Files.createTempDirectory(USER_DIR, "mods");
+        createExplodedModule(dir.resolve("m"), "m",
+                "com/.ignore",
+                "com/foo/.ignore",
+                "com/foo/foo.properties");
+
+        ModuleFinder finder = ModuleFinder.of(dir);
+        ModuleReference mref = finder.find("m").orElse(null);
+        assertNotNull(mref);
+
+        Set<String> expectedPackages;
+        if (System.getProperty("os.name").startsWith("Windows")) {
+            expectedPackages = Set.of("com", "com.foo");
+        } else {
+            expectedPackages = Set.of("com.foo");
+        }
+        assertEquals(mref.descriptor().packages(), expectedPackages);
+    }
+
+
+    /**
      * Test ModuleFinder.of with a truncated module-info.class
      */
     public void testOfWithTruncatedModuleInfo() throws Exception {