1 /*
2  * Copyright (c) 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
opDoubleArrayAsync(std::pair<const Ice::Double *,const Ice::Double * > in,std::function<void (const Test::DoubleSeq &,const Test::DoubleSeq &)> response,std::function<void (std::exception_ptr)>,const Ice::Current &)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;
opByteArrayAsync(std::pair<const Ice::Byte *,const Ice::Byte * > in,std::function<void (const std::pair<const Ice::Byte *,const Ice::Byte * > &,const std::pair<const Ice::Byte *,const Ice::Byte * > &)> response,std::function<void (std::exception_ptr)>,const Ice::Current &)29 import jdk.jpackage.test.Annotations.Test;
30 import jdk.jpackage.test.JPackageCommand;
31 import jdk.jpackage.test.TKit;
32 
33 /*
34  * @test
35  * @summary jpackage application version testing
36  * @library ../../../../helpers
37  * @build jdk.jpackage.test.*
opVariableArrayAsync(std::pair<const Test::Variable *,const Test::Variable * > in,std::function<void (const Test::VariableList &,const Test::VariableList &)> response,std::function<void (std::exception_ptr)>,const Ice::Current &)38  * @modules jdk.jpackage/jdk.jpackage.internal
39  * @compile JLinkOptionsTest.java
40  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
41  *  --jpt-run=jdk.jpackage.tests.JLinkOptionsTest
42  */
43 
44 public final class JLinkOptionsTest {
45 
46     @Parameters
47     public static Collection input() {
48         return List.of(new Object[][]{
49             // default but with strip-native-commands removed
50             {"Hello", new String[]{
51                     "--jlink-options",
52                     "--strip-debug --no-man-pages --no-header-files",
53                     },
54                     // non modular should have everything
55                     new String[]{"jdk.jartool", "jdk.unsupported"},
56                     null,
57                     },
58             // multiple jlink-options
59             {"com.other/com.other.Hello", new String[]{
60                     "--jlink-options",
61                     "--strip-debug --no-man-pages --no-header-files",
62                     "--jlink-options",
63                     "--bind-services",
64                     },
65                     // with bind-services should have some services
66                     new String[]{"java.smartcardio", "jdk.crypto.ec"},
67                     null,
68                     },
69             // bind-services
70             {"Hello", new String[]{
71                     "--jlink-options", "--bind-services",
72                     },
73                     // non modular should have everything
74                     new String[]{"jdk.jartool", "jdk.unsupported"},
75                     null,
76                     },
77 
78             // jlink-options --bind-services
79             {"com.other/com.other.Hello", new String[]{
80                     "--jlink-options", "--bind-services",
81                     },
82                     // with bind-services should have some services
83                     new String[]{"java.smartcardio", "jdk.crypto.ec"},
84                     null,
85                     },
86 
87             // limit modules
88             {"com.other/com.other.Hello", new String[]{
89                     "--jlink-options",
90                     "--limit-modules java.base,java.datatransfer,java.xml,java.prefs,java.desktop,com.other",
91                     },
92                     // should have whatever it needs
93                     new String[]{"java.base", "com.other"},
94                     // should not have whatever it doesn't need
95                     new String[]{"jdk.jpackage"},
96                     },
97 
98             // bind-services and limit-options
99             {"com.other/com.other.Hello", new String[]{
100                     "--jlink-options",
101                     "--bind-services",
102                     "--jlink-options",
103                     "--limit-modules java.base,java.datatransfer,java.xml,java.prefs,java.desktop,com.other,java.smartcardio",
104                     },
105                     // with bind-services should have some services
106                     new String[]{"java.smartcardio"},
107                     // but not limited
108                     new String[]{"jdk.crypto.ec"},
109                     },
110 
111         });
112     }
113 
114     public JLinkOptionsTest(String javaAppDesc, String[] jpackageArgs, String[] required, String[] prohibited) {
115         this.required = required;
116         this.prohibited = prohibited;
117         cmd = JPackageCommand
118                 .helloAppImage(javaAppDesc)
119                 .ignoreDefaultRuntime(true)
120                 .addArguments(jpackageArgs);
121     }
122 
123     @Test
124     public void test() {
125         cmd.executeAndAssertHelloAppImageCreated();
126 
127         List<String> release = cmd.readRuntimeReleaseFile();
128         List<String> mods = List.of(release.get(1));
129         if (required != null) {
130             for (String s : required) {
131                 TKit.assertTextStream(s).label("mods").apply(mods.stream());
132             }
133         }
134         if (prohibited != null) {
135             for (String s : prohibited) {
136                 TKit.assertTextStream(s).label("mods").negate().apply(mods.stream());
137             }
138         }
139     }
140 
141     private final String[] required;
142     private final String[] prohibited;
143     private final JPackageCommand cmd;
144 }
145