test/jdk/tools/jpackage/linux/base/LicenseBase.java
branchJDK-8200758-branch
changeset 57742 e3d4b9bc5093
parent 57543 bcd1ab268a7d
child 57807 4a15115716ea
equal deleted inserted replaced
57741:38856ef4a19c 57742:e3d4b9bc5093
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.File;
    24 import java.io.File;
       
    25 import java.nio.file.Files;
       
    26 import java.nio.file.Path;
    25 import java.util.ArrayList;
    27 import java.util.ArrayList;
    26 import java.util.List;
    28 import java.util.List;
    27 
    29 
    28 public class LicenseBase {
    30 public class LicenseBase {
    29 
    31 
    46 
    48 
    47     private static void verifyInstall() throws Exception {
    49     private static void verifyInstall() throws Exception {
    48         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
    50         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
    49         JPackageInstallerHelper.validateApp(app);
    51         JPackageInstallerHelper.validateApp(app);
    50 
    52 
       
    53         if (EXT.equals("rpm")) {
       
    54             verifyInstallRpm();
       
    55         }
       
    56     }
       
    57 
       
    58     private static File getRpmLicenseFileInstallLocation() throws Exception {
       
    59         final String infoResult = "infoResult.txt";
       
    60         int retVal = JPackageHelper.execute(new File(infoResult), "rpm",
       
    61                 "--eval", "%{_defaultlicensedir}");
       
    62         if (retVal != 0) {
       
    63             throw new AssertionError("rpm exited with error: " + retVal);
       
    64         }
       
    65 
       
    66         final String rootLicenseDir = Files.readString(Path.of(infoResult)).replaceAll(
       
    67                 "(\\r|\\n)", "");
       
    68 
       
    69         retVal = JPackageHelper.execute(new File(infoResult), "rpm",
       
    70                 "-qp", "--queryformat", "%{name}-%{version}",
       
    71                 OUTPUT.toLowerCase());
       
    72         if (retVal != 0) {
       
    73             throw new AssertionError("rpm exited with error: " + retVal);
       
    74         }
       
    75 
       
    76         final String testPackageName = Files.readString(Path.of(infoResult));
       
    77 
       
    78         return Path.of(rootLicenseDir, testPackageName, new File(
       
    79                 JPackagePath.getLicenseFilePath()).getName()).toFile();
       
    80     }
       
    81 
       
    82     private static void verifyInstallRpm() throws Exception {
       
    83         final File licenseFile = getRpmLicenseFileInstallLocation();
       
    84         if (!licenseFile.exists()) {
       
    85             throw new AssertionError(
       
    86                     "Error: " + licenseFile.getAbsolutePath() + " not found");
       
    87         }
    51     }
    88     }
    52 
    89 
    53     private static void verifyUnInstall() throws Exception {
    90     private static void verifyUnInstall() throws Exception {
    54         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
    91         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
    55         File folder = new File(folderPath);
    92         File folder = new File(folderPath);
    56         if (folder.exists()) {
    93         if (folder.exists()) {
    57             throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
    94             throw new AssertionError(
       
    95                     "Error: " + folder.getAbsolutePath() + " exist");
       
    96         }
       
    97 
       
    98         if (EXT.equals("rpm")) {
       
    99             final File licenseFileFolder = getRpmLicenseFileInstallLocation().getParentFile();
       
   100             if (folder.exists()) {
       
   101                 throw new AssertionError(
       
   102                         "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
       
   103             }
    58         }
   104         }
    59     }
   105     }
    60 
   106 
    61     private static void init(String name, String ext) throws Exception {
   107     private static void init(String name, String ext) throws Exception {
    62         TEST_NAME = name;
   108         TEST_NAME = name;