Coverage details for com.topcoder.testframework.web.PrepareTestWarTask

LineHitsSource
1 /*
2  * Copyright (C) 2006 TopCoder Inc., All Rights Reserved.
3  */
4 package com.topcoder.testframework.web;
5  
6 import org.apache.cactus.integration.ant.CactifyWarTask;
7 import org.apache.tools.ant.BuildException;
8 import org.apache.tools.ant.Task;
9 import org.apache.tools.ant.types.FileSet;
10 import org.apache.tools.ant.types.ZipFileSet;
11  
12 import java.io.File;
13  
14  
15 /**
16  * This class represents an Ant task that injects elements necessary to run the tests into an existing WAR file. It can
17  * be used to prepare WARs for {@link DefaultWebApplicationServer} class.
18  * <p/>
19  * This class is mutable, i.e. not thread-safe.
20  *
21  * @author real_vg, TCSDEVELOPER
22  * @version 1.0
23  */
24 public class PrepareTestWarTask extends Task {
25  
26     /**
27      * This field stores a wrapped {@link org.apache.cactus.integration.ant.CactifyWarTask} instance. It is initialized
28      * in field initializer. The instance in this field is the delegate to which all implementation and functionality is
29      * delegated.
30      */
3111    private final CactifyWarTask cactifyWarTask = new CactifyWarTask();
32  
33     /**
34      * Creates a new PrepareTestWarTask.
35      */
3611    public PrepareTestWarTask() {
37         // This constructor is intentionally empty
3811    }
39  
40     /**
41      * This method sets the value of <tt>srcfile</tt> attribute, which specifies the source archive to inject the
42      * elements required to run tests into.
43      *
44      * @param srcFile the source archive to inject the elements required to run tests into
45      */
46     public void setSrcFile(final File srcFile) {
475        cactifyWarTask.setSrcFile(srcFile);
485    }
49  
50     /**
51      * This method sets the value of <tt>destfile</tt> attribute, which specifies the destination file, archive with the
52      * injected elements required to run tests will be written to.
53      *
54      * @param destFile the destination file archive with the injected elements required to run tests will be written to
55      */
56     public void setDestFile(final File destFile) {
575        cactifyWarTask.setDestFile(destFile);
585    }
59  
60     /**
61      * This method adds a fileset to the preparation task. The fileset is used to specify additional files that are to
62      * be included in the prepared war file as content (i.e. JSP files to be put relative to the WAR root).
63      *
64      * @param set the fileset specifying the files to be added
65      */
66     public void addFileset(final FileSet set) {
671        cactifyWarTask.addFileset(set);
681    }
69  
70     /**
71      * This method adds a ZipFileSet to the preparation task. The fileset is used to specify additional library jar
72      * files that are to be included in the prepared war file as libraries (i.e. JAR files to be put relative to
73      * <tt>/WEB-INF/lib</tt>).
74      *
75      * @param set the ZipFileSet specifying the files to be added
76      */
77     public void addLib(final ZipFileSet set) {
781        cactifyWarTask.addLib(set);
791    }
80  
81     /**
82      * This method adds a ZipFileSet to the preparation task. The fileset is used to specify additional class files that
83      * are to be included in the prepared war file as loadable classes (i.e. <tt>*.class</tt> files to be put relative
84      * to <tt>/WEB-INF/classes</tt>).
85      *
86      * @param set the ZipFileSet specifying the files to be added
87      */
88     public void addClasses(final ZipFileSet set) {
891        cactifyWarTask.addClasses(set);
901    }
91  
92     /**
93      * This method runs the preparation task.
94      *
95      * @throws org.apache.tools.ant.BuildException
96      * if any error happens
97      */
98     public void execute() {
994        cactifyWarTask.setProject(getProject());
100         try {
1014            cactifyWarTask.execute();
1023        } catch (Exception e) {
103             // Catch of Exception is normally discouraged by TC style, but as we want
104             // to 'shield' the caller from the internals of the wrapped implementation
105             // of cactus (which sometimes can throw NPEs) we simply wrap everything
106             // into BuildException to assure normal ant behavior
1073            throw new BuildException("Error while preparing the war file.", e);
1081        }
1091    }
110  
111 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.