KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > ant > taskdefs > J2EEArtifactDeployTask


1 /*
2  * Copyright (c) 2002-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant.ant.taskdefs;
8
9
10 import java.io.File JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Task;
16
17
18 /**
19  * <p>
20  * This class is a task that allows for J2EE applications to
21  * be configured and setup with artifacts and artifact groups.
22  * </p>
23  *
24  * @author Brian Pontarelli
25  */

26 public class J2EEArtifactDeployTask extends Task {
27
28     private File JavaDoc todir;
29     private List JavaDoc ears = new ArrayList JavaDoc();
30
31
32     public File JavaDoc getTodir() {
33         return todir;
34     }
35
36     public void setTodir(File JavaDoc todir) {
37         this.todir = todir;
38     }
39
40     /**
41      * Adds a new configured EAR, which is an ArtifactCopyTask.
42      *
43      * @param ear The new EAR to add
44      */

45     public void addConfiguredEar(Ear ear) {
46         String JavaDoc name = ear.getName();
47         if (name == null) {
48             throw new BuildException("All ear elements must be named");
49         }
50
51         File JavaDoc earDir = new File JavaDoc(todir, name);
52         ear.setTodir(earDir);
53         ear.setFlatten(true);
54         ears.add(ear);
55     }
56
57     /**
58      * Performs the deployment.
59      */

60     public void execute() {
61         for (int i = 0; i < ears.size(); i++) {
62             ArtifactCopyTask act = (ArtifactCopyTask) ears.get(i);
63             act.perform();
64         }
65     }
66
67
68     public static class Ear extends ArtifactCopyTask {
69
70         private String JavaDoc name;
71         private List JavaDoc wars = new ArrayList JavaDoc();
72
73         /**
74          * Returns the name of this EAR.
75          */

76         public String JavaDoc getName() {
77             return name;
78         }
79
80         /**
81          * Sets the name of this EAR.
82          */

83         public void setName(String JavaDoc name) {
84             this.name = name;
85         }
86
87         public void addConfiguredWar(War war) {
88             String JavaDoc name = war.getName();
89             if (name == null) {
90                 throw new BuildException("All war elements must be named");
91             }
92
93             war.setFlatten(true);
94             wars.add(war);
95         }
96
97         /**
98          * Performs the deployment.
99          */

100         public void execute() {
101             for (int i = 0; i < wars.size(); i++) {
102                 War war = (War) wars.get(i);
103                 String JavaDoc warPath = war.getName() + File.separator + "WEB-INF" +
104                     File.separator + "lib";
105                 File JavaDoc warDir = new File JavaDoc(super.destDir, warPath);
106
107                 war.setTodir(warDir);
108                 war.perform();
109             }
110         }
111     }
112
113     public static class War extends ArtifactCopyTask {
114
115         private String JavaDoc name;
116
117         /**
118          * Returns the name of this WAR.
119          */

120         public String JavaDoc getName() {
121             return name;
122         }
123
124         /**
125          * Sets the name of this WAR.
126          */

127         public void setName(String JavaDoc name) {
128             this.name = name;
129         }
130     }
131 }
132
Popular Tags