1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.apache.maven.plugin.lifecycle.io.xpp3; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
import java.io.Writer; |
15 | |
import java.text.DateFormat; |
16 | |
import java.util.Iterator; |
17 | |
import java.util.Locale; |
18 | |
import org.apache.maven.plugin.lifecycle.Execution; |
19 | |
import org.apache.maven.plugin.lifecycle.Lifecycle; |
20 | |
import org.apache.maven.plugin.lifecycle.LifecycleConfiguration; |
21 | |
import org.apache.maven.plugin.lifecycle.Phase; |
22 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
23 | |
import org.codehaus.plexus.util.xml.pull.MXSerializer; |
24 | |
import org.codehaus.plexus.util.xml.pull.XmlSerializer; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class LifecycleMappingsXpp3Writer |
32 | |
{ |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | private static final String NAMESPACE = null; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void write( Writer writer, LifecycleConfiguration lifecycleConfiguration ) |
56 | |
throws java.io.IOException |
57 | |
{ |
58 | 0 | XmlSerializer serializer = new MXSerializer(); |
59 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
60 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
61 | 0 | serializer.setOutput( writer ); |
62 | 0 | serializer.startDocument( lifecycleConfiguration.getModelEncoding(), null ); |
63 | 0 | writeLifecycleConfiguration( lifecycleConfiguration, "lifecycles", serializer ); |
64 | 0 | serializer.endDocument(); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
private void writeExecution( Execution execution, String tagName, XmlSerializer serializer ) |
76 | |
throws java.io.IOException |
77 | |
{ |
78 | 0 | if ( execution != null ) |
79 | |
{ |
80 | 0 | serializer.startTag( NAMESPACE, tagName ); |
81 | 0 | if ( execution.getConfiguration() != null ) |
82 | |
{ |
83 | 0 | ((Xpp3Dom) execution.getConfiguration()).writeToSerializer( NAMESPACE, serializer ); |
84 | |
} |
85 | 0 | if ( ( execution.getGoals() != null ) && ( execution.getGoals().size() > 0 ) ) |
86 | |
{ |
87 | 0 | serializer.startTag( NAMESPACE, "goals" ); |
88 | 0 | for ( Iterator iter = execution.getGoals().iterator(); iter.hasNext(); ) |
89 | |
{ |
90 | 0 | String goal = (String) iter.next(); |
91 | 0 | serializer.startTag( NAMESPACE, "goal" ).text( goal ).endTag( NAMESPACE, "goal" ); |
92 | 0 | } |
93 | 0 | serializer.endTag( NAMESPACE, "goals" ); |
94 | |
} |
95 | 0 | serializer.endTag( NAMESPACE, tagName ); |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private void writeLifecycle( Lifecycle lifecycle, String tagName, XmlSerializer serializer ) |
108 | |
throws java.io.IOException |
109 | |
{ |
110 | 0 | if ( lifecycle != null ) |
111 | |
{ |
112 | 0 | serializer.startTag( NAMESPACE, tagName ); |
113 | 0 | if ( lifecycle.getId() != null ) |
114 | |
{ |
115 | 0 | serializer.startTag( NAMESPACE, "id" ).text( lifecycle.getId() ).endTag( NAMESPACE, "id" ); |
116 | |
} |
117 | 0 | if ( ( lifecycle.getPhases() != null ) && ( lifecycle.getPhases().size() > 0 ) ) |
118 | |
{ |
119 | 0 | serializer.startTag( NAMESPACE, "phases" ); |
120 | 0 | for ( Iterator iter = lifecycle.getPhases().iterator(); iter.hasNext(); ) |
121 | |
{ |
122 | 0 | Phase o = (Phase) iter.next(); |
123 | 0 | writePhase( o, "phase", serializer ); |
124 | 0 | } |
125 | 0 | serializer.endTag( NAMESPACE, "phases" ); |
126 | |
} |
127 | 0 | serializer.endTag( NAMESPACE, tagName ); |
128 | |
} |
129 | 0 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
private void writeLifecycleConfiguration( LifecycleConfiguration lifecycleConfiguration, String tagName, XmlSerializer serializer ) |
140 | |
throws java.io.IOException |
141 | |
{ |
142 | 0 | if ( lifecycleConfiguration != null ) |
143 | |
{ |
144 | 0 | serializer.setPrefix( "", "http://maven.apache.org/LIFECYCLE/1.0.0" ); |
145 | 0 | serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
146 | 0 | serializer.startTag( NAMESPACE, tagName ); |
147 | 0 | serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/LIFECYCLE/1.0.0 http://maven.apache.org/xsd/lifecycle-1.0.0.xsd" ); |
148 | 0 | if ( ( lifecycleConfiguration.getLifecycles() != null ) && ( lifecycleConfiguration.getLifecycles().size() > 0 ) ) |
149 | |
{ |
150 | 0 | for ( Iterator iter = lifecycleConfiguration.getLifecycles().iterator(); iter.hasNext(); ) |
151 | |
{ |
152 | 0 | Lifecycle o = (Lifecycle) iter.next(); |
153 | 0 | writeLifecycle( o, "lifecycle", serializer ); |
154 | 0 | } |
155 | |
} |
156 | 0 | serializer.endTag( NAMESPACE, tagName ); |
157 | |
} |
158 | 0 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
private void writePhase( Phase phase, String tagName, XmlSerializer serializer ) |
169 | |
throws java.io.IOException |
170 | |
{ |
171 | 0 | if ( phase != null ) |
172 | |
{ |
173 | 0 | serializer.startTag( NAMESPACE, tagName ); |
174 | 0 | if ( phase.getId() != null ) |
175 | |
{ |
176 | 0 | serializer.startTag( NAMESPACE, "id" ).text( phase.getId() ).endTag( NAMESPACE, "id" ); |
177 | |
} |
178 | 0 | if ( ( phase.getExecutions() != null ) && ( phase.getExecutions().size() > 0 ) ) |
179 | |
{ |
180 | 0 | serializer.startTag( NAMESPACE, "executions" ); |
181 | 0 | for ( Iterator iter = phase.getExecutions().iterator(); iter.hasNext(); ) |
182 | |
{ |
183 | 0 | Execution o = (Execution) iter.next(); |
184 | 0 | writeExecution( o, "execution", serializer ); |
185 | 0 | } |
186 | 0 | serializer.endTag( NAMESPACE, "executions" ); |
187 | |
} |
188 | 0 | if ( phase.getConfiguration() != null ) |
189 | |
{ |
190 | 0 | ((Xpp3Dom) phase.getConfiguration()).writeToSerializer( NAMESPACE, serializer ); |
191 | |
} |
192 | 0 | serializer.endTag( NAMESPACE, tagName ); |
193 | |
} |
194 | 0 | } |
195 | |
|
196 | |
|
197 | |
} |