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.apache.tools.ant.Project;
21 import org.apache.tools.ant.types.Path;
22 import org.codehaus.mojo.weblogic.util.WeblogicMojoUtilities;
23 import weblogic.ant.taskdefs.webservices.servicegen.ServiceGenTask;
24
25 import java.io.File;
26
27 /**
28 * Runs Service Gen on a given WSDL.
29 *
30 * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
31 * @version $Id: ServiceGenMojo.java 6622 2008-04-01 02:21:19Z jonnio $
32 * @description This mojo will run service gen on an ear file.
33 * @goal servicegen
34 * @requiresDependencyResolution compile
35 */
36 public class ServiceGenMojo
37 extends AbstractWeblogicMojo
38 {
39
40 /**
41 * The full path to the artifact to be compiled. It can be an EAR, War or
42 * Jar. If the project packaging is ejb then the .ejb suffix will be
43 * replaced with .jar if needed.
44 *
45 * @parameter expression="${project.build.directory}/${project.build.finalName}.${project.packaging}"
46 */
47 private String inputArtifactPath;
48
49 /**
50 * The directory to output the geneated code to.
51 *
52 * @parameter default-value="${basedir}/src/main/java"
53 */
54 private String outputDir;
55
56 /**
57 * The package name of the output code.
58 *
59 * @parameter default-value="com.test.webservice"
60 */
61 private String packageName;
62
63 /**
64 * The service configurations to generate
65 *
66 * @parameter
67 */
68 private Service services[];
69
70 /**
71 * The context uri for the service
72 *
73 * @parameter
74 * @required
75 */
76 private String contextUri;
77
78 /**
79 * this is the name of the war to execute the service gen against.
80 *
81 * @parameter
82 * @required
83 */
84 private String warName;
85
86 /**
87 * This method will run client gen on the given WSDL.
88 *
89 * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
90 */
91 public void execute()
92 throws MojoExecutionException
93 {
94 super.execute();
95 if ( getLog().isInfoEnabled() )
96 {
97 getLog().info( "Weblogic service gen beginning " );
98 }
99 inputArtifactPath = WeblogicMojoUtilities.updateArtifactName( inputArtifactPath, "ear" );
100
101 try
102 {
103 final Project project = new Project();
104 project.setName( "servicegen" );
105 final Path path = new Path( project, WeblogicMojoUtilities
106 .getDependencies( this.getArtifacts() ) );
107 final ServiceGenTask servicegen = new ServiceGenTask();
108 servicegen.setProject( project );
109 if ( getLog().isInfoEnabled() )
110 {
111 getLog().info( "Weblogic service gen using classpath: " + path );
112 }
113 servicegen.setClasspath( path );
114 servicegen.setWarName( this.warName );
115 servicegen.setContextURI( this.contextUri );
116 final File source = new File( this.inputArtifactPath );
117 servicegen.setDestear( source );
118 servicegen.setKeepGenerated( true );
119
120 // setup the services for generation
121
122 for ( int i = 0; i < services.length; i++ )
123 {
124 if ( getLog().isInfoEnabled() )
125 {
126 getLog().info( "Configuring service " + services[i].getServiceName() );
127 }
128 weblogic.ant.taskdefs.webservices.servicegen.Service service = servicegen
129 .createService();
130 service.setIncludeEjbs( services[i].getIncludeEJBs() );
131 service.setServiceName( services[i].getServiceName() );
132 service.setServiceURI( services[i].getServiceUri() );
133 service.setTargetNamespace( services[i].getTargetNamespace() );
134 service.setGenerateTypes( services[i].isGenerateTypes() );
135 service.setExpandMethods( services[i].isExpandMethods() );
136 service.setEjbJar( WeblogicMojoUtilities
137 .getEjbJarFileName( getArtifacts() ) );
138
139 }
140 servicegen.execute();
141 }
142 catch ( Exception ex )
143 {
144 getLog().error( "Exception encountered during service gen ", ex );
145 throw new MojoExecutionException( "Exception encountered during listapps", ex );
146 }
147
148 if ( getLog().isInfoEnabled() )
149 {
150 getLog().info( "Weblogic service gen successful " );
151 }
152 }
153
154 /**
155 * Getter for property output dir.
156 *
157 * @return The value of output dir.
158 */
159 public String getOutputDir()
160 {
161 return this.outputDir;
162 }
163
164 /**
165 * Setter for the output dir.
166 *
167 * @param inOutputDir The value of output dir.
168 */
169 public void setOutputDir( final String inOutputDir )
170 {
171 this.outputDir = inOutputDir;
172 }
173
174 /**
175 * Getter for property package name.
176 *
177 * @return The value of package name.
178 */
179 public String getPackageName()
180 {
181 return this.packageName;
182 }
183
184 /**
185 * Setter for the package name.
186 *
187 * @param inPackageName The value of package name.
188 */
189 public void setPackageName( String inPackageName )
190 {
191 this.packageName = inPackageName;
192 }
193
194 /**
195 * Getter for the services
196 *
197 * @return the list of services
198 */
199 public Service[] getServices()
200 {
201 return services;
202 }
203
204 /**
205 * Setter for the services
206 *
207 * @param services the services
208 */
209 public void setServices( Service[] services )
210 {
211 this.services = services;
212 }
213
214 /**
215 * toString method: creates a String representation of the object
216 *
217 * @return the String representation
218 */
219 public String toString()
220 {
221 StringBuffer buffer = new StringBuffer();
222 buffer.append( "ServiceGenMojo[" );
223 buffer.append( "warName = " ).append( warName );
224 buffer.append( ", outputDir = " ).append( outputDir );
225 buffer.append( ", packageName = " ).append( packageName );
226 buffer.append( "]" );
227 return buffer.toString();
228 }
229
230 /**
231 * Getter for the war name.
232 *
233 * @return the war name in side the ear that contains the services
234 */
235 public String getWarName()
236 {
237 return warName;
238 }
239
240 /**
241 * Getter for the input artifact path
242 *
243 * @return the inputArtifactPath
244 */
245 public String getInputArtifactPath()
246 {
247 return inputArtifactPath;
248 }
249
250 /**
251 * Setter for the input artifact path
252 *
253 * @param inputArtifactPath the input artifact path
254 */
255 public void setInputArtifactPath( String inputArtifactPath )
256 {
257 this.inputArtifactPath = inputArtifactPath;
258 }
259
260 /**
261 * Setter for the war name.
262 *
263 * @param warName the war name
264 */
265 public void setWarName( String warName )
266 {
267 this.warName = warName;
268 }
269
270 /**
271 * Getter for the context uri
272 *
273 * @return the contextUri
274 */
275 public String getContextUri()
276 {
277 return contextUri;
278 }
279
280 /**
281 * Setter for the context uri
282 *
283 * @param contextUri the contextUri
284 */
285 public void setContextUri( String contextUri )
286 {
287 this.contextUri = contextUri;
288 }
289 }