test/jdk/tools/jlink/JLinkReproducibleTest.java
changeset 58843 63994dedec49
parent 52814 abccada595dd
equal deleted inserted replaced
58842:6c255334120d 58843:63994dedec49
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, 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.
    41         var pb = new ProcessBuilder(cmd.toArray(new String[0]));
    41         var pb = new ProcessBuilder(cmd.toArray(new String[0]));
    42         var res = ProcessTools.executeProcess(pb);
    42         var res = ProcessTools.executeProcess(pb);
    43         res.shouldHaveExitValue(0);
    43         res.shouldHaveExitValue(0);
    44     }
    44     }
    45 
    45 
    46     private static void jlink(Path image) throws Exception {
    46     private static void jlink(Path image, boolean with_default_trace_file) throws Exception {
    47         var cmd = new ArrayList<String>();
    47         var cmd = new ArrayList<String>();
    48         cmd.add(JDKToolFinder.getJDKTool("jlink"));
    48         cmd.add(JDKToolFinder.getJDKTool("jlink"));
    49         cmd.addAll(List.of(
    49         cmd.addAll(List.of(
    50             "--module-path", JMODS_DIR.toString() + File.pathSeparator + CLASS_DIR.toString(),
    50             "--module-path", JMODS_DIR.toString() + File.pathSeparator + CLASS_DIR.toString(),
    51             "--add-modules", "main",
    51             "--add-modules", "main",
    52             "--compress=2",
    52             "--compress=2",
    53             "--output", image.toString()
    53             "--output", image.toString()
    54         ));
    54         ));
       
    55         if (!with_default_trace_file) {
       
    56             cmd.add("--generate-jli-classes=@file-not-exists");
       
    57         }
    55         run(cmd);
    58         run(cmd);
    56     }
    59     }
    57 
    60 
    58     private static void javac(String... args) throws Exception {
    61     private static void javac(String... args) throws Exception {
    59         var cmd = new ArrayList<String>();
    62         var cmd = new ArrayList<String>();
    96               "--module", "main",
    99               "--module", "main",
    97               "-d", CLASS_DIR.toString());
   100               "-d", CLASS_DIR.toString());
    98 
   101 
    99         // Link the first image
   102         // Link the first image
   100         var firstImage = Path.of("image-first");
   103         var firstImage = Path.of("image-first");
   101         jlink(firstImage);
   104         jlink(firstImage, true);
   102         var firstModulesFile = firstImage.resolve("lib")
   105         var firstModulesFile = firstImage.resolve("lib")
   103                                          .resolve("modules");
   106                                          .resolve("modules");
   104 
   107 
   105         // Link the second image
   108         // Link the second image
   106         var secondImage = Path.of("image-second");
   109         var secondImage = Path.of("image-second");
   107         jlink(secondImage);
   110         jlink(secondImage, true);
   108         var secondModulesFile = secondImage.resolve("lib")
   111         var secondModulesFile = secondImage.resolve("lib")
   109                                            .resolve("modules");
   112                                            .resolve("modules");
   110 
   113 
   111         // Ensure module files are identical
   114         // Ensure module files are identical
   112         assertEquals(-1L, Files.mismatch(firstModulesFile, secondModulesFile));
   115         assertEquals(-1L, Files.mismatch(firstModulesFile, secondModulesFile));
       
   116 
       
   117         // Link the third image
       
   118         var thirdImage = Path.of("image-third");
       
   119         jlink(thirdImage, false);
       
   120         var thirdModulesFile = thirdImage.resolve("lib")
       
   121                                          .resolve("modules");
       
   122         // Link the fourth image
       
   123         var fourthImage = Path.of("image-fourth");
       
   124         jlink(fourthImage, false);
       
   125         var fourthModulesFile = fourthImage.resolve("lib")
       
   126                                            .resolve("modules");
       
   127 
       
   128         // Ensure module files are identical
       
   129         assertEquals(-1L, Files.mismatch(thirdModulesFile, fourthModulesFile));
   113     }
   130     }
   114 }
   131 }