136 Path path = Paths.get(arg); 137 if (Files.exists(path)) { 138 throw taskHelper.newBadArgs("err.dir.exists", path); 139 } 140 task.options.packagedModulesPath = path; 141 }, true, "--keep-packaged-modules"), 142 new Option<JlinkTask>(true, (task, opt, arg) -> { 143 task.options.saveoptsfile = arg; 144 }, "--save-opts"), 145 new Option<JlinkTask>(false, (task, opt, arg) -> { 146 task.options.fullVersion = true; 147 }, true, "--full-version"),}; 148 149 private static final String PROGNAME = "jlink"; 150 private final OptionsValues options = new OptionsValues(); 151 152 private static final OptionsHelper<JlinkTask> optionsHelper 153 = taskHelper.newOptionsHelper(JlinkTask.class, recognizedOptions); 154 private PrintWriter log; 155 156 void setLog(PrintWriter out) { 157 log = out; 158 taskHelper.setLog(log); 159 } 160 161 /** 162 * Result codes. 163 */ 164 static final int EXIT_OK = 0, // Completed with no errors. 165 EXIT_ERROR = 1, // Completed but reported errors. 166 EXIT_CMDERR = 2, // Bad command-line arguments 167 EXIT_SYSERR = 3, // System error or resource exhaustion. 168 EXIT_ABNORMAL = 4;// terminated abnormally 169 170 static class OptionsValues { 171 boolean help; 172 String saveoptsfile; 173 boolean version; 174 boolean fullVersion; 175 List<Path> modulePath = new ArrayList<>(); 176 Set<String> limitMods = new HashSet<>(); 177 Set<String> addMods = new HashSet<>(); 178 Path output; 179 Path packagedModulesPath; 180 ByteOrder endian = ByteOrder.nativeOrder(); 181 } 182 183 int run(String[] args) { 184 if (log == null) { 185 setLog(new PrintWriter(System.out, true)); 186 } 187 try { 188 optionsHelper.handleOptions(this, args); 189 if (options.help) { 190 optionsHelper.showHelp(PROGNAME); 191 return EXIT_OK; 192 } 193 if (optionsHelper.shouldListPlugins()) { 194 optionsHelper.listPlugins(); 195 return EXIT_OK; 196 } 197 if (options.version || options.fullVersion) { 198 taskHelper.showVersion(options.fullVersion); 199 return EXIT_OK; 200 } 201 if (taskHelper.getExistingImage() == null) { 202 if (options.modulePath == null || options.modulePath.isEmpty()) { 203 throw taskHelper.newBadArgs("err.modulepath.must.be.specified").showUsage(true); 204 } 205 createImage(); | 136 Path path = Paths.get(arg); 137 if (Files.exists(path)) { 138 throw taskHelper.newBadArgs("err.dir.exists", path); 139 } 140 task.options.packagedModulesPath = path; 141 }, true, "--keep-packaged-modules"), 142 new Option<JlinkTask>(true, (task, opt, arg) -> { 143 task.options.saveoptsfile = arg; 144 }, "--save-opts"), 145 new Option<JlinkTask>(false, (task, opt, arg) -> { 146 task.options.fullVersion = true; 147 }, true, "--full-version"),}; 148 149 private static final String PROGNAME = "jlink"; 150 private final OptionsValues options = new OptionsValues(); 151 152 private static final OptionsHelper<JlinkTask> optionsHelper 153 = taskHelper.newOptionsHelper(JlinkTask.class, recognizedOptions); 154 private PrintWriter log; 155 156 void setLog(PrintWriter out, PrintWriter err) { 157 log = out; 158 taskHelper.setLog(log); 159 } 160 161 /** 162 * Result codes. 163 */ 164 static final int EXIT_OK = 0, // Completed with no errors. 165 EXIT_ERROR = 1, // Completed but reported errors. 166 EXIT_CMDERR = 2, // Bad command-line arguments 167 EXIT_SYSERR = 3, // System error or resource exhaustion. 168 EXIT_ABNORMAL = 4;// terminated abnormally 169 170 static class OptionsValues { 171 boolean help; 172 String saveoptsfile; 173 boolean version; 174 boolean fullVersion; 175 List<Path> modulePath = new ArrayList<>(); 176 Set<String> limitMods = new HashSet<>(); 177 Set<String> addMods = new HashSet<>(); 178 Path output; 179 Path packagedModulesPath; 180 ByteOrder endian = ByteOrder.nativeOrder(); 181 } 182 183 int run(String[] args) { 184 if (log == null) { 185 setLog(new PrintWriter(System.out, true), 186 new PrintWriter(System.err, true)); 187 } 188 try { 189 optionsHelper.handleOptions(this, args); 190 if (options.help) { 191 optionsHelper.showHelp(PROGNAME); 192 return EXIT_OK; 193 } 194 if (optionsHelper.shouldListPlugins()) { 195 optionsHelper.listPlugins(); 196 return EXIT_OK; 197 } 198 if (options.version || options.fullVersion) { 199 taskHelper.showVersion(options.fullVersion); 200 return EXIT_OK; 201 } 202 if (taskHelper.getExistingImage() == null) { 203 if (options.modulePath == null || options.modulePath.isEmpty()) { 204 throw taskHelper.newBadArgs("err.modulepath.must.be.specified").showUsage(true); 205 } 206 createImage(); |