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.incubator.jpackage.internal; 26 27 import java.nio.file.Path; 28 import java.util.Map; 29 30 31 /** 32 * Application directory layout. 33 */ 34 public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayout> { 35 enum PathRole { 36 RUNTIME, APP, LAUNCHERS, DESKTOP, APP_MODS, DLLS 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 public Path launchersDirectory() { 61 return pathGroup().getPath(PathRole.LAUNCHERS); 62 } 63 64 /** 65 * Path to directory with dynamic libraries. 66 */ 67 public Path dllDirectory() { 68 return pathGroup().getPath(PathRole.DLLS); 69 } 70 71 /** 72 * Path to application data directory. 73 */ 74 public Path appDirectory() { 75 return pathGroup().getPath(PathRole.APP); 76 } 77 78 /** 79 * Path to Java runtime directory. 80 */ 81 public Path runtimeDirectory() { 82 return pathGroup().getPath(PathRole.RUNTIME); 83 } 84 85 /** 86 * Path to application mods directory. 87 */ 88 public Path appModsDirectory() { 89 return pathGroup().getPath(PathRole.APP_MODS); 90 } 91 92 /** 93 * Path to directory with application's desktop integration files. 94 */ 95 public Path destktopIntegrationDirectory() { 96 return pathGroup().getPath(PathRole.DESKTOP); 97 } 98 99 static ApplicationLayout linuxAppImage() { 100 return new ApplicationLayout(Map.of( 101 PathRole.LAUNCHERS, Path.of("bin"), 102 PathRole.APP, Path.of("lib/app"), 103 PathRole.RUNTIME, Path.of("lib/runtime"), 104 PathRole.DESKTOP, Path.of("lib"), 105 PathRole.DLLS, Path.of("lib"), 106 PathRole.APP_MODS, Path.of("lib/app/mods") 107 )); 108 } 109 110 static ApplicationLayout windowsAppImage() { 111 return new ApplicationLayout(Map.of( 112 PathRole.LAUNCHERS, Path.of(""), 113 PathRole.APP, Path.of("app"), 114 PathRole.RUNTIME, Path.of("runtime"), 115 PathRole.DESKTOP, Path.of(""), 116 PathRole.DLLS, Path.of(""), 117 PathRole.APP_MODS, Path.of("app/mods") 118 )); 119 } 120 121 static ApplicationLayout macAppImage() { 122 return new ApplicationLayout(Map.of( 123 PathRole.LAUNCHERS, Path.of("Contents/MacOS"), 124 PathRole.APP, Path.of("Contents/app"), 125 PathRole.RUNTIME, Path.of("Contents/runtime"), 126 PathRole.DESKTOP, Path.of("Contents/Resources"), 127 PathRole.DLLS, Path.of("Contents/MacOS"), 128 PathRole.APP_MODS, Path.of("Contents/app/mods") 129 )); 130 } 131 132 public static ApplicationLayout platformAppImage() { 133 if (Platform.isWindows()) { 134 return windowsAppImage(); 135 } 136 137 if (Platform.isLinux()) { 138 return linuxAppImage(); 139 } 140 141 if (Platform.isMac()) { 142 return macAppImage(); 143 } 144 145 throw Platform.throwUnknownPlatformError(); 146 } 147 148 public static ApplicationLayout javaRuntime() { 149 return new ApplicationLayout(Map.of(PathRole.RUNTIME, Path.of(""))); 150 } 151 152 private final PathGroup data; 153 }