author | herrick |
Thu, 26 Sep 2019 09:19:46 -0400 | |
branch | JDK-8200758-branch |
changeset 58359 | e065fd274bc1 |
parent 57776 | 783db59cd8d3 |
permissions | -rw-r--r-- |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57071
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
4 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
6 |
* published by the Free Software Foundation. Oracle designates this |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
7 |
* particular file as subject to the "Classpath" exception as provided |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
8 |
* by Oracle in the LICENSE file that accompanied this code. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
9 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
14 |
* accompanied this code). |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
15 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License version |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
19 |
* |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
22 |
* questions. |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
23 |
*/ |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
24 |
|
57039 | 25 |
package jdk.jpackage.main; |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
26 |
|
57039 | 27 |
import jdk.jpackage.internal.Arguments; |
28 |
import jdk.jpackage.internal.Log; |
|
29 |
import jdk.jpackage.internal.CLIHelp; |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
30 |
import java.io.PrintWriter; |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
31 |
import java.util.ResourceBundle; |
57447 | 32 |
import java.io.FileNotFoundException; |
57391 | 33 |
import java.io.IOException; |
57447 | 34 |
import java.text.MessageFormat; |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
35 |
|
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
36 |
public class Main { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
37 |
|
57447 | 38 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
57059 | 39 |
"jdk.jpackage.internal.resources.MainResources"); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
40 |
|
56982
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
41 |
/** |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
42 |
* main(String... args) |
57039 | 43 |
* This is the entry point for the jpackage tool. |
56982
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
44 |
* |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
45 |
* @param args command line arguments |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
46 |
*/ |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
47 |
public static void main(String... args) throws Exception { |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
48 |
// Create logger with default system.out and system.err |
57776 | 49 |
Log.setLogger(null); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
50 |
|
57391 | 51 |
int status = new jdk.jpackage.main.Main().execute(args); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
52 |
System.exit(status); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
53 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
54 |
|
56982
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
55 |
/** |
57391 | 56 |
* execute() - this is the entry point for the ToolProvider API. |
56982
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
57 |
* |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
58 |
* @param out output stream |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
59 |
* @param err error output stream |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
60 |
* @param args command line arguments |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
61 |
* @return an exit code. 0 means success, non-zero means an error occurred. |
e094d5483bd6
8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents:
56933
diff
changeset
|
62 |
*/ |
57391 | 63 |
public int execute(PrintWriter out, PrintWriter err, String... args) { |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
64 |
// Create logger with provided streams |
57776 | 65 |
Log.Logger logger = new Log.Logger(); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
66 |
logger.setPrintWriter(out, err); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
67 |
Log.setLogger(logger); |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
68 |
|
57391 | 69 |
return execute(args); |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
70 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
71 |
|
57391 | 72 |
private int execute(String... args) { |
58359
e065fd274bc1
8230649 : Make jpackage tool an experimental feature
herrick
parents:
57776
diff
changeset
|
73 |
Log.info(I18N.getString("warning.experimental")); |
57391 | 74 |
try { |
75 |
String[] newArgs; |
|
76 |
try { |
|
77 |
newArgs = CommandLine.parse(args); |
|
57447 | 78 |
} catch (FileNotFoundException fnfe) { |
79 |
Log.error(MessageFormat.format(I18N.getString( |
|
80 |
"ERR_CannotParseOptions"), fnfe.getMessage())); |
|
81 |
return 1; |
|
57391 | 82 |
} catch (IOException ioe) { |
83 |
Log.error(ioe.getMessage()); |
|
84 |
return 1; |
|
57071 | 85 |
} |
57391 | 86 |
|
87 |
if (newArgs.length == 0) { |
|
88 |
CLIHelp.showHelp(true); |
|
89 |
} else if (hasHelp(newArgs)){ |
|
90 |
if (hasVersion(newArgs)) { |
|
57392 | 91 |
Log.info(System.getProperty("java.version") + "\n"); |
57391 | 92 |
} |
93 |
CLIHelp.showHelp(false); |
|
94 |
} else if (hasVersion(newArgs)) { |
|
57392 | 95 |
Log.info(System.getProperty("java.version")); |
57391 | 96 |
} else { |
57214
cb63761b7079
8219695: Use a copy of javac's implementation of @argfile in jpackager
herrick
parents:
57106
diff
changeset
|
97 |
Arguments arguments = new Arguments(newArgs); |
57071 | 98 |
if (!arguments.processArguments()) { |
57391 | 99 |
// processArguments() will log error message if failed. |
100 |
return 1; |
|
57022
81021f910bc2
8213333: Fix issues found in jpackager with automated tests
herrick
parents:
57017
diff
changeset
|
101 |
} |
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
102 |
} |
57391 | 103 |
return 0; |
104 |
} finally { |
|
105 |
Log.flush(); |
|
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
106 |
} |
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
107 |
} |
56933
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
108 |
|
57391 | 109 |
private boolean hasHelp(String[] args) { |
56933
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
110 |
for (String a : args) { |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
111 |
if ("--help".equals(a) || "-h".equals(a)) { |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
112 |
return true; |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
113 |
} |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
114 |
} |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
115 |
return false; |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
116 |
} |
9f59eeb3cc0f
8211182: Remove jdk.packager.services.UserJvmOptionsService
herrick
parents:
56869
diff
changeset
|
117 |
|
57391 | 118 |
private boolean hasVersion(String[] args) { |
57071 | 119 |
for (String a : args) { |
57261
13b6672477df
8220505: Allow building available installers when --installer-type not specified
herrick
parents:
57214
diff
changeset
|
120 |
if ("--version".equals(a)) { |
57071 | 121 |
return true; |
122 |
} |
|
123 |
} |
|
124 |
return false; |
|
125 |
} |
|
126 |
||
56821
565d54ca1f41
8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff
changeset
|
127 |
} |