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.plugin.jxr.stubs;
20  
21  import java.io.FileReader;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.model.ReportPlugin;
28  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
29  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30  
31  /**
32   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
33   */
34  public class DefaultConfigurationMavenProjectStub extends MavenProjectStub {
35      private List<ReportPlugin> reportPlugins = new ArrayList<>();
36  
37      public DefaultConfigurationMavenProjectStub() {
38          MavenXpp3Reader pomReader = new MavenXpp3Reader();
39          Model model = null;
40  
41          try {
42              model = pomReader.read(new FileReader(getBasedir()
43                      + "/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml"));
44              setModel(model);
45          } catch (Exception ignored) {
46  
47          }
48  
49          setArtifactId(model.getArtifactId());
50          setGroupId(model.getGroupId());
51          setVersion(model.getVersion());
52          setPackaging(model.getPackaging());
53          setInceptionYear(model.getInceptionYear());
54  
55          String basedir = getBasedir().getAbsolutePath();
56          List<String> compileSourceRoots = new ArrayList<>();
57          compileSourceRoots.add(basedir + "/src/test/resources/unit/default-configuration/def/configuration");
58          setCompileSourceRoots(compileSourceRoots);
59  
60          // set the report plugins
61          reportPlugins = new ArrayList<>(model.getReporting().getPlugins());
62  
63          Artifact artifact = new JxrPluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging());
64          artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
65          setArtifact(artifact);
66      }
67  
68      @Override
69      public List<ReportPlugin> getReportPlugins() {
70          return reportPlugins;
71      }
72  }