1 package org.apache.maven.model.converter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.model.Model;
23 import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
24 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
25 import org.apache.maven.shared.utils.io.IOUtil;
26 import org.apache.maven.shared.utils.StringUtils;
27
28 import java.io.Reader;
29 import java.io.StringReader;
30 import java.io.StringWriter;
31 import java.io.Writer;
32 import java.util.List;
33
34
35
36
37
38 public class V3PomRewriter
39 implements ArtifactPomRewriter
40 {
41
42
43
44 private ModelConverter translator;
45
46 public void rewrite( Reader from, Writer to, boolean reportOnly, String groupId, String artifactId, String version,
47 String packaging )
48 throws Exception
49 {
50 Model v4Model;
51
52 if ( from != null )
53 {
54 MavenXpp3Reader v3Reader = new MavenXpp3Reader();
55
56 StringWriter w = new StringWriter();
57 IOUtil.copy( from, w );
58 String content = StringUtils.replace( w.toString(), "${pom.currentVersion}", "${project.version}" );
59
60 org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( new StringReader( content ) );
61 v4Model = translator.translate( v3Model );
62 }
63 else
64 {
65 v4Model = new Model();
66 }
67
68 if ( v4Model != null )
69 {
70 translator.validateV4Basics( v4Model, groupId, artifactId, version, packaging );
71
72 if ( !reportOnly )
73 {
74 MavenXpp3Writer v4Writer = new MavenXpp3Writer();
75 v4Writer.write( to, v4Model );
76 }
77 }
78 }
79
80 public List getWarnings()
81 {
82 return translator.getWarnings();
83 }
84
85 }