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.codehaus.plexus.util.IOUtil; |
26 | |
import org.codehaus.plexus.util.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 | 1 | 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 | 1 | if ( from != null ) |
53 | |
{ |
54 | 1 | MavenXpp3Reader v3Reader = new MavenXpp3Reader(); |
55 | |
|
56 | 1 | StringWriter w = new StringWriter(); |
57 | 1 | IOUtil.copy( from, w ); |
58 | 1 | String content = StringUtils.replace( w.toString(), "${pom.currentVersion}", "${project.version}" ); |
59 | |
|
60 | 1 | org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( new StringReader( content ) ); |
61 | 1 | v4Model = translator.translate( v3Model ); |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | v4Model = new Model(); |
66 | |
} |
67 | |
|
68 | 1 | if ( v4Model != null ) |
69 | |
{ |
70 | 1 | translator.validateV4Basics( v4Model, groupId, artifactId, version, packaging ); |
71 | |
|
72 | 1 | if ( !reportOnly ) |
73 | |
{ |
74 | 1 | MavenXpp3Writer v4Writer = new MavenXpp3Writer(); |
75 | 1 | v4Writer.write( to, v4Model ); |
76 | |
} |
77 | |
} |
78 | 1 | } |
79 | |
|
80 | |
public List getWarnings() |
81 | |
{ |
82 | 0 | return translator.getWarnings(); |
83 | |
} |
84 | |
|
85 | |
} |