27 import javax.xml.parsers.DocumentBuilder;
28 import javax.xml.parsers.DocumentBuilderFactory;
29 import javax.xml.xpath.XPath;
30 import javax.xml.xpath.XPathConstants;
31 import javax.xml.xpath.XPathFactory;
32
33 /*
34 * @test
35 * @summary jpackage create image bundle identifier test
36 * @library ../../helpers
37 * @build JPackageHelper
38 * @build JPackagePath
39 * @modules jdk.jpackage
40 * @requires (os.family == "mac")
41 * @run main/othervm -Xmx512m JPackageCreateAppImageBundleIdentifierTest
42 */
43 public class JPackageCreateAppImageBundleIdentifierTest {
44 private static final String OUTPUT = "output";
45 private static final String app = JPackagePath.getApp();
46 private static final String appOutput = JPackagePath.getAppOutputFile();
47 private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
48 private static final String MAC_BUNDLE_IDENTIFIER = "TestBundleIdentifier";
49 private static final String APP_NAME = "test";
50 private static final String MAIN_CLASS = "Hello";
51
52 private static final String [] CMD_1 = {
53 "--input", "input",
54 "--output", OUTPUT,
55 "--name", APP_NAME,
56 "--main-jar", "hello.jar",
57 "--main-class", MAIN_CLASS
58 };
59
60 private static final String [] CMD_2 = {
61 "--input", "input",
62 "--output", OUTPUT,
63 "--name", APP_NAME,
64 "--main-jar", "hello.jar",
65 "--main-class", MAIN_CLASS,
66 "--mac-bundle-identifier", MAC_BUNDLE_IDENTIFIER
67 };
71 throw new AssertionError(
72 "Unexpected number of lines: " + result.length);
73 }
74
75 if (!result[0].trim().equals("jpackage test application")) {
76 throw new AssertionError("Unexpected result[0]: " + result[0]);
77 }
78
79 if (!result[1].trim().equals("args.length: 0")) {
80 throw new AssertionError("Unexpected result[1]: " + result[1]);
81 }
82 }
83
84 private static void validate() throws Exception {
85 int retVal = JPackageHelper.execute(null, app);
86 if (retVal != 0) {
87 throw new AssertionError(
88 "Test application exited with error: " + retVal);
89 }
90
91 File outfile = new File(appWorkingDir + File.separator + appOutput);
92 if (!outfile.exists()) {
93 throw new AssertionError(appOutput + " was not created");
94 }
95
96 String output = Files.readString(outfile.toPath());
97 String[] result = output.split("\n");
98 validateResult(result);
99 }
100
101 private static void validateBundleIdentifier(String bundleIdentifier)
102 throws Exception {
103 System.out.println("Validating bundleIdentifier: " + bundleIdentifier);
104
105 File infoPList = new File(OUTPUT + File.separator + APP_NAME + ".app" +
106 File.separator + "Contents" + File.separator + "Info.plist");
107
108 DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
109 dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
110 DocumentBuilder b = dbf.newDocumentBuilder();
111 org.w3c.dom.Document doc = b.parse(new FileInputStream(
|
27 import javax.xml.parsers.DocumentBuilder;
28 import javax.xml.parsers.DocumentBuilderFactory;
29 import javax.xml.xpath.XPath;
30 import javax.xml.xpath.XPathConstants;
31 import javax.xml.xpath.XPathFactory;
32
33 /*
34 * @test
35 * @summary jpackage create image bundle identifier test
36 * @library ../../helpers
37 * @build JPackageHelper
38 * @build JPackagePath
39 * @modules jdk.jpackage
40 * @requires (os.family == "mac")
41 * @run main/othervm -Xmx512m JPackageCreateAppImageBundleIdentifierTest
42 */
43 public class JPackageCreateAppImageBundleIdentifierTest {
44 private static final String OUTPUT = "output";
45 private static final String app = JPackagePath.getApp();
46 private static final String appOutput = JPackagePath.getAppOutputFile();
47 private static final String MAC_BUNDLE_IDENTIFIER = "TestBundleIdentifier";
48 private static final String APP_NAME = "test";
49 private static final String MAIN_CLASS = "Hello";
50
51 private static final String [] CMD_1 = {
52 "--input", "input",
53 "--output", OUTPUT,
54 "--name", APP_NAME,
55 "--main-jar", "hello.jar",
56 "--main-class", MAIN_CLASS
57 };
58
59 private static final String [] CMD_2 = {
60 "--input", "input",
61 "--output", OUTPUT,
62 "--name", APP_NAME,
63 "--main-jar", "hello.jar",
64 "--main-class", MAIN_CLASS,
65 "--mac-bundle-identifier", MAC_BUNDLE_IDENTIFIER
66 };
70 throw new AssertionError(
71 "Unexpected number of lines: " + result.length);
72 }
73
74 if (!result[0].trim().equals("jpackage test application")) {
75 throw new AssertionError("Unexpected result[0]: " + result[0]);
76 }
77
78 if (!result[1].trim().equals("args.length: 0")) {
79 throw new AssertionError("Unexpected result[1]: " + result[1]);
80 }
81 }
82
83 private static void validate() throws Exception {
84 int retVal = JPackageHelper.execute(null, app);
85 if (retVal != 0) {
86 throw new AssertionError(
87 "Test application exited with error: " + retVal);
88 }
89
90 File outfile = new File(appOutput);
91 if (!outfile.exists()) {
92 throw new AssertionError(appOutput + " was not created");
93 }
94
95 String output = Files.readString(outfile.toPath());
96 String[] result = output.split("\n");
97 validateResult(result);
98 }
99
100 private static void validateBundleIdentifier(String bundleIdentifier)
101 throws Exception {
102 System.out.println("Validating bundleIdentifier: " + bundleIdentifier);
103
104 File infoPList = new File(OUTPUT + File.separator + APP_NAME + ".app" +
105 File.separator + "Contents" + File.separator + "Info.plist");
106
107 DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
108 dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
109 DocumentBuilder b = dbf.newDocumentBuilder();
110 org.w3c.dom.Document doc = b.parse(new FileInputStream(
|