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         serializer.endTag( NAMESPACE, tagName );
172     } //-- void writeArtifact( Artifact, String, XmlSerializer )
173 
174     /**
175      * Method writeBuild.
176      * 
177      * @param build a build object.
178      * @param serializer a serializer object.
179      * @param tagName a tagName object.
180      * @throws java.io.IOException java.io.IOException if any.
181      */
182     private void writeBuild( Build build, String tagName, XmlSerializer serializer )
183         throws java.io.IOException
184     {
185         if ( this.fileComment != null )
186         {
187         serializer.comment(this.fileComment);
188         }
189         serializer.setPrefix( "", "http://maven.apache.org/BUILD-CACHE-BUILD/1.2.0" );
190         serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
191         serializer.startTag( NAMESPACE, tagName );
192         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" );
193         if ( build.getCacheImplementationVersion() != null )
194         {
195             serializer.startTag( NAMESPACE, "cacheImplementationVersion" ).text( build.getCacheImplementationVersion() ).endTag( NAMESPACE, "cacheImplementationVersion" );
196         }
197         if ( build.is_final() != null )
198         {
199             serializer.startTag( NAMESPACE, "final" ).text( String.valueOf( build.is_final() ) ).endTag( NAMESPACE, "final" );
200         }
201         if ( build.getHashFunction() != null )
202         {
203             serializer.startTag( NAMESPACE, "hashFunction" ).text( build.getHashFunction() ).endTag( NAMESPACE, "hashFunction" );
204         }
205         if ( build.getBuildTime() != null )
206         {
207             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" );
208         }
209         if ( build.getBuildServer() != null )
210         {
211             serializer.startTag( NAMESPACE, "buildServer" ).text( build.getBuildServer() ).endTag( NAMESPACE, "buildServer" );
212         }
213         if ( build.getScm() != null )
214         {
215             writeScm( (Scm) build.getScm(), "scm", serializer );
216         }
217         if ( ( build.getGoals() != null ) && ( build.getGoals().size() > 0 ) )
218         {
219             serializer.startTag( NAMESPACE, "goals" );
220             for ( Iterator iter = build.getGoals().iterator(); iter.hasNext(); )
221             {
222                 String goal = (String) iter.next();
223                 serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" );
224             }
225             serializer.endTag( NAMESPACE, "goals" );
226         }
227         if ( build.getArtifact() != null )
228         {
229             writeArtifact( (Artifact) build.getArtifact(), "artifact", serializer );
230         }
231         if ( ( build.getAttachedArtifacts() != null ) && ( build.getAttachedArtifacts().size() > 0 ) )
232         {
233             serializer.startTag( NAMESPACE, "attachedArtifacts" );
234             for ( Iterator iter = build.getAttachedArtifacts().iterator(); iter.hasNext(); )
235             {
236                 Artifact o = (Artifact) iter.next();
237                 writeArtifact( o, "attachedArtifact", serializer );
238             }
239             serializer.endTag( NAMESPACE, "attachedArtifacts" );
240         }
241         if ( ( build.getExecutions() != null ) && ( build.getExecutions().size() > 0 ) )
242         {
243             serializer.startTag( NAMESPACE, "executions" );
244             for ( Iterator iter = build.getExecutions().iterator(); iter.hasNext(); )
245             {
246                 CompletedExecution o = (CompletedExecution) iter.next();
247                 writeCompletedExecution( o, "execution", serializer );
248             }
249             serializer.endTag( NAMESPACE, "executions" );
250         }
251         if ( build.getProjectsInputInfo() != null )
252         {
253             writeProjectsInputInfo( (ProjectsInputInfo) build.getProjectsInputInfo(), "projectsInputInfo", serializer );
254         }
255         serializer.endTag( NAMESPACE, tagName );
256     } //-- void writeBuild( Build, String, XmlSerializer )
257 
258     /**
259      * Method writeCompletedExecution.
260      * 
261      * @param completedExecution a completedExecution object.
262      * @param serializer a serializer object.
263      * @param tagName a tagName object.
264      * @throws java.io.IOException java.io.IOException if any.
265      */
266     private void writeCompletedExecution( CompletedExecution completedExecution, String tagName, XmlSerializer serializer )
267         throws java.io.IOException
268     {
269         serializer.startTag( NAMESPACE, tagName );
270         if ( completedExecution.getExecutionKey() != null )
271         {
272             serializer.startTag( NAMESPACE, "executionKey" ).text( completedExecution.getExecutionKey() ).endTag( NAMESPACE, "executionKey" );
273         }
274         if ( completedExecution.getMojoClassName() != null )
275         {
276             serializer.startTag( NAMESPACE, "mojoClassName" ).text( completedExecution.getMojoClassName() ).endTag( NAMESPACE, "mojoClassName" );
277         }
278         if ( ( completedExecution.getProperties() != null ) && ( completedExecution.getProperties().size() > 0 ) )
279         {
280             serializer.startTag( NAMESPACE, "properties" );
281             for ( Iterator iter = completedExecution.getProperties().iterator(); iter.hasNext(); )
282             {
283                 PropertyValue o = (PropertyValue) iter.next();
284                 writePropertyValue( o, "property", serializer );
285             }
286             serializer.endTag( NAMESPACE, "properties" );
287         }
288         serializer.endTag( NAMESPACE, tagName );
289     } //-- void writeCompletedExecution( CompletedExecution, String, XmlSerializer )
290 
291     /**
292      * Method writeDigestItem.
293      * 
294      * @param digestItem a digestItem object.
295      * @param serializer a serializer object.
296      * @param tagName a tagName object.
297      * @throws java.io.IOException java.io.IOException if any.
298      */
299     private void writeDigestItem( DigestItem digestItem, String tagName, XmlSerializer serializer )
300         throws java.io.IOException
301     {
302         serializer.startTag( NAMESPACE, tagName );
303         if ( digestItem.getType() != null )
304         {
305             serializer.attribute( NAMESPACE, "type", digestItem.getType() );
306         }
307         if ( digestItem.getHash() != null )
308         {
309             serializer.attribute( NAMESPACE, "hash", digestItem.getHash() );
310         }
311         if ( digestItem.getFileChecksum() != null )
312         {
313             serializer.attribute( NAMESPACE, "fileChecksum", digestItem.getFileChecksum() );
314         }
315         if ( digestItem.getContent() != null )
316         {
317             serializer.attribute( NAMESPACE, "content", digestItem.getContent() );
318         }
319         if ( digestItem.getIsText() != null )
320         {
321             serializer.attribute( NAMESPACE, "isText", digestItem.getIsText() );
322         }
323         if ( digestItem.getCharset() != null )
324         {
325             serializer.attribute( NAMESPACE, "charset", digestItem.getCharset() );
326         }
327         if ( digestItem.getEol() != null )
328         {
329             serializer.attribute( NAMESPACE, "eol", digestItem.getEol() );
330         }
331         serializer.text( digestItem.getValue() );
332         serializer.endTag( NAMESPACE, tagName );
333     } //-- void writeDigestItem( DigestItem, String, XmlSerializer )
334 
335     /**
336      * Method writeProjectsInputInfo.
337      * 
338      * @param projectsInputInfo a projectsInputInfo object.
339      * @param serializer a serializer object.
340      * @param tagName a tagName object.
341      * @throws java.io.IOException java.io.IOException if any.
342      */
343     private void writeProjectsInputInfo( ProjectsInputInfo projectsInputInfo, String tagName, XmlSerializer serializer )
344         throws java.io.IOException
345     {
346         serializer.startTag( NAMESPACE, tagName );
347         if ( projectsInputInfo.getChecksum() != null )
348         {
349             serializer.startTag( NAMESPACE, "checksum" ).text( projectsInputInfo.getChecksum() ).endTag( NAMESPACE, "checksum" );
350         }
351         if ( ( projectsInputInfo.getItems() != null ) && ( projectsInputInfo.getItems().size() > 0 ) )
352         {
353             serializer.startTag( NAMESPACE, "items" );
354             for ( Iterator iter = projectsInputInfo.getItems().iterator(); iter.hasNext(); )
355             {
356                 DigestItem o = (DigestItem) iter.next();
357                 writeDigestItem( o, "item", serializer );
358             }
359             serializer.endTag( NAMESPACE, "items" );
360         }
361         serializer.endTag( NAMESPACE, tagName );
362     } //-- void writeProjectsInputInfo( ProjectsInputInfo, String, XmlSerializer )
363 
364     /**
365      * Method writePropertyValue.
366      * 
367      * @param propertyValue a propertyValue object.
368      * @param serializer a serializer object.
369      * @param tagName a tagName object.
370      * @throws java.io.IOException java.io.IOException if any.
371      */
372     private void writePropertyValue( PropertyValue propertyValue, String tagName, XmlSerializer serializer )
373         throws java.io.IOException
374     {
375         serializer.startTag( NAMESPACE, tagName );
376         if ( propertyValue.getName() != null )
377         {
378             serializer.attribute( NAMESPACE, "name", propertyValue.getName() );
379         }
380         if ( propertyValue.isTracked() != null )
381         {
382             serializer.attribute( NAMESPACE, "tracked", String.valueOf( propertyValue.isTracked() ) );
383         }
384         serializer.text( propertyValue.getValue() );
385         serializer.endTag( NAMESPACE, tagName );
386     } //-- void writePropertyValue( PropertyValue, String, XmlSerializer )
387 
388     /**
389      * Method writeScm.
390      * 
391      * @param scm a scm object.
392      * @param serializer a serializer object.
393      * @param tagName a tagName object.
394      * @throws java.io.IOException java.io.IOException if any.
395      */
396     private void writeScm( Scm scm, String tagName, XmlSerializer serializer )
397         throws java.io.IOException
398     {
399         serializer.startTag( NAMESPACE, tagName );
400         if ( scm.getSourceBranch() != null )
401         {
402             serializer.startTag( NAMESPACE, "sourceBranch" ).text( scm.getSourceBranch() ).endTag( NAMESPACE, "sourceBranch" );
403         }
404         if ( scm.getRevision() != null )
405         {
406             serializer.startTag( NAMESPACE, "revision" ).text( scm.getRevision() ).endTag( NAMESPACE, "revision" );
407         }
408         serializer.endTag( NAMESPACE, tagName );
409     } //-- void writeScm( Scm, String, XmlSerializer )
410 
411 }