author | herrick |
Fri, 16 Aug 2019 17:29:33 -0400 | |
branch | JDK-8200758-branch |
changeset 57789 | 9280ca6669a2 |
parent 57450 | 82c78b40b39d |
child 57911 | f052c884af39 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57091
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 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 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
28 |
import java.io.File; |
|
29 |
import java.io.FileInputStream; |
|
30 |
import java.io.FileOutputStream; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStream; |
|
33 |
import java.io.OutputStream; |
|
34 |
import java.io.OutputStreamWriter; |
|
35 |
import java.io.UncheckedIOException; |
|
36 |
import java.io.Writer; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.attribute.PosixFilePermission; |
|
40 |
import java.text.MessageFormat; |
|
41 |
import java.util.HashMap; |
|
42 |
import java.util.List; |
|
43 |
import java.util.Map; |
|
44 |
import java.util.Objects; |
|
45 |
import java.util.ResourceBundle; |
|
46 |
import java.util.Set; |
|
47 |
||
57039 | 48 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57038 | 49 |
|
50 |
public class LinuxAppImageBuilder extends AbstractAppImageBuilder { |
|
51 |
||
52 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 53 |
"jdk.jpackage.internal.resources.LinuxResources"); |
57038 | 54 |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
55 |
private static final String LIBRARY_NAME = "libapplauncher.so"; |
57038 | 56 |
|
57 |
private final Path root; |
|
58 |
private final Path appDir; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
59 |
private final Path appModsDir; |
57038 | 60 |
private final Path runtimeDir; |
57407 | 61 |
private final Path binDir; |
57038 | 62 |
private final Path mdir; |
63 |
||
64 |
public static final BundlerParamInfo<File> ICON_PNG = |
|
65 |
new StandardBundlerParam<>( |
|
66 |
"icon.png", |
|
67 |
File.class, |
|
68 |
params -> { |
|
69 |
File f = ICON.fetchFrom(params); |
|
70 |
if (f != null && !f.getName().toLowerCase().endsWith(".png")) { |
|
71 |
Log.error(MessageFormat.format(I18N.getString( |
|
72 |
"message.icon-not-png"), f)); |
|
73 |
return null; |
|
74 |
} |
|
75 |
return f; |
|
76 |
}, |
|
77 |
(s, p) -> new File(s)); |
|
78 |
||
57789 | 79 |
public LinuxAppImageBuilder(Map<String, Object> params, Path imageOutDir) |
57038 | 80 |
throws IOException { |
57789 | 81 |
super(params, |
82 |
imageOutDir.resolve(APP_NAME.fetchFrom(params) + "/runtime")); |
|
57038 | 83 |
|
84 |
Objects.requireNonNull(imageOutDir); |
|
85 |
||
57789 | 86 |
this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params)); |
57038 | 87 |
this.appDir = root.resolve("app"); |
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
88 |
this.appModsDir = appDir.resolve("mods"); |
57038 | 89 |
this.runtimeDir = root.resolve("runtime"); |
57407 | 90 |
this.binDir = root.resolve("bin"); |
57038 | 91 |
this.mdir = runtimeDir.resolve("lib"); |
92 |
Files.createDirectories(appDir); |
|
93 |
Files.createDirectories(runtimeDir); |
|
94 |
} |
|
95 |
||
96 |
public LinuxAppImageBuilder(String appName, Path imageOutDir) |
|
97 |
throws IOException { |
|
98 |
super(null, imageOutDir.resolve(appName)); |
|
99 |
||
100 |
Objects.requireNonNull(imageOutDir); |
|
101 |
||
102 |
this.root = imageOutDir.resolve(appName); |
|
103 |
this.appDir = null; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
104 |
this.appModsDir = null; |
57038 | 105 |
this.runtimeDir = null; |
57407 | 106 |
this.binDir = null; |
57038 | 107 |
this.mdir = null; |
108 |
} |
|
109 |
||
110 |
private void writeEntry(InputStream in, Path dstFile) throws IOException { |
|
111 |
Files.createDirectories(dstFile.getParent()); |
|
112 |
Files.copy(in, dstFile); |
|
113 |
} |
|
114 |
||
115 |
// it is static for the sake of sharing with "installer" bundlers |
|
116 |
// that may skip calls to validate/bundle in this class! |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
117 |
public static File getRootDir(File outDir, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
118 |
Map<String, ? super Object> params) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
119 |
return new File(outDir, APP_NAME.fetchFrom(params)); |
57038 | 120 |
} |
121 |
||
57407 | 122 |
public static String getLauncherRelativePath( |
123 |
Map<String, ? super Object> params) { |
|
124 |
return "bin" + File.separator + APP_NAME.fetchFrom(params); |
|
125 |
} |
|
126 |
||
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
127 |
private static String getLauncherName(Map<String, ? super Object> params) { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
128 |
return APP_NAME.fetchFrom(params); |
57038 | 129 |
} |
130 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
131 |
public static String getLauncherCfgName( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
132 |
Map<String, ? super Object> params) { |
57407 | 133 |
return "app" + File.separator + APP_NAME.fetchFrom(params) + ".cfg"; |
57038 | 134 |
} |
135 |
||
136 |
@Override |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
137 |
public Path getAppDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
138 |
return appDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
139 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
140 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
141 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
142 |
public Path getAppModsDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
143 |
return appModsDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
144 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
145 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
146 |
@Override |
57789 | 147 |
public void prepareApplicationFiles(Map<String, ? super Object> params) |
148 |
throws IOException { |
|
57038 | 149 |
Map<String, ? super Object> originalParams = new HashMap<>(params); |
150 |
||
57407 | 151 |
try { |
152 |
IOUtils.writableOutputDir(root); |
|
153 |
IOUtils.writableOutputDir(binDir); |
|
154 |
} catch (PackagerException pe) { |
|
155 |
throw new RuntimeException(pe); |
|
156 |
} |
|
157 |
||
57038 | 158 |
// create the primary launcher |
57263 | 159 |
createLauncherForEntryPoint(params); |
57038 | 160 |
|
161 |
// Copy library to the launcher folder |
|
162 |
try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
|
57407 | 163 |
writeEntry(is_lib, binDir.resolve(LIBRARY_NAME)); |
57038 | 164 |
} |
165 |
||
57256 | 166 |
// create the additional launchers, if any |
57038 | 167 |
List<Map<String, ? super Object>> entryPoints |
57256 | 168 |
= StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params); |
57038 | 169 |
for (Map<String, ? super Object> entryPoint : entryPoints) { |
57259
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
170 |
createLauncherForEntryPoint( |
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
171 |
AddLauncherArguments.merge(originalParams, entryPoint)); |
57038 | 172 |
} |
173 |
||
174 |
// Copy class path entries to Java folder |
|
57789 | 175 |
copyApplication(params); |
57038 | 176 |
|
177 |
// Copy icon to Resources folder |
|
57789 | 178 |
copyIcon(params); |
57038 | 179 |
} |
180 |
||
181 |
@Override |
|
57789 | 182 |
public void prepareJreFiles(Map<String, ? super Object> params) |
183 |
throws IOException {} |
|
57038 | 184 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
185 |
private void createLauncherForEntryPoint( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
186 |
Map<String, ? super Object> params) throws IOException { |
57038 | 187 |
// Copy executable to Linux folder |
57407 | 188 |
Path executableFile = binDir.resolve(getLauncherName(params)); |
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
189 |
try (InputStream is_launcher = |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
190 |
getResourceAsStream("jpackageapplauncher")) { |
57038 | 191 |
writeEntry(is_launcher, executableFile); |
192 |
} |
|
193 |
||
194 |
executableFile.toFile().setExecutable(true, false); |
|
195 |
executableFile.toFile().setWritable(true, true); |
|
196 |
||
57450
82c78b40b39d
8227058: Regressions related to no longer setting user.dir
herrick
parents:
57446
diff
changeset
|
197 |
writeCfgFile(params, root.resolve(getLauncherCfgName(params)).toFile()); |
57038 | 198 |
} |
199 |
||
57789 | 200 |
private void copyIcon(Map<String, ? super Object> params) |
201 |
throws IOException { |
|
57038 | 202 |
File icon = ICON_PNG.fetchFrom(params); |
203 |
if (icon != null) { |
|
57407 | 204 |
File iconTarget = new File(binDir.toFile(), |
57119 | 205 |
APP_NAME.fetchFrom(params) + ".png"); |
57038 | 206 |
IOUtils.copyFile(icon, iconTarget); |
207 |
} |
|
208 |
} |
|
209 |
||
57789 | 210 |
private void copyApplication(Map<String, ? super Object> params) |
211 |
throws IOException { |
|
57038 | 212 |
for (RelativeFileSet appResources : |
213 |
APP_RESOURCES_LIST.fetchFrom(params)) { |
|
214 |
if (appResources == null) { |
|
215 |
throw new RuntimeException("Null app resources?"); |
|
216 |
} |
|
217 |
File srcdir = appResources.getBaseDirectory(); |
|
218 |
for (String fname : appResources.getIncludedFiles()) { |
|
219 |
copyEntry(appDir, srcdir, fname); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
} |