|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | +import java.nio.file.Files; |
24 | 26 | import java.nio.file.Path;
|
25 |
| -import jdk.jpackage.test.JPackageCommand; |
| 27 | +import jdk.jpackage.test.PackageTest; |
26 | 28 | import jdk.jpackage.test.Annotations.Test;
|
27 |
| -import jdk.jpackage.internal.ApplicationLayout; |
| 29 | +import jdk.jpackage.test.JPackageCommand; |
| 30 | +import jdk.jpackage.test.PackageType; |
| 31 | +import jdk.jpackage.test.TKit; |
28 | 32 |
|
29 | 33 | /**
|
30 |
| - * Tests generation of app image with input folder containing empty folders. |
| 34 | + * Tests generation of packages and app image with input folder containing empty folders. |
| 35 | + */ |
| 36 | + |
| 37 | +/* |
| 38 | + * @test |
| 39 | + * @summary jpackage for package with input containing empty folders |
| 40 | + * @library ../helpers |
| 41 | + * @library /test/lib |
| 42 | + * @key jpackagePlatformPackage |
| 43 | + * @build jdk.jpackage.test.* |
| 44 | + * @build EmptyFolderTest |
| 45 | + * @modules jdk.jpackage/jdk.jpackage.internal |
| 46 | + * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main |
| 47 | + * --jpt-run=EmptyFolderTest.testPackage |
31 | 48 | */
|
32 | 49 |
|
33 | 50 | /*
|
34 | 51 | * @test
|
35 |
| - * @summary jpackage with input containing empty folders |
| 52 | + * @summary jpackage for app image with input containing empty folders |
36 | 53 | * @library ../helpers
|
37 | 54 | * @library /test/lib
|
38 |
| - * @build EmptyFolderBase |
39 | 55 | * @build jdk.jpackage.test.*
|
40 | 56 | * @build EmptyFolderTest
|
41 | 57 | * @modules jdk.jpackage/jdk.jpackage.internal
|
42 | 58 | * @run main/othervm -Xmx512m jdk.jpackage.test.Main
|
43 |
| - * --jpt-run=EmptyFolderTest |
| 59 | + * --jpt-run=EmptyFolderTest.testAppImage |
44 | 60 | */
|
| 61 | + |
45 | 62 | public class EmptyFolderTest {
|
46 | 63 |
|
47 | 64 | @Test
|
48 |
| - public static void test() throws Exception { |
49 |
| - JPackageCommand cmd = JPackageCommand.helloAppImage(); |
| 65 | + public static void testPackage() { |
| 66 | + new PackageTest() |
| 67 | + .configureHelloApp() |
| 68 | + .addInitializer(EmptyFolderTest::createDirTree) |
| 69 | + .addInitializer(cmd -> { |
| 70 | + cmd.setArgumentValue("--name", "EmptyFolderPackageTest"); |
| 71 | + }) |
| 72 | + .addInstallVerifier(EmptyFolderTest::validateDirTree) |
| 73 | + .run(); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public static void testAppImage() throws IOException { |
| 78 | + var cmd = JPackageCommand.helloAppImage(); |
50 | 79 |
|
51 | 80 | // Add more files into input folder
|
52 |
| - Path input = cmd.inputDir(); |
53 |
| - EmptyFolderBase.createDirStrcture(input); |
| 81 | + createDirTree(cmd); |
54 | 82 |
|
55 | 83 | // Create app image
|
56 | 84 | cmd.executeAndAssertHelloAppImageCreated();
|
57 | 85 |
|
58 |
| - // Verify directory strcture |
59 |
| - ApplicationLayout appLayout = cmd.appLayout(); |
60 |
| - Path appDir = appLayout.appDirectory(); |
61 |
| - EmptyFolderBase.validateDirStrcture(appDir); |
| 86 | + // Verify directory structure |
| 87 | + validateDirTree(cmd); |
| 88 | + } |
| 89 | + |
| 90 | + private static void createDirTree(JPackageCommand cmd) throws IOException { |
| 91 | + var baseDir = cmd.inputDir(); |
| 92 | + for (var path : DIR_STRUCT) { |
| 93 | + path = baseDir.resolve(path); |
| 94 | + if (isFile(path)) { |
| 95 | + Files.createDirectories(path.getParent()); |
| 96 | + Files.write(path, new byte[0]); |
| 97 | + } else { |
| 98 | + Files.createDirectories(path); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private static void validateDirTree(JPackageCommand cmd) { |
| 104 | + var outputBaseDir = cmd.appLayout().appDirectory(); |
| 105 | + var inputBaseDir = cmd.inputDir(); |
| 106 | + for (var path : DIR_STRUCT) { |
| 107 | + Path outputPath = outputBaseDir.resolve(path); |
| 108 | + if (isFile(outputPath)) { |
| 109 | + TKit.assertFileExists(outputPath); |
| 110 | + } else if (!PackageType.WINDOWS.contains(cmd.packageType())) { |
| 111 | + TKit.assertDirectoryExists(outputPath); |
| 112 | + } else if (inputBaseDir.resolve(path).toFile().list().length == 0) { |
| 113 | + // MSI packages don't support empty folders |
| 114 | + TKit.assertPathExists(outputPath, false); |
| 115 | + } else { |
| 116 | + TKit.assertDirectoryNotEmpty(outputPath); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + private static boolean isFile(Path path) { |
| 122 | + return path.getFileName().toString().endsWith(".txt"); |
62 | 123 | }
|
63 | 124 |
|
| 125 | + // Note: To specify file use ".txt" extension. |
| 126 | + private static final Path [] DIR_STRUCT = { |
| 127 | + Path.of("folder-empty"), |
| 128 | + Path.of("folder-not-empty"), |
| 129 | + Path.of("folder-not-empty", "folder-empty"), |
| 130 | + Path.of("folder-not-empty", "another-folder-empty"), |
| 131 | + Path.of("folder-not-empty", "folder-non-empty2", "file.txt") |
| 132 | + }; |
64 | 133 | }
|
0 commit comments