1 package org.apache.maven.its.plugins;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStreamWriter;
26 import java.io.Writer;
27
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.codehaus.plexus.util.IOUtil;
32 import org.codehaus.plexus.util.xml.Xpp3Dom;
33 import org.codehaus.plexus.util.xml.pull.MXSerializer;
34 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
35
36
37
38
39
40 public class SerializeMojo
41 extends AbstractMojo
42 {
43
44
45
46
47 private File file;
48
49 public void execute()
50 throws MojoExecutionException, MojoFailureException
51 {
52 Writer writer = null;
53 XmlSerializer s = new MXSerializer();
54 try
55 {
56 file.getParentFile().mkdirs();
57 writer = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" );
58 s.setOutput( writer );
59
60 Xpp3Dom dom = new Xpp3Dom( "root" );
61
62 dom.writeToSerializer( "", s );
63 }
64 catch ( IOException e )
65 {
66 throw new MojoExecutionException( e.getMessage(), e );
67 }
68 finally
69 {
70 IOUtil.close( writer );
71 }
72 }
73 }