zipadd adds a file (or a group of files) into a zip archive within the current DropZone. If the zip archive does not currently exist then zipadd will create it.  WAR, JAR and EAR files are simply ZIP files with a different extension. You can thus use zipadd (and zipget and zipdel) with WAR, JAR and EAR files as well as with ZIP archives. This provides a powerful way of manipulating WAR, JAR and EAR files in the DropZone before onward deployment to the target Endpoint(s).


zipadd takes a mandatory named parameter. Other parameters can be specified depending on what is being added to the zipfile:


zipfile:

Mandatory. The name of the zipfile in the DropZone to which files should be added. The file is automatically created if it does not currently exist in the DropZone.

files:

Optional. If specified, refers to either an array or list of DropZoneFile objects. Each file in the array or list is added into the specified zipfile. If the file already exists in the zipfile, then it is automatically replaced. The filename added into the zipfile index is taken from the dzpath of the DropZoneFile object. Note: if the file referenced by the DropZoneFile object does not exist in the current DropZone, then a run-time error is thrown.

file:

Optional. If specified, refers to either a DropZoneFile object or a string giving the filename of a file within the current DropZone. If the file parameter refers to a DropZoneFile object, then the filename added is taken from the dzpath of that object. If the file parameter is a string, then it is taken to be a path to a file within the DropZone (unless the stream parameter is also given). In either case, the specified file is added to the specified zipfile. If a file with the same name already exists in the zipfile then it is automatically replaced. If the file referenced does not exist in the current DropZone (and stream is not specified), then a run-time error is thrown.

delete:

Optional. A Boolean flag indicating whether the specified file(s) should be removed from the DropZone after they have been added to the zipfile. Defaults to false. If the delete flag is specified and is set to true then the file(s) are deleted from the DropZone after they have been added to the zipfile. They will no longer be deployed to the Endpoint in any subsequent transfer operation.

stream:

Optional. Only valid along with the file parameter. If specified, the file parameter should be a string and need not refer to a file in the DropZone. Instead, the file is created within the zipfile (with the name given by the file parameter) and its content is taken from the contents of the specified stream.


Example 1:


Zip all the files in the DropZone into a zip archive and remove them from the DropZone. If this is done as a pre-action to a Component then the Component will deploy a single zipfile and not the individual files that were checked out for the Component items.


set dzfiles = ${DropZone.files};

zipadd(zipfile: "myapp.war", files: $dzfiles, delete: true);


Example 2:


Create a "readme.txt" file and include it in the web archive to be deployed:


using stream $readme {

   echo "This is Application ${Application.name}";

   echo "It uses the following Components:";

   set complist = ${Application.Components};

   iterate(comp: $complist) {

       echo "${comp.name}";

   }

   echo "It was deployed by ${user.name}";

}

//

// Assuming the Component is webapp.war, add the README.TXT

// file to the root of the WAR file.

//

zipadd(zipfile: "webapp.war", file: "README.TXT", stream: $readme);