Skip to content

Commit 185e38a

Browse files
Make PackageType.getName() public and rename it into PackageType.getType(); Add PackageType.isEnabled(). Make PackageType.isEnabled() and PackageType.isSupported() public.
1 parent 4fc37b2 commit 185e38a

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/PackageTestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public Executor.Result execute(int expectedExitCode) {
376376
};
377377
}).setExpectedExitCode(expectedJPackageExitCode)
378378
.setExpectedInstallExitCode(handlersSpec.installExitCode)
379-
.isPackageTypeSupported(type -> true)
379+
.isPackageTypeEnabled(type -> true)
380380
.forTypes().packageHandlers(handlers);
381381
}
382382

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ public void run() {
12381238
() -> {
12391239
Map<String, PackageType> reply = new HashMap<>();
12401240
for (PackageType type : PackageType.values()) {
1241-
reply.put(type.getName(), type);
1241+
reply.put(type.getType(), type);
12421242
}
12431243
return reply;
12441244
}).get();

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
public final class PackageTest extends RunnablePackageTest {
7272

7373
public PackageTest() {
74-
isPackageTypeSupported = PackageType::isSupported;
74+
isPackageTypeEnabled = PackageType::isEnabled;
7575
jpackageFactory = JPackageCommand::new;
7676
packageHandlers = new HashMap<>();
7777
disabledInstallers = new HashSet<>();
@@ -102,7 +102,7 @@ public PackageTest forTypes(PackageType... types) {
102102
newTypes = Stream.of(types).collect(Collectors.toSet());
103103
}
104104
currentTypes = newTypes.stream()
105-
.filter(isPackageTypeSupported)
105+
.filter(isPackageTypeEnabled)
106106
.filter(Predicate.not(excludeTypes::contains))
107107
.collect(Collectors.toUnmodifiableSet());
108108
return this;
@@ -394,9 +394,9 @@ PackageTest packageHandlers(PackageHandlers v) {
394394
return this;
395395
}
396396

397-
PackageTest isPackageTypeSupported(Predicate<PackageType> v) {
397+
PackageTest isPackageTypeEnabled(Predicate<PackageType> v) {
398398
Objects.requireNonNull(v);
399-
isPackageTypeSupported = v;
399+
isPackageTypeEnabled = v;
400400
return this;
401401
}
402402

@@ -505,7 +505,7 @@ public void accept(Action action) {
505505
case UNPACK -> {
506506
cmd.setUnpackedPackageLocation(null);
507507
final var unpackRootDir = TKit.createTempDirectory(
508-
String.format("unpacked-%s", type.getName()));
508+
String.format("unpacked-%s", type.getType()));
509509
final Path unpackDir = packageHandlers.unpack(cmd, unpackRootDir);
510510
if (!unpackDir.startsWith(TKit.workDir())) {
511511
state.deleteUnpackDirs.add(unpackDir);
@@ -918,7 +918,7 @@ private static boolean isOfType(JPackageCommand cmd, Set<PackageType> packageTyp
918918
private final Map<PackageType, PackageHandlers> packageHandlers;
919919
private final Set<PackageType> disabledInstallers;
920920
private final Set<PackageType> disabledUninstallers;
921-
private Predicate<PackageType> isPackageTypeSupported;
921+
private Predicate<PackageType> isPackageTypeEnabled;
922922
private Supplier<JPackageCommand> jpackageFactory;
923923
private boolean ignoreBundleOutputDir;
924924
private boolean createMsiLog;

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.lang.reflect.InvocationTargetException;
2727
import java.lang.reflect.Method;
2828
import java.util.Collections;
29+
import java.util.Objects;
2930
import java.util.Optional;
3031
import java.util.Set;
3132
import java.util.concurrent.atomic.AtomicBoolean;
@@ -48,19 +49,23 @@ public enum PackageType {
4849
TKit.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null),
4950
MAC_DMG(".dmg", TKit.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null),
5051
MAC_PKG(".pkg", TKit.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null),
51-
IMAGE("app-image", null, null);
52+
IMAGE;
53+
54+
PackageType() {
55+
type = "app-image";
56+
suffix = null;
57+
supported = true;
58+
enabled = true;
59+
}
5260

5361
PackageType(String packageName, String bundleSuffix, String bundlerClass) {
54-
name = packageName;
55-
suffix = bundleSuffix;
56-
if (bundlerClass != null && !Inner.DISABLED_PACKAGERS.contains(getName())) {
57-
supported = isBundlerSupported(bundlerClass);
58-
} else {
59-
supported = false;
60-
}
62+
type = Objects.requireNonNull(packageName);
63+
suffix = Objects.requireNonNull(bundleSuffix);
64+
supported = Optional.ofNullable(bundlerClass).map(PackageType::isBundlerSupported).orElse(false);
65+
enabled = supported && !Inner.DISABLED_PACKAGERS.contains(getType());
6166

62-
if (suffix != null && supported) {
63-
TKit.trace(String.format("Bundler %s supported", getName()));
67+
if (suffix != null && enabled) {
68+
TKit.trace(String.format("Bundler %s enabled", getType()));
6469
}
6570
}
6671

@@ -69,30 +74,23 @@ public enum PackageType {
6974
}
7075

7176
void applyTo(JPackageCommand cmd) {
72-
cmd.setArgumentValue("--type", getName());
77+
cmd.setArgumentValue("--type", getType());
7378
}
7479

7580
String getSuffix() {
76-
return suffix;
81+
return Optional.ofNullable(suffix).orElseThrow(UnsupportedOperationException::new);
7782
}
7883

79-
boolean isSupported() {
84+
public boolean isSupported() {
8085
return supported;
8186
}
8287

83-
String getName() {
84-
return name;
88+
public boolean isEnabled() {
89+
return supported;
8590
}
8691

87-
static PackageType fromSuffix(String packageFilename) {
88-
if (packageFilename != null) {
89-
for (PackageType v : values()) {
90-
if (packageFilename.endsWith(v.getSuffix())) {
91-
return v;
92-
}
93-
}
94-
}
95-
return null;
92+
public String getType() {
93+
return type;
9694
}
9795

9896
private static boolean isBundlerSupportedImpl(String bundlerClass) {
@@ -133,8 +131,9 @@ private static boolean isBundlerSupported(String bundlerClass) {
133131
return reply.get();
134132
}
135133

136-
private final String name;
134+
private final String type;
137135
private final String suffix;
136+
private final boolean enabled;
138137
private final boolean supported;
139138

140139
public static final Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM);

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static Optional<Path> configureMsiLogFile(JPackageCommand cmd, boolean c
107107
final Optional<Path> msiLogFile;
108108
if (createMsiLog) {
109109
msiLogFile = Optional.of(TKit.createTempFile(String.format("logs\\%s-msi.log",
110-
cmd.packageType().getName())));
110+
cmd.packageType().getType())));
111111
} else {
112112
msiLogFile = Optional.empty();
113113
}

0 commit comments

Comments
 (0)