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.Site;
27  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29  import org.codehaus.plexus.util.IOUtil;
30  import org.codehaus.plexus.util.ReaderFactory;
31  import org.codehaus.plexus.util.xml.XmlStreamReader;
32  
33  /**
34   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
35   * @version $Id: SiteMavenProjectStub.html 980320 2016-02-13 14:12:53Z hboutemy $
36   */
37  public class SiteMavenProjectStub
38      extends MavenProjectStub
39  {
40      private File basedir;
41  
42      DistributionManagement distributionManagement = new DistributionManagement();
43      
44      public SiteMavenProjectStub( String projectName )
45      {
46          basedir = new File( super.getBasedir() + "/src/test/resources/unit/" + projectName );
47  
48          XmlStreamReader reader = null;
49          try
50          {
51              reader = ReaderFactory.newXmlReader( new File( getBasedir(), "pom.xml" ) );
52              setModel( new MavenXpp3Reader().read( reader ) );
53          }
54          catch ( Exception e )
55          {
56              throw new RuntimeException( e );
57          }
58          finally
59          {
60              IOUtil.close( reader);
61          }
62          Site site = new Site();
63          site.setId( "localhost" );
64          distributionManagement.setSite( site );
65      }
66  
67      /**
68       * @see org.apache.maven.project.MavenProject#getName()
69       */
70      public String getName()
71      {
72          return getModel().getName();
73      }
74  
75      /**
76       * @see org.apache.maven.project.MavenProject#getProperties()
77       */
78      public Properties getProperties()
79      {
80          return new Properties();
81      }
82  
83      @Override
84      public DistributionManagement getDistributionManagement()
85      {
86          return distributionManagement;
87      }
88  
89      /** {@inheritDoc} */
90      public File getBasedir()
91      {
92          return basedir;
93      }
94  
95      public void setBasedir( File basedir )
96      {
97          this.basedir = basedir;
98      }
99  }