1 package org.apache.maven.artifact.ant;
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.IOException;
24 import java.io.Writer;
25
26 import org.apache.maven.model.Model;
27 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
28 import org.apache.tools.ant.BuildException;
29 import org.apache.tools.ant.Task;
30 import org.codehaus.plexus.util.IOUtil;
31 import org.codehaus.plexus.util.WriterFactory;
32
33
34
35
36
37
38 public class WritePomTask
39 extends Task
40 {
41 private String pomRefId;
42
43 private File file;
44
45 private boolean trim = true;
46
47 public void execute()
48 {
49
50 Pom pom = (Pom) getProject().getReference( pomRefId );
51 Model model = pom.getModel();
52 if ( trim )
53 {
54 trimModel ( model );
55 }
56 writeModel( model, file );
57 }
58
59
60
61
62
63 public void trimModel( Model model )
64 {
65 model.setBuild( null );
66 model.setReporting( null );
67 model.setProperties( null );
68 model.setRepositories( null );
69 model.setPluginRepositories( null );
70 model.setProfiles( null );
71 model.setDistributionManagement( null );
72 model.setModules( null );
73 }
74
75
76
77
78
79
80
81
82 public void writeModel( Model model, File outputFile )
83 throws BuildException
84 {
85 Writer fw = null;
86 try
87 {
88 fw = WriterFactory.newXmlWriter( outputFile );
89 new MavenXpp3Writer().write( fw, model );
90 }
91 catch ( IOException e )
92 {
93 throw new BuildException( "Error writing temporary pom file: " + e.getMessage(), e );
94 }
95 finally
96 {
97 IOUtil.close( fw );
98 }
99 }
100
101 public void setPomRefId( String pomRefId )
102 {
103 this.pomRefId = pomRefId;
104 }
105
106 public String getPomRefId()
107 {
108 return pomRefId;
109 }
110
111 public void setFile( File file )
112 {
113 this.file = file;
114 }
115
116 public File getFile()
117 {
118 return file;
119 }
120
121 public void setTrim( boolean trim )
122 {
123 this.trim = trim;
124 }
125
126 public boolean isTrim()
127 {
128 return trim;
129 }
130 }