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.wsee.tools.anttasks.JwsFileSet;
24  import weblogic.wsee.tools.anttasks.JwsModule.Descriptor;
25  import weblogic.wsee.tools.anttasks.JwscTask;
26  import weblogic.wsee.tools.anttasks.MultipleJwsModule;
27  
28  import java.io.File;
29  import java.util.Iterator;
30  
31  /**
32   * Runs the JWSC compiler task for web service enabled code.
33   *
34   * @author <a href="mailto:josborn@belltracy.com">Jon Osborn</a>
35   * @version $Id: JwscMojo.java 7025 2008-05-21 01:50:58Z jonnio $
36   * @description This mojo will run the JSWC ant task
37   * @goal jwsc
38   * @requiresDependencyResolution compile
39   * @since weblogic-maven-plugin-2.9.1-SNAPSHOT
40   */
41  public class JwscMojo
42      extends AbstractWeblogicMojo
43  {
44  
45      /**
46       * The directory to output the generated code to.
47       *
48       * @parameter default-value="${project.build.directory}"
49       */
50      private String outputDir;
51  
52      /**
53       * The directory to find the jwsc enabled files.
54       *
55       * @parameter default-value="${basedir}/src/main/java"
56       */
57      private String inputDir;
58  
59      /**
60       * The name of the war to use when evaluating the ear file.
61       *
62       * @required
63       * @parameter default-value="${project.artifactId}-${project.version}"
64       */
65      private String outputName;
66  
67      /**
68       * The flag to set when desiring verbose output
69       *
70       * @parameter default-value="false"
71       */
72      private boolean verbose;
73  
74      /**
75       * The flag to set when debugging the process
76       *
77       * @parameter default-value="false"
78       */
79      private boolean debug;
80  
81      /**
82       * The flag to set when wanting exploded output. Defaults to true.
83       *
84       * @parameter default-value="true"
85       */
86      private boolean explode;
87  
88      /**
89       * The flag to set when requiring optimization. Defaults to true.
90       *
91       * @parameter default-value="true"
92       */
93      private boolean optimize;
94  
95      /**
96       * The deployed context of the web service.
97       *
98       * @parameter
99       * @required
100      */
101     private String contextPath;
102 
103     /**
104      * The web.xml descriptor to use if a new one should not be generated. The
105      * path should be fully qualified.
106      *
107      * @parameter
108      */
109     private String descriptor;
110 
111     /**
112      * This method will run the jswc on the target files
113      *
114      * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
115      */
116     public void execute()
117         throws MojoExecutionException
118     {
119         super.execute();
120         if ( getLog().isInfoEnabled() )
121         {
122             getLog().info( "Weblogic jwsc beginning for output " + this.outputName );
123         }
124         if ( getLog().isDebugEnabled() )
125         {
126             getLog().debug( "inputDir=" + this.inputDir + "  contextPath=" + this.contextPath );
127         }
128         if ( this.contextPath == null )
129         {
130             getLog().warn( "Context path is null. It will be required if " + "more than one web service is present." );
131         }
132         try
133         {
134             Iterator iter = getDependencies().iterator();
135             while ( iter.hasNext() )
136             {
137                 getLog().debug( iter.next().toString() );
138             }
139             final JwscTask task = new JwscTask();
140             final Project project = new Project();
141             project.addBuildListener( getDefaultLogger() );
142             project.setName( "jwsc" );
143             final Path path = new Path( project, WeblogicMojoUtilities
144                 .getDependencies( this.getArtifacts(), this.getPluginArtifacts() ) );
145             if ( getLog().isDebugEnabled() )
146             {
147                 getLog().debug( "Path=" + path.toString() );
148             }
149             task.setProject( project );
150             task.setTaskName( project.getName() );
151             task.setNowarn( false );
152             // Set the class path
153             task.setClasspath( path );
154             task.setDestdir( new File( this.outputDir ) );
155             task.setVerbose( this.verbose );
156             task.setOptimize( this.optimize );
157             task.setDebug( this.debug );
158             task.setSrcdir( new File( this.inputDir ) );
159             final MultipleJwsModule module = task.createModule();
160             final JwsFileSet jwsFileSet = module.createJwsFileSet();
161             jwsFileSet.setProject( project );
162             jwsFileSet.setSrcdir( new Path( project, this.inputDir ) );
163             if ( getLog().isInfoEnabled() )
164             {
165                 getLog().info( "fileset=" + jwsFileSet.getSrcdir().toString() );
166             }
167             if ( this.descriptor != null )
168             {
169                 final Descriptor descriptor = module.createDescriptor();
170                 descriptor.setFile( new File( this.descriptor ) );
171             }
172             module.setName( this.outputName );
173             module.setExplode( this.explode );
174             module.setContextPath( this.contextPath );
175             task.execute();
176         }
177         catch ( Exception ex )
178         {
179             getLog().error( "Exception encountered during jwsc", ex );
180             throw new MojoExecutionException( "Exception encountered during jwsc", ex );
181         }
182     }
183 
184     /**
185      * @return the outputName
186      */
187     public String getOutputName()
188     {
189         return outputName;
190     }
191 
192     /**
193      * @param outputName the outputName to set
194      */
195     public void setOutputName( String outputName )
196     {
197         this.outputName = outputName;
198     }
199 
200     /**
201      * @return the outputDir
202      */
203     public String getOutputDir()
204     {
205         return outputDir;
206     }
207 
208     /**
209      * @param outputDir the outputDir to set
210      */
211     public void setOutputDir( String outputDir )
212     {
213         this.outputDir = outputDir;
214     }
215 
216     /**
217      * Getter for inputDir
218      *
219      * @return the inputDir
220      */
221     public String getInputDir()
222     {
223         return inputDir;
224     }
225 
226     /**
227      * Setter for inputDir
228      *
229      * @param inputDir the inputDir to set
230      */
231     public void setInputDir( String inputDir )
232     {
233         this.inputDir = inputDir;
234     }
235 
236     /**
237      * Getter for verbose
238      *
239      * @return the verbose
240      */
241     public boolean isVerbose()
242     {
243         return verbose;
244     }
245 
246     /**
247      * @param verbose the verbose to set
248      */
249     public void setVerbose( boolean verbose )
250     {
251         this.verbose = verbose;
252     }
253 
254     /**
255      * @return the debug
256      */
257     public boolean isDebug()
258     {
259         return debug;
260     }
261 
262     /**
263      * @param debug the debug to set
264      */
265     public void setDebug( boolean debug )
266     {
267         this.debug = debug;
268     }
269 
270     /**
271      * @return the explode
272      */
273     public boolean isExplode()
274     {
275         return explode;
276     }
277 
278     /**
279      * @param explode the explode to set
280      */
281     public void setExplode( boolean explode )
282     {
283         this.explode = explode;
284     }
285 
286     /**
287      * @return the optimize
288      */
289     public boolean isOptimize()
290     {
291         return optimize;
292     }
293 
294     /**
295      * @param optimize the optimize to set
296      */
297     public void setOptimize( boolean optimize )
298     {
299         this.optimize = optimize;
300     }
301 
302     /**
303      * @return the contextPath
304      */
305     public String getContextPath()
306     {
307         return contextPath;
308     }
309 
310     /**
311      * @param contextPath the contextPath to set
312      */
313     public void setContextPath( String contextPath )
314     {
315         this.contextPath = contextPath;
316     }
317 
318     /**
319      * @return the descriptor
320      */
321     public String getDescriptor()
322     {
323         return descriptor;
324     }
325 
326     /**
327      * @param descriptor the descriptor to set
328      */
329     public void setDescriptor( String descriptor )
330     {
331         this.descriptor = descriptor;
332     }
333 
334     /**
335      * Meaningful toString implementation
336      *
337      * @return the string representation of this object
338      */
339     public String toString()
340     {
341         return "JwscMojo{" + "outputDir='" + outputDir + '\'' + ", inputDir='" + inputDir + '\'' + ", outputName='" +
342             outputName + '\'' + ", verbose=" + verbose + ", debug=" + debug + ", explode=" + explode + ", optimize=" +
343             optimize + ", contextPath='" + contextPath + '\'' + ", descriptor='" + descriptor + '\'' + '}';
344     }
345 }