1 package org.codehaus.mojo.axistools;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.LinkedHashSet;
25 import java.util.Set;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.maven.artifact.DependencyResolutionRequiredException;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.plugin.MojoFailureException;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.project.MavenProjectHelper;
34 import org.codehaus.mojo.axistools.axis.AxisPluginException;
35 import org.codehaus.mojo.axistools.java2wsdl.DefaultJava2WSDLPlugin;
36
37 /**
38 * A Plugin for generating WSDL files using Axis Java2WSDL.
39 *
40 * @author jesse <jesse.mcconnell@gmail.com>
41 * @version $Id$
42 * @goal java2wsdl
43 * @phase process-classes
44 * @requiresDependencyResolution compile
45 * @description Java2WSDL plugin
46 */
47 public class Java2WSDLMojo
48 extends AbstractMojo
49 {
50 /**
51 * The directory the compile objects will be located for java2wsdl to source from.
52 * @parameter default-value="${project.build.outputDirectory}"
53 */
54 private File classesDirectory;
55
56 /**
57 * Directory for generated content.
58 *
59 * Corresponds to the <code>-o, --output</code> option in the Java2WSDL command line tool,
60 * together with the {@linkplain #filename} parameter.
61 *
62 * @parameter default-value="${project.build.directory}/generated-sources/axistools/java2wsdl"
63 */
64 private File outputDirectory;
65
66 /**
67 * Indicates the name of the output WSDL file.
68 *
69 * Corresponds to the <code>-o, --output</code> option in the Java2WSDL command line tool,
70 * together with the {@linkplain #outputDirectory} parameter.
71 *
72 * @parameter expression="${fileName}"
73 * @required
74 */
75 private String filename;
76
77 /**
78 * The class-of-portType.
79 *
80 * @parameter expression="${classOfPortType}"
81 */
82 private String classOfPortType;
83
84 /**
85 * Optional parameter that indicates the name of the input wsdl file.
86 * The output wsdl file will contain everything from the input wsdl file plus the new constructs.
87 * If a new construct is already present in the input wsdl file, it is not added.
88 * This option is useful for constructing a wsdl file with multiple ports, bindings, or portTypes.
89 *
90 * Corresponds to the <code>-I, --input</code> option in the Java2WSDL command line tool.
91 *
92 * @parameter expression="${input}"
93 */
94 private String input;
95
96 /**
97 * Indicates the url of the location of the service.
98 * The name after the last slash or backslash is the name of the service port
99 * (unless overridden by the servicePortName option).
100 * The service port address location attribute is assigned the specified value.
101 *
102 * Corresponds to the <code>-l, --location</code> option in the Java2WSDL command line tool.
103 *
104 * @parameter expression="${location}"
105 */
106 private String location;
107
108 /**
109 * Indicates the name to use for the portType element. If not specified, the
110 * {@linkplain #classOfPortType} name is used.
111 *
112 * Corresponds to the <code>-P, --portTypeName</code> option in the Java2WSDL command line tool.
113 *
114 * @parameter expression="${portTypeName}"
115 */
116 private String portTypeName;
117
118 /**
119 * Indicates the name to use for the binding element.
120 * If not specified, the value of the {@linkplain #servicePortName} + "SoapBinding" is used.
121 *
122 * Corresponds to the <code>-b, --bindingName</code> option in the Java2WSDL command line tool.
123 *
124 * @parameter expression="${bindingName}"
125 */
126 private String bindingName;
127
128 /**
129 * Service element name (defaults to servicePortName value + "Service").
130 *
131 * Corresponds to the <code>-S, --serviceElementName</code> option in the Java2WSDL command line tool.
132 *
133 * @parameter expression="${serviceElementName}"
134 */
135 private String serviceElementName;
136
137 /**
138 * Indicates the name of the service port.
139 * If not specified, the service port name is derived from the location value.
140 *
141 * Corresponds to the <code>-s, --servicePortName</code> option in the Java2WSDL command line tool.
142 *
143 * @parameter expression="${servicePortName}"
144 */
145 private String servicePortName;
146
147 /**
148 * Indicates the name of the target namespace of the WSDL.
149 *
150 * Corresponds to the <code>-n, --namespace</code> option in the Java2WSDL command line tool.
151 *
152 * @parameter expression="${namespace}"
153 */
154 private String namespace;
155
156 /**
157 * Package=namespace, name value pair.
158 * The plugin currently only supports one name value pair.
159 *
160 * Corresponds to the <code>-p, --PkgtoNS</code> option in the Java2WSDL command line tool.
161 *
162 * @parameter expression="${packageToNamespace}"
163 */
164 private String packageToNamespace;
165
166 /**
167 * Methods to export.
168 *
169 * Corresponds to the <code>-m, --methods</code> option in the Java2WSDL command line tool.
170 *
171 * @parameter expression="${methods}"
172 */
173 private ArrayList methods;
174
175 /**
176 * Look for allowed methods in inherited class.
177 *
178 * Corresponds to the <code>-a, --all</code> option in the Java2WSDL command line tool.
179 *
180 * @parameter expression="false"
181 */
182 private boolean all;
183
184 /**
185 * Indicates the kind of WSDL to generate. Accepted values are:
186 * <ul>
187 * <li>All --- (default) Generates wsdl containing both interface and
188 * implementation WSDL constructs.</li>
189 * <li>Interface --- Generates a WSDL containing the interface constructs
190 * (no service element).</li>
191 * <li>Implementation -- Generates a WSDL containing the implementation.
192 * The interface WSDL is imported via the {@linkplain #locationImport}
193 * option.</li>
194 * </ul>
195 *
196 * Corresponds to the <code>-w, --outputWsdlMode</code> option in the Java2WSDL command line tool.
197 *
198 * @parameter expression="${outputWSDLMode}"
199 */
200 private String outputWSDLMode;
201
202 /**
203 * Used to indicate the location of the interface WSDL when generating an implementation WSDL.
204 *
205 * Corresponds to the <code>-L, --locationImport</code> option in the Java2WSDL command line tool.
206 *
207 * @parameter expression="${locationImport}"
208 */
209 private String locationImport;
210
211 /**
212 * Namespace of the implementation WSDL.
213 *
214 * Corresponds to the <code>-N, --namespaceImpl</code> option in the Java2WSDL command line tool.
215 *
216 * @parameter expression="${namespaceImpl}"
217 */
218 private String namespaceImpl;
219
220 /**
221 * Use this option to indicate the name of the output implementation WSDL file.
222 * If specified, Java2WSDL will produce interface and implementation WSDL files.
223 * If this option is used, the {@linkplain #outputWSDLMode} option is ignored.
224 *
225 * Corresponds to the <code>-O, --outputImpl</code> option in the Java2WSDL command line tool.
226 *
227 * @parameter expression="${outputImpl}"
228 */
229 private String outputImpl;
230
231 /**
232 * Sometimes extra information is available in the implementation class file.
233 * Use this option to specify the implementation class.
234 *
235 * Corresponds to the <code>-i, --implClass</code> option in the Java2WSDL command line tool.
236 *
237 * @parameter expression="${implClass}"
238 */
239 private String implClass;
240
241 /**
242 * List of methods not to export.
243 *
244 * Corresponds to the <code>-x, --exclude</code> option in the Java2WSDL command line tool.
245 *
246 * @parameter expression="${exclude}"
247 */
248 private ArrayList excludes;
249
250 /**
251 * List of classes which stop the Java2WSDL inheritance search.
252 *
253 * Corresponds to the <code>-c, --stopClasses</code> option in the Java2WSDL command line tool.
254 *
255 * @parameter expression="${stopClasses}"
256 */
257 private ArrayList stopClasses;
258
259 /**
260 * Choose the default type mapping registry to use. Either 1.1 or 1.2.
261 *
262 * Corresponds to the <code>-T, --typeMappingVersion</code> option in the Java2WSDL command line tool.
263 *
264 * @parameter expression="${typeMappingVersion}"
265 */
266 private String typeMappingVersion;
267
268 /**
269 * The value of the operations soapAction field.
270 * Values are DEFAULT, OPERATION or NONE.
271 * OPERATION forces soapAction to the name of the operation.
272 * DEFAULT causes the soapAction to be set according to the operation's meta data (usually "").
273 * NONE forces the soapAction to "". The default is DEFAULT.
274 *
275 * Corresponds to the <code>-A, --soapAction</code> option in the Java2WSDL command line tool.
276 *
277 * @parameter expression="${soapAction}"
278 */
279 private String soapAction;
280
281 /**
282 * The style of the WSDL document: RPC, DOCUMENT or WRAPPED.
283 * The default is RPC. If RPC is specified, an rpc wsdl is generated.
284 * If DOCUMENT is specified, a document wsdl is generated.
285 * If WRAPPED is specified, a document/literal wsdl is generated using the wrapped approach.
286 * Wrapped style forces the use attribute to be literal.
287 *
288 * Corresponds to the <code>-y, --style</code> option in the Java2WSDL command line tool.
289 *
290 * @parameter expression="${style}"
291 */
292 private String style;
293
294 /**
295 * The use of the WSDL document: LITERAL or ENCODED.
296 * If LITERAL is specified, the XML Schema defines the representation of the XML for the request.
297 * If ENCODED is specified, SOAP encoding is specified in the generated WSDL.
298 *
299 * Corresponds to the <code>-u, --use</code> option in the Java2WSDL command line tool.
300 *
301 * @parameter expression="${use}"
302 */
303 private String use;
304
305 /**
306 * Specify a list of class names which should be included in the types
307 * section of the WSDL document.
308 * This is useful in the case where your service interface references a base
309 * class and you would like your WSDL to contain XML Schema type definitions
310 * for these other classes.
311 *
312 * Corresponds to the <code>-e, --extraClasses</code> option in the Java2WSDL command line tool.
313 *
314 * @parameter expression="${extraClasses}"
315 */
316 private ArrayList extraClasses;
317
318 /**
319 * A file or URL to an XML Schema that should be physically imported into the generated WSDL.
320 *
321 * Corresponds to the <code>-C, --importSchema</code> option in the Java2WSDL command line tool.
322 *
323 * @parameter expression="${importSchema}"
324 */
325 private String importSchema;
326
327 /**
328 * @parameter expression="${project}"
329 * @required
330 * @readonly
331 */
332 private MavenProject project;
333
334 /**
335 * @component
336 */
337 private MavenProjectHelper projectHelper;
338
339 public void execute()
340 throws MojoExecutionException, MojoFailureException
341 {
342 DefaultJava2WSDLPlugin plugin = new DefaultJava2WSDLPlugin();
343
344 String classpath = getCompileClasspath();
345
346 plugin.setAll( all );
347 plugin.setBindingName( bindingName );
348 plugin.setClasspath( classpath );
349 plugin.setClassOfPortType( classOfPortType );
350 plugin.setExcludes( excludes );
351 plugin.setExtraClasses( extraClasses );
352 plugin.setFilename( filename );
353 plugin.setImplClass( implClass );
354 plugin.setImportSchema( importSchema );
355 plugin.setInput( input );
356 plugin.setLocation( location );
357 plugin.setLocationImport( locationImport );
358 plugin.setMethods( methods );
359 plugin.setNamespace( namespace );
360 plugin.setNamespaceImpl( namespaceImpl );
361 plugin.setOutputDirectory( outputDirectory );
362 plugin.setOutputImpl( outputImpl );
363 plugin.setOutputWSDLMode( outputWSDLMode );
364 plugin.setPackageToNamespace( packageToNamespace );
365 plugin.setPortTypeName( portTypeName );
366 plugin.setServiceElementName( serviceElementName );
367 plugin.setServicePortName( servicePortName );
368 plugin.setSoapAction( soapAction );
369 plugin.setStopClasses( stopClasses );
370 plugin.setStyle( style );
371 plugin.setTypeMappingVersion( typeMappingVersion );
372 plugin.setUse( use );
373 plugin.setLog( getLog() );
374 plugin.setProjectHelper( projectHelper );
375 plugin.setProject( project );
376
377 try
378 {
379 plugin.execute();
380 }
381 catch ( AxisPluginException e )
382 {
383 throw new MojoExecutionException( "Error executing creating WSDL from the Java code.", e );
384 }
385 }
386
387 /**
388 * Computes the runtime classpath.
389 *
390 * @return A representation of the computed runtime classpath.
391 * @throws MojoExecutionException in case of dependency resolution failure
392 */
393 private String getCompileClasspath()
394 throws MojoExecutionException
395 {
396 try
397 {
398 // get the union of compile- and runtime classpath elements
399 Set dependencySet = new LinkedHashSet();
400 dependencySet.addAll( project.getCompileClasspathElements() );
401 dependencySet.add( classesDirectory.getAbsolutePath() );
402 String compileClasspath = StringUtils.join( dependencySet, File.pathSeparator );
403
404 return compileClasspath;
405 }
406 catch ( DependencyResolutionRequiredException e )
407 {
408 throw new MojoExecutionException( e.getMessage(), e );
409 }
410 }
411
412 }