1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.utils;
18
19 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationConstants;
20 import org.apache.geronimo.ews.ws4j2ee.toWs.Ws4J2ee;
21 import org.apache.tools.ant.AntClassLoader;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Location;
24 import org.apache.tools.ant.Task;
25 import org.apache.tools.ant.types.Path;
26
27 import java.io.File;
28 import java.io.FileWriter;
29 import java.io.IOException;
30 import java.io.PrintWriter;
31
32 /***
33 * @author hemapani@opensource.lk
34 */
35 public class EWSTask extends Task {
36 private String outDir = ".";
37 private String module = null;
38 private Path classpath;
39 private File root;
40 private boolean compile = false;
41 private String implStyle = GenerationConstants.USE_INTERNALS;
42 private String j2eeContainer = GenerationConstants.GERONIMO_CONTAINER;
43
44 public void execute() throws BuildException {
45 try {
46 if (module == null) {
47 throw new BuildException("the module name not specifed");
48 }
49 root = project.getBaseDir();
50 File moduleFile = new File(root, module);
51 File outDirFile = new File(root, outDir);
52 AntClassLoader cl = new AntClassLoader(getClass().getClassLoader(),
53 project,
54 classpath,
55 true);
56 Thread.currentThread().setContextClassLoader(cl);
57 AntDeployContext deployContext
58 = new AntDeployContext(moduleFile.getAbsolutePath(),
59 outDirFile.getAbsolutePath(), cl, implStyle, j2eeContainer);
60 Ws4J2ee ws4j2ee = new Ws4J2ee(deployContext, null);
61 ws4j2ee.generate();
62 } catch (Throwable e) {
63 try {
64 File errorDump = new File(root, "ews.log");
65 PrintWriter pw = new PrintWriter(new FileWriter(errorDump));
66 e.printStackTrace(pw);
67 pw.close();
68 System.out.println(classpath);
69 System.out.println("ERROR .. dump to " + errorDump.getAbsolutePath());
70 } catch (IOException e1) {
71 }
72 throw new BuildException(e);
73 }
74 }
75
76 public Location getLocation() {
77 return super.getLocation();
78 }
79
80 public String getTaskName() {
81 return super.getTaskName();
82 }
83
84 public void init() throws BuildException {
85 super.init();
86 }
87
88 public void setLocation(Location arg0) {
89 super.setLocation(arg0);
90 }
91
92 public void setTaskName(String arg0) {
93 super.setTaskName(arg0);
94 }
95
96 /***
97 * @return
98 */
99 public Path getClasspath() {
100 return classpath;
101 }
102
103 /***
104 * @return
105 */
106 public String getModule() {
107 return module;
108 }
109
110 /***
111 * @return
112 */
113 public String getOutDir() {
114 return outDir;
115 }
116
117 /***
118 * @param path
119 */
120 public void setClasspath(Path path) {
121 classpath = path;
122 }
123
124 /***
125 * @param string
126 */
127 public void setModule(String string) {
128 module = string;
129 }
130
131 /***
132 * @param string
133 */
134 public void setOutDir(String string) {
135 outDir = string;
136 }
137
138 public Path createClasspath() {
139 if (classpath == null) {
140 classpath = new Path(project);
141 }
142 return classpath.createPath();
143 }
144
145 /***
146 * @return
147 */
148 public boolean isCompile() {
149 return compile;
150 }
151
152 /***
153 * @param b
154 */
155 public void setCompile(boolean b) {
156 compile = b;
157 }
158
159 /***
160 * @return
161 */
162 public String getImplStyle() {
163 return implStyle;
164 }
165
166 /***
167 * @return
168 */
169 public String getJ2eeContainer() {
170 return j2eeContainer;
171 }
172
173 /***
174 * @param string
175 */
176 public void setImplStyle(String string) {
177 implStyle = string;
178 }
179
180 /***
181 * @param string
182 */
183 public void setJ2eeContainer(String string) {
184 j2eeContainer = string;
185 }
186
187 }