Coverage Report - org.apache.maven.model.converter.V3PomRewriter
 
Classes in this File Line Coverage Branch Coverage Complexity
V3PomRewriter
88%
14/16
50%
3/6
2,5
 
 1  
 package org.apache.maven.model.converter;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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  
  * @author jdcasey
 36  
  * @plexus.component role="org.apache.maven.model.converter.ArtifactPomRewriter" role-hint="v3"
 37  
  */
 38  1
 public class V3PomRewriter
 39  
     implements ArtifactPomRewriter
 40  
 {
 41  
     /**
 42  
      * @plexus.requirement
 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  
 }