1 /*
   2  * Copyright (c) 2019, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.jpackage.internal;
  26 
  27 import java.nio.file.Path;
  28 import java.util.Map;
  29 
  30 
  31 /**
  32  * Application directory layout.
  33  */
  34 final class ApplicationLayout implements PathGroup.Facade<ApplicationLayout> {
  35     enum PathRole {
  36         RUNTIME, APP, LAUNCHERS_DIR, DESKTOP
  37     }
  38 
  39     ApplicationLayout(Map<Object, Path> paths) {
  40         data = new PathGroup(paths);
  41     }
  42 
  43     private ApplicationLayout(PathGroup data) {
  44         this.data = data;
  45     }
  46 
  47     @Override
  48     public PathGroup pathGroup() {
  49         return data;
  50     }
  51 
  52     @Override
  53     public ApplicationLayout resolveAt(Path root) {
  54         return new ApplicationLayout(pathGroup().resolveAt(root));
  55     }
  56 
  57     /**
  58      * Path to launchers directory.
  59      */
  60     Path launchersDirectory() {
  61         return pathGroup().getPath(PathRole.LAUNCHERS_DIR);
  62     }
  63 
  64     /**
  65      * Path to application data directory.
  66      */
  67     Path appDirectory() {
  68         return pathGroup().getPath(PathRole.APP);
  69     }
  70 
  71     /**
  72      * Path to Java runtime directory.
  73      */
  74     Path runtimeDirectory() {
  75         return pathGroup().getPath(PathRole.RUNTIME);
  76     }
  77 
  78     /**
  79      * Path to directory with application's desktop integration files.
  80      */
  81     Path destktopIntegrationDirectory() {
  82         return pathGroup().getPath(PathRole.DESKTOP);
  83     }
  84 
  85     static ApplicationLayout unixApp() {
  86         return new ApplicationLayout(Map.of(
  87                 PathRole.LAUNCHERS_DIR, Path.of("bin"),
  88                 PathRole.APP, Path.of("app"),
  89                 PathRole.RUNTIME, Path.of("runtime"),
  90                 PathRole.DESKTOP, Path.of("bin")
  91         ));
  92     }
  93 
  94     static ApplicationLayout windowsApp() {
  95         return new ApplicationLayout(Map.of(
  96                 PathRole.LAUNCHERS_DIR, Path.of(""),
  97                 PathRole.APP, Path.of("app"),
  98                 PathRole.RUNTIME, Path.of("runtime"),
  99                 PathRole.DESKTOP, Path.of("")
 100         ));
 101     }
 102 
 103     static ApplicationLayout platformApp() {
 104         if (Platform.getPlatform() == Platform.WINDOWS) {
 105             return windowsApp();
 106         }
 107 
 108         return unixApp();
 109     }
 110 
 111     static ApplicationLayout javaRuntime() {
 112         return new ApplicationLayout(Map.of(PathRole.RUNTIME, Path.of("")));
 113     }
 114 
 115     private final PathGroup data;
 116 }