src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java
branchJDK-8200758-branch
changeset 57450 82c78b40b39d
parent 57446 5a5b85f00a63
child 57687 c56bbf4aaf98
equal deleted inserted replaced
57448:ac7b7fe5f7d8 57450:82c78b40b39d
    66 
    66 
    67     public abstract void prepareApplicationFiles() throws IOException;
    67     public abstract void prepareApplicationFiles() throws IOException;
    68     public abstract void prepareJreFiles() throws IOException;
    68     public abstract void prepareJreFiles() throws IOException;
    69     public abstract Path getAppDir();
    69     public abstract Path getAppDir();
    70     public abstract Path getAppModsDir();
    70     public abstract Path getAppModsDir();
    71     public abstract String getRelativeModsDir();
       
    72 
    71 
    73     public Path getRoot() {
    72     public Path getRoot() {
    74         return this.root;
    73         return this.root;
    75     }
    74     }
    76 
    75 
   171             return result;
   170             return result;
   172         }
   171         }
   173     }
   172     }
   174 
   173 
   175     public void writeCfgFile(Map<String, ? super Object> params,
   174     public void writeCfgFile(Map<String, ? super Object> params,
   176             File cfgFileName, String runtimeLocation) throws IOException {
   175             File cfgFileName) throws IOException {
   177         cfgFileName.delete();
   176         cfgFileName.delete();
   178         File mainJar = JLinkBundlerHelper.getMainJar(params);
   177         File mainJar = JLinkBundlerHelper.getMainJar(params);
   179         ModFile.ModType mainJarType = ModFile.ModType.Unknown;
   178         ModFile.ModType mainJarType = ModFile.ModType.Unknown;
   180 
   179 
   181         if (mainJar != null) {
   180         if (mainJar != null) {
   187         try (PrintStream out = new PrintStream(cfgFileName)) {
   186         try (PrintStream out = new PrintStream(cfgFileName)) {
   188 
   187 
   189             out.println("[Application]");
   188             out.println("[Application]");
   190             out.println("app.name=" + APP_NAME.fetchFrom(params));
   189             out.println("app.name=" + APP_NAME.fetchFrom(params));
   191             out.println("app.version=" + VERSION.fetchFrom(params));
   190             out.println("app.version=" + VERSION.fetchFrom(params));
   192             out.println("app.runtime=" + runtimeLocation);
   191             out.println("app.runtime=" + getCfgRuntimeDir());
   193             out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
   192             out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
   194             out.println("app.classpath=" + CLASSPATH.fetchFrom(params));
   193             out.println("app.classpath="
       
   194                     + getCfgClassPath(CLASSPATH.fetchFrom(params)));
   195 
   195 
   196             // The main app is required to be a jar, modular or unnamed.
   196             // The main app is required to be a jar, modular or unnamed.
   197             if (mainModule != null &&
   197             if (mainModule != null &&
   198                     (mainJarType == ModFile.ModType.Unknown ||
   198                     (mainJarType == ModFile.ModType.Unknown ||
   199                     mainJarType == ModFile.ModType.ModularJar)) {
   199                     mainJarType == ModFile.ModType.ModularJar)) {
   202                 String mainClass = JLinkBundlerHelper.getMainClass(params);
   202                 String mainClass = JLinkBundlerHelper.getMainClass(params);
   203                 // If the app is contained in an unnamed jar then launch it the
   203                 // If the app is contained in an unnamed jar then launch it the
   204                 // legacy way and the main class string must be
   204                 // legacy way and the main class string must be
   205                 // of the format com/foo/Main
   205                 // of the format com/foo/Main
   206                 if (mainJar != null) {
   206                 if (mainJar != null) {
   207                     out.println("app.mainjar="
   207                     out.println("app.mainjar=" + getCfgAppDir()
   208                             + mainJar.toPath().getFileName().toString());
   208                             + mainJar.toPath().getFileName().toString());
   209                 }
   209                 }
   210                 if (mainClass != null) {
   210                 if (mainClass != null) {
   211                     out.println("app.mainclass="
   211                     out.println("app.mainclass="
   212                             + mainClass.replaceAll("\\.", "/"));
   212                             + mainClass.replace("\\", "/"));
   213                 }
   213                 }
   214             }
   214             }
   215 
   215 
   216             out.println();
   216             out.println();
   217             out.println("[JavaOptions]");
   217             out.println("[JavaOptions]");
   221             }
   221             }
   222             Path modsDir = getAppModsDir();
   222             Path modsDir = getAppModsDir();
   223 
   223 
   224             if (modsDir != null && modsDir.toFile().exists()) {
   224             if (modsDir != null && modsDir.toFile().exists()) {
   225                 out.println("--module-path");
   225                 out.println("--module-path");
   226                 out.println("$APPDIR/" + getRelativeModsDir());
   226                 out.println(getCfgAppDir().replace("\\","/") + "mods");
   227             }
   227             }
   228 
   228 
   229             out.println();
   229             out.println();
   230             out.println("[ArgOptions]");
   230             out.println("[ArgOptions]");
   231             List<String> args = ARGUMENTS.fetchFrom(params);
   231             List<String> args = ARGUMENTS.fetchFrom(params);
   239                 }
   239                 }
   240             }
   240             }
   241         }
   241         }
   242     }
   242     }
   243 
   243 
       
   244     String getCfgAppDir() {
       
   245         return "$APPDIR" + File.separator
       
   246                 + getAppDir().getFileName() + File.separator;
       
   247     }
       
   248 
       
   249     String getCfgRuntimeDir() {
       
   250         return "$APPDIR" + File.separator + "runtime";
       
   251     }
       
   252 
       
   253     String getCfgClassPath(String classpath) {
       
   254         String cfgAppDir = getCfgAppDir();
       
   255 
       
   256         StringBuilder sb = new StringBuilder();
       
   257         for (String path : classpath.split("[:;]")) {
       
   258             if (path.length() > 0) {
       
   259                 sb.append(cfgAppDir);
       
   260                 sb.append(path);
       
   261                 sb.append(File.pathSeparator);
       
   262             }
       
   263         }
       
   264         if (sb.length() > 0) {
       
   265             sb.deleteCharAt(sb.length() - 1);
       
   266         }
       
   267         return sb.toString();
       
   268     }
   244 }
   269 }