jdk/test/tools/jmod/hashes/HashesTest.java
changeset 40261 86a49ba76f52
parent 37779 7c84df693837
child 41484 834b7539ada3
equal deleted inserted replaced
40260:4e69b50ccd97 40261:86a49ba76f52
     1 /**
     1 /**
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    86         jmod("m3");
    86         jmod("m3");
    87 
    87 
    88         // build m1
    88         // build m1
    89         compileModule("m1", modSrc);
    89         compileModule("m1", modSrc);
    90         // no hash is recorded since m1 has outgoing edges
    90         // no hash is recorded since m1 has outgoing edges
    91         jmod("m1", "--modulepath", jmods.toString(), "--hash-modules", ".*");
    91         jmod("m1", "--module-path", jmods.toString(), "--hash-modules", ".*");
    92 
    92 
    93         // compile org.bar and org.foo
    93         // compile org.bar and org.foo
    94         compileModule("org.bar", modSrc);
    94         compileModule("org.bar", modSrc);
    95         compileModule("org.foo", modSrc);
    95         compileModule("org.foo", modSrc);
    96 
    96 
   107         for (String mn : modules) {
   107         for (String mn : modules) {
   108             assertFalse(hashes(mn).isPresent());
   108             assertFalse(hashes(mn).isPresent());
   109         }
   109         }
   110 
   110 
   111         // hash m1 in m2
   111         // hash m1 in m2
   112         jmod("m2", "--modulepath", jmods.toString(), "--hash-modules", "m1");
   112         jmod("m2", "--module-path", jmods.toString(), "--hash-modules", "m1");
   113         checkHashes(hashes("m2").get(), "m1");
   113         checkHashes(hashes("m2").get(), "m1");
   114 
   114 
   115         // hash m1 in m2
   115         // hash m1 in m2
   116         jmod("m2", "--modulepath", jmods.toString(), "--hash-modules", ".*");
   116         jmod("m2", "--module-path", jmods.toString(), "--hash-modules", ".*");
   117         checkHashes(hashes("m2").get(), "m1");
   117         checkHashes(hashes("m2").get(), "m1");
   118 
   118 
   119         // create m2.jmod with no hash
   119         // create m2.jmod with no hash
   120         jmod("m2");
   120         jmod("m2");
   121         // run jmod hash command to hash m1 in m2 and m3
   121         // run jmod hash command to hash m1 in m2 and m3
   122         runJmod(Arrays.asList("hash", "--modulepath", jmods.toString(),
   122         runJmod(Arrays.asList("hash", "--module-path", jmods.toString(),
   123                 "--hash-modules", ".*"));
   123                 "--hash-modules", ".*"));
   124         checkHashes(hashes("m2").get(), "m1");
   124         checkHashes(hashes("m2").get(), "m1");
   125         checkHashes(hashes("m3").get(), "m1");
   125         checkHashes(hashes("m3").get(), "m1");
   126 
   126 
   127         jmod("org.bar");
   127         jmod("org.bar");
   128         jmod("org.foo");
   128         jmod("org.foo");
   129 
   129 
   130         jmod("org.bar", "--modulepath", jmods.toString(), "--hash-modules", "org.*");
   130         jmod("org.bar", "--module-path", jmods.toString(), "--hash-modules", "org.*");
   131         checkHashes(hashes("org.bar").get(), "org.foo");
   131         checkHashes(hashes("org.bar").get(), "org.foo");
   132 
   132 
   133         jmod("m3", "--modulepath", jmods.toString(), "--hash-modules", ".*");
   133         jmod("m3", "--module-path", jmods.toString(), "--hash-modules", ".*");
   134         checkHashes(hashes("m3").get(), "org.foo", "org.bar", "m1");
   134         checkHashes(hashes("m3").get(), "org.foo", "org.bar", "m1");
   135     }
   135     }
   136 
   136 
   137     private void checkHashes(ModuleHashes hashes, String... hashModules) {
   137     private void checkHashes(ModuleHashes hashes, String... hashModules) {
   138         assertTrue(hashes.names().equals(Set.of(hashModules)));
   138         assertTrue(hashes.names().equals(Set.of(hashModules)));
   183         });
   183         });
   184     }
   184     }
   185 
   185 
   186     private void compileModule(String moduleName, Path src) throws IOException {
   186     private void compileModule(String moduleName, Path src) throws IOException {
   187         Path msrc = src.resolve(moduleName);
   187         Path msrc = src.resolve(moduleName);
   188         assertTrue(CompilerUtils.compile(msrc, mods, "-modulesourcepath", src.toString()));
   188         assertTrue(CompilerUtils.compile(msrc, mods, "--module-source-path", src.toString()));
   189     }
   189     }
   190 
   190 
   191     private void jmod(String moduleName, String... options) throws IOException {
   191     private void jmod(String moduleName, String... options) throws IOException {
   192         Path mclasses = mods.resolve(moduleName);
   192         Path mclasses = mods.resolve(moduleName);
   193         Path outfile = jmods.resolve(moduleName + ".jmod");
   193         Path outfile = jmods.resolve(moduleName + ".jmod");