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