1 /*
   2  * Copyright (c) 2018, 2020, 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 package jdk.jpackage.tests;
  25 
  26 import java.util.Collection;
  27 import java.util.List;
  28 import jdk.jpackage.test.Annotations.Parameters;
  29 import jdk.jpackage.test.Annotations.Test;
  30 import jdk.jpackage.test.JPackageCommand;
  31 import jdk.jpackage.test.HelloApp;
  32 import jdk.jpackage.test.Executor;
  33 import jdk.jpackage.test.TKit;
  34 
  35 /*
  36  * @test
  37  * @summary jpackage create image with --java-options test
  38  * @library ../../../../helpers
  39  * @build jdk.jpackage.test.*
  40  * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
  41  * @compile JavaOptionsEqualsTest.java
  42  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
  43  *  --jpt-run=jdk.jpackage.tests.JavaOptionsEqualsTest
  44  *  --jpt-before-run=jdk.jpackage.test.JPackageCommand.useExecutableByDefault
  45  */
  46 
  47 /*
  48  * @test
  49  * @summary jpackage create image with --java-options test
  50  * @library ../../../../helpers
  51  * @build jdk.jpackage.test.*
  52  * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
  53  * @compile JavaOptionsEqualsTest.java
  54  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
  55  *  --jpt-run=jdk.jpackage.tests.JavaOptionsEqualsTest
  56  *  --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault
  57  */
  58 
  59 public class JavaOptionsEqualsTest {
  60 
  61     private final static String OPTION1 =
  62         "--add-exports=java.base/sun.util=me.mymodule.foo,ALL-UNNAMED";
  63     private final static String OPTION2 =
  64         "--add-exports=java.base/sun.security.util=other.mod.bar,ALL-UNNAMED";
  65     private final static String WARNING1 =
  66         "WARNING: Unknown module: me.mymodule.foo";
  67     private final static String WARNING2 =
  68         "WARNING: Unknown module: other.mod.bar";
  69 
  70     private final JPackageCommand cmd;
  71 
  72     @Parameters
  73     public static Collection input() {
  74         return List.of(new Object[][]{
  75             {"Hello", new String[]{"--java-options", OPTION1,
  76                                    "--java-options", OPTION2 },
  77             },
  78         });
  79     }
  80 
  81     public JavaOptionsEqualsTest(String javaAppDesc, String[] jpackageArgs) {
  82         cmd = JPackageCommand.helloAppImage(javaAppDesc);
  83         if (jpackageArgs != null) {
  84             cmd.addArguments(jpackageArgs);
  85         }
  86     }
  87 
  88     @Test
  89     public void test() {
  90         cmd.executeAndAssertHelloAppImageCreated();
  91         List<String> output = HelloApp.executeLauncher(cmd).getOutput();
  92         TKit.assertNotNull(output, "output is null");
  93         TKit.assertTextStream(WARNING1).apply(output.stream());
  94         TKit.assertTextStream(WARNING2).apply(output.stream());
  95     }
  96 }