1 package org.codehaus.mojo.weblogic;
2
3 /*
4 * Copyright 2006 The Apache Software Foundation.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import org.apache.maven.plugin.MojoExecutionException;
20 import org.codehaus.mojo.weblogic.util.WeblogicMojoUtilities;
21 import weblogic.webservice.tools.clientgen.ClientGen;
22
23 import java.io.File;
24
25 /**
26 * Runs Client Gen on a given WSDL.
27 *
28 * @author <a href="mailto:scott@theryansplace.com">Scott Ryan</a>
29 * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
30 * @version $Id: ClientGenMojo.java 7025 2008-05-21 01:50:58Z jonnio $
31 * @description This mojo will run client gen on a given WSDL.
32 * @goal clientgen
33 * @requiresDependencyResolution compile
34 */
35 public class ClientGenMojo
36 extends AbstractWeblogicMojo
37 {
38
39 /**
40 * The wsdl to client gen from.
41 *
42 * @parameter default-value="http://localhost:7001"
43 */
44 private String inputWSDL;
45
46 /**
47 * The directory to output the geneated code to.
48 *
49 * @parameter default-value="${basedir}/src/main/java"
50 */
51 private String outputDir;
52
53 /**
54 * The package name of the output code.
55 *
56 * @parameter default-value="com.test.webservice"
57 */
58 private String packageName;
59
60 /**
61 * The name of the service.
62 *
63 * @parameter default-value="test"
64 */
65 private String serviceName;
66
67 /**
68 * The ear dependency flag. Use this in concert with the {@link #warName} parameter
69 * to locate a wsdl inside of the webservice war file.
70 *
71 * @parameter default-value="false"
72 */
73 private boolean useEarDependency;
74
75 /**
76 * The war name inside of the ear within which to find the wsdl file name.
77 *
78 * @parameter expression="${pom.artifactId}-${pom.version}.war"
79 */
80 private String warName;
81
82 /**
83 * Set to true if the client gen should copy .class files from the classpath into the
84 * target jar file.
85 *
86 * @parameter default-value="false"
87 */
88 private boolean useServerTypes;
89
90 /**
91 * This method will run client gen on the given WSDL.
92 *
93 * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
94 */
95 public void execute()
96 throws MojoExecutionException
97 {
98
99 if ( getLog().isInfoEnabled() )
100 {
101 getLog().info( "Weblogic client gen beginning " );
102 }
103 if ( getLog().isDebugEnabled() )
104 {
105 getLog().debug( "Plugin dependencies: " + this.getPluginArtifacts() );
106 }
107 try
108 {
109 final ClientGen clientGen = new ClientGen();
110 if ( this.useEarDependency )
111 {
112 clientGen.setEar( WeblogicMojoUtilities
113 .getEarFileName( this.getArtifacts() ) );
114 clientGen.setWarName( this.warName );
115 if ( getLog().isInfoEnabled() )
116 {
117 getLog().info( "Weblogic client gen using ear " + WeblogicMojoUtilities
118 .getEarFileName( this.getArtifacts() ) + " with warName " + this.warName );
119 }
120 }
121 else
122 {
123 clientGen.setWSDL( this.inputWSDL );
124 }
125 clientGen.setClientJar( new File( this.outputDir ) );
126 clientGen.setClientPackageName( this.packageName );
127 clientGen.setServiceName( this.serviceName );
128 clientGen.setUseServerTypes( this.useServerTypes );
129 // Set the classpath
130 clientGen.setClasspath(
131 WeblogicMojoUtilities.getDependencies( this.getArtifacts(), this.getPluginArtifacts() ) );
132 clientGen.generateClientJar();
133 }
134 catch ( Exception ex )
135 {
136 getLog().error( "Exception encountered during client gen ", ex );
137 throw new MojoExecutionException( "Exception encountered during listapps", ex );
138 }
139
140 if ( getLog().isInfoEnabled() )
141 {
142 getLog().info( "Weblogic client gen successful " );
143 }
144 }
145
146 /**
147 * Getter for property input WSDL.
148 *
149 * @return The value of input WSDL.
150 */
151 public String getInputWSDL()
152 {
153 return this.inputWSDL;
154 }
155
156 /**
157 * Setter for the input WSDL.
158 *
159 * @param inInputWSDL The value of input WSDL.
160 */
161 public void setInputWSDL( final String inInputWSDL )
162 {
163 this.inputWSDL = inInputWSDL;
164 }
165
166 /**
167 * Getter for property output dir.
168 *
169 * @return The value of output dir.
170 */
171 public String getOutputDir()
172 {
173 return this.outputDir;
174 }
175
176 /**
177 * Setter for the output dir.
178 *
179 * @param inOutputDir The value of output dir.
180 */
181 public void setOutputDir( final String inOutputDir )
182 {
183 this.outputDir = inOutputDir;
184 }
185
186 /**
187 * Getter for property package name.
188 *
189 * @return The value of package name.
190 */
191 public String getPackageName()
192 {
193 return this.packageName;
194 }
195
196 /**
197 * Setter for the package name.
198 *
199 * @param inPackageName The value of package name.
200 */
201 public void setPackageName( String inPackageName )
202 {
203 this.packageName = inPackageName;
204 }
205
206 /**
207 * Getter for property service name.
208 *
209 * @return The value of service name.
210 */
211 public String getServiceName()
212 {
213 return this.serviceName;
214 }
215
216 /**
217 * Setter for the service name.
218 *
219 * @param inServiceName The value of service name.
220 */
221 public void setServiceName( final String inServiceName )
222 {
223 this.serviceName = inServiceName;
224 }
225
226 /**
227 * Getter for the ear dependency flag
228 *
229 * @return true if the mojo should look in the ear for the wsdl
230 */
231 public boolean isUseEarDependency()
232 {
233 return useEarDependency;
234 }
235
236 /**
237 * Setter for the ear dependency.
238 *
239 * @param useEarDependency true if the mojo should look in the ear for the wsdl
240 */
241 public void setUseEarDependency( boolean useEarDependency )
242 {
243 this.useEarDependency = useEarDependency;
244 }
245
246 /**
247 * Getter for the name of the war to look inside for the wsdl file
248 *
249 * @return the war name inside of the ear
250 */
251 public String getWarName()
252 {
253 return warName;
254 }
255
256 /**
257 * The setter for the war name. Use this in conjuction with the {@link #useEarDependency} flag.
258 *
259 * @param warName the war name to look inside
260 */
261 public void setWarName( String warName )
262 {
263 this.warName = warName;
264 }
265
266 /**
267 * Getter for the {@link #useServerTypes} parameter. Returns true if the client gen
268 * should copy .class files from the class path instead of creating .java and compiling them.
269 *
270 * @return true if server types should be copied
271 */
272 public boolean isUseServerTypes()
273 {
274 return useServerTypes;
275 }
276
277 /**
278 * Setter for the {@link #useServerTypes} parameter.
279 *
280 * @param useServerTypes true if the server types should be used
281 */
282 public void setUseServerTypes( boolean useServerTypes )
283 {
284 this.useServerTypes = useServerTypes;
285 }
286
287 /**
288 * toString method: creates a String representation of the object
289 *
290 * @return the String representation
291 */
292 public String toString()
293 {
294 return "ClientGenMojo{" + "inputWSDL='" + inputWSDL + '\'' + ", outputDir='" + outputDir + '\'' +
295 ", packageName='" + packageName + '\'' + ", serviceName='" + serviceName + '\'' + ", useEarDependency=" +
296 useEarDependency + ", warName='" + warName + '\'' + ", useServerTypes=" + useServerTypes + '}';
297 }
298 }