1
2
3
4
5
6 package org.apache.maven.buildcache.xml.report.io.xpp3;
7
8
9
10
11
12 import java.io.OutputStream;
13 import java.io.Writer;
14 import java.util.Iterator;
15 import org.apache.maven.buildcache.xml.report.CacheReport;
16 import org.apache.maven.buildcache.xml.report.ProjectReport;
17 import org.codehaus.plexus.util.xml.pull.MXSerializer;
18 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
19
20
21
22
23
24
25 @SuppressWarnings( "all" )
26 public class BuildCacheReportXpp3Writer
27 {
28
29
30
31
32
33
34
35
36 private static final String NAMESPACE = null;
37
38
39
40
41 private String fileComment = null;
42
43
44
45
46
47
48
49
50
51
52
53 public void setFileComment( String fileComment )
54 {
55 this.fileComment = fileComment;
56 }
57
58
59
60
61
62
63
64
65 public void write( Writer writer, CacheReport cacheReport )
66 throws java.io.IOException
67 {
68 XmlSerializer serializer = new MXSerializer();
69 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
70 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
71 serializer.setOutput( writer );
72 serializer.startDocument( cacheReport.getModelEncoding(), null );
73 writeCacheReport( cacheReport, "cacheReport", serializer );
74 serializer.endDocument();
75 }
76
77
78
79
80
81
82
83
84 public void write( OutputStream stream, CacheReport cacheReport )
85 throws java.io.IOException
86 {
87 XmlSerializer serializer = new MXSerializer();
88 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
89 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
90 serializer.setOutput( stream, cacheReport.getModelEncoding() );
91 serializer.startDocument( cacheReport.getModelEncoding(), null );
92 writeCacheReport( cacheReport, "cacheReport", serializer );
93 serializer.endDocument();
94 }
95
96
97
98
99
100
101
102
103
104 private void writeCacheReport( CacheReport cacheReport, String tagName, XmlSerializer serializer )
105 throws java.io.IOException
106 {
107 if ( this.fileComment != null )
108 {
109 serializer.comment(this.fileComment);
110 }
111 serializer.setPrefix( "", "http://maven.apache.org/BUILD-CACHE-REPORT/1.0.0" );
112 serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
113 serializer.startTag( NAMESPACE, tagName );
114 serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/BUILD-CACHE-REPORT/1.0.0 https://maven.apache.org/xsd/build-cache-report-1.0.0.xsd" );
115 if ( ( cacheReport.getProjects() != null ) && ( cacheReport.getProjects().size() > 0 ) )
116 {
117 serializer.startTag( NAMESPACE, "projects" );
118 for ( Iterator iter = cacheReport.getProjects().iterator(); iter.hasNext(); )
119 {
120 ProjectReport o = (ProjectReport) iter.next();
121 writeProjectReport( o, "project", serializer );
122 }
123 serializer.endTag( NAMESPACE, "projects" );
124 }
125 serializer.endTag( NAMESPACE, tagName );
126 }
127
128
129
130
131
132
133
134
135
136 private void writeProjectReport( ProjectReport projectReport, String tagName, XmlSerializer serializer )
137 throws java.io.IOException
138 {
139 serializer.startTag( NAMESPACE, tagName );
140 if ( projectReport.getGroupId() != null )
141 {
142 serializer.startTag( NAMESPACE, "groupId" ).text( projectReport.getGroupId() ).endTag( NAMESPACE, "groupId" );
143 }
144 if ( projectReport.getArtifactId() != null )
145 {
146 serializer.startTag( NAMESPACE, "artifactId" ).text( projectReport.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
147 }
148 if ( projectReport.getChecksum() != null )
149 {
150 serializer.startTag( NAMESPACE, "checksum" ).text( projectReport.getChecksum() ).endTag( NAMESPACE, "checksum" );
151 }
152 if ( projectReport.isChecksumMatched() != null )
153 {
154 serializer.startTag( NAMESPACE, "checksumMatched" ).text( String.valueOf( projectReport.isChecksumMatched() ) ).endTag( NAMESPACE, "checksumMatched" );
155 }
156 if ( projectReport.isLifecycleMatched() != null )
157 {
158 serializer.startTag( NAMESPACE, "lifecycleMatched" ).text( String.valueOf( projectReport.isLifecycleMatched() ) ).endTag( NAMESPACE, "lifecycleMatched" );
159 }
160 if ( projectReport.isPluginsMatched() != null )
161 {
162 serializer.startTag( NAMESPACE, "pluginsMatched" ).text( String.valueOf( projectReport.isPluginsMatched() ) ).endTag( NAMESPACE, "pluginsMatched" );
163 }
164 if ( projectReport.getSource() != null )
165 {
166 serializer.startTag( NAMESPACE, "source" ).text( projectReport.getSource() ).endTag( NAMESPACE, "source" );
167 }
168 if ( projectReport.isSharedToRemote() != null )
169 {
170 serializer.startTag( NAMESPACE, "sharedToRemote" ).text( String.valueOf( projectReport.isSharedToRemote() ) ).endTag( NAMESPACE, "sharedToRemote" );
171 }
172 if ( projectReport.getUrl() != null )
173 {
174 serializer.startTag( NAMESPACE, "url" ).text( projectReport.getUrl() ).endTag( NAMESPACE, "url" );
175 }
176 serializer.endTag( NAMESPACE, tagName );
177 }
178
179 }