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.5.1,
20   any modifications will be overwritten.
21   ==============================================================
22   */
23  
24  package org.apache.maven.buildcache.xml.build.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.buildcache.xml.build.Artifact;
34  import org.apache.maven.buildcache.xml.build.Build;
35  import org.apache.maven.buildcache.xml.build.CompletedExecution;
36  import org.apache.maven.buildcache.xml.build.DigestItem;
37  import org.apache.maven.buildcache.xml.build.ProjectsInputInfo;
38  import org.apache.maven.buildcache.xml.build.PropertyValue;
39  import org.apache.maven.buildcache.xml.build.Scm;
40  import org.codehaus.plexus.util.xml.pull.MXSerializer;
41  import org.codehaus.plexus.util.xml.pull.XmlSerializer;
42  
43  /**
44   * Class BuildCacheBuildXpp3Writer.
45   * 
46   * @version $Revision$ $Date$
47   */
48  @SuppressWarnings( "all" )
49  public class BuildCacheBuildXpp3Writer
50  {
51  
52        //--------------------------/
53       //- Class/Member Variables -/
54      //--------------------------/
55  
56      /**
57       * Field NAMESPACE.
58       */
59      private static final String NAMESPACE = null;
60  
61      /**
62       * Field fileComment.
63       */
64      private String fileComment = null;
65  
66  
67        //-----------/
68       //- Methods -/
69      //-----------/
70  
71      /**
72       * Method setFileComment.
73       * 
74       * @param fileComment a fileComment object.
75       */
76      public void setFileComment( String fileComment )
77      {
78          this.fileComment = fileComment;
79      } //-- void setFileComment( String )
80  
81      /**
82       * Method write.
83       * 
84       * @param writer a writer object.
85       * @param build a build object.
86       * @throws java.io.IOException java.io.IOException if any.
87       */
88      public void write( Writer writer, Build build )
89          throws java.io.IOException
90      {
91          XmlSerializer serializer = new MXSerializer();
92          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  " );
93          serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
94          serializer.setOutput( writer );
95          serializer.startDocument( build.getModelEncoding(), null );
96          writeBuild( build, "build", serializer );
97          serializer.endDocument();
98      } //-- void write( Writer, Build )
99  
100     /**
101      * Method write.
102      * 
103      * @param stream a stream object.
104      * @param build a build object.
105      * @throws java.io.IOException java.io.IOException if any.
106      */
107     public void write( OutputStream stream, Build build )
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, build.getModelEncoding() );
114         serializer.startDocument( build.getModelEncoding(), null );
115         writeBuild( build, "build", serializer );
116         serializer.endDocument();
117     } //-- void write( OutputStream, Build )
118 
119     /**
120      * Method writeArtifact.
121      * 
122      * @param artifact a artifact 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 writeArtifact( Artifact artifact, String tagName, XmlSerializer serializer )
128         throws java.io.IOException
129     {
130         serializer.startTag( NAMESPACE, tagName );
131         if ( artifact.getGroupId() != null )
132         {
133             serializer.startTag( NAMESPACE, "groupId" ).text( artifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
134         }
135         if ( artifact.getArtifactId() != null )
136         {
137             serializer.startTag( NAMESPACE, "artifactId" ).text( artifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
138         }
139         if ( artifact.getVersion() != null )
140         {
141             serializer.startTag( NAMESPACE, "version" ).text( artifact.getVersion() ).endTag( NAMESPACE, "version" );
142         }
143         if ( artifact.getClassifier() != null )
144         {
145             serializer.startTag( NAMESPACE, "classifier" ).text( artifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
146         }
147         if ( artifact.getType() != null )
148         {
149             serializer.startTag( NAMESPACE, "type" ).text( artifact.getType() ).endTag( NAMESPACE, "type" );
150         }
151         if ( artifact.getScope() != null )
152         {
153             serializer.startTag( NAMESPACE, "scope" ).text( artifact.getScope() ).endTag( NAMESPACE, "scope" );
154         }
155         if ( artifact.getFileName() != null )
156         {
157             serializer.startTag( NAMESPACE, "fileName" ).text( artifact.getFileName() ).endTag( NAMESPACE, "fileName" );
158         }
159         if ( artifact.getFileHash() != null )
160         {
161             serializer.startTag( NAMESPACE, "fileHash" ).text( artifact.getFileHash() ).endTag( NAMESPACE, "fileHash" );
162         }
163         if ( artifact.getFileSize() != 0L )
164         {
165             serializer.startTag( NAMESPACE, "fileSize" ).text( String.valueOf( artifact.getFileSize() ) ).endTag( NAMESPACE, "fileSize" );
166         }
167         if ( artifact.getFilePath() != null )
168         {
169             serializer.startTag( NAMESPACE, "filePath" ).text( artifact.getFilePath() ).endTag( NAMESPACE, "filePath" );
170         }
171         if ( artifact.isIsDirectory() != false )
172         {
173             serializer.startTag( NAMESPACE, "isDirectory" ).text( String.valueOf( artifact.isIsDirectory() ) ).endTag( NAMESPACE, "isDirectory" );
174         }
175         serializer.endTag( NAMESPACE, tagName );
176     } //-- void writeArtifact( Artifact, String, XmlSerializer )
177 
178     /**
179      * Method writeBuild.
180      * 
181      * @param build a build 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 writeBuild( Build build, 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/BUILD-CACHE-BUILD/1.2.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/BUILD-CACHE-BUILD/1.2.0 https://maven.apache.org/xsd/build-cache-build-1.2.0.xsd" );
197         if ( build.getCacheImplementationVersion() != null )
198         {
199             serializer.startTag( NAMESPACE, "cacheImplementationVersion" ).text( build.getCacheImplementationVersion() ).endTag( NAMESPACE, "cacheImplementationVersion" );
200         }
201         if ( build.is_final() != null )
202         {
203             serializer.startTag( NAMESPACE, "final" ).text( String.valueOf( build.is_final() ) ).endTag( NAMESPACE, "final" );
204         }
205         if ( build.getHashFunction() != null )
206         {
207             serializer.startTag( NAMESPACE, "hashFunction" ).text( build.getHashFunction() ).endTag( NAMESPACE, "hashFunction" );
208         }
209         if ( build.getBuildTime() != null )
210         {
211             serializer.startTag( NAMESPACE, "buildTime" ).text( new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS", java.util.Locale.US ).format( build.getBuildTime() ) ).endTag( NAMESPACE, "buildTime" );
212         }
213         if ( build.getBuildServer() != null )
214         {
215             serializer.startTag( NAMESPACE, "buildServer" ).text( build.getBuildServer() ).endTag( NAMESPACE, "buildServer" );
216         }
217         if ( build.getScm() != null )
218         {
219             writeScm( (Scm) build.getScm(), "scm", serializer );
220         }
221         if ( ( build.getGoals() != null ) && ( build.getGoals().size() > 0 ) )
222         {
223             serializer.startTag( NAMESPACE, "goals" );
224             for ( Iterator iter = build.getGoals().iterator(); iter.hasNext(); )
225             {
226                 String goal = (String) iter.next();
227                 serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" );
228             }
229             serializer.endTag( NAMESPACE, "goals" );
230         }
231         if ( build.getArtifact() != null )
232         {
233             writeArtifact( (Artifact) build.getArtifact(), "artifact", serializer );
234         }
235         if ( ( build.getAttachedArtifacts() != null ) && ( build.getAttachedArtifacts().size() > 0 ) )
236         {
237             serializer.startTag( NAMESPACE, "attachedArtifacts" );
238             for ( Iterator iter = build.getAttachedArtifacts().iterator(); iter.hasNext(); )
239             {
240                 Artifact o = (Artifact) iter.next();
241                 writeArtifact( o, "attachedArtifact", serializer );
242             }
243             serializer.endTag( NAMESPACE, "attachedArtifacts" );
244         }
245         if ( ( build.getExecutions() != null ) && ( build.getExecutions().size() > 0 ) )
246         {
247             serializer.startTag( NAMESPACE, "executions" );
248             for ( Iterator iter = build.getExecutions().iterator(); iter.hasNext(); )
249             {
250                 CompletedExecution o = (CompletedExecution) iter.next();
251                 writeCompletedExecution( o, "execution", serializer );
252             }
253             serializer.endTag( NAMESPACE, "executions" );
254         }
255         if ( build.getProjectsInputInfo() != null )
256         {
257             writeProjectsInputInfo( (ProjectsInputInfo) build.getProjectsInputInfo(), "projectsInputInfo", serializer );
258         }
259         serializer.endTag( NAMESPACE, tagName );
260     } //-- void writeBuild( Build, String, XmlSerializer )
261 
262     /**
263      * Method writeCompletedExecution.
264      * 
265      * @param completedExecution a completedExecution object.
266      * @param serializer a serializer object.
267      * @param tagName a tagName object.
268      * @throws java.io.IOException java.io.IOException if any.
269      */
270     private void writeCompletedExecution( CompletedExecution completedExecution, String tagName, XmlSerializer serializer )
271         throws java.io.IOException
272     {
273         serializer.startTag( NAMESPACE, tagName );
274         if ( completedExecution.getExecutionKey() != null )
275         {
276             serializer.startTag( NAMESPACE, "executionKey" ).text( completedExecution.getExecutionKey() ).endTag( NAMESPACE, "executionKey" );
277         }
278         if ( completedExecution.getMojoClassName() != null )
279         {
280             serializer.startTag( NAMESPACE, "mojoClassName" ).text( completedExecution.getMojoClassName() ).endTag( NAMESPACE, "mojoClassName" );
281         }
282         if ( ( completedExecution.getProperties() != null ) && ( completedExecution.getProperties().size() > 0 ) )
283         {
284             serializer.startTag( NAMESPACE, "properties" );
285             for ( Iterator iter = completedExecution.getProperties().iterator(); iter.hasNext(); )
286             {
287                 PropertyValue o = (PropertyValue) iter.next();
288                 writePropertyValue( o, "property", serializer );
289             }
290             serializer.endTag( NAMESPACE, "properties" );
291         }
292         serializer.endTag( NAMESPACE, tagName );
293     } //-- void writeCompletedExecution( CompletedExecution, String, XmlSerializer )
294 
295     /**
296      * Method writeDigestItem.
297      * 
298      * @param digestItem a digestItem object.
299      * @param serializer a serializer object.
300      * @param tagName a tagName object.
301      * @throws java.io.IOException java.io.IOException if any.
302      */
303     private void writeDigestItem( DigestItem digestItem, String tagName, XmlSerializer serializer )
304         throws java.io.IOException
305     {
306         serializer.startTag( NAMESPACE, tagName );
307         if ( digestItem.getType() != null )
308         {
309             serializer.attribute( NAMESPACE, "type", digestItem.getType() );
310         }
311         if ( digestItem.getHash() != null )
312         {
313             serializer.attribute( NAMESPACE, "hash", digestItem.getHash() );
314         }
315         if ( digestItem.getFileChecksum() != null )
316         {
317             serializer.attribute( NAMESPACE, "fileChecksum", digestItem.getFileChecksum() );
318         }
319         if ( digestItem.getContent() != null )
320         {
321             serializer.attribute( NAMESPACE, "content", digestItem.getContent() );
322         }
323         if ( digestItem.getIsText() != null )
324         {
325             serializer.attribute( NAMESPACE, "isText", digestItem.getIsText() );
326         }
327         if ( digestItem.getCharset() != null )
328         {
329             serializer.attribute( NAMESPACE, "charset", digestItem.getCharset() );
330         }
331         if ( digestItem.getEol() != null )
332         {
333             serializer.attribute( NAMESPACE, "eol", digestItem.getEol() );
334         }
335         serializer.text( digestItem.getValue() );
336         serializer.endTag( NAMESPACE, tagName );
337     } //-- void writeDigestItem( DigestItem, String, XmlSerializer )
338 
339     /**
340      * Method writeProjectsInputInfo.
341      * 
342      * @param projectsInputInfo a projectsInputInfo object.
343      * @param serializer a serializer object.
344      * @param tagName a tagName object.
345      * @throws java.io.IOException java.io.IOException if any.
346      */
347     private void writeProjectsInputInfo( ProjectsInputInfo projectsInputInfo, String tagName, XmlSerializer serializer )
348         throws java.io.IOException
349     {
350         serializer.startTag( NAMESPACE, tagName );
351         if ( projectsInputInfo.getChecksum() != null )
352         {
353             serializer.startTag( NAMESPACE, "checksum" ).text( projectsInputInfo.getChecksum() ).endTag( NAMESPACE, "checksum" );
354         }
355         if ( ( projectsInputInfo.getItems() != null ) && ( projectsInputInfo.getItems().size() > 0 ) )
356         {
357             serializer.startTag( NAMESPACE, "items" );
358             for ( Iterator iter = projectsInputInfo.getItems().iterator(); iter.hasNext(); )
359             {
360                 DigestItem o = (DigestItem) iter.next();
361                 writeDigestItem( o, "item", serializer );
362             }
363             serializer.endTag( NAMESPACE, "items" );
364         }
365         serializer.endTag( NAMESPACE, tagName );
366     } //-- void writeProjectsInputInfo( ProjectsInputInfo, String, XmlSerializer )
367 
368     /**
369      * Method writePropertyValue.
370      * 
371      * @param propertyValue a propertyValue object.
372      * @param serializer a serializer object.
373      * @param tagName a tagName object.
374      * @throws java.io.IOException java.io.IOException if any.
375      */
376     private void writePropertyValue( PropertyValue propertyValue, String tagName, XmlSerializer serializer )
377         throws java.io.IOException
378     {
379         serializer.startTag( NAMESPACE, tagName );
380         if ( propertyValue.getName() != null )
381         {
382             serializer.attribute( NAMESPACE, "name", propertyValue.getName() );
383         }
384         if ( propertyValue.isTracked() != null )
385         {
386             serializer.attribute( NAMESPACE, "tracked", String.valueOf( propertyValue.isTracked() ) );
387         }
388         serializer.text( propertyValue.getValue() );
389         serializer.endTag( NAMESPACE, tagName );
390     } //-- void writePropertyValue( PropertyValue, String, XmlSerializer )
391 
392     /**
393      * Method writeScm.
394      * 
395      * @param scm a scm object.
396      * @param serializer a serializer object.
397      * @param tagName a tagName object.
398      * @throws java.io.IOException java.io.IOException if any.
399      */
400     private void writeScm( Scm scm, String tagName, XmlSerializer serializer )
401         throws java.io.IOException
402     {
403         serializer.startTag( NAMESPACE, tagName );
404         if ( scm.getSourceBranch() != null )
405         {
406             serializer.startTag( NAMESPACE, "sourceBranch" ).text( scm.getSourceBranch() ).endTag( NAMESPACE, "sourceBranch" );
407         }
408         if ( scm.getRevision() != null )
409         {
410             serializer.startTag( NAMESPACE, "revision" ).text( scm.getRevision() ).endTag( NAMESPACE, "revision" );
411         }
412         serializer.endTag( NAMESPACE, tagName );
413     } //-- void writeScm( Scm, String, XmlSerializer )
414 
415 }