View Javadoc

1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.8.1,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.plugin.descriptor.model.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.OutputStream;
13  import java.io.Writer;
14  import java.util.Iterator;
15  import org.apache.maven.plugin.descriptor.model.Configuration;
16  import org.apache.maven.plugin.descriptor.model.Dependency;
17  import org.apache.maven.plugin.descriptor.model.MojoDescriptor;
18  import org.apache.maven.plugin.descriptor.model.Parameter;
19  import org.apache.maven.plugin.descriptor.model.PluginDescriptor;
20  import org.apache.maven.plugin.descriptor.model.Requirement;
21  import org.codehaus.plexus.util.xml.pull.MXSerializer;
22  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
23  
24  /**
25   * Class PluginDescriptorXpp3Writer.
26   * 
27   * @version $Revision: 877610 $ $Date: 2013-09-07 17:25:53 +0200 (Sat, 07 Sep 2013) $
28   */
29  @SuppressWarnings( "all" )
30  public class PluginDescriptorXpp3Writer
31  {
32  
33        //--------------------------/
34       //- Class/Member Variables -/
35      //--------------------------/
36  
37      /**
38       * Field NAMESPACE.
39       */
40      private static final String NAMESPACE = null;
41  
42  
43        //-----------/
44       //- Methods -/
45      //-----------/
46  
47      /**
48       * Method write.
49       * 
50       * @param writer
51       * @param pluginDescriptor
52       * @throws java.io.IOException
53       */
54      public void write( Writer writer, PluginDescriptor pluginDescriptor )
55          throws java.io.IOException
56      {
57          XmlSerializer serializer = new MXSerializer();
58          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
59          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
60          serializer.setOutput( writer );
61          serializer.startDocument( pluginDescriptor.getModelEncoding(), null );
62          writePluginDescriptor( pluginDescriptor, "plugin", serializer );
63          serializer.endDocument();
64      } //-- void write( Writer, PluginDescriptor )
65  
66      /**
67       * Method write.
68       * 
69       * @param stream
70       * @param pluginDescriptor
71       * @throws java.io.IOException
72       */
73      public void write( OutputStream stream, PluginDescriptor pluginDescriptor )
74          throws java.io.IOException
75      {
76          XmlSerializer serializer = new MXSerializer();
77          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
78          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
79          serializer.setOutput( stream, pluginDescriptor.getModelEncoding() );
80          serializer.startDocument( pluginDescriptor.getModelEncoding(), null );
81          writePluginDescriptor( pluginDescriptor, "plugin", serializer );
82          serializer.endDocument();
83      } //-- void write( OutputStream, PluginDescriptor )
84  
85      /**
86       * Method writeConfiguration.
87       * 
88       * @param configuration
89       * @param serializer
90       * @param tagName
91       * @throws java.io.IOException
92       */
93      private void writeConfiguration( Configuration configuration, String tagName, XmlSerializer serializer )
94          throws java.io.IOException
95      {
96          serializer.startTag( NAMESPACE, tagName );
97          if ( configuration.getImplementation() != null )
98          {
99              serializer.attribute( NAMESPACE, "implementation", configuration.getImplementation() );
100         }
101         if ( configuration.getDefaultValue() != null )
102         {
103             serializer.attribute( NAMESPACE, "default-value", configuration.getDefaultValue() );
104         }
105         serializer.text( configuration.getExpression() );
106         serializer.endTag( NAMESPACE, tagName );
107     } //-- void writeConfiguration( Configuration, String, XmlSerializer )
108 
109     /**
110      * Method writeDependency.
111      * 
112      * @param dependency
113      * @param serializer
114      * @param tagName
115      * @throws java.io.IOException
116      */
117     private void writeDependency( Dependency dependency, String tagName, XmlSerializer serializer )
118         throws java.io.IOException
119     {
120         serializer.startTag( NAMESPACE, tagName );
121         if ( dependency.getGroupId() != null )
122         {
123             serializer.startTag( NAMESPACE, "groupId" ).text( dependency.getGroupId() ).endTag( NAMESPACE, "groupId" );
124         }
125         if ( dependency.getArtifactId() != null )
126         {
127             serializer.startTag( NAMESPACE, "artifactId" ).text( dependency.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
128         }
129         if ( dependency.getVersion() != null )
130         {
131             serializer.startTag( NAMESPACE, "version" ).text( dependency.getVersion() ).endTag( NAMESPACE, "version" );
132         }
133         if ( ( dependency.getType() != null ) && !dependency.getType().equals( "jar" ) )
134         {
135             serializer.startTag( NAMESPACE, "type" ).text( dependency.getType() ).endTag( NAMESPACE, "type" );
136         }
137         serializer.endTag( NAMESPACE, tagName );
138     } //-- void writeDependency( Dependency, String, XmlSerializer )
139 
140     /**
141      * Method writeMojoDescriptor.
142      * 
143      * @param mojoDescriptor
144      * @param serializer
145      * @param tagName
146      * @throws java.io.IOException
147      */
148     private void writeMojoDescriptor( MojoDescriptor mojoDescriptor, String tagName, XmlSerializer serializer )
149         throws java.io.IOException
150     {
151         serializer.startTag( NAMESPACE, tagName );
152         if ( mojoDescriptor.getGoal() != null )
153         {
154             serializer.startTag( NAMESPACE, "goal" ).text( mojoDescriptor.getGoal() ).endTag( NAMESPACE, "goal" );
155         }
156         if ( mojoDescriptor.getDescription() != null )
157         {
158             serializer.startTag( NAMESPACE, "description" ).text( mojoDescriptor.getDescription() ).endTag( NAMESPACE, "description" );
159         }
160         if ( mojoDescriptor.getImplementation() != null )
161         {
162             serializer.startTag( NAMESPACE, "implementation" ).text( mojoDescriptor.getImplementation() ).endTag( NAMESPACE, "implementation" );
163         }
164         if ( ( mojoDescriptor.getLanguage() != null ) && !mojoDescriptor.getLanguage().equals( "java" ) )
165         {
166             serializer.startTag( NAMESPACE, "language" ).text( mojoDescriptor.getLanguage() ).endTag( NAMESPACE, "language" );
167         }
168         if ( mojoDescriptor.getPhase() != null )
169         {
170             serializer.startTag( NAMESPACE, "phase" ).text( mojoDescriptor.getPhase() ).endTag( NAMESPACE, "phase" );
171         }
172         if ( mojoDescriptor.getExecutePhase() != null )
173         {
174             serializer.startTag( NAMESPACE, "executePhase" ).text( mojoDescriptor.getExecutePhase() ).endTag( NAMESPACE, "executePhase" );
175         }
176         if ( mojoDescriptor.getExecuteGoal() != null )
177         {
178             serializer.startTag( NAMESPACE, "executeGoal" ).text( mojoDescriptor.getExecuteGoal() ).endTag( NAMESPACE, "executeGoal" );
179         }
180         if ( mojoDescriptor.getExecuteLifecycle() != null )
181         {
182             serializer.startTag( NAMESPACE, "executeLifecycle" ).text( mojoDescriptor.getExecuteLifecycle() ).endTag( NAMESPACE, "executeLifecycle" );
183         }
184         if ( ( mojoDescriptor.getRequiresDependencyResolution() != null ) && !mojoDescriptor.getRequiresDependencyResolution().equals( "runtime" ) )
185         {
186             serializer.startTag( NAMESPACE, "requiresDependencyResolution" ).text( mojoDescriptor.getRequiresDependencyResolution() ).endTag( NAMESPACE, "requiresDependencyResolution" );
187         }
188         if ( mojoDescriptor.getRequiresDependencyCollection() != null )
189         {
190             serializer.startTag( NAMESPACE, "requiresDependencyCollection" ).text( mojoDescriptor.getRequiresDependencyCollection() ).endTag( NAMESPACE, "requiresDependencyCollection" );
191         }
192         if ( mojoDescriptor.isRequiresDirectInvocation() != false )
193         {
194             serializer.startTag( NAMESPACE, "requiresDirectInvocation" ).text( String.valueOf( mojoDescriptor.isRequiresDirectInvocation() ) ).endTag( NAMESPACE, "requiresDirectInvocation" );
195         }
196         if ( mojoDescriptor.isRequiresProject() != true )
197         {
198             serializer.startTag( NAMESPACE, "requiresProject" ).text( String.valueOf( mojoDescriptor.isRequiresProject() ) ).endTag( NAMESPACE, "requiresProject" );
199         }
200         if ( mojoDescriptor.isRequiresReports() != false )
201         {
202             serializer.startTag( NAMESPACE, "requiresReports" ).text( String.valueOf( mojoDescriptor.isRequiresReports() ) ).endTag( NAMESPACE, "requiresReports" );
203         }
204         if ( mojoDescriptor.isRequiresOnline() != false )
205         {
206             serializer.startTag( NAMESPACE, "requiresOnline" ).text( String.valueOf( mojoDescriptor.isRequiresOnline() ) ).endTag( NAMESPACE, "requiresOnline" );
207         }
208         if ( mojoDescriptor.isAggregator() != false )
209         {
210             serializer.startTag( NAMESPACE, "aggregator" ).text( String.valueOf( mojoDescriptor.isAggregator() ) ).endTag( NAMESPACE, "aggregator" );
211         }
212         if ( mojoDescriptor.isInheritedByDefault() != true )
213         {
214             serializer.startTag( NAMESPACE, "inheritedByDefault" ).text( String.valueOf( mojoDescriptor.isInheritedByDefault() ) ).endTag( NAMESPACE, "inheritedByDefault" );
215         }
216         if ( mojoDescriptor.isThreadSafe() != false )
217         {
218             serializer.startTag( NAMESPACE, "threadSafe" ).text( String.valueOf( mojoDescriptor.isThreadSafe() ) ).endTag( NAMESPACE, "threadSafe" );
219         }
220         if ( ( mojoDescriptor.getInstantiationStrategy() != null ) && !mojoDescriptor.getInstantiationStrategy().equals( "per-lookup" ) )
221         {
222             serializer.startTag( NAMESPACE, "instantiationStrategy" ).text( mojoDescriptor.getInstantiationStrategy() ).endTag( NAMESPACE, "instantiationStrategy" );
223         }
224         if ( ( mojoDescriptor.getExecutionStrategy() != null ) && !mojoDescriptor.getExecutionStrategy().equals( "once-per-session" ) )
225         {
226             serializer.startTag( NAMESPACE, "executionStrategy" ).text( mojoDescriptor.getExecutionStrategy() ).endTag( NAMESPACE, "executionStrategy" );
227         }
228         if ( mojoDescriptor.getSince() != null )
229         {
230             serializer.startTag( NAMESPACE, "since" ).text( mojoDescriptor.getSince() ).endTag( NAMESPACE, "since" );
231         }
232         if ( mojoDescriptor.getDeprecated() != null )
233         {
234             serializer.startTag( NAMESPACE, "deprecated" ).text( mojoDescriptor.getDeprecated() ).endTag( NAMESPACE, "deprecated" );
235         }
236         if ( mojoDescriptor.getConfigurator() != null )
237         {
238             serializer.startTag( NAMESPACE, "configurator" ).text( mojoDescriptor.getConfigurator() ).endTag( NAMESPACE, "configurator" );
239         }
240         if ( mojoDescriptor.getComposer() != null )
241         {
242             serializer.startTag( NAMESPACE, "composer" ).text( mojoDescriptor.getComposer() ).endTag( NAMESPACE, "composer" );
243         }
244         if ( ( mojoDescriptor.getParameters() != null ) && ( mojoDescriptor.getParameters().size() > 0 ) )
245         {
246             serializer.startTag( NAMESPACE, "parameters" );
247             for ( Iterator iter = mojoDescriptor.getParameters().iterator(); iter.hasNext(); )
248             {
249                 Parameter o = (Parameter) iter.next();
250                 writeParameter( o, "parameter", serializer );
251             }
252             serializer.endTag( NAMESPACE, "parameters" );
253         }
254         if ( ( mojoDescriptor.getConfiguration() != null ) && ( mojoDescriptor.getConfiguration().size() > 0 ) )
255         {
256             serializer.startTag( NAMESPACE, "configuration" );
257             for ( Iterator iter = mojoDescriptor.getConfiguration().iterator(); iter.hasNext(); )
258             {
259                 Configuration o = (Configuration) iter.next();
260                 writeConfiguration( o, "paramName", serializer );
261             }
262             serializer.endTag( NAMESPACE, "configuration" );
263         }
264         if ( ( mojoDescriptor.getRequirements() != null ) && ( mojoDescriptor.getRequirements().size() > 0 ) )
265         {
266             serializer.startTag( NAMESPACE, "requirements" );
267             for ( Iterator iter = mojoDescriptor.getRequirements().iterator(); iter.hasNext(); )
268             {
269                 Requirement o = (Requirement) iter.next();
270                 writeRequirement( o, "requirement", serializer );
271             }
272             serializer.endTag( NAMESPACE, "requirements" );
273         }
274         serializer.endTag( NAMESPACE, tagName );
275     } //-- void writeMojoDescriptor( MojoDescriptor, String, XmlSerializer )
276 
277     /**
278      * Method writeParameter.
279      * 
280      * @param parameter
281      * @param serializer
282      * @param tagName
283      * @throws java.io.IOException
284      */
285     private void writeParameter( Parameter parameter, String tagName, XmlSerializer serializer )
286         throws java.io.IOException
287     {
288         serializer.startTag( NAMESPACE, tagName );
289         if ( parameter.getName() != null )
290         {
291             serializer.startTag( NAMESPACE, "name" ).text( parameter.getName() ).endTag( NAMESPACE, "name" );
292         }
293         if ( parameter.getAlias() != null )
294         {
295             serializer.startTag( NAMESPACE, "alias" ).text( parameter.getAlias() ).endTag( NAMESPACE, "alias" );
296         }
297         if ( parameter.getType() != null )
298         {
299             serializer.startTag( NAMESPACE, "type" ).text( parameter.getType() ).endTag( NAMESPACE, "type" );
300         }
301         if ( parameter.isRequired() != false )
302         {
303             serializer.startTag( NAMESPACE, "required" ).text( String.valueOf( parameter.isRequired() ) ).endTag( NAMESPACE, "required" );
304         }
305         if ( parameter.isEditable() != true )
306         {
307             serializer.startTag( NAMESPACE, "editable" ).text( String.valueOf( parameter.isEditable() ) ).endTag( NAMESPACE, "editable" );
308         }
309         if ( parameter.getImplementation() != null )
310         {
311             serializer.startTag( NAMESPACE, "implementation" ).text( parameter.getImplementation() ).endTag( NAMESPACE, "implementation" );
312         }
313         if ( parameter.getDescription() != null )
314         {
315             serializer.startTag( NAMESPACE, "description" ).text( parameter.getDescription() ).endTag( NAMESPACE, "description" );
316         }
317         if ( parameter.getSince() != null )
318         {
319             serializer.startTag( NAMESPACE, "since" ).text( parameter.getSince() ).endTag( NAMESPACE, "since" );
320         }
321         if ( parameter.getDeprecated() != null )
322         {
323             serializer.startTag( NAMESPACE, "deprecated" ).text( parameter.getDeprecated() ).endTag( NAMESPACE, "deprecated" );
324         }
325         serializer.endTag( NAMESPACE, tagName );
326     } //-- void writeParameter( Parameter, String, XmlSerializer )
327 
328     /**
329      * Method writePluginDescriptor.
330      * 
331      * @param pluginDescriptor
332      * @param serializer
333      * @param tagName
334      * @throws java.io.IOException
335      */
336     private void writePluginDescriptor( PluginDescriptor pluginDescriptor, String tagName, XmlSerializer serializer )
337         throws java.io.IOException
338     {
339         serializer.setPrefix( "", "http://maven.apache.org/PLUGIN/1.0.0" );
340         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
341         serializer.startTag( NAMESPACE, tagName );
342         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PLUGIN/1.0.0 http://maven.apache.org/xsd/plugin-1.0.0.xsd" );
343         if ( pluginDescriptor.getDescription() != null )
344         {
345             serializer.startTag( NAMESPACE, "description" ).text( pluginDescriptor.getDescription() ).endTag( NAMESPACE, "description" );
346         }
347         if ( pluginDescriptor.getGroupId() != null )
348         {
349             serializer.startTag( NAMESPACE, "groupId" ).text( pluginDescriptor.getGroupId() ).endTag( NAMESPACE, "groupId" );
350         }
351         if ( pluginDescriptor.getArtifactId() != null )
352         {
353             serializer.startTag( NAMESPACE, "artifactId" ).text( pluginDescriptor.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
354         }
355         if ( pluginDescriptor.getVersion() != null )
356         {
357             serializer.startTag( NAMESPACE, "version" ).text( pluginDescriptor.getVersion() ).endTag( NAMESPACE, "version" );
358         }
359         if ( pluginDescriptor.getGoalPrefix() != null )
360         {
361             serializer.startTag( NAMESPACE, "goalPrefix" ).text( pluginDescriptor.getGoalPrefix() ).endTag( NAMESPACE, "goalPrefix" );
362         }
363         if ( pluginDescriptor.isIsolatedRealm() != false )
364         {
365             serializer.startTag( NAMESPACE, "isolatedRealm" ).text( String.valueOf( pluginDescriptor.isIsolatedRealm() ) ).endTag( NAMESPACE, "isolatedRealm" );
366         }
367         if ( pluginDescriptor.isInheritedByDefault() != true )
368         {
369             serializer.startTag( NAMESPACE, "inheritedByDefault" ).text( String.valueOf( pluginDescriptor.isInheritedByDefault() ) ).endTag( NAMESPACE, "inheritedByDefault" );
370         }
371         if ( ( pluginDescriptor.getMojos() != null ) && ( pluginDescriptor.getMojos().size() > 0 ) )
372         {
373             serializer.startTag( NAMESPACE, "mojos" );
374             for ( Iterator iter = pluginDescriptor.getMojos().iterator(); iter.hasNext(); )
375             {
376                 MojoDescriptor o = (MojoDescriptor) iter.next();
377                 writeMojoDescriptor( o, "mojo", serializer );
378             }
379             serializer.endTag( NAMESPACE, "mojos" );
380         }
381         if ( ( pluginDescriptor.getDependencies() != null ) && ( pluginDescriptor.getDependencies().size() > 0 ) )
382         {
383             serializer.startTag( NAMESPACE, "dependencies" );
384             for ( Iterator iter = pluginDescriptor.getDependencies().iterator(); iter.hasNext(); )
385             {
386                 Dependency o = (Dependency) iter.next();
387                 writeDependency( o, "dependency", serializer );
388             }
389             serializer.endTag( NAMESPACE, "dependencies" );
390         }
391         serializer.endTag( NAMESPACE, tagName );
392     } //-- void writePluginDescriptor( PluginDescriptor, String, XmlSerializer )
393 
394     /**
395      * Method writeRequirement.
396      * 
397      * @param requirement
398      * @param serializer
399      * @param tagName
400      * @throws java.io.IOException
401      */
402     private void writeRequirement( Requirement requirement, String tagName, XmlSerializer serializer )
403         throws java.io.IOException
404     {
405         serializer.startTag( NAMESPACE, tagName );
406         if ( requirement.getRole() != null )
407         {
408             serializer.startTag( NAMESPACE, "role" ).text( requirement.getRole() ).endTag( NAMESPACE, "role" );
409         }
410         if ( requirement.getRoleHint() != null )
411         {
412             serializer.startTag( NAMESPACE, "role-hint" ).text( requirement.getRoleHint() ).endTag( NAMESPACE, "role-hint" );
413         }
414         if ( requirement.getFieldName() != null )
415         {
416             serializer.startTag( NAMESPACE, "field-name" ).text( requirement.getFieldName() ).endTag( NAMESPACE, "field-name" );
417         }
418         serializer.endTag( NAMESPACE, tagName );
419     } //-- void writeRequirement( Requirement, String, XmlSerializer )
420 
421 }