View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.site.stubs;
20  
21  import java.io.File;
22  import java.io.FileInputStream;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.util.Properties;
26  
27  import org.apache.maven.model.DistributionManagement;
28  import org.apache.maven.model.Site;
29  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
31  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
32  
33  /**
34   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
35   *
36   */
37  public class SiteMavenProjectStub extends MavenProjectStub {
38      private File basedir;
39  
40      DistributionManagement distributionManagement = new DistributionManagement();
41  
42      public SiteMavenProjectStub(String projectName) {
43          basedir = new File(super.getBasedir() + "/src/test/resources/unit/" + projectName);
44  
45          File pom = new File(getBasedir(), "pom.xml");
46          try (InputStream in = new FileInputStream(pom)) {
47              setModel(new MavenXpp3Reader().read(in));
48              Site site = new Site();
49              site.setId("localhost");
50              distributionManagement.setSite(site);
51          } catch (IOException | XmlPullParserException e) {
52              throw new RuntimeException(e);
53          }
54      }
55  
56      /**
57       * @see org.apache.maven.project.MavenProject#getName()
58       */
59      @Override
60      public String getName() {
61          return getModel().getName();
62      }
63  
64      /**
65       * @see org.apache.maven.project.MavenProject#getProperties()
66       */
67      @Override
68      public Properties getProperties() {
69          return new Properties();
70      }
71  
72      @Override
73      public DistributionManagement getDistributionManagement() {
74          return distributionManagement;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public File getBasedir() {
80          return basedir;
81      }
82  
83      public void setBasedir(File basedir) {
84          this.basedir = basedir;
85      }
86  }