Package org.opensourcephysics.tools
Class JarTool
java.lang.Object
org.opensourcephysics.tools.JarTool
This provides a simple way to package files in a single JAR or ZIP file
- Version:
- 1.0
- Author:
- Francisco Esquembre (http://fem.um.es), Doug Brown
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Sets the overwrite feature to true.static boolean
Compresses a directory into a single JAR or ZIP file.static boolean
Compresses a list of files and/or directories into a single JAR or ZIP file.static boolean
Copies a file.called by LaunchBuilder Creates a JAR file out of the list of contents provided.static Manifest
createManifest
(String classpath, String mainclass) From LaunchBuilder save jar Creates a Manifest for a JAR file with the given parametersstatic void
This method is kept for backwards compatibility.static File
From ResourceLoader Extracts a given file from a compressed (ZIP, JAR or TRZ) filestatic Collection<File>
getContents
(File directory) Returns all the files under a given directorystatic JarTool
for LaunchBuilder Gets the shared JarTool.static void
Sets the overwrite feature to false.static boolean
Completely removes a directory (without warning!)void
run()
void
Sends a job to this tool and specifies a tool to reply to.static void
setOwnerFrame
(Frame owner) called by LaunchBuilder Sets the owner frame for progress dialogs that may appear when creating a JAR file.static boolean
Uncompresses a ZIP or JAR file into a given directory.static boolean
unzipNoOverwrite
(File source, File targetDirectory) Uncompresses a ZIP or JAR file into a given directory.static boolean
unzipWithAWarning
(File source, File targetDirectory) Uncompresses a ZIP or JAR file into a given directory.unzipWithWarning
(InputStream zipStream, File targetDirectory, JLabel label, String prefix) Uncompresses a ZIP or JAR file into a given directory.
-
Method Details
-
getInstance
for LaunchBuilder Gets the shared JarTool.- Returns:
- the shared JarTool
-
run
public void run() -
send
Sends a job to this tool and specifies a tool to reply to. -
disableWarning
public static void disableWarning()This method is kept for backwards compatibility. It is equivalent to alwaysOverwrite(). -
neverOverwrite
public static void neverOverwrite()Sets the overwrite feature to false. By default, the packaging methods create() and append() will warn the user before overwritting a duplicated file. Calling this method before running those methods disables this warning and makes sure a new file will NEVER overwrite an older one. The methods create() and append() set the warning feature back.- See Also:
-
alwayOverwrite
-
alwaysOverwrite
public static void alwaysOverwrite()Sets the overwrite feature to true. By default, the packaging methods create() and append() will warn the user before overwritting a duplicated file. Calling this method before running those methods disables this warning AND makes sure a new file will ALWAYS overwrite an older one. The methods create() and append() set the warning feature back.- See Also:
-
setOwnerFrame
called by LaunchBuilder Sets the owner frame for progress dialogs that may appear when creating a JAR file.- Parameters:
owner
- Frame
-
create
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 relative path as provided. As an exception, you can also add files in parent directories, such as, "../../../WhateverDir/WhateverFile.xml", but ALL leading "../" will be removed when saved. Directories are added recursively. Compressed files can, on the contrary, be placed anywhere and their contents are stored with the same directory structure as in the original jar file, irrespective of the original location of the source compressed file. If a file appears more than once, succesive files could overwrite previous ones. The user will be warned of this, except if either neverOverwrite() or alwaysOverwrite() have been invoked immediately before calling this method. (Calling this method resets the warning feature back.)- Parameters:
sources
- ArrayList The list of content files to add. Each item in the list is a String with the relative name of a file or directory under the given parent directory, or of a compressed file anywhere in the hard disk.parent
- File The parent directory for all relative filenamestarget
- File The target compressed file. Its name must end in .zip, .jar or .trz. The user will be prompted to confirm the target.manifest
- Manifest A manifest for the newly created JAR file.- Returns:
- File The file that will eventually be created. Note that the main work is done using a separate thread, hence the method returns BEFORE the JAR file is actually created.
- See Also:
-
createManifest
From LaunchBuilder save jar Creates a Manifest for a JAR file with the given parameters- Parameters:
classpath
- Stringmainclass
- String- Returns:
- Manifest
-
extract
From ResourceLoader Extracts a given file from a compressed (ZIP, JAR or TRZ) file- Parameters:
source
- File The compressed file to extract the file fromfilename
- String The path of the file to extractdestination
- String The full (or relative to whatever the current user directory is) path where to save the extracted file- Returns:
- File The extracted file, null if failed
-
copy
Copies a file. If the target file exists, it will be overwritten.- Parameters:
source
- File The file to copytarget
- File destination file- Returns:
- boolean true if successful
-
compress
Compresses a directory into a single JAR or ZIP file. If the target file exists it will be overwritten.- Parameters:
source
- File The directory to compresstarget
- File The output filemanifest
- Manifest The manifest (in case of a JAR file)- Returns:
- boolean
-
compress
Compresses a list of files and/or directories into a single JAR or ZIP file. All files/dirs must be in the same directory. If the target file exists it will be overwritten.- Parameters:
sources
- ArrayList The list of files or directories to compresstarget
- File The output filemanifest
- Manifest The manifest (in case of a JAR file)- Returns:
- boolean
-
remove
Completely removes a directory (without warning!)- Parameters:
directory
- File The directory to delete
-
getContents
Returns all the files under a given directory- Parameters:
directory
- File- Returns:
- ArrayList
-
unzip
Uncompresses a ZIP or JAR file into a given directory. Duplicated files will be overwritten.- Parameters:
source
- File The compressed file to uncompresstargetDirectory
- File The target directory- Returns:
- boolean
- See Also:
-
unzipNoOverwrite
Uncompresses a ZIP or JAR file into a given directory. Duplicated files will NOT be overwriten.- Parameters:
source
- File The compressed file to uncompresstargetDirectory
- File The target directory- Returns:
- boolean
- See Also:
-
unzipWithAWarning
Uncompresses a ZIP or JAR file into a given directory. The system will issue a warning before duplicating existing files.- Parameters:
source
- File The compressed file to uncompresstargetDirectory
- File The target directory- Returns:
- boolean
- See Also:
-
unzipWithWarning
public static List<File> unzipWithWarning(InputStream zipStream, File targetDirectory, JLabel label, String prefix) Uncompresses a ZIP or JAR file into a given directory. policy.value indicates what to do on duplicated files.- Parameters:
zipStream
- The InputStream to read fromtargetDirectory
- File The target directorylabel
- An optional JLabel to display messagesprefix
- A prefix to add to the extracted file in order to create the message- Returns:
- java.util.List
the set of files extracted, null if cancelled
-