View Javadoc

1   package org.apache.maven.plugins.site.stubs;
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 java.io.File;
23  import java.util.Properties;
24  
25  import org.apache.maven.model.DistributionManagement;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.model.Site;
28  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
29  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30  import org.codehaus.plexus.util.ReaderFactory;
31  
32  /**
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   * @version $Id: SiteMavenProjectStub.html 816568 2012-05-08 12:09:38Z hboutemy $
35   */
36  public class SiteMavenProjectStub
37      extends MavenProjectStub
38  {
39      DistributionManagement distributionManagement = new DistributionManagement();
40      
41      public SiteMavenProjectStub()
42      {
43          this( null );
44      }    
45      
46      public SiteMavenProjectStub(String pomFilePath)
47      {
48          MavenXpp3Reader pomReader = new MavenXpp3Reader();
49          Model model = null;
50  
51          try
52          {
53              File pomFile = new File( getBasedir(),pomFilePath == null ? "/src/test/resources/unit/interpolated-site/pom.xml" : pomFilePath );
54              model = pomReader.read( ReaderFactory.newXmlReader( pomFile ) );
55              setModel( model );
56          }
57          catch ( Exception e )
58          {
59              throw new RuntimeException( e );
60          }
61          Site site = new Site();
62          site.setId( "localhost" );
63          distributionManagement.setSite( site );
64      }
65  
66      /**
67       * @see org.apache.maven.project.MavenProject#getName()
68       */
69      public String getName()
70      {
71          return getModel().getName();
72      }
73  
74      /**
75       * @see org.apache.maven.project.MavenProject#getProperties()
76       */
77      public Properties getProperties()
78      {
79          return new Properties();
80      }
81  
82      @Override
83      public DistributionManagement getDistributionManagement()
84      {
85          return distributionManagement;
86      }
87  }