|
| 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 | +import java.nio.file.Path; |
| 25 | +import java.nio.file.Files; |
| 26 | +import jdk.jpackage.internal.ApplicationLayout; |
| 27 | +import jdk.jpackage.test.PackageTest; |
| 28 | +import jdk.jpackage.test.PackageType; |
| 29 | +import jdk.jpackage.test.TKit; |
| 30 | +import jdk.jpackage.test.Annotations.Test; |
| 31 | +import jdk.jpackage.test.Annotations.Parameter; |
| 32 | +import jdk.jpackage.test.Annotations.Parameters; |
| 33 | +import java.util.Arrays; |
| 34 | +import java.util.Collection; |
| 35 | +import java.util.List; |
| 36 | + |
| 37 | + |
| 38 | +/** |
| 39 | + * Tests generation of packages with input folder containing empty folders. |
| 40 | + */ |
| 41 | + |
| 42 | +/* |
| 43 | + * @test |
| 44 | + * @summary jpackage with --app-content option |
| 45 | + * @library ../helpers |
| 46 | + * @library /test/lib |
| 47 | + * @key jpackagePlatformPackage |
| 48 | + * @build jdk.jpackage.test.* |
| 49 | + * @build AppContentTest |
| 50 | + * @modules jdk.jpackage/jdk.jpackage.internal |
| 51 | + * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main |
| 52 | + * --jpt-run=AppContentTest |
| 53 | + */ |
| 54 | +public class AppContentTest { |
| 55 | + |
| 56 | + private static final String TEST_JAVA = TKit.TEST_SRC_ROOT.resolve( |
| 57 | + "apps/PrintEnv.java").toString(); |
| 58 | + private static final String TEST_DUKE = TKit.TEST_SRC_ROOT.resolve( |
| 59 | + "apps/dukeplug.png").toString(); |
| 60 | + private static final String TEST_DIR = TKit.TEST_SRC_ROOT.resolve( |
| 61 | + "apps").toString(); |
| 62 | + private static final String TEST_BAD = TKit.TEST_SRC_ROOT.resolve( |
| 63 | + "non-existant").toString(); |
| 64 | + |
| 65 | + private final List<String> testPathArgs; |
| 66 | + |
| 67 | + @Parameters |
| 68 | + public static Collection data() { |
| 69 | + return List.of(new String[][]{ |
| 70 | + {TEST_JAVA, TEST_DUKE}, // include two files in two options |
| 71 | + {TEST_JAVA, TEST_BAD}, // try to include non-existant content |
| 72 | + {TEST_JAVA + "," + TEST_DUKE, TEST_DIR}, // two files in one option, |
| 73 | + // and a dir tree in another option. |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + public AppContentTest(String... testPathArgs) { |
| 78 | + this.testPathArgs = List.of(testPathArgs); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void test() throws Exception { |
| 83 | + |
| 84 | + new PackageTest().configureHelloApp() |
| 85 | + .addInitializer(cmd -> { |
| 86 | + for (String arg : testPathArgs) { |
| 87 | + cmd.addArguments("--app-content", arg); |
| 88 | + } |
| 89 | + }) |
| 90 | + .addInstallVerifier(cmd -> { |
| 91 | + ApplicationLayout appLayout = cmd.appLayout(); |
| 92 | + Path contentDir = appLayout.contentDirectory(); |
| 93 | + for (String arg : testPathArgs) { |
| 94 | + List<String> paths = Arrays.asList(arg.split(",")); |
| 95 | + for (String p : paths) { |
| 96 | + Path name = Path.of(p).getFileName(); |
| 97 | + TKit.assertPathExists(contentDir.resolve(name), true); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + }) |
| 102 | + .setExpectedExitCode(testPathArgs.contains(TEST_BAD) ? 1 : 0) |
| 103 | + .run(); |
| 104 | + } |
| 105 | +} |
0 commit comments