View Javadoc
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 org.apache.maven.artifact.factory.ArtifactFactory;
23  import org.apache.maven.artifact.repository.ArtifactRepository;
24  import org.apache.maven.plugin.AbstractMojo;
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugin.MojoFailureException;
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.mojo.axistools.axis.AxisPluginException;
29  import org.codehaus.mojo.axistools.wsdl2java.DefaultWSDL2JavaPlugin;
30  import org.codehaus.mojo.axistools.wsdl2java.WSDL2JavaPlugin;
31  
32  import java.io.File;
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  /**
37   * A Plugin for generating stubs for WSDL files using Axis WSDL2Java.
38   *
39   * @author jesse <jesse.mcconnell@gmail.com>
40   * @author Christoph Schoenfeld <christophster@gmail.com>
41   * @version $Id$
42   * @requiresDependencyResolution test
43   * @goal wsdl2java
44   * @phase generate-sources
45   * @description WSDL2Java plugin
46   */
47  public class WSDL2JavaMojo
48      extends AbstractMojo
49  {
50      /**
51       * List of URLs to process.
52       *
53       * @parameter expression=""
54       */
55      private ArrayList urls;
56  
57      /**
58       * List of WSDL files from {@link #sourceDirectory} to process.
59       * The files will be processed in the order they appear in your configuration.
60       *
61       * @parameter expression=""
62       */
63      private ArrayList wsdlFiles;
64  
65      /**
66       * List of source dependencies in the format groupId:artifactId:version:file.
67       *
68       * @parameter expression=""
69       */
70      private ArrayList sourceDependencies;
71  
72      /**
73       * Cache directory for WSDLs from URLs.
74       *
75       * @parameter default-value="${project.build.directory}/axistools/wsdl2java/urlDownloads"
76       */
77      private File urlDownloadDirectory;
78  
79      /**
80       * Cache directory for WSDLs from sourceDependencies.
81       *
82       * @parameter default-value="${project.build.directory}/axistools/wsdl2java/sourceDependencies"
83       */
84      private File sourceDependencyDirectory;
85  
86      /**
87       * Use the Emitter for generating the java files as opposed to the commandline wsdl2java tool.
88       *
89       * @parameter default-value="false"
90       */
91      private boolean useEmitter;
92  
93      /**
94       * Mappings of &lt;namespace&gt; to &lt;targetPackage&gt;.
95       *
96       * @parameter expression=""
97       */
98      private ArrayList mappings;
99  
100     /**
101      * Emit server-side bindings for web service.
102      *
103      * Corresponds to the <code>-s, --server-side</code> option in the WSDL2Java command line tool.
104      *
105      * @parameter expression="${serverSide}"
106      */
107     private boolean serverSide;
108 
109     /**
110      * Package to create the java files under, for example <code>com.company.wsdl</code>.
111      *
112      * Corresponds to the <code>-p, --package</code> option in the WSDL2Java command line tool.
113      *
114      * @parameter expression="${packageSpace}"
115      */
116     private String packageSpace;
117 
118     /**
119      * See what the tool is generating as it is generating it.
120      *
121      * Corresponds to the <code>-v, --verbose</code> option in the WSDL2Java command line tool.
122      *
123      * @parameter expression="${verbose}"
124      */
125     private boolean verbose;
126 
127     /**
128      * Generate the test cases.
129      *
130      * Corresponds to the <code>-t, --testCase</code> option in the WSDL2Java command line tool.
131      *
132      * @parameter expression="${testCases}"
133      */
134     private boolean testCases;
135 
136     /**
137      * Copy the generated test cases to a generated-sources test directory to be
138      * compiled and run as normal Surefire unit tests.
139      *
140      * @parameter default-value="false"
141      */
142     private boolean runTestCasesAsUnitTests;
143 
144     /**
145      * Generate code for all elements, even unreferenced ones.
146      * By default, WSDL2Java only generates code for those elements in the WSDL file that are referenced.
147      * A note about what it means to be referenced.
148      * We cannot simply say: start with the services, generate all bindings referenced by the service,
149      * generate all portTypes referenced by the referenced bindings, etc.
150      * What if we're generating code from a WSDL file that only contains portTypes, messages, and types?
151      * If WSDL2Java used service as an anchor, and there's no service in the file, then nothing will be generated.
152      * So the anchor is the lowest element that exists in the WSDL file in the order:
153      * <ol>
154      *   <li>types
155      *   <li>portTypes
156      *   <li>bindings
157      *   <li>services
158      * </ol>
159      * For example, if a WSDL file only contained types, then all the listed
160      * types would be generated. But if a WSDL file contained types and a
161      * portType, then that portType will be generated and only those types that
162      * are referenced by that portType. Note that the anchor is searched for in
163      * the WSDL file appearing on the command line, not in imported WSDL files.
164      * This allows one WSDL file to import constructs defined in another WSDL
165      * file without the nuisance of having all the imported WSDL file's
166      * constructs generated.
167      *
168      * Corresponds to the <code>-a, --all</code> option in the WSDL2Java command line tool.
169      *
170      * @parameter expression="${allElements}"
171      */
172     private boolean allElements;
173 
174     /**
175      * Print debug information, which currently is WSDL2Java's symbol table.
176      * Note that this is only printed after the symbol table is complete, ie., after the WSDL is parsed successfully.
177      *
178      * Corresponds to the <code>-D, --Debug</code> option in the WSDL2Java command line tool.
179      *
180      * @parameter default-value="false"
181      */
182     private boolean debug;
183 
184     /**
185      * Timeout in seconds (default is 45, specify -1 to disable).
186      *
187      * Corresponds to the <code>-O, --timeout</code> option in the WSDL2Java command line tool.
188      *
189      * @parameter expression="${timeout}"
190      */
191     private Integer timeout;
192 
193     /**
194      * Only generate code for the immediate WSDL document.
195      *
196      * Corresponds to the <code>-n, --noImports</code> option in the WSDL2Java command line tool.
197      *
198      * @parameter default-value="false"
199      */
200     private boolean noImports;
201 
202     /**
203      * Turn off support for "wrapped" document/literal.
204      *
205      * Corresponds to the <code>-W, --noWrapped</code> option in the WSDL2Java command line tool.
206      *
207      * @parameter default-value="false"
208      */
209     private boolean noWrapped;
210 
211     /**
212      * Prefer generating JavaBean classes like "ArrayOfString" for certain
213      * schema array patterns.
214      *
215      * Corresponds to the <code>-w, --wrapArrays</code> option in the WSDL2Java command line tool.
216      *
217      * @parameter default-value="true"
218      * NJS 6 July 2006
219      */
220     private boolean wrapArrays;
221 
222     /**
223      * Deploy skeleton (true) or implementation (false) in deploy.wsdd.
224      *
225      * Corresponds to the <code>-S, --skeletonDeploy</code> option in the WSDL2Java command line tool.
226      *
227      * @parameter default-value="false"
228      */
229     private boolean skeletonDeploy;
230 
231     /**
232      * Mapping of namespace to package.
233      * This is only used when <code>useEmitter</code> is set to <code>true</code>.
234      * If <code>useEmitter</code> is set to <code>false</code> you should use {@linkplain #mappings} instead.
235      *
236      * Corresponds to the <code>-N, --NStoPkg</code> option in the WSDL2Java command line tool.
237      *
238      * @parameter expression="${namespaceToPackage}"
239      */
240     private String namespaceToPackage;
241 
242     /**
243      * File containing namespace to package mappings.
244      *
245      * Corresponds to the <code>-f, --fileNStoPkg</code> option in the WSDL2Java command line tool.
246      *
247      * @parameter expression="${fileNamespaceToPackage}"
248      */
249     private File fileNamespaceToPackage;
250 
251     /**
252      * Add scope to deploy.xml: "Application", "Request", "Session".
253      *
254      * Corresponds to the <code>-d, --deployScope</code> option in the WSDL2Java command line tool.
255      *
256      * @parameter expression="${deployScope}"
257      */
258     private String deployScope;
259 
260     /**
261      * Indicate either 1.1 or 1.2, where 1.1 means SOAP 1.1 JAX-RPC compliant
262      * and 1.2 indicates SOAP 1.1 encoded.
263      *
264      * Corresponds to the <code>-T, --typeMappingVersion</code> option in the WSDL2Java command line tool.
265      *
266      * @parameter expression="${typeMappingVersion}" default-value="1.1"
267      */
268     private String typeMappingVersion;
269 
270     /**
271      * Name of a custom class that implements GeneratorFactory interface
272      * (for extending Java generation functions).
273      *
274      * Corresponds to the <code>-F, --factory</code> option in the WSDL2Java command line tool.
275      *
276      * @parameter expression="${factory}"
277      */
278     private String factory;
279 
280     /**
281      * Namescape to specifically include in the generated code (defaults to
282      * all namespaces unless specifically excluded with the {@linkplain #nsExcludes} option).
283      *
284      * Corresponds to the <code>-i, --nsInclude</code> option in the WSDL2Java command line tool.
285      *
286      * @parameter
287      */
288     private ArrayList nsIncludes;
289 
290     /**
291      * Namespace to specifically exclude from the generated code (defaults to
292      * none excluded until first namespace included with {@linkplain #nsIncludes} option).
293      *
294      * Corresponds to the <code>-x, --nsExclude</code> option in the WSDL2Java command line tool.
295      *
296      * @parameter
297      */
298     private ArrayList nsExcludes;
299 
300     /**
301      * Emits separate Helper classes for meta data.
302      *
303      * Corresponds to the <code>-H, --helperGen</code> option in the WSDL2Java command line tool.
304      *
305      * @parameter default-value="false"
306      */
307     private boolean helperGen;
308 
309     /**
310      * Username to access the WSDL-URI.
311      *
312      * Corresponds to the <code>-U, --user</code> option in the WSDL2Java command line tool.
313      *
314      * @parameter expression="${username}"
315      */
316     private String username;
317 
318     /**
319      * Password to access the WSDL-URI.
320      *
321      * Corresponds to the <code>-P, --password</code> option in the WSDL2Java command line tool.
322      *
323      * @parameter expression="${password}"
324      */
325     private String password;
326 
327     /**
328      * Use this as the implementation class.
329      *
330      * Corresponds to the <code>-c, --implementationClassName</code> option in the WSDL2Java command line tool.
331      *
332      * @parameter expression="${implementationClassName}"
333      */
334     private String implementationClassName;
335 
336     /**
337      * load.wsdl would further subpackage into load.*
338      *
339      * @parameter expression="${subPackageByFileName}"
340      */
341     private boolean subPackageByFileName;
342 
343     /**
344      * Location to place generated test source files.
345      *
346      * @parameter default-value="${project.build.directory}/generated-test-sources/wsdl"
347      */
348     private File testSourceDirectory;
349 
350     /**
351      * Source directory that contains .wsdl files.
352      *
353      * @parameter default-value="${basedir}/src/main/wsdl"
354      */
355     private File sourceDirectory;
356 
357     /**
358      * Location to place generated java source files.
359      *
360      * Corresponds to the <code>-o, --output</code> option in the WSDL2Java command line tool.
361      *
362      * @parameter default-value="${project.build.directory}/generated-sources/axistools/wsdl2java"
363      * @required
364      */
365     private File outputDirectory;
366 
367     /**
368      * Directory used when evaluating whether files are up to date or stale.
369      *
370      * @parameter default-value="${project.build.directory}"
371      * @required
372      */
373     private File timestampDirectory;
374 
375     /**
376      * The granularity in milliseconds of the last modification
377      * date for testing whether a source needs recompilation.
378      *
379      * @parameter expression="${lastModGranularityMs}" default-value="0"
380      */
381     private int staleMillis;
382 
383     /**
384      * @parameter expression="${project}"
385      * @required
386      * @readonly
387      */
388     private MavenProject project;
389 
390     /**
391      * @parameter expression="${localRepository}"
392      * @required
393      * @readonly
394      */
395     private ArtifactRepository localRepository;
396 
397     /**
398      * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
399      * @required
400      * @readonly
401      */
402     private ArtifactFactory artifactFactory;
403 
404     /**
405      * @parameter expression="${plugin.artifacts}"
406      * @required
407      * @readonly
408      */
409     private List pluginArtifacts;
410 
411     public void execute()
412         throws MojoExecutionException, MojoFailureException
413     {
414         WSDL2JavaPlugin plugin = new DefaultWSDL2JavaPlugin();
415 
416         plugin.setAllElements( allElements );
417         plugin.setDebug( debug );
418         plugin.setDeployScope( deployScope );
419         plugin.setFactory( factory );
420         plugin.setFileNamespaceToPackage( fileNamespaceToPackage );
421         plugin.setHelperGen( helperGen );
422         plugin.setImplementationClassName( implementationClassName );
423         plugin.setMappings( mappings );
424         plugin.setNamespaceToPackage( namespaceToPackage );
425         plugin.setNoImports( noImports );
426         plugin.setNoWrapped( noWrapped );
427         plugin.setWrapArrays( wrapArrays );
428         plugin.setNsExcludes( nsExcludes );
429         plugin.setNsIncludes( nsIncludes );
430         plugin.setPackageSpace( packageSpace );
431         plugin.setPassword( password );
432         plugin.setRunTestCasesAsUnitTests( runTestCasesAsUnitTests );
433         plugin.setServerSide( serverSide );
434         plugin.setSkeletonDeploy( skeletonDeploy );
435         plugin.setSourceDependencies( sourceDependencies );
436         plugin.setSourceDependencyDirectory( sourceDependencyDirectory );
437         plugin.setStaleMillis( staleMillis );
438         plugin.setSubPackageByFileName( subPackageByFileName );
439         plugin.setTestCases( testCases );
440         plugin.setTestSourceDirectory( testSourceDirectory );
441         plugin.setTimeout( timeout );
442         plugin.setTypeMappingVersion( typeMappingVersion );
443         plugin.setUrlDownloadDirectory( urlDownloadDirectory );
444         plugin.setUrls( urls );
445         plugin.setWsdlFiles( wsdlFiles );
446         plugin.setUseEmitter( useEmitter );
447         plugin.setUsername( username );
448         plugin.setVerbose( verbose );
449         plugin.setProject( project );
450         plugin.setOutputDirectory( outputDirectory );
451         plugin.setSourceDirectory( sourceDirectory );
452         plugin.setTimestampDirectory( timestampDirectory );
453         plugin.setLocalRepository( localRepository );
454         plugin.setArtifactFactory( artifactFactory );
455         plugin.setPluginArtifacts( pluginArtifacts );
456         plugin.setLog( getLog() );
457 
458         try
459         {
460             plugin.execute();
461         }
462         catch ( AxisPluginException e )
463         {
464             throw new MojoExecutionException( "Error generating Java code from WSDL.", e );
465         }
466     }
467 }