test/jdk/tools/jpackage/share/AppVersionModuleTest.java
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58647 2c43b89b1679
child 58670 6fb9e12d5595
equal deleted inserted replaced
58647:2c43b89b1679 58648:3bf53ffa9ae7
     1 /*
       
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.io.File;
       
    25 import java.nio.file.Files;
       
    26 
       
    27 /*
       
    28  * @test
       
    29  * @summary jpackage create image using version from main module
       
    30  * @library ../helpers
       
    31  * @build JPackageHelper
       
    32  * @build JPackagePath
       
    33  * @modules jdk.jpackage
       
    34  * @run main/othervm -Xmx512m AppVersionModuleTest
       
    35  */
       
    36 public class AppVersionModuleTest {
       
    37     private static final String OUTPUT = "output";
       
    38     private static final String appCfg = JPackagePath.getAppCfg();
       
    39     private static final String MODULE_VERSION = "2.7";
       
    40     private static final String CLI_VERSION = "3.5";
       
    41 
       
    42     private static final String[] CMD_MODULE_VERSION = {
       
    43         "--package-type", "app-image",
       
    44         "--input", "input",
       
    45         "--dest", OUTPUT,
       
    46         "--name", "test",
       
    47         "--module", "com.hello/com.hello.Hello",
       
    48         "--module-path", "input"
       
    49     };
       
    50 
       
    51     private static final String[] CMD_CLI_VERSION = {
       
    52         "--package-type", "app-image",
       
    53         "--input", "input",
       
    54         "--dest", OUTPUT,
       
    55         "--name", "test",
       
    56         "--module", "com.hello/com.hello.Hello",
       
    57         "--module-path", "input",
       
    58         "--app-version", CLI_VERSION
       
    59     };
       
    60 
       
    61     private static void validate(String version)
       
    62             throws Exception {
       
    63         File outfile = new File(appCfg);
       
    64         if (!outfile.exists()) {
       
    65             throw new AssertionError(appCfg + " was not created");
       
    66         }
       
    67 
       
    68         String output = Files.readString(outfile.toPath());
       
    69         if (version == null) {
       
    70             version = MODULE_VERSION;
       
    71         }
       
    72 
       
    73         String expected = "app.version=" + version;
       
    74         if (!output.contains(expected)) {
       
    75             System.err.println("Expected: " + expected);
       
    76             throw new AssertionError("Cannot find expected entry in config file");
       
    77         }
       
    78     }
       
    79 
       
    80     private static void testVersion() throws Exception {
       
    81         JPackageHelper.executeCLI(true, CMD_MODULE_VERSION);
       
    82         validate(null);
       
    83         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    84         JPackageHelper.executeCLI(true, CMD_CLI_VERSION);
       
    85         validate(CLI_VERSION);
       
    86     }
       
    87 
       
    88     private static void testVersionToolProvider() throws Exception {
       
    89         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    90         JPackageHelper.executeToolProvider(true, CMD_MODULE_VERSION);
       
    91         validate(null);
       
    92         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    93         JPackageHelper.executeToolProvider(true, CMD_CLI_VERSION);
       
    94         validate(CLI_VERSION);
       
    95     }
       
    96 
       
    97     public static void main(String[] args) throws Exception {
       
    98         JPackageHelper.createHelloModule(
       
    99                 new JPackageHelper.ModuleArgs(MODULE_VERSION, null));
       
   100         testVersion();
       
   101         testVersionToolProvider();
       
   102     }
       
   103 
       
   104 }