KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > model > converter > V3PomRewriter


1 package org.apache.maven.model.converter;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.model.Model;
20 import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
21 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
22 import org.codehaus.plexus.util.IOUtil;
23 import org.codehaus.plexus.util.StringUtils;
24
25 import java.io.Reader JavaDoc;
26 import java.io.StringReader JavaDoc;
27 import java.io.StringWriter JavaDoc;
28 import java.io.Writer JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * @author jdcasey
33  */

34 public class V3PomRewriter
35     implements ArtifactPomRewriter
36 {
37     private ModelConverter translator;
38
39     public void rewrite( Reader from, Writer to, boolean reportOnly, String JavaDoc groupId, String JavaDoc artifactId, String JavaDoc version,
40                          String JavaDoc packaging )
41         throws Exception JavaDoc
42     {
43         Model v4Model;
44
45         if ( from != null )
46         {
47             MavenXpp3Reader v3Reader = new MavenXpp3Reader();
48
49             StringWriter JavaDoc w = new StringWriter JavaDoc();
50             IOUtil.copy( from, w );
51             String JavaDoc content = StringUtils.replace( w.toString(), "${pom.currentVersion}", "${project.version}" );
52
53             org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( new StringReader JavaDoc( content ) );
54             v4Model = translator.translate( v3Model );
55         }
56         else
57         {
58             v4Model = new Model();
59         }
60
61         if ( v4Model != null )
62         {
63             translator.validateV4Basics( v4Model, groupId, artifactId, version, packaging );
64
65             if ( !reportOnly )
66             {
67                 MavenXpp3Writer v4Writer = new MavenXpp3Writer();
68                 v4Writer.write( to, v4Model );
69             }
70         }
71     }
72
73     public List JavaDoc getWarnings()
74     {
75         return translator.getWarnings();
76     }
77
78 }
Popular Tags