View Javadoc
1   /*
2    Licensed to the Apache Software Foundation (ASF) under one
3    or more contributor license agreements.  See the NOTICE file
4    distributed with this work for additional information
5    regarding copyright ownership.  The ASF licenses this file
6    to you under the Apache License, Version 2.0 (the
7    "License"); you may not use this file except in compliance
8    with the License.  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,
13   software distributed under the License is distributed on an
14   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   KIND, either express or implied.  See the License for the
16   specific language governing permissions and limitations
17   under the License.
18   =================== DO NOT EDIT THIS FILE ====================
19   Generated by Modello 2.4.0,
20   any modifications will be overwritten.
21   ==============================================================
22   */
23  
24  package org.apache.maven.plugin.lifecycle.io.xpp3;
25  
26    //---------------------------------/
27   //- Imported classes and packages -/
28  //---------------------------------/
29  
30  import java.io.OutputStream;
31  import java.io.Writer;
32  import java.util.Iterator;
33  import org.apache.maven.plugin.lifecycle.Execution;
34  import org.apache.maven.plugin.lifecycle.Lifecycle;
35  import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
36  import org.apache.maven.plugin.lifecycle.Phase;
37  import org.codehaus.plexus.util.xml.Xpp3Dom;
38  import org.codehaus.plexus.util.xml.pull.MXSerializer;
39  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
40  
41  /**
42   * Class LifecycleMappingsXpp3Writer.
43   * 
44   * @version $Revision$ $Date$
45   */
46  @SuppressWarnings( "all" )
47  public class LifecycleMappingsXpp3Writer
48  {
49  
50        //--------------------------/
51       //- Class/Member Variables -/
52      //--------------------------/
53  
54      /**
55       * Field NAMESPACE.
56       */
57      private static final String NAMESPACE = null;
58  
59      /**
60       * Field fileComment.
61       */
62      private String fileComment = null;
63  
64  
65        //-----------/
66       //- Methods -/
67      //-----------/
68  
69      /**
70       * Method setFileComment.
71       * 
72       * @param fileComment a fileComment object.
73       */
74      public void setFileComment( String fileComment )
75      {
76          this.fileComment = fileComment;
77      } //-- void setFileComment( String )
78  
79      /**
80       * Method write.
81       * 
82       * @param writer a writer object.
83       * @param lifecycleConfiguration a lifecycleConfiguration
84       * object.
85       * @throws java.io.IOException java.io.IOException if any.
86       */
87      public void write( Writer writer, LifecycleConfiguration lifecycleConfiguration )
88          throws java.io.IOException
89      {
90          XmlSerializer serializer = new MXSerializer();
91          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
92          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
93          serializer.setOutput( writer );
94          serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
95          writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
96          serializer.endDocument();
97      } //-- void write( Writer, LifecycleConfiguration )
98  
99      /**
100      * Method write.
101      * 
102      * @param stream a stream object.
103      * @param lifecycleConfiguration a lifecycleConfiguration
104      * object.
105      * @throws java.io.IOException java.io.IOException if any.
106      */
107     public void write( OutputStream stream, LifecycleConfiguration lifecycleConfiguration )
108         throws java.io.IOException
109     {
110         XmlSerializer serializer = new MXSerializer();
111         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
112         serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
113         serializer.setOutput( stream, lifecycleConfiguration.getModelEncoding() );
114         serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null );
115         writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer );
116         serializer.endDocument();
117     } //-- void write( OutputStream, LifecycleConfiguration )
118 
119     /**
120      * Method writeExecution.
121      * 
122      * @param execution a execution object.
123      * @param serializer a serializer object.
124      * @param tagName a tagName object.
125      * @throws java.io.IOException java.io.IOException if any.
126      */
127     private void writeExecution( Execution execution, String tagName, XmlSerializer serializer )
128         throws java.io.IOException
129     {
130         serializer.startTag( NAMESPACE, tagName );
131         if ( execution.getConfiguration() != null )
132         {
133             ((Xpp3Dom) execution.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
134         }
135         if ( ( execution.getGoals() != null ) && ( execution.getGoals().size() > 0 ) )
136         {
137             serializer.startTag( NAMESPACE, "goals" );
138             for ( Iterator iter = execution.getGoals().iterator(); iter.hasNext(); )
139             {
140                 String goal = (String) iter.next();
141                 serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" );
142             }
143             serializer.endTag( NAMESPACE, "goals" );
144         }
145         serializer.endTag( NAMESPACE, tagName );
146     } //-- void writeExecution( Execution, String, XmlSerializer )
147 
148     /**
149      * Method writeLifecycle.
150      * 
151      * @param lifecycle a lifecycle object.
152      * @param serializer a serializer object.
153      * @param tagName a tagName object.
154      * @throws java.io.IOException java.io.IOException if any.
155      */
156     private void writeLifecycle( Lifecycle lifecycle, String tagName, XmlSerializer serializer )
157         throws java.io.IOException
158     {
159         serializer.startTag( NAMESPACE, tagName );
160         if ( lifecycle.getId() != null )
161         {
162             serializer.startTag( NAMESPACE, "id" ).text( lifecycle.getId() ).endTag( NAMESPACE, "id" );
163         }
164         if ( ( lifecycle.getPhases() != null ) && ( lifecycle.getPhases().size() > 0 ) )
165         {
166             serializer.startTag( NAMESPACE, "phases" );
167             for ( Iterator iter = lifecycle.getPhases().iterator(); iter.hasNext(); )
168             {
169                 Phase o = (Phase) iter.next();
170                 writePhase( o, "phase", serializer );
171             }
172             serializer.endTag( NAMESPACE, "phases" );
173         }
174         serializer.endTag( NAMESPACE, tagName );
175     } //-- void writeLifecycle( Lifecycle, String, XmlSerializer )
176 
177     /**
178      * Method writeLifecycleConfiguration.
179      * 
180      * @param lifecycleConfiguration a lifecycleConfiguration
181      * object.
182      * @param serializer a serializer object.
183      * @param tagName a tagName object.
184      * @throws java.io.IOException java.io.IOException if any.
185      */
186     private void writeLifecycleConfiguration( LifecycleConfiguration lifecycleConfiguration, String tagName, XmlSerializer serializer )
187         throws java.io.IOException
188     {
189         if ( this.fileComment != null )
190         {
191         serializer.comment(this.fileComment);
192         }
193         serializer.setPrefix( "", "http://maven.apache.org/LIFECYCLE/1.0.0" );
194         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
195         serializer.startTag( NAMESPACE, tagName );
196         serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/LIFECYCLE/1.0.0 https://maven.apache.org/xsd/lifecycle-1.0.0.xsd" );
197         if ( ( lifecycleConfiguration.getLifecycles() != null ) && ( lifecycleConfiguration.getLifecycles().size() > 0 ) )
198         {
199             for ( Iterator iter = lifecycleConfiguration.getLifecycles().iterator(); iter.hasNext(); )
200             {
201                 Lifecycle o = (Lifecycle) iter.next();
202                 writeLifecycle( o, "lifecycle", serializer );
203             }
204         }
205         serializer.endTag( NAMESPACE, tagName );
206     } //-- void writeLifecycleConfiguration( LifecycleConfiguration, String, XmlSerializer )
207 
208     /**
209      * Method writePhase.
210      * 
211      * @param phase a phase object.
212      * @param serializer a serializer object.
213      * @param tagName a tagName object.
214      * @throws java.io.IOException java.io.IOException if any.
215      */
216     private void writePhase( Phase phase, String tagName, XmlSerializer serializer )
217         throws java.io.IOException
218     {
219         serializer.startTag( NAMESPACE, tagName );
220         if ( phase.getId() != null )
221         {
222             serializer.startTag( NAMESPACE, "id" ).text( phase.getId() ).endTag( NAMESPACE, "id" );
223         }
224         if ( ( phase.getExecutions() != null ) && ( phase.getExecutions().size() > 0 ) )
225         {
226             serializer.startTag( NAMESPACE, "executions" );
227             for ( Iterator iter = phase.getExecutions().iterator(); iter.hasNext(); )
228             {
229                 Execution o = (Execution) iter.next();
230                 writeExecution( o, "execution", serializer );
231             }
232             serializer.endTag( NAMESPACE, "executions" );
233         }
234         if ( phase.getConfiguration() != null )
235         {
236             ((Xpp3Dom) phase.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
237         }
238         serializer.endTag( NAMESPACE, tagName );
239     } //-- void writePhase( Phase, String, XmlSerializer )
240 
241 }