jdk/test/tools/jlink/plugins/ExcludeVMPluginTest.java
changeset 38320 e24c7029e8ba
parent 36511 9d0388c6b336
child 39151 34455cc82f5e
equal deleted inserted replaced
37948:caf97b37ebec 38320:e24c7029e8ba
    30  * @run main ExcludeVMPluginTest
    30  * @run main ExcludeVMPluginTest
    31  */
    31  */
    32 import java.io.ByteArrayInputStream;
    32 import java.io.ByteArrayInputStream;
    33 import java.util.HashMap;
    33 import java.util.HashMap;
    34 import java.util.Map;
    34 import java.util.Map;
    35 import jdk.tools.jlink.internal.PoolImpl;
    35 import jdk.tools.jlink.internal.ModulePoolImpl;
    36 
    36 
    37 import jdk.tools.jlink.internal.plugins.ExcludeVMPlugin;
    37 import jdk.tools.jlink.internal.plugins.ExcludeVMPlugin;
    38 import jdk.tools.jlink.plugin.Plugin;
    38 import jdk.tools.jlink.plugin.Plugin;
    39 import jdk.tools.jlink.plugin.Pool;
    39 import jdk.tools.jlink.plugin.ModulePool;
    40 import jdk.tools.jlink.plugin.Pool.ModuleData;
    40 import jdk.tools.jlink.plugin.ModuleEntry;
    41 import jdk.tools.jlink.plugin.Pool.ModuleDataType;
       
    42 import jdk.tools.jlink.plugin.TransformerPlugin;
    41 import jdk.tools.jlink.plugin.TransformerPlugin;
    43 
    42 
    44 public class ExcludeVMPluginTest {
    43 public class ExcludeVMPluginTest {
    45 
    44 
    46     private static final String TAG = "# orig in test\n";
    45     private static final String TAG = "# orig in test\n";
   163     }
   162     }
   164 
   163 
   165     private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
   164     private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
   166         // Create a pool with jvm.cfg and the input paths.
   165         // Create a pool with jvm.cfg and the input paths.
   167         byte[] jvmcfgContent = jvmcfg.getBytes();
   166         byte[] jvmcfgContent = jvmcfg.getBytes();
   168         Pool pool = new PoolImpl();
   167         ModulePool pool = new ModulePoolImpl();
   169         pool.add(Pool.newImageFile("java.base", "/java.base/native/jvm.cfg",
   168         pool.add(ModuleEntry.create("java.base", "/java.base/native/jvm.cfg",
   170                 ModuleDataType.NATIVE_LIB, new ByteArrayInputStream(jvmcfgContent), jvmcfgContent.length));
   169                 ModuleEntry.Type.NATIVE_LIB, new ByteArrayInputStream(jvmcfgContent), jvmcfgContent.length));
   171         for (String in : input) {
   170         for (String in : input) {
   172             pool.add(Pool.newImageFile("java.base", in,
   171             pool.add(ModuleEntry.create("java.base", in,
   173                     ModuleDataType.NATIVE_LIB, new ByteArrayInputStream(new byte[0]), 0));
   172                     ModuleEntry.Type.NATIVE_LIB, new ByteArrayInputStream(new byte[0]), 0));
   174         }
   173         }
   175         Pool out = new PoolImpl();
   174         ModulePool out = new ModulePoolImpl();
   176 
   175 
   177         TransformerPlugin p = new ExcludeVMPlugin();
   176         TransformerPlugin p = new ExcludeVMPlugin();
   178         Map<String, String> config = new HashMap<>();
   177         Map<String, String> config = new HashMap<>();
   179         if (vm != null) {
   178         if (vm != null) {
   180             config.put(ExcludeVMPlugin.NAME, vm);
   179             config.put(ExcludeVMPlugin.NAME, vm);
   181         }
   180         }
   182         p.configure(config);
   181         p.configure(config);
   183         p.visit(pool, out);
   182         p.visit(pool, out);
   184 
   183 
   185         String newContent = new String(out.get("/java.base/native/jvm.cfg").stream().readAllBytes());
   184         String newContent = new String(out.findEntry("/java.base/native/jvm.cfg").get().stream().readAllBytes());
   186 
   185 
   187         if (!expectdJvmCfg.equals(newContent)) {
   186         if (!expectdJvmCfg.equals(newContent)) {
   188             throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg);
   187             throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg);
   189         }
   188         }
   190 
   189 
   191         if (out.getContent().size() != (expectedOutput.length + 1)) {
   190         if (out.getEntryCount() != (expectedOutput.length + 1)) {
   192             for (ModuleData m : out.getContent()) {
   191             out.entries().forEach(m -> {
   193                 System.err.println(m.getPath());
   192                 System.err.println(m.getPath());
   194             }
   193             });
   195             throw new Exception("Invalid output size " + out.getContent().size() + " expected " + (expectedOutput.length + 1));
   194             throw new Exception("Invalid output size " + out.getEntryCount() + " expected " + (expectedOutput.length + 1));
   196         }
   195         }
   197 
   196 
   198         for (ModuleData md : out.getContent()) {
   197         out.entries().forEach(md -> {
   199             if (md.getPath().equals("/java.base/native/jvm.cfg")) {
   198             if (md.getPath().equals("/java.base/native/jvm.cfg")) {
   200                 continue;
   199                 return;
   201             }
   200             }
   202             boolean contained = false;
   201             boolean contained = false;
   203             for (String o : expectedOutput) {
   202             for (String o : expectedOutput) {
   204                 if (md.getPath().equals(o)) {
   203                 if (md.getPath().equals(o)) {
   205                     contained = true;
   204                     contained = true;
   206                     break;
   205                     break;
   207                 }
   206                 }
   208             }
   207             }
   209             if (!contained) {
   208             if (!contained) {
   210                 throw new Exception(md.getPath() + " not expected");
   209                 throw new RuntimeException(md.getPath() + " not expected");
   211             }
   210             }
   212         }
   211         });
   213 
   212 
   214     }
   213     }
   215 
   214 
   216     private static boolean isWindows() {
   215     private static boolean isWindows() {
   217         return System.getProperty("os.name").startsWith("Windows");
   216         return System.getProperty("os.name").startsWith("Windows");