called by LaunchBuilder Creates a JAR file out of the list of contents provided. Each entry in the sources list can be either a single file, a directory, or a compressed (ZIP, JAR or TRZ) file. Regular files and directories must exist under the given parent directory, and are saved with the same re
(ArrayList<String> sources, File parent, File target, Manifest manifest)
| 240 | * @see java.util.jar.Manifest |
| 241 | */ |
| 242 | public File create(ArrayList<String> sources, File parent, File target, Manifest manifest) { |
| 243 | OverwriteValue policy = new OverwriteValue(overwritePolicy); |
| 244 | overwritePolicy = NO; |
| 245 | if (sources.size() <= 0) { |
| 246 | return null; |
| 247 | } |
| 248 | try { |
| 249 | boolean warnBeforeOverwritting = true; |
| 250 | if (target != null) { |
| 251 | chooser.setCurrentDirectory(target.getParentFile()); |
| 252 | chooser.setSelectedFile(target); |
| 253 | } else { |
| 254 | chooser.setSelectedFile(new File("default.jar")); //$NON-NLS-1$ |
| 255 | } |
| 256 | String targetName = OSPRuntime.chooseFilename(chooser); |
| 257 | if (targetName == null) { |
| 258 | return null; |
| 259 | } |
| 260 | if (!(targetName.toLowerCase().endsWith(".jar") || //$NON-NLS-1$ |
| 261 | targetName.toLowerCase().endsWith(".trz") || //$NON-NLS-1$ |
| 262 | targetName.toLowerCase().endsWith(".zip"))) { //$NON-NLS-1$ |
| 263 | targetName = targetName + ".jar"; //$NON-NLS-1$ |
| 264 | } else { |
| 265 | warnBeforeOverwritting = false; // the chooser already checked if the target file exists |
| 266 | } |
| 267 | target = new File(targetName); |
| 268 | if (org.opensourcephysics.controls.XML.forwardSlash(target.getAbsolutePath()) |
| 269 | .equals(OSPRuntime.getLaunchJarPath())) { |
| 270 | String[] message = new String[] { res.getString("JarTool.JarNotCreated"), //$NON-NLS-1$ |
| 271 | res.getString("JarTool.FileIsForbidden") + " " + target }; //$NON-NLS-1$ //$NON-NLS-2$ |
| 272 | JOptionPane.showMessageDialog((JFrame) null, message, res.getString("JarTool.Error"), //$NON-NLS-1$ |
| 273 | JOptionPane.WARNING_MESSAGE); |
| 274 | return create(sources, parent, target, manifest); // added by D Brown June 2007 |
| 275 | } |
| 276 | if (warnBeforeOverwritting && target.exists()) { |
| 277 | int selected = JOptionPane.showConfirmDialog(null, |
| 278 | DisplayRes.getString("DrawingFrame.ReplaceExisting_message") + " " + //$NON-NLS-1$ //$NON-NLS-2$ |
| 279 | target.getName() + DisplayRes.getString("DrawingFrame.QuestionMark"), //$NON-NLS-1$ |
| 280 | DisplayRes.getString("DrawingFrame.ReplaceFile_option_title"), //$NON-NLS-1$ |
| 281 | JOptionPane.YES_NO_CANCEL_OPTION); |
| 282 | if (selected != JOptionPane.YES_OPTION) { |
| 283 | return null; |
| 284 | } |
| 285 | } |
| 286 | if (OSPRuntime.isJS) { |
| 287 | System.err.println("Warning: JarTool not supported in JavaScript."); |
| 288 | } else { |
| 289 | JarTool builder = new JarTool(sources, parent, target, manifest, policy, ownerFrame); |
| 290 | java.lang.Thread thread = new Thread(builder); |
| 291 | thread.setPriority(Thread.NORM_PRIORITY); |
| 292 | thread.start(); |
| 293 | } |
| 294 | return target; |
| 295 | // return compressList(sources,parent,target,manifest,policy,ownerFrame); |
| 296 | } catch (Exception exception) { |
| 297 | exception.printStackTrace(); |
| 298 | return null; |
| 299 | } |
no test coverage detected