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: War.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.ant.archive;
025:
026: import org.apache.tools.ant.Project;
027: import org.apache.tools.ant.Task;
028: import org.apache.tools.ant.types.ZipFileSet;
029: import org.ow2.easybeans.ant.archive.api.IWar;
030: import org.ow2.easybeans.ant.archive.exploded.WarExploded;
031: import org.ow2.easybeans.ant.archive.file.WarFile;
032: import org.ow2.easybeans.ant.archive.info.WarInfo;
033:
034: /**
035: * Task that creates a War archive (.war file or .war directory).
036: * @author Florent Benoit
037: */
038: public class War extends AbsArchive {
039:
040: /**
041: * Path of the WEB-INF folder.
042: */
043: private static final String WEBINF_FOLDER = "WEB-INF/";
044:
045: /**
046: * WEB-INF/lib folder.
047: */
048: private static final String LIB_FOLDER = WEBINF_FOLDER + "lib/";
049:
050: /**
051: * WEB-INF/classes folder.
052: */
053: private static final String CLASSES_FOLDER = WEBINF_FOLDER
054: + "classes/";
055:
056: /**
057: * Default constructor.
058: */
059: public War() {
060: super ();
061: }
062:
063: /**
064: * Add files in WEB-INF/classes folder.
065: * @param zipFileSet the fileset that contains the files.
066: */
067: public void addClasses(final ZipFileSet zipFileSet) {
068: zipFileSet.setPrefix(CLASSES_FOLDER);
069: addFileSet(zipFileSet);
070: }
071:
072: /**
073: * Add files in WEB-INF/lib folder.
074: * @param zipFileSet the fileset that contains the files.
075: */
076: public void addLib(final ZipFileSet zipFileSet) {
077: zipFileSet.setPrefix(LIB_FOLDER);
078: addFileSet(zipFileSet);
079: }
080:
081: /**
082: * Add files in WEB-INF folder.
083: * @param zipFileSet the fileset that contains the files.
084: */
085: public void addWebinf(final ZipFileSet zipFileSet) {
086: zipFileSet.setPrefix(WEBINF_FOLDER);
087: addFileSet(zipFileSet);
088: }
089:
090: /**
091: * Execute the task by using either exploded or file mode.
092: */
093: @Override
094: public void execute() {
095:
096: log("Building War in '" + getDest() + "'.", Project.MSG_INFO);
097:
098: IWar war = null;
099:
100: // 2 cases, exploded mode or not
101: if (isExploded()) {
102: war = new WarExploded(getProject());
103: } else {
104: war = new WarFile(getProject());
105: }
106:
107: // Set the name of the task
108: ((Task) war).setTaskName(getTaskName());
109:
110: // Build the info object
111: WarInfo warInfo = new WarInfo();
112: war.setWarInfo(warInfo);
113:
114: // Fill archive properties
115: updateArchiveInfo(warInfo);
116:
117: // Execute the task
118: war.execute();
119:
120: }
121:
122: }
|