1 package org.apache.maven.model.converter; 2 3 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 ; 26 import java.io.StringReader ; 27 import java.io.StringWriter ; 28 import java.io.Writer ; 29 import java.util.List ; 30 31 34 public class V3PomRewriter 35 implements ArtifactPomRewriter 36 { 37 private ModelConverter translator; 38 39 public void rewrite( Reader from, Writer to, boolean reportOnly, String groupId, String artifactId, String version, 40 String packaging ) 41 throws Exception 42 { 43 Model v4Model; 44 45 if ( from != null ) 46 { 47 MavenXpp3Reader v3Reader = new MavenXpp3Reader(); 48 49 StringWriter w = new StringWriter (); 50 IOUtil.copy( from, w ); 51 String content = StringUtils.replace( w.toString(), "${pom.currentVersion}", "${project.version}" ); 52 53 org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( new StringReader ( 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 getWarnings() 74 { 75 return translator.getWarnings(); 76 } 77 78 } | Popular Tags |