|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 2021, 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.io.IOException; |
| 27 | +import java.nio.file.Files; |
| 28 | +import java.util.Collection; |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.List; |
| 31 | +import java.util.stream.Stream; |
| 32 | +import java.nio.file.Path; |
| 33 | +import jdk.jpackage.test.Annotations.Parameters; |
| 34 | +import jdk.jpackage.test.Annotations.Test; |
| 35 | +import jdk.jpackage.test.Executor; |
| 36 | +import jdk.jpackage.test.JPackageCommand; |
| 37 | +import jdk.jpackage.test.JavaAppDesc; |
| 38 | +import jdk.jpackage.test.JavaTool; |
| 39 | +import jdk.jpackage.test.TKit; |
| 40 | +import jdk.jpackage.test.HelloApp; |
| 41 | + |
| 42 | + |
| 43 | +/* |
| 44 | + * @test |
| 45 | + * @summary test '--runtime-image' option of jpackage |
| 46 | + * @library ../../../../helpers |
| 47 | + * @build jdk.jpackage.test.* |
| 48 | + * @modules jdk.jpackage/jdk.jpackage.internal |
| 49 | + * @compile NoMPathRuntimeTest.java |
| 50 | + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
| 51 | + * --jpt-run=jdk.jpackage.tests.NoMPathRuntimeTest |
| 52 | + */ |
| 53 | + |
| 54 | +public final class NoMPathRuntimeTest { |
| 55 | + |
| 56 | + public NoMPathRuntimeTest(String jlinkOutputSubdir, String runtimeSubdir) { |
| 57 | + this.jlinkOutputSubdir = Path.of(jlinkOutputSubdir); |
| 58 | + this.runtimeSubdir = Path.of(runtimeSubdir); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void test() throws IOException { |
| 63 | + JavaAppDesc appDesc = JavaAppDesc.parse("com.foo/com.foo.main.Aloha"); |
| 64 | + |
| 65 | + JPackageCommand cmd = JPackageCommand.helloAppImage(appDesc); |
| 66 | + |
| 67 | + // Build module jar. |
| 68 | + cmd.executePrerequisiteActions(); |
| 69 | + |
| 70 | + final Path workDir = TKit.createTempDirectory("runtime").resolve("data"); |
| 71 | + final Path jlinkOutputDir = workDir.resolve(jlinkOutputSubdir); |
| 72 | + Files.createDirectories(jlinkOutputDir.getParent()); |
| 73 | + |
| 74 | + // List of modules required for test app. |
| 75 | + final var modules = new String[] { |
| 76 | + "java.base", |
| 77 | + "java.desktop" |
| 78 | + }; |
| 79 | + |
| 80 | + Executor jlink = new Executor() |
| 81 | + .setToolProvider(JavaTool.JLINK) |
| 82 | + .dumpOutput() |
| 83 | + .addArguments( |
| 84 | + "--add-modules", String.join(",", modules), |
| 85 | + "--output", jlinkOutputDir.toString(), |
| 86 | + "--strip-debug", |
| 87 | + "--no-header-files", |
| 88 | + "--no-man-pages"); |
| 89 | + |
| 90 | + jlink.addArguments("--add-modules", appDesc.moduleName(), |
| 91 | + "--module-path", Path.of(cmd.getArgumentValue("--module-path")) |
| 92 | + .resolve("hello.jar").toString()); |
| 93 | + |
| 94 | + jlink.execute(); |
| 95 | + |
| 96 | + // non-modular jar in current dir caused error whe no module-path given |
| 97 | + cmd.removeArgumentWithValue("--module-path"); |
| 98 | + |
| 99 | + cmd.setArgumentValue("--runtime-image", workDir.resolve(runtimeSubdir)); |
| 100 | + Path junkJar = null; |
| 101 | + try { |
| 102 | + // create a non-modular jar in the current directory |
| 103 | + junkJar = HelloApp.createBundle( |
| 104 | + JavaAppDesc.parse("junk.jar:Hello"), Path.of(".")); |
| 105 | + |
| 106 | + cmd.executeAndAssertHelloAppImageCreated(); |
| 107 | + } finally { |
| 108 | + if (junkJar != null) { |
| 109 | + TKit.deleteIfExists(junkJar); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + @Parameters |
| 116 | + public static Collection data() { |
| 117 | + |
| 118 | + final List<String[]> paths = new ArrayList<>(); |
| 119 | + paths.add(new String[] { "", "" }); |
| 120 | + if (TKit.isOSX()) { |
| 121 | + // On OSX jpackage should accept both runtime root and runtime home |
| 122 | + // directories. |
| 123 | + paths.add(new String[] { "Contents/Home", "" }); |
| 124 | + } |
| 125 | + |
| 126 | + List<Object[]> data = new ArrayList<>(); |
| 127 | + for (var pathCfg : paths) { |
| 128 | + data.add(new Object[] { pathCfg[0], pathCfg[1] }); |
| 129 | + } |
| 130 | + |
| 131 | + return data; |
| 132 | + } |
| 133 | + |
| 134 | + private final Path jlinkOutputSubdir; |
| 135 | + private final Path runtimeSubdir; |
| 136 | +} |
0 commit comments