< prev index next >

test/jdk/tools/jpackage/linux/base/LicenseBase.java

Print this page




  33     private static String EXT;
  34     private static String OUTPUT;
  35     private static String[] CMD;
  36 
  37     private static void copyResults() throws Exception {
  38         List<String> files = new ArrayList<>();
  39         files.add(OUTPUT.toLowerCase());
  40         JPackageInstallerHelper.copyTestResults(files);
  41     }
  42 
  43     private static void testCreateInstaller() throws Exception {
  44         JPackageHelper.executeCLI(true, CMD);
  45         JPackageInstallerHelper.validateOutput(OUTPUT);
  46         copyResults();
  47     }
  48 
  49     private static void verifyInstall() throws Exception {
  50         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
  51         JPackageInstallerHelper.validateApp(app);
  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         }
  88     }
  89 
  90     private static void verifyUnInstall() throws Exception {
  91         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
  92         File folder = new File(folderPath);
  93         if (folder.exists()) {
  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             }
 104         }
 105     }
 106 
 107     private static void init(String name, String ext) throws Exception {
 108         TEST_NAME = name;
 109         EXT = ext;
 110         if (EXT.equals("rpm")) {
 111             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
 112         } else {
 113             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
 114         }
 115         CMD = new String [] {
 116         "--package-type", EXT,
 117         "--input", "input",
 118         "--output", "output",
 119         "--name", TEST_NAME,


  33     private static String EXT;
  34     private static String OUTPUT;
  35     private static String[] CMD;
  36 
  37     private static void copyResults() throws Exception {
  38         List<String> files = new ArrayList<>();
  39         files.add(OUTPUT.toLowerCase());
  40         JPackageInstallerHelper.copyTestResults(files);
  41     }
  42 
  43     private static void testCreateInstaller() throws Exception {
  44         JPackageHelper.executeCLI(true, CMD);
  45         JPackageInstallerHelper.validateOutput(OUTPUT);
  46         copyResults();
  47     }
  48 
  49     private static void verifyInstall() throws Exception {
  50         String app = JPackagePath.getLinuxInstalledApp(TEST_NAME);
  51         JPackageInstallerHelper.validateApp(app);
  52 
  53         File licenseFile = null;
  54         if (EXT.equals("rpm")) {
  55             licenseFile = getRpmLicenseFileInstallLocation();
  56         } else if (EXT.equals("deb")) {
  57             licenseFile = getDebLicenseFileInstallLocation();
  58         }
  59         if (!licenseFile.exists()) {
  60             throw new AssertionError(
  61                     "Error: " + licenseFile.getAbsolutePath() + " not found");
  62         }
  63     }
  64 
  65     private static File getRpmLicenseFileInstallLocation() throws Exception {
  66         final String infoResult = "infoResult.txt";
  67         int retVal = JPackageHelper.execute(new File(infoResult), "rpm",
  68                 "--eval", "%{_defaultlicensedir}");
  69         if (retVal != 0) {
  70             throw new AssertionError("rpm exited with error: " + retVal);
  71         }
  72 
  73         final String rootLicenseDir = Files.readString(Path.of(infoResult)).replaceAll(
  74                 "(\\r|\\n)", "");
  75 
  76         retVal = JPackageHelper.execute(new File(infoResult), "rpm",
  77                 "-q", "--queryformat", "%{name}-%{version}",
  78                 TEST_NAME.toLowerCase());
  79         if (retVal != 0) {
  80             throw new AssertionError("rpm exited with error: " + retVal);
  81         }
  82 
  83         final String testPackageName = Files.readString(Path.of(infoResult));
  84 
  85         return Path.of(rootLicenseDir, testPackageName, new File(
  86                 JPackagePath.getLicenseFilePath()).getName()).toFile();
  87     }
  88 
  89     private static File getDebLicenseFileInstallLocation() throws Exception {
  90         return Path.of("/usr", "share", "doc", TEST_NAME.toLowerCase(),
  91                 "copyright").toFile();



  92     }
  93 
  94     private static void verifyUnInstall() throws Exception {
  95         String folderPath = JPackagePath.getLinuxInstallFolder(TEST_NAME);
  96         File folder = new File(folderPath);
  97         if (folder.exists()) {
  98             throw new AssertionError(
  99                     "Error: " + folder.getAbsolutePath() + " exist");
 100         }
 101 
 102         if (EXT.equals("rpm")) {
 103             final File licenseFileFolder = getRpmLicenseFileInstallLocation().getParentFile();
 104             if (folder.exists()) {
 105                 throw new AssertionError(
 106                         "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
 107             }
 108         } else if (EXT.equals("deb")) {
 109             final File licenseFileFolder = getDebLicenseFileInstallLocation().getParentFile();
 110             if (folder.exists()) {
 111                 throw new AssertionError(
 112                         "Error: " + licenseFileFolder.getAbsolutePath() + " exist");
 113             }
 114         }
 115     }
 116 
 117     private static void init(String name, String ext) throws Exception {
 118         TEST_NAME = name;
 119         EXT = ext;
 120         if (EXT.equals("rpm")) {
 121             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0-1." + Base.getRpmArch() + "." + EXT;
 122         } else {
 123             OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
 124         }
 125         CMD = new String [] {
 126         "--package-type", EXT,
 127         "--input", "input",
 128         "--output", "output",
 129         "--name", TEST_NAME,
< prev index next >