< prev index next >

test/jdk/jdk/internal/jrtfs/Basic.java

Print this page
rev 55068 : 8224908: Revert: 8216553: JrtFileSystemProvider getPath(URI) omits /modules element from file path
Reviewed-by:


  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 /*
  25  * @test
  26  * @summary Basic test of jrt file system provider
  27  * @run testng Basic
  28  */
  29 
  30 import java.io.InputStream;
  31 import java.io.IOError;
  32 import java.io.IOException;
  33 import java.io.DataInputStream;
  34 import java.nio.file.DirectoryStream;
  35 import java.nio.file.InvalidPathException;
  36 import java.nio.file.Files;
  37 import java.nio.file.FileSystem;
  38 import java.nio.file.FileSystems;
  39 import java.nio.file.Path;
  40 import java.nio.file.PathMatcher;
  41 import java.nio.file.Paths;
  42 import java.net.URI;
  43 import java.util.Collections;
  44 import java.util.HashMap;
  45 import java.util.Iterator;
  46 import java.util.Map;
  47 import java.util.NoSuchElementException;
  48 import java.util.stream.Stream;
  49 
  50 import org.testng.annotations.AfterClass;
  51 import org.testng.annotations.BeforeClass;


 255     }
 256 
 257     @Test(dataProvider = "topLevelPkgDirs")
 258     public void testNotExists(String path) throws Exception {
 259         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 260         Path dir = fs.getPath(path);
 261 
 262         // package directories should not be there at top level
 263         assertTrue(Files.notExists(dir));
 264     }
 265 
 266     /**
 267      * Test the URI of every file in the jrt file system
 268      */
 269     @Test
 270     public void testToAndFromUri() throws Exception {
 271         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 272         Path top = fs.getPath("/");
 273         try (Stream<Path> stream = Files.walk(top)) {
 274             stream.forEach(path -> {
 275                 String pathStr = path.toAbsolutePath().toString();
 276                 URI u = null;
 277                 try {
 278                     u = path.toUri();
 279                 } catch (IOError e) {
 280                     assertFalse(pathStr.startsWith("/modules"));
 281                     return;
 282                 }
 283 
 284                 assertTrue(u.getScheme().equalsIgnoreCase("jrt"));
 285                 assertFalse(u.isOpaque());
 286                 assertTrue(u.getAuthority() == null);
 287 
 288                 pathStr = pathStr.substring("/modules".length());
 289                 if (pathStr.isEmpty()) {
 290                     pathStr = "/";
 291                 }
 292                 assertEquals(u.getPath(), pathStr);
 293                 Path p = Paths.get(u);
 294                 assertEquals(p, path);
 295             });
 296         }
 297     }
 298 
 299     // @bug 8216553: JrtFIleSystemProvider getPath(URI) omits /modules element from file path
 300     @Test
 301     public void testPathToURIConversion() throws Exception {
 302         var uri = URI.create("jrt:/java.base/module-info.class");
 303         var path = Path.of(uri);
 304         assertTrue(Files.exists(path));
 305 
 306         uri = URI.create("jrt:/java.base/../java.base/module-info.class");
 307         boolean seenIAE = false;
 308         try {
 309             Path.of(uri);
 310         } catch (IllegalArgumentException iaExp) {
 311             seenIAE = true;
 312         }
 313         assertTrue(seenIAE);
 314 
 315         // check round-trip
 316         var jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
 317         assertTrue(Files.exists(jrtfs.getPath(path.toString())));
 318 
 319         path = jrtfs.getPath("/modules/../modules/java.base/");
 320         boolean seenIOError = false;
 321         try {
 322             path.toUri();
 323         } catch (IOError ioError) {
 324             seenIOError = true;
 325         }
 326         assertTrue(seenIOError);
 327     }
 328 
 329     @Test
 330     public void testDirectoryNames() throws Exception {
 331         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 332         Path top = fs.getPath("/");
 333         // check that directory names do not have trailing '/' char
 334         try (Stream<Path> stream = Files.walk(top)) {
 335             stream.skip(1).filter(Files::isDirectory).forEach(path -> {
 336                 assertFalse(path.toString().endsWith("/"));
 337             });
 338         }
 339     }
 340 
 341     @DataProvider(name = "pathPrefixs")
 342     private Object[][] pathPrefixes() {
 343         return new Object[][] {
 344             { "/"                       },
 345             { "modules/java.base/java/lang"     },
 346             { "./modules/java.base/java/lang"   },
 347             { "/modules/java.base/java/lang"    },
 348             { "/./modules/java.base/java/lang"  },




  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 /*
  25  * @test
  26  * @summary Basic test of jrt file system provider
  27  * @run testng Basic
  28  */
  29 
  30 import java.io.InputStream;

  31 import java.io.IOException;
  32 import java.io.DataInputStream;
  33 import java.nio.file.DirectoryStream;
  34 import java.nio.file.InvalidPathException;
  35 import java.nio.file.Files;
  36 import java.nio.file.FileSystem;
  37 import java.nio.file.FileSystems;
  38 import java.nio.file.Path;
  39 import java.nio.file.PathMatcher;
  40 import java.nio.file.Paths;
  41 import java.net.URI;
  42 import java.util.Collections;
  43 import java.util.HashMap;
  44 import java.util.Iterator;
  45 import java.util.Map;
  46 import java.util.NoSuchElementException;
  47 import java.util.stream.Stream;
  48 
  49 import org.testng.annotations.AfterClass;
  50 import org.testng.annotations.BeforeClass;


 254     }
 255 
 256     @Test(dataProvider = "topLevelPkgDirs")
 257     public void testNotExists(String path) throws Exception {
 258         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 259         Path dir = fs.getPath(path);
 260 
 261         // package directories should not be there at top level
 262         assertTrue(Files.notExists(dir));
 263     }
 264 
 265     /**
 266      * Test the URI of every file in the jrt file system
 267      */
 268     @Test
 269     public void testToAndFromUri() throws Exception {
 270         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 271         Path top = fs.getPath("/");
 272         try (Stream<Path> stream = Files.walk(top)) {
 273             stream.forEach(path -> {
 274                 URI u = path.toUri();








 275                 assertTrue(u.getScheme().equalsIgnoreCase("jrt"));
 276                 assertFalse(u.isOpaque());
 277                 assertTrue(u.getAuthority() == null);
 278                 assertEquals(u.getPath(), path.toAbsolutePath().toString());





 279                 Path p = Paths.get(u);
 280                 assertEquals(p, path);
 281             });
 282         }
 283     }
 284 






























 285     @Test
 286     public void testDirectoryNames() throws Exception {
 287         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
 288         Path top = fs.getPath("/");
 289         // check that directory names do not have trailing '/' char
 290         try (Stream<Path> stream = Files.walk(top)) {
 291             stream.skip(1).filter(Files::isDirectory).forEach(path -> {
 292                 assertFalse(path.toString().endsWith("/"));
 293             });
 294         }
 295     }
 296 
 297     @DataProvider(name = "pathPrefixs")
 298     private Object[][] pathPrefixes() {
 299         return new Object[][] {
 300             { "/"                       },
 301             { "modules/java.base/java/lang"     },
 302             { "./modules/java.base/java/lang"   },
 303             { "/modules/java.base/java/lang"    },
 304             { "/./modules/java.base/java/lang"  },


< prev index next >