test/jdk/tools/jpackage/share/LicenseTest.java
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58418 7cd20dbeee36
child 58761 88e2753a2334
equal deleted inserted replaced
58647:2c43b89b1679 58648:3bf53ffa9ae7
    36 import jdk.jpackage.test.LinuxHelper;
    36 import jdk.jpackage.test.LinuxHelper;
    37 import jdk.jpackage.test.Executor;
    37 import jdk.jpackage.test.Executor;
    38 import jdk.jpackage.test.TKit;
    38 import jdk.jpackage.test.TKit;
    39 
    39 
    40 /**
    40 /**
    41  * Test --license-file parameter. Output of the test should be licensetest*.*
    41  * Test --license-file parameter. Output of the test should be commonlicensetest*.*
    42  * package bundle. The output package should provide the same functionality as
    42  * package bundle. The output package should provide the same functionality as
    43  * the default package and also incorporate license information from
    43  * the default package and also incorporate license information from
    44  * test/jdk/tools/jpackage/resources/license.txt file from OpenJDK repo.
    44  * test/jdk/tools/jpackage/resources/license.txt file from OpenJDK repo.
    45  *
    45  *
    46  * deb:
    46  * deb:
    47  *
    47  *
    48  * Package should install license file /usr/share/doc/licensetest/copyright
    48  * Package should install license file /opt/commonlicensetest/share/doc/copyright
    49  * file.
    49  * file.
    50  *
    50  *
    51  * rpm:
    51  * rpm:
    52  *
    52  *
    53  * Package should install license file in
    53  * Package should install license file in
    86 
    86 
    87 public class LicenseTest {
    87 public class LicenseTest {
    88     public static void testCommon() {
    88     public static void testCommon() {
    89         new PackageTest().configureHelloApp()
    89         new PackageTest().configureHelloApp()
    90         .addInitializer(cmd -> {
    90         .addInitializer(cmd -> {
    91             Path licenseCopy = TKit.workDir().resolve(LICENSE_FILE.getFileName()).toAbsolutePath().normalize();
    91             cmd.addArguments("--license-file", TKit.createRelativePathCopy(
    92             Files.copy(LICENSE_FILE, licenseCopy,
    92                     LICENSE_FILE));
    93                     StandardCopyOption.REPLACE_EXISTING);
       
    94             final Path basePath = Path.of(".").toAbsolutePath().normalize();
       
    95             try {
       
    96                 licenseCopy = basePath.relativize(licenseCopy);
       
    97             } catch (IllegalArgumentException ex) {
       
    98                 // May happen on Windows: java.lang.IllegalArgumentException: 'other' has different root
       
    99                 TKit.trace(String.format(
       
   100                         "Not using relative path to license file for --license-file parameter. Failed to relativize [%s] at [%s]",
       
   101                         licenseCopy, basePath));
       
   102                 ex.printStackTrace();
       
   103             }
       
   104             cmd.addArguments("--license-file", licenseCopy);
       
   105         })
    93         })
   106         .forTypes(PackageType.LINUX)
    94         .forTypes(PackageType.LINUX)
   107         .addBundleVerifier(cmd -> {
    95         .addBundleVerifier(cmd -> {
   108             verifyLicenseFileInLinuxPackage(cmd, linuxLicenseFile(cmd));
    96             verifyLicenseFileInLinuxPackage(cmd, linuxLicenseFile(cmd));
   109         })
    97         })