Line | Hits | Source |
---|---|---|
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 | */ | |
31 | 11 | private final CactifyWarTask cactifyWarTask = new CactifyWarTask(); |
32 | ||
33 | /** | |
34 | * Creates a new PrepareTestWarTask. | |
35 | */ | |
36 | 11 | public PrepareTestWarTask() { |
37 | // This constructor is intentionally empty | |
38 | 11 | } |
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) { | |
47 | 5 | cactifyWarTask.setSrcFile(srcFile); |
48 | 5 | } |
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) { | |
57 | 5 | cactifyWarTask.setDestFile(destFile); |
58 | 5 | } |
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) { | |
67 | 1 | cactifyWarTask.addFileset(set); |
68 | 1 | } |
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) { | |
78 | 1 | cactifyWarTask.addLib(set); |
79 | 1 | } |
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) { | |
89 | 1 | cactifyWarTask.addClasses(set); |
90 | 1 | } |
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() { | |
99 | 4 | cactifyWarTask.setProject(getProject()); |
100 | try { | |
101 | 4 | cactifyWarTask.execute(); |
102 | 3 | } 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 | |
107 | 3 | throw new BuildException("Error while preparing the war file.", e); |
108 | 1 | } |
109 | 1 | } |
110 | ||
111 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |