View Javadoc

1   package org.codehaus.mojo.weblogic;
2   
3   /*
4    * Copyright 2008 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.wsdlgen.WSDLGen;
24  
25  import java.io.File;
26  
27  /**
28   * This class generates wsdl from ear/war package
29   *
30   * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
31   * @version $Id: WsdlGenMojo.java 6622 2008-04-01 02:21:19Z jonnio $
32   * @description Run wsdlgen on an ear.
33   * @goal wsdlgen
34   * @requiresDependencyResolution compile
35   */
36  public class WsdlGenMojo
37      extends AbstractWeblogicMojo
38  {
39      /**
40       * The service name to generate the wsdl for
41       *
42       * @parameter
43       * @required
44       */
45      private String serviceName;
46  
47      /**
48       * The war name inside of the ear that contains the services
49       *
50       * @parameter
51       * @required
52       */
53      private String warName;
54  
55      /**
56       * The wsdl file to output when complete.
57       *
58       * @parameter expression="${project.build.directory}/${project.build.finalName}.wsdl"
59       */
60      private String wsdlFile;
61  
62      /**
63       * The default endpoint address
64       *
65       * @parameter default-value="http://localhost:7001/"
66       */
67      private String defaultEndpoint;
68  
69      /**
70       * The input ear file to use with the wsdl gen. If this is null the service
71       * will look in the dependencies for an ear file to use
72       */
73      private String earFileName;
74  
75      /**
76       * Set to false to not overwrite existing resources.
77       *
78       * @parameter default-value="true"
79       */
80      private boolean overwrite;
81  
82      /**
83       * Execute the wsdlgen step to leave the artifacts around
84       */
85      public void execute()
86          throws MojoExecutionException
87      {
88          super.execute();
89  
90          if ( getLog().isInfoEnabled() )
91          {
92              getLog().info( "Weblogic wsdl gen beginning " );
93          }
94  
95          File earFile;
96          if ( this.earFileName == null )
97          {
98              earFile = WeblogicMojoUtilities.getEarFileName( getArtifacts() );
99          }
100         else
101         {
102             earFile = new File( this.earFileName );
103         }
104         final String classPath = WeblogicMojoUtilities
105             .getDependencies( getArtifacts() );
106 
107         if ( getLog().isInfoEnabled() )
108         {
109             getLog().info( "Weblogic wsdl gen for ear " + earFile );
110         }
111 
112         try
113         {
114             final WSDLGen wsdl = new WSDLGen();
115             final Project antProject = new Project();
116             antProject.setName( "wsdlgen" );
117             wsdl.setProject( antProject );
118             wsdl.setClasspath( new Path( antProject, classPath ) );
119             wsdl.setEar( earFile );
120             wsdl.setWarName( this.warName );
121             final File wsdlFileFile = new File( this.wsdlFile );
122             wsdl.setWsdlFile( wsdlFileFile );
123             wsdl.setServiceName( this.serviceName );
124             wsdl.execute();
125         }
126         catch ( Exception ex )
127         {
128             getLog().error( "Exception encountered during WSDLGen processing ", ex );
129             throw new MojoExecutionException( "Exception encountered during WSDLGen processing", ex );
130         }
131 
132     }
133 
134     /**
135      * Getter for the service name
136      *
137      * @return the service name
138      */
139     public String getServiceName()
140     {
141         return serviceName;
142     }
143 
144     /**
145      * Setter for the service name
146      *
147      * @param serviceName the service name to set
148      */
149     public void setServiceName( String serviceName )
150     {
151         this.serviceName = serviceName;
152     }
153 
154     public String getWarName()
155     {
156         return warName;
157     }
158 
159     public void setWarName( String warName )
160     {
161         this.warName = warName;
162     }
163 
164     public String getWsdlFile()
165     {
166         return wsdlFile;
167     }
168 
169     public void setWsdlFile( String wsdlFile )
170     {
171         this.wsdlFile = wsdlFile;
172     }
173 
174     public String getDefaultEndpoint()
175     {
176         return defaultEndpoint;
177     }
178 
179     public void setDefaultEndpoint( String defaultEndpoint )
180     {
181         this.defaultEndpoint = defaultEndpoint;
182     }
183 
184     public String getEarFileName()
185     {
186         return earFileName;
187     }
188 
189     public void setEarFileName( String earFileName )
190     {
191         this.earFileName = earFileName;
192     }
193 
194     public boolean isOverwrite()
195     {
196         return overwrite;
197     }
198 
199     public void setOverwrite( boolean overwrite )
200     {
201         this.overwrite = overwrite;
202     }
203 
204     /**
205      * toString method: creates a String representation of the object
206      *
207      * @return the String representation
208      */
209     public String toString()
210     {
211         StringBuffer buffer = new StringBuffer();
212         buffer.append( "ClientGenMojo[" );
213         buffer.append( "earFileName = " ).append( earFileName );
214         buffer.append( ", warName = " ).append( warName );
215         buffer.append( ", serviceName = " ).append( serviceName );
216         buffer.append( ", overwrite = " ).append( overwrite );
217         buffer.append( "]" );
218         return buffer.toString();
219     }
220 }