View Javadoc

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.io.xpp3.MavenXpp3Reader;
24  import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
25  
26  import java.io.Reader;
27  import java.io.Writer;
28  import java.util.List;
29  
30  /**
31   * @author jdcasey
32   * @plexus.component role="org.apache.maven.model.converter.ArtifactPomRewriter" role-hint="v4"
33   */
34  public class V4PomRewriter
35      implements ArtifactPomRewriter
36  {
37      /**
38       * @plexus.requirement
39       */
40      private ModelConverter translator;
41  
42      public void rewrite( Reader from, Writer to, boolean reportOnly, String groupId, String artifactId, String version,
43                           String packaging )
44          throws Exception
45      {
46          Model model = null;
47  
48          if ( from != null )
49          {
50              MavenXpp3Reader reader = new MavenXpp3Reader();
51  
52              model = reader.read( from );
53          }
54          else
55          {
56              model = new Model();
57          }
58  
59          if ( model != null )
60          {
61              translator.validateV4Basics( model, groupId, artifactId, version, packaging );
62  
63              if ( !reportOnly )
64              {
65                  MavenXpp3Writer writer = new MavenXpp3Writer();
66                  writer.write( to, model );
67              }
68          }
69      }
70  
71      public List getWarnings()
72      {
73          return translator.getWarnings();
74      }
75  }