test/jdk/tools/jpackage/junit/jdk/incubator/jpackage/internal/ApplicationLayoutTest.java
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 58416 test/jdk/tools/jpackage/junit/jdk/jpackage/internal/ApplicationLayoutTest.java@f09bf58c1f17
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58302
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     1
/*
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     4
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    10
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    15
 * accompanied this code).
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    16
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    20
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    23
 * questions.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    24
 */
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents: 58416
diff changeset
    25
package jdk.incubator.jpackage.internal;
58302
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    26
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    27
import java.io.IOException;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    28
import java.nio.file.Files;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    29
import java.nio.file.Path;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    30
import org.junit.Test;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    31
import org.junit.Rule;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    32
import org.junit.rules.TemporaryFolder;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    33
import static org.junit.Assert.*;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    34
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    35
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    36
public class ApplicationLayoutTest {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    37
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    38
    @Rule
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    39
    public final TemporaryFolder tempFolder = new TemporaryFolder();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    40
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    41
    private void fillLinuxAppImage() throws IOException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    42
        appImage = tempFolder.newFolder("Foo").toPath();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    43
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    44
        Path base = appImage.getFileName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    45
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    46
        tempFolder.newFolder(base.toString(), "bin");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    47
        tempFolder.newFolder(base.toString(), "lib", "app", "mods");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    48
        tempFolder.newFolder(base.toString(), "lib", "runtime", "bin");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    49
        tempFolder.newFile(base.resolve("bin/Foo").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    50
        tempFolder.newFile(base.resolve("lib/app/Foo.cfg").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    51
        tempFolder.newFile(base.resolve("lib/app/hello.jar").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    52
        tempFolder.newFile(base.resolve("lib/Foo.png").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    53
        tempFolder.newFile(base.resolve("lib/libapplauncher.so").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    54
        tempFolder.newFile(base.resolve("lib/runtime/bin/java").toString());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    55
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    56
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    57
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    58
    public void testLinux() throws IOException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    59
        fillLinuxAppImage();
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58302
diff changeset
    60
        testApplicationLayout(ApplicationLayout.linuxAppImage());
58302
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    61
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    62
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    63
    private void testApplicationLayout(ApplicationLayout layout) throws IOException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    64
        ApplicationLayout srcLayout = layout.resolveAt(appImage);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    65
        assertApplicationLayout(srcLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    66
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    67
        ApplicationLayout dstLayout = layout.resolveAt(
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    68
                appImage.getParent().resolve(
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    69
                        "Copy" + appImage.getFileName().toString()));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    70
        srcLayout.move(dstLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    71
        Files.deleteIfExists(appImage);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    72
        assertApplicationLayout(dstLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    73
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    74
        dstLayout.copy(srcLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    75
        assertApplicationLayout(srcLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    76
        assertApplicationLayout(dstLayout);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    77
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    78
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    79
    private void assertApplicationLayout(ApplicationLayout layout) throws IOException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    80
        assertTrue(Files.isRegularFile(layout.appDirectory().resolve("Foo.cfg")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    81
        assertTrue(Files.isRegularFile(layout.appDirectory().resolve("hello.jar")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    82
        assertTrue(Files.isDirectory(layout.appModsDirectory()));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    83
        assertTrue(Files.isRegularFile(layout.launchersDirectory().resolve("Foo")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    84
        assertTrue(Files.isRegularFile(layout.destktopIntegrationDirectory().resolve("Foo.png")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    85
        assertTrue(Files.isRegularFile(layout.dllDirectory().resolve("libapplauncher.so")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    86
        assertTrue(Files.isRegularFile(layout.runtimeDirectory().resolve("bin/java")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    87
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    88
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    89
    private Path appImage;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    90
}