001: /**
002: * EasyBeans
003: * Copyright (C) 2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: AbsArchive.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.ant.archive;
025:
026: import java.io.File;
027: import java.util.ArrayList;
028: import java.util.List;
029:
030: import org.apache.tools.ant.BuildException;
031: import org.apache.tools.ant.Task;
032: import org.apache.tools.ant.types.FileSet;
033: import org.apache.tools.ant.types.ZipFileSet;
034: import org.ow2.easybeans.ant.archive.info.ArchiveInfo;
035:
036: /**
037: * Common task that creates archives.
038: * @author Florent Benoit
039: */
040: public class AbsArchive extends Task {
041:
042: /**
043: * Reference to the standard deployment descriptor.
044: */
045: private File deploymentDescriptor = null;
046:
047: /**
048: * Full path to the archive.
049: */
050: private File dest = null;
051:
052: /**
053: * Relative Name of the archive (when embedded).
054: */
055: private String name = null;
056:
057: /**
058: * Exploded mode or not ? (default = file).
059: */
060: private boolean exploded = false;
061:
062: /**
063: * List of fileset used to add files.
064: */
065: private List<FileSet> fileSetList = null;
066:
067: /**
068: * Default constructor.
069: */
070: public AbsArchive() {
071: fileSetList = new ArrayList<FileSet>();
072: }
073:
074: /**
075: * Add the given fileset to the list of existing fileset.
076: * @param zipFileSet the fileset to add.
077: */
078: public void addFileSet(final ZipFileSet zipFileSet) {
079: fileSetList.add(zipFileSet);
080: }
081:
082: /**
083: * Gets the list of fileset to include in the archive.
084: * @return the list of fileset to include in the archive.
085: */
086: public List<FileSet> getFileSetList() {
087: return fileSetList;
088: }
089:
090: /**
091: * Sets the exploded mode to true or false.
092: * @param exploded boolean true/false
093: */
094: public void setExploded(final boolean exploded) {
095: this .exploded = exploded;
096: }
097:
098: /**
099: * Gets the state : exploded mode or not ?
100: * @return the state : exploded mode or not ?
101: */
102: public boolean isExploded() {
103: return exploded;
104: }
105:
106: /**
107: * Sets the reference to the deployment descriptor.
108: * @param dd the given deployment descriptor.
109: */
110: public void setDD(final File dd) {
111: // Ignore empty value
112: if ("empty-value".equals(dd.getName())) {
113: return;
114: }
115:
116: if (!dd.exists()) {
117: throw new BuildException("The given file '" + dd
118: + "' for the deployment descriptor does not exist.");
119: }
120: this .deploymentDescriptor = dd;
121: }
122:
123: /**
124: * Sets the path to the archive that will be built.
125: * @param dest the reference to resulting archive path.
126: */
127: public void setDest(final File dest) {
128: this .dest = dest;
129: }
130:
131: /**
132: * Gets the path to the archive that will be built.
133: * @return the reference to resulting archive path.
134: */
135: public File getDest() {
136: return dest;
137: }
138:
139: /**
140: * Sets the relative Name of the archive (when embedded).
141: * @param name the relative Name of the archive.
142: */
143: public void setName(final String name) {
144: this .name = name;
145: }
146:
147: /**
148: * Gets the relative Name of the archive (when embedded).
149: * @return the relative Name of the archive.
150: */
151: public String getName() {
152: return name;
153: }
154:
155: /**
156: * Update the given archive info object with some attributes.
157: * @param archiveInfo the object to update
158: */
159: protected void updateArchiveInfo(final ArchiveInfo archiveInfo) {
160: archiveInfo.setDest(dest);
161: archiveInfo.setDD(deploymentDescriptor);
162: archiveInfo.setExploded(exploded);
163:
164: // Add the given fileset
165: for (FileSet fileSet : getFileSetList()) {
166: archiveInfo.addFileSet(fileSet);
167: }
168:
169: }
170: }
|