test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java
branchJDK-8200758-branch
changeset 58416 f09bf58c1f17
parent 58301 e0efb29609bd
child 58648 3bf53ffa9ae7
equal deleted inserted replaced
58415:73f8e557549a 58416:f09bf58c1f17
    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.Optional;
    27 import java.util.Optional;
    28 import java.util.Set;
    28 import java.util.Set;
    29 import java.util.function.Supplier;
       
    30 import java.util.stream.Collectors;
    29 import java.util.stream.Collectors;
    31 import java.util.stream.Stream;
    30 import java.util.stream.Stream;
    32 
    31 
    33 /**
    32 /**
    34  * jpackage package type traits.
    33  * jpackage package type traits.
    35  */
    34  */
    36 public enum PackageType {
    35 public enum PackageType {
    37     WIN_MSI(".msi",
    36     WIN_MSI(".msi",
    38             Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null),
    37             TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null),
    39     WIN_EXE(".exe",
    38     WIN_EXE(".exe",
    40             Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null),
    39             TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null),
    41     LINUX_DEB(".deb",
    40     LINUX_DEB(".deb",
    42             Test.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null),
    41             TKit.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null),
    43     LINUX_RPM(".rpm",
    42     LINUX_RPM(".rpm",
    44             Test.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null),
    43             TKit.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null),
    45     MAC_DMG(".dmg", Test.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null),
    44     MAC_DMG(".dmg", TKit.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null),
    46     MAC_PKG(".pkg", Test.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null),
    45     MAC_PKG(".pkg", TKit.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null),
    47     IMAGE("app-image", null, null);
    46     IMAGE("app-image", null, null);
    48 
    47 
    49     PackageType(String packageName, String bundleSuffix, String bundlerClass) {
    48     PackageType(String packageName, String bundleSuffix, String bundlerClass) {
    50         name  = packageName;
    49         name  = packageName;
    51         suffix = bundleSuffix;
    50         suffix = bundleSuffix;
    54         } else {
    53         } else {
    55             supported = false;
    54             supported = false;
    56         }
    55         }
    57 
    56 
    58         if (suffix != null && supported) {
    57         if (suffix != null && supported) {
    59             Test.trace(String.format("Bundler %s supported", getName()));
    58             TKit.trace(String.format("Bundler %s supported", getName()));
    60         }
    59         }
    61     }
    60     }
    62 
    61 
    63     PackageType(String bundleSuffix, String bundlerClass) {
    62     PackageType(String bundleSuffix, String bundlerClass) {
    64         this(bundleSuffix.substring(1), bundleSuffix, bundlerClass);
    63         this(bundleSuffix.substring(1), bundleSuffix, bundlerClass);
    93 
    92 
    94     private static boolean isBundlerSupported(String bundlerClass) {
    93     private static boolean isBundlerSupported(String bundlerClass) {
    95         try {
    94         try {
    96             Class clazz = Class.forName(bundlerClass);
    95             Class clazz = Class.forName(bundlerClass);
    97             Method supported = clazz.getMethod("supported", boolean.class);
    96             Method supported = clazz.getMethod("supported", boolean.class);
    98             return ((Boolean) supported.invoke(clazz.newInstance(), true));
    97             return ((Boolean) supported.invoke(
    99         } catch (ClassNotFoundException ex) {
    98                     clazz.getConstructor().newInstance(), true));
   100             return false;
    99         } catch (ClassNotFoundException | IllegalAccessException ex) {
   101         } catch (InstantiationException | NoSuchMethodException
   100         } catch (InstantiationException | NoSuchMethodException
   102                 | IllegalAccessException | InvocationTargetException ex) {
   101                 | InvocationTargetException ex) {
   103             throw new RuntimeException(ex);
   102             Functional.rethrowUnchecked(ex);
   104         }
   103         }
       
   104         return false;
   105     }
   105     }
   106 
   106 
   107     private String name;
   107     private final String name;
   108     private final String suffix;
   108     private final String suffix;
   109     private final boolean supported;
   109     private final boolean supported;
   110 
   110 
   111     public final static Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM);
   111     public final static Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM);
   112     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);
   113     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);
   114     public final static Set<PackageType> NATIVE = Stream.concat(
   114     public final static Set<PackageType> NATIVE = Stream.concat(
   115             Stream.concat(LINUX.stream(), WINDOWS.stream()),
   115             Stream.concat(LINUX.stream(), WINDOWS.stream()),
   116             MAC.stream()).collect(Collectors.toUnmodifiableSet());
   116             MAC.stream()).collect(Collectors.toUnmodifiableSet());
   117 
   117 
   118     public final static PackageType DEFAULT = ((Supplier<PackageType>) () -> {
       
   119         if (Test.isLinux()) {
       
   120             return LINUX.stream().filter(v -> v.isSupported()).findFirst().orElseThrow();
       
   121         }
       
   122 
       
   123         if (Test.isWindows()) {
       
   124             return WIN_EXE;
       
   125         }
       
   126 
       
   127         if (Test.isOSX()) {
       
   128             return MAC_DMG;
       
   129         }
       
   130 
       
   131         throw new IllegalStateException("Unknwon platform");
       
   132     }).get();
       
   133 
       
   134     private final static class Inner {
   118     private final static class Inner {
   135 
   119 
   136         private final static Set<String> DISABLED_PACKAGERS = Stream.of(
   120         private final static Set<String> DISABLED_PACKAGERS = Stream.of(
   137                 Optional.ofNullable(
   121                 Optional.ofNullable(
   138                         Test.getConfigProperty("disabledPackagers")).orElse(
   122                         TKit.getConfigProperty("disabledPackagers")).orElse(
   139                         "").split(",")).collect(Collectors.toUnmodifiableSet());
   123                         "").split(",")).collect(Collectors.toUnmodifiableSet());
   140     }
   124     }
   141 }
   125 }