test/jdk/tools/jpackage/helpers/JPackageHelper.java
branchJDK-8200758-branch
changeset 58360 fd45b7e2c027
parent 58359 e065fd274bc1
child 58888 d802578912f3
equal deleted inserted replaced
58359:e065fd274bc1 58360:fd45b7e2c027
    48     private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
    48     private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin");
    49     private static final Path JPACKAGE;
    49     private static final Path JPACKAGE;
    50     private static final Path JAVAC;
    50     private static final Path JAVAC;
    51     private static final Path JAR;
    51     private static final Path JAR;
    52     private static final Path JLINK;
    52     private static final Path JLINK;
       
    53 
       
    54     public static class ModuleArgs {
       
    55         private final String version;
       
    56         private final String mainClass;
       
    57 
       
    58         ModuleArgs(String version, String mainClass) {
       
    59             this.version = version;
       
    60             this.mainClass = mainClass;
       
    61         }
       
    62 
       
    63         public String getVersion() {
       
    64             return version;
       
    65         }
       
    66 
       
    67         public String getMainClass() {
       
    68             return mainClass;
       
    69         }
       
    70     }
    53 
    71 
    54     static {
    72     static {
    55         if (OS.startsWith("win")) {
    73         if (OS.startsWith("win")) {
    56             JPACKAGE = BIN_DIR.resolve("jpackage.exe");
    74             JPACKAGE = BIN_DIR.resolve("jpackage.exe");
    57             JAVAC = BIN_DIR.resolve("javac.exe");
    75             JAVAC = BIN_DIR.resolve("javac.exe");
   373 
   391 
   374     public static void createHelloModule() throws Exception {
   392     public static void createHelloModule() throws Exception {
   375         createModule("Hello.java", "input", "hello", null, true);
   393         createModule("Hello.java", "input", "hello", null, true);
   376     }
   394     }
   377 
   395 
   378     public static void createHelloModule(String version) throws Exception {
   396     public static void createHelloModule(ModuleArgs moduleArgs) throws Exception {
   379         createModule("Hello.java", "input", "hello", version, true);
   397         createModule("Hello.java", "input", "hello", moduleArgs, true);
   380     }
   398     }
   381 
   399 
   382     public static void createOtherModule() throws Exception {
   400     public static void createOtherModule() throws Exception {
   383         createModule("Other.java", "input-other", "other", null, false);
   401         createModule("Other.java", "input-other", "other", null, false);
   384     }
   402     }
   385 
   403 
   386     private static void createModule(String javaFile, String inputDir,
   404     private static void createModule(String javaFile, String inputDir, String aName,
   387             String aName, String version, boolean createModularJar) throws Exception {
   405             ModuleArgs moduleArgs, boolean createModularJar) throws Exception {
   388         int retVal;
   406         int retVal;
   389 
   407 
   390         File input = new File(inputDir);
   408         File input = new File(inputDir);
   391         if (!input.exists()) {
   409         if (!input.exists()) {
   392             input.mkdir();
   410             input.mkdir();
   429                 List<String> args = new ArrayList<>();
   447                 List<String> args = new ArrayList<>();
   430                 args.add(JAR.toString());
   448                 args.add(JAR.toString());
   431                 args.add("--create");
   449                 args.add("--create");
   432                 args.add("--file");
   450                 args.add("--file");
   433                 args.add(inputDir + File.separator + "com." + aName + ".jar");
   451                 args.add(inputDir + File.separator + "com." + aName + ".jar");
   434                 if (version != null) {
   452                 if (moduleArgs != null) {
   435                     args.add("--module-version");
   453                     if (moduleArgs.getVersion() != null) {
   436                     args.add(version);
   454                         args.add("--module-version");
       
   455                         args.add(moduleArgs.getVersion());
       
   456                     }
       
   457 
       
   458                     if (moduleArgs.getMainClass()!= null) {
       
   459                         args.add("--main-class");
       
   460                         args.add(moduleArgs.getMainClass());
       
   461                     }
   437                 }
   462                 }
   438                 args.add("-C");
   463                 args.add("-C");
   439                 args.add("module" + File.separator + "com." + aName);
   464                 args.add("module" + File.separator + "com." + aName);
   440                 args.add(".");
   465                 args.add(".");
   441 
   466