src/jdk.packager/share/classes/jdk/packager/internal/DeployParams.java
branchJDK-8200758-branch
changeset 56985 5e6ced665587
parent 56982 e094d5483bd6
child 56987 0d2ff0d6bb94
equal deleted inserted replaced
56984:51600bf3a6e7 56985:5e6ced665587
   295         return testFile.isAbsolute() ?
   295         return testFile.isAbsolute() ?
   296                 testFile : new File(baseDir == null ?
   296                 testFile : new File(baseDir == null ?
   297                         null : baseDir.getAbsolutePath(), path);
   297                         null : baseDir.getAbsolutePath(), path);
   298     }
   298     }
   299 
   299 
       
   300     public static void validateAppName(String s) throws PackagerException {
       
   301         if (s == null || s.length() == 0) {
       
   302             // empty or null string - there is no unsupported char
       
   303             return;
       
   304         }
       
   305 
       
   306         int last = s.length() - 1;
       
   307 
       
   308         char fc = s.charAt(0);
       
   309         char lc = s.charAt(last);
       
   310 
       
   311         // illegal to end in backslash escape char
       
   312         if (lc == '\\') {
       
   313             throw new PackagerException("ERR_InvalidCharacterInArgument", "--name");
       
   314         }
       
   315 
       
   316         for (int i = 0; i < s.length(); i++) {
       
   317             char a = s.charAt(i);
       
   318             // We check for ASCII codes first which we accept. If check fails,
       
   319             // then check if it is acceptable extended ASCII or unicode character.
       
   320             if (a < ' ' || a > '~' || a == '%') {
       
   321                 // Reject '%', whitespaces and ISO Control.
       
   322                 // Accept anything else including special characters like copyright
       
   323                 // symbols. Note: space will be included by ASCII check above,
       
   324                 // but other whitespace like tabs or new line will be ignored.
       
   325                 if (Character.isISOControl(a) || Character.isWhitespace(a) || a == '%') {
       
   326                     throw new PackagerException("ERR_InvalidCharacterInArgument", "--name");
       
   327                 }
       
   328             }
       
   329             if (a == '"') {
       
   330                 throw new PackagerException("ERR_InvalidCharacterInArgument", "--name");
       
   331             }
       
   332         }
       
   333     }
   300 
   334 
   301     @Override
   335     @Override
   302     public void validate() throws PackagerException {
   336     public void validate() throws PackagerException {
   303         if (outdir == null) {
   337         if (outdir == null) {
   304             throw new PackagerException("ERR_MissingArgument", "--output");
   338             throw new PackagerException("ERR_MissingArgument", "--output");
   325             if (!hasMain) {
   359             if (!hasMain) {
   326                 throw new PackagerException("ERR_MissingArgument",
   360                 throw new PackagerException("ERR_MissingArgument",
   327                         "--main-jar");
   361                         "--main-jar");
   328             }
   362             }
   329         }
   363         }
       
   364 
       
   365         String name = (String)bundlerArguments.get(Arguments.CLIOptions.NAME.getId());
       
   366         validateAppName(name);
   330 
   367 
   331         // Validate app image if set
   368         // Validate app image if set
   332         String appImage = (String)bundlerArguments.get(
   369         String appImage = (String)bundlerArguments.get(
   333                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
   370                 Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
   334         if (appImage != null) {
   371         if (appImage != null) {