001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.anttasks.builder.tools;
016:
017: import java.io.File;
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.apache.tools.ant.BuildException;
023: import org.apache.tools.ant.Project;
024: import org.apache.tools.ant.taskdefs.War;
025: import org.apache.tools.ant.types.FileSet;
026: import org.apache.tools.ant.types.ZipFileSet;
027:
028: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
029: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
030:
031: /** This definition is responsible for invocation of War standard ant target */
032: public class AntWarInvocationDefinition extends
033: ToolInvocationDefinition {
034: private File mDestFile = null;
035: private File mWebXmlFile = null;
036: private List mFileSets = new ArrayList();
037: private List mWebInfZipFileSets = new ArrayList();
038: private List mClassesZipFileSets = new ArrayList();
039: private List mLibZipFileSets = new ArrayList();
040:
041: /** Public constructor for the invocation */
042: public AntWarInvocationDefinition(MetaBossBuilderTask pOwnerTask,
043: String pTaskName) {
044: super (pOwnerTask, pTaskName);
045: }
046:
047: /** Setter for the path of the destination war file to be created */
048: public void setDestFilePath(String pDestFilePath) {
049: mDestFile = new File(pDestFilePath).getAbsoluteFile();
050: }
051:
052: /** Gets the path of the directory to be created */
053: public File getDestFile() {
054: if (mDestFile == null)
055: throw new BuildException(
056: "Missing DestFile, which is mandatory for ant task invocation.");
057: return mDestFile;
058: }
059:
060: /** Setter for the path of the web xml file to be used created */
061: public void setWebXmlFilePath(String pWebXmlFilePath) {
062: mWebXmlFile = new File(pWebXmlFilePath).getAbsoluteFile();
063: }
064:
065: /** Gets the path of the directory to be created */
066: public File getWebXmlFile() {
067: if (mWebXmlFile == null)
068: throw new BuildException(
069: "Missing WebXmlFile, which is mandatory for ant task invocation.");
070: return mWebXmlFile;
071: }
072:
073: // Adds file set to the root area of the war file
074: public void addFileset(FileSet pFileSet) {
075: mFileSets.add(pFileSet);
076: }
077:
078: // Adds file set to the WebInf area of the war file
079: public void addWebInfFileset(ZipFileSet pFileSet) {
080: mWebInfZipFileSets.add(pFileSet);
081: }
082:
083: // Adds file set to the Classes area of the war file
084: public void addClassesFileset(ZipFileSet pFileSet) {
085: mClassesZipFileSets.add(pFileSet);
086: }
087:
088: // Adds file set to the WebInf area of the war file
089: public void addLibFileset(ZipFileSet pFileSet) {
090: mLibZipFileSets.add(pFileSet);
091: }
092:
093: /** Overridden to compare details of the invocation */
094: public boolean equals(Object pOther) {
095: if (this == pOther)
096: return true;
097: return false;
098: }
099:
100: /** This method will have to invoke the generator */
101: public void invoke() throws BuildException {
102: MetaBossBuilderTask lOwnerTask = getOwnerTask();
103: Project lThisProject = getOwnerTask().getProject();
104: // Now create and execute the java compiler task
105: War lWarTask = (War) lThisProject.createTask("war");
106: lWarTask.setTaskName(lOwnerTask.getTaskName());
107: lWarTask.setDestFile(getDestFile());
108: lWarTask.setWebxml(getWebXmlFile());
109: for (Iterator lWebInfFileSetsIterator = mWebInfZipFileSets
110: .iterator(); lWebInfFileSetsIterator.hasNext();)
111: lWarTask.addWebinf((ZipFileSet) lWebInfFileSetsIterator
112: .next());
113: for (Iterator lClassesFileSetsIterator = mClassesZipFileSets
114: .iterator(); lClassesFileSetsIterator.hasNext();)
115: lWarTask.addClasses((ZipFileSet) lClassesFileSetsIterator
116: .next());
117: for (Iterator lLibFileSetsIterator = mLibZipFileSets.iterator(); lLibFileSetsIterator
118: .hasNext();)
119: lWarTask.addLib((ZipFileSet) lLibFileSetsIterator.next());
120: for (Iterator lFileSetsIterator = mFileSets.iterator(); lFileSetsIterator
121: .hasNext();)
122: lWarTask.addFileset((FileSet) lFileSetsIterator.next());
123: lWarTask.execute();
124: }
125: }
|