Skip to content

Commit a890185

Browse files
author
Alexey Semenyuk
committed
8333727: Use JOpt in jpackage to parse command line
8371384: libapplauncher.so is copied to a wrong location in two step packaging when --install-dir=/usr Reviewed-by: almatvee
1 parent 45a2fd3 commit a890185

File tree

163 files changed

+18471
-6636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+18471
-6636
lines changed

src/jdk.internal.opt/share/classes/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
exports jdk.internal.joptsimple to
3333
jdk.jlink,
3434
jdk.jshell,
35+
jdk.jpackage,
3536
jdk.jdeps;
3637
exports jdk.internal.opt to
3738
jdk.compiler,

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppBundler.java

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2025, 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 static java.util.stream.Collectors.toMap;
28+
import static jdk.jpackage.internal.LinuxFromOptions.createLinuxApplication;
29+
import static jdk.jpackage.internal.LinuxPackagingPipeline.APPLICATION_LAYOUT;
30+
import static jdk.jpackage.internal.cli.StandardBundlingOperation.CREATE_LINUX_APP_IMAGE;
31+
import static jdk.jpackage.internal.cli.StandardBundlingOperation.CREATE_LINUX_DEB;
32+
import static jdk.jpackage.internal.cli.StandardBundlingOperation.CREATE_LINUX_RPM;
33+
34+
import java.util.Map;
35+
import java.util.Optional;
36+
import java.util.stream.Stream;
37+
import jdk.jpackage.internal.cli.Options;
38+
import jdk.jpackage.internal.cli.StandardBundlingOperation;
39+
import jdk.jpackage.internal.model.BundlingOperationDescriptor;
40+
import jdk.jpackage.internal.model.LinuxPackage;
41+
import jdk.jpackage.internal.model.PackageType;
42+
import jdk.jpackage.internal.util.Result;
43+
44+
public class LinuxBundlingEnvironment extends DefaultBundlingEnvironment {
45+
46+
public LinuxBundlingEnvironment() {
47+
super(build()
48+
.defaultOperation(() -> {
49+
return LazyLoad.SYS_ENV.value().map(LinuxSystemEnvironment::nativePackageType).map(DESCRIPTORS::get);
50+
})
51+
.bundler(CREATE_LINUX_APP_IMAGE, LinuxBundlingEnvironment::createAppImage)
52+
.bundler(CREATE_LINUX_DEB, LazyLoad::debSysEnv, LinuxBundlingEnvironment::createDebPackage)
53+
.bundler(CREATE_LINUX_RPM, LazyLoad::rpmSysEnv, LinuxBundlingEnvironment::createRpmPackage));
54+
}
55+
56+
private static void createDebPackage(Options options, LinuxDebSystemEnvironment sysEnv) {
57+
58+
createNativePackage(options,
59+
LinuxFromOptions::createLinuxDebPackage,
60+
buildEnv()::create,
61+
LinuxBundlingEnvironment::buildPipeline,
62+
(env, pkg, outputDir) -> {
63+
return new LinuxDebPackager(env, pkg, outputDir, sysEnv);
64+
});
65+
}
66+
67+
private static void createRpmPackage(Options options, LinuxRpmSystemEnvironment sysEnv) {
68+
69+
createNativePackage(options,
70+
LinuxFromOptions::createLinuxRpmPackage,
71+
buildEnv()::create,
72+
LinuxBundlingEnvironment::buildPipeline,
73+
(env, pkg, outputDir) -> {
74+
return new LinuxRpmPackager(env, pkg, outputDir, sysEnv);
75+
});
76+
}
77+
78+
private static void createAppImage(Options options) {
79+
80+
final var app = createLinuxApplication(options);
81+
82+
createApplicationImage(options, app, LinuxPackagingPipeline.build(Optional.empty()));
83+
}
84+
85+
private static PackagingPipeline.Builder buildPipeline(LinuxPackage pkg) {
86+
return LinuxPackagingPipeline.build(Optional.of(pkg));
87+
}
88+
89+
private static BuildEnvFromOptions buildEnv() {
90+
return new BuildEnvFromOptions().predefinedAppImageLayout(APPLICATION_LAYOUT);
91+
}
92+
93+
private static final class LazyLoad {
94+
95+
static Result<LinuxDebSystemEnvironment> debSysEnv() {
96+
return DEB_SYS_ENV;
97+
}
98+
99+
static Result<LinuxRpmSystemEnvironment> rpmSysEnv() {
100+
return RPM_SYS_ENV;
101+
}
102+
103+
private static final Result<LinuxSystemEnvironment> SYS_ENV = LinuxSystemEnvironment.create();
104+
105+
private static final Result<LinuxDebSystemEnvironment> DEB_SYS_ENV = LinuxDebSystemEnvironment.create(SYS_ENV);
106+
107+
private static final Result<LinuxRpmSystemEnvironment> RPM_SYS_ENV = LinuxRpmSystemEnvironment.create(SYS_ENV);
108+
}
109+
110+
private static final Map<PackageType, BundlingOperationDescriptor> DESCRIPTORS = Stream.of(
111+
CREATE_LINUX_DEB,
112+
CREATE_LINUX_RPM
113+
).collect(toMap(StandardBundlingOperation::packageType, StandardBundlingOperation::descriptor));
114+
}

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 2025, 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 static jdk.jpackage.internal.FromOptions.buildApplicationBuilder;
28+
import static jdk.jpackage.internal.FromOptions.createPackageBuilder;
29+
import static jdk.jpackage.internal.LinuxPackagingPipeline.APPLICATION_LAYOUT;
30+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_APP_CATEGORY;
31+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_DEB_MAINTAINER_EMAIL;
32+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_MENU_GROUP;
33+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_PACKAGE_DEPENDENCIES;
34+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_PACKAGE_NAME;
35+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_RELEASE;
36+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_RPM_LICENSE_TYPE;
37+
import static jdk.jpackage.internal.cli.StandardOption.LINUX_SHORTCUT_HINT;
38+
import static jdk.jpackage.internal.model.StandardPackageType.LINUX_DEB;
39+
import static jdk.jpackage.internal.model.StandardPackageType.LINUX_RPM;
40+
41+
import jdk.jpackage.internal.cli.Options;
42+
import jdk.jpackage.internal.model.Launcher;
43+
import jdk.jpackage.internal.model.LinuxApplication;
44+
import jdk.jpackage.internal.model.LinuxDebPackage;
45+
import jdk.jpackage.internal.model.LinuxLauncher;
46+
import jdk.jpackage.internal.model.LinuxLauncherMixin;
47+
import jdk.jpackage.internal.model.LinuxRpmPackage;
48+
import jdk.jpackage.internal.model.StandardPackageType;
49+
50+
final class LinuxFromOptions {
51+
52+
static LinuxApplication createLinuxApplication(Options options) {
53+
54+
final var launcherFromOptions = new LauncherFromOptions().faWithDefaultDescription();
55+
56+
final var appBuilder = buildApplicationBuilder().create(options, launcherOptions -> {
57+
58+
final var launcher = launcherFromOptions.create(launcherOptions);
59+
60+
final var shortcut = LINUX_SHORTCUT_HINT.findIn(launcherOptions);
61+
62+
return LinuxLauncher.create(launcher, new LinuxLauncherMixin.Stub(shortcut));
63+
64+
}, (LinuxLauncher linuxLauncher, Launcher launcher) -> {
65+
return LinuxLauncher.create(launcher, linuxLauncher);
66+
}, APPLICATION_LAYOUT);
67+
68+
appBuilder.launchers().map(LinuxPackagingPipeline::normalizeShortcuts).ifPresent(appBuilder::launchers);
69+
70+
return LinuxApplication.create(appBuilder.create());
71+
}
72+
73+
static LinuxRpmPackage createLinuxRpmPackage(Options options) {
74+
75+
final var superPkgBuilder = createLinuxPackageBuilder(options, LINUX_RPM);
76+
77+
final var pkgBuilder = new LinuxRpmPackageBuilder(superPkgBuilder);
78+
79+
LINUX_RPM_LICENSE_TYPE.ifPresentIn(options, pkgBuilder::licenseType);
80+
81+
return pkgBuilder.create();
82+
}
83+
84+
static LinuxDebPackage createLinuxDebPackage(Options options) {
85+
86+
final var superPkgBuilder = createLinuxPackageBuilder(options, LINUX_DEB);
87+
88+
final var pkgBuilder = new LinuxDebPackageBuilder(superPkgBuilder);
89+
90+
LINUX_DEB_MAINTAINER_EMAIL.ifPresentIn(options, pkgBuilder::maintainerEmail);
91+
92+
final var pkg = pkgBuilder.create();
93+
94+
// Show warning if license file is missing
95+
if (pkg.licenseFile().isEmpty()) {
96+
Log.verbose(I18N.getString("message.debs-like-licenses"));
97+
}
98+
99+
return pkg;
100+
}
101+
102+
private static LinuxPackageBuilder createLinuxPackageBuilder(Options options, StandardPackageType type) {
103+
104+
final var app = createLinuxApplication(options);
105+
106+
final var superPkgBuilder = createPackageBuilder(options, app, type);
107+
108+
final var pkgBuilder = new LinuxPackageBuilder(superPkgBuilder);
109+
110+
LINUX_PACKAGE_DEPENDENCIES.ifPresentIn(options, pkgBuilder::additionalDependencies);
111+
LINUX_APP_CATEGORY.ifPresentIn(options, pkgBuilder::category);
112+
LINUX_MENU_GROUP.ifPresentIn(options, pkgBuilder::menuGroupName);
113+
LINUX_RELEASE.ifPresentIn(options, pkgBuilder::release);
114+
LINUX_PACKAGE_NAME.ifPresentIn(options, pkgBuilder::literalName);
115+
116+
return pkgBuilder;
117+
}
118+
119+
}

0 commit comments

Comments
 (0)