src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java
branchJDK-8200758-branch
changeset 57080 bd4ce7f9ea2c
parent 57067 9c17d779808e
child 57091 06bc4bd64599
equal deleted inserted replaced
57079:c53a2eca0f57 57080:bd4ce7f9ea2c
   189                 APP_NAME.fetchFrom(params) + "-license.plist");
   189                 APP_NAME.fetchFrom(params) + "-license.plist");
   190     }
   190     }
   191 
   191 
   192     private void prepareLicense(Map<String, ? super Object> params) {
   192     private void prepareLicense(Map<String, ? super Object> params) {
   193         try {
   193         try {
   194             File licFile = null;
   194             String licFileStr = LICENSE_FILE.fetchFrom(params);
   195 
   195             if (licFileStr == null) {
   196             List<String> licFiles = LICENSE_FILE.fetchFrom(params);
       
   197             if (licFiles.isEmpty()) {
       
   198                 return;
   196                 return;
   199             }
   197             }
   200             String licFileStr = licFiles.get(0);
   198 
   201 
   199             File licFile = new File(licFileStr);
   202             for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(params)) {
       
   203                 if (rfs.contains(licFileStr)) {
       
   204                     licFile = new File(rfs.getBaseDirectory(), licFileStr);
       
   205                     break;
       
   206                 }
       
   207             }
       
   208 
       
   209             if (licFile == null) {
       
   210                 // this is NPE protection,
       
   211                 // validate should have already caught it's absence
       
   212                 Log.error("Licence file is null");
       
   213                 return;
       
   214             }
       
   215 
       
   216             byte[] licenseContentOriginal = Files.readAllBytes(licFile.toPath());
   200             byte[] licenseContentOriginal = Files.readAllBytes(licFile.toPath());
   217             String licenseInBase64 =
   201             String licenseInBase64 =
   218                     Base64.getEncoder().encodeToString(licenseContentOriginal);
   202                     Base64.getEncoder().encodeToString(licenseContentOriginal);
   219 
   203 
   220             Map<String, String> data = new HashMap<>();
   204             Map<String, String> data = new HashMap<>();
   533 
   517 
   534             //run basic validation to ensure requirements are met
   518             //run basic validation to ensure requirements are met
   535             //we are not interested in return code, only possible exception
   519             //we are not interested in return code, only possible exception
   536             validateAppImageAndBundeler(params);
   520             validateAppImageAndBundeler(params);
   537 
   521 
   538             // validate license file, if used, exists in the proper place
       
   539             if (params.containsKey(LICENSE_FILE.getID())) {
       
   540                 List<RelativeFileSet> appResourcesList =
       
   541                     APP_RESOURCES_LIST.fetchFrom(params);
       
   542                 for (String license : LICENSE_FILE.fetchFrom(params)) {
       
   543                     boolean found = false;
       
   544                     for (RelativeFileSet appResources : appResourcesList) {
       
   545                         found = found || appResources.contains(license);
       
   546                     }
       
   547                     if (!found) {
       
   548                         throw new ConfigException(
       
   549                                 I18N.getString("error.license-missing"),
       
   550                                 MessageFormat.format(I18N.getString(
       
   551                                 "error.license-missing.advice"), license));
       
   552                     }
       
   553                 }
       
   554             }
       
   555 
       
   556             return true;
   522             return true;
   557         } catch (RuntimeException re) {
   523         } catch (RuntimeException re) {
   558             if (re.getCause() instanceof ConfigException) {
   524             if (re.getCause() instanceof ConfigException) {
   559                 throw (ConfigException) re.getCause();
   525                 throw (ConfigException) re.getCause();
   560             } else {
   526             } else {