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