equal
deleted
inserted
replaced
52 import java.util.Optional; |
52 import java.util.Optional; |
53 import java.util.ResourceBundle; |
53 import java.util.ResourceBundle; |
54 import java.util.Set; |
54 import java.util.Set; |
55 import java.util.concurrent.atomic.AtomicReference; |
55 import java.util.concurrent.atomic.AtomicReference; |
56 import java.util.function.Consumer; |
56 import java.util.function.Consumer; |
|
57 import javax.xml.parsers.DocumentBuilder; |
|
58 import javax.xml.parsers.DocumentBuilderFactory; |
|
59 import javax.xml.xpath.XPath; |
|
60 import javax.xml.xpath.XPathConstants; |
|
61 import javax.xml.xpath.XPathFactory; |
57 |
62 |
58 import static jdk.jpackage.internal.StandardBundlerParam.*; |
63 import static jdk.jpackage.internal.StandardBundlerParam.*; |
59 import static jdk.jpackage.internal.MacBaseInstallerBundler.*; |
64 import static jdk.jpackage.internal.MacBaseInstallerBundler.*; |
60 import static jdk.jpackage.internal.MacAppBundler.*; |
65 import static jdk.jpackage.internal.MacAppBundler.*; |
61 |
66 |
110 |
115 |
111 public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER = |
116 public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER = |
112 new StandardBundlerParam<>( |
117 new StandardBundlerParam<>( |
113 Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(), |
118 Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(), |
114 String.class, |
119 String.class, |
115 IDENTIFIER::fetchFrom, |
120 params -> { |
|
121 // Get identifier from app image if user provided |
|
122 // app image and did not provide the identifier via CLI. |
|
123 String identifier = extractBundleIdentifier(params); |
|
124 if (identifier != null) { |
|
125 return identifier; |
|
126 } |
|
127 |
|
128 return IDENTIFIER.fetchFrom(params); |
|
129 }, |
116 (s, p) -> s); |
130 (s, p) -> s); |
117 |
131 |
118 public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION = |
132 public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION = |
119 new StandardBundlerParam<>( |
133 new StandardBundlerParam<>( |
120 "mac.CFBundleVersion", |
134 "mac.CFBundleVersion", |
927 } |
941 } |
928 |
942 |
929 return true; |
943 return true; |
930 } |
944 } |
931 |
945 |
|
946 private static String extractBundleIdentifier(Map<String, Object> params) { |
|
947 if (PREDEFINED_APP_IMAGE.fetchFrom(params) == null) { |
|
948 return null; |
|
949 } |
|
950 |
|
951 try { |
|
952 File infoPList = new File(PREDEFINED_APP_IMAGE.fetchFrom(params) + |
|
953 File.separator + "Contents" + |
|
954 File.separator + "Info.plist"); |
|
955 |
|
956 DocumentBuilderFactory dbf |
|
957 = DocumentBuilderFactory.newDefaultInstance(); |
|
958 dbf.setFeature("http://apache.org/xml/features/" + |
|
959 "nonvalidating/load-external-dtd", false); |
|
960 DocumentBuilder b = dbf.newDocumentBuilder(); |
|
961 org.w3c.dom.Document doc = b.parse(new FileInputStream( |
|
962 infoPList.getAbsolutePath())); |
|
963 |
|
964 XPath xPath = XPathFactory.newInstance().newXPath(); |
|
965 // Query for the value of <string> element preceding <key> |
|
966 // element with value equal to CFBundleIdentifier |
|
967 String v = (String) xPath.evaluate( |
|
968 "//string[preceding-sibling::key = \"CFBundleIdentifier\"][1]", |
|
969 doc, XPathConstants.STRING); |
|
970 |
|
971 if (v != null && !v.isEmpty()) { |
|
972 return v; |
|
973 } |
|
974 } catch (Exception ex) { |
|
975 Log.verbose(ex); |
|
976 } |
|
977 |
|
978 return null; |
|
979 } |
|
980 |
932 } |
981 } |