22 */ |
22 */ |
23 package jdk.jpackage.test; |
23 package jdk.jpackage.test; |
24 |
24 |
25 import java.lang.reflect.InvocationTargetException; |
25 import java.lang.reflect.InvocationTargetException; |
26 import java.lang.reflect.Method; |
26 import java.lang.reflect.Method; |
27 import java.util.HashMap; |
|
28 import java.util.Map; |
|
29 import java.util.Optional; |
27 import java.util.Optional; |
30 import java.util.Set; |
28 import java.util.Set; |
31 import java.util.function.Supplier; |
29 import java.util.function.Supplier; |
32 import java.util.stream.Collectors; |
30 import java.util.stream.Collectors; |
33 import java.util.stream.Stream; |
31 import java.util.stream.Stream; |
59 |
57 |
60 if (suffix != null && supported) { |
58 if (suffix != null && supported) { |
61 Test.trace(String.format("Bundler %s supported", getName())); |
59 Test.trace(String.format("Bundler %s supported", getName())); |
62 } |
60 } |
63 } |
61 } |
64 |
62 |
65 PackageType(String bundleSuffix, String bundlerClass) { |
63 PackageType(String bundleSuffix, String bundlerClass) { |
66 this(bundleSuffix.substring(1), bundleSuffix, bundlerClass); |
64 this(bundleSuffix.substring(1), bundleSuffix, bundlerClass); |
67 } |
65 } |
68 |
66 |
69 void applyTo(JPackageCommand cmd) { |
67 void applyTo(JPackageCommand cmd) { |
94 } |
92 } |
95 |
93 |
96 private static boolean isBundlerSupported(String bundlerClass) { |
94 private static boolean isBundlerSupported(String bundlerClass) { |
97 try { |
95 try { |
98 Class clazz = Class.forName(bundlerClass); |
96 Class clazz = Class.forName(bundlerClass); |
99 Method isSupported = clazz.getDeclaredMethod("isSupported"); |
97 Method supported = clazz.getMethod("supported", boolean.class); |
100 return ((Boolean) isSupported.invoke(clazz)); |
98 return ((Boolean) supported.invoke(clazz.newInstance(), true)); |
101 } catch (ClassNotFoundException ex) { |
99 } catch (ClassNotFoundException ex) { |
102 return false; |
100 return false; |
103 } catch (IllegalAccessException | InvocationTargetException ex) { |
101 } catch (InstantiationException | NoSuchMethodException |
|
102 | IllegalAccessException | InvocationTargetException ex) { |
104 throw new RuntimeException(ex); |
103 throw new RuntimeException(ex); |
105 } catch (NoSuchMethodException ex) { |
|
106 // Not all bundler classes has isSupported() method. |
|
107 return true; |
|
108 } |
104 } |
109 } |
105 } |
110 |
106 |
111 private String name; |
107 private String name; |
112 private final String suffix; |
108 private final String suffix; |
116 public final static Set<PackageType> WINDOWS = Set.of(WIN_EXE, WIN_MSI); |
112 public final static Set<PackageType> WINDOWS = Set.of(WIN_EXE, WIN_MSI); |
117 public final static Set<PackageType> MAC = Set.of(MAC_PKG, MAC_DMG); |
113 public final static Set<PackageType> MAC = Set.of(MAC_PKG, MAC_DMG); |
118 public final static Set<PackageType> NATIVE = Stream.concat( |
114 public final static Set<PackageType> NATIVE = Stream.concat( |
119 Stream.concat(LINUX.stream(), WINDOWS.stream()), |
115 Stream.concat(LINUX.stream(), WINDOWS.stream()), |
120 MAC.stream()).collect(Collectors.toUnmodifiableSet()); |
116 MAC.stream()).collect(Collectors.toUnmodifiableSet()); |
121 |
117 |
122 public final static PackageType DEFAULT = ((Supplier<PackageType>) () -> { |
118 public final static PackageType DEFAULT = ((Supplier<PackageType>) () -> { |
123 if (Test.isLinux()) { |
119 if (Test.isLinux()) { |
124 return LINUX.stream().filter(v -> v.isSupported()).findFirst().orElseThrow(); |
120 return LINUX.stream().filter(v -> v.isSupported()).findFirst().orElseThrow(); |
125 } |
121 } |
126 |
122 |
127 if (Test.isWindows()) { |
123 if (Test.isWindows()) { |
128 return WIN_EXE; |
124 return WIN_EXE; |
129 } |
125 } |
130 |
126 |
131 if (Test.isOSX()) { |
127 if (Test.isOSX()) { |
132 return MAC_DMG; |
128 return MAC_DMG; |
133 } |
129 } |
134 |
130 |
135 throw new IllegalStateException("Unknwon platform"); |
131 throw new IllegalStateException("Unknwon platform"); |
136 }).get(); |
132 }).get(); |
137 |
133 |
138 private final static class Inner { |
134 private final static class Inner { |
139 |
135 |
140 private final static Set<String> DISABLED_PACKAGERS = Stream.of( |
136 private final static Set<String> DISABLED_PACKAGERS = Stream.of( |
141 Optional.ofNullable( |
137 Optional.ofNullable( |
142 System.getProperty("jpackage.test.disabledPackagers")).orElse( |
138 Test.getConfigProperty("disabledPackagers")).orElse( |
143 "").split(",")).collect(Collectors.toUnmodifiableSet()); |
139 "").split(",")).collect(Collectors.toUnmodifiableSet()); |
144 } |
140 } |
145 } |
141 } |