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.File;
22  import java.io.FileReader;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.model.Build;
27  import org.apache.maven.model.Model;
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:vincent.siveton@gmail.com">Vincent Siveton</a>
33   */
34  public class PomMavenProjectStub extends MavenProjectStub {
35      private Build build;
36  
37      public PomMavenProjectStub() {
38          MavenXpp3Reader pomReader = new MavenXpp3Reader();
39          Model model;
40  
41          try {
42              model = pomReader.read(new FileReader(new File(getBasedir(), "pom-test-plugin-config.xml")));
43              setModel(model);
44          } catch (Exception e) {
45              throw new RuntimeException(e);
46          }
47  
48          setGroupId(model.getGroupId());
49          setArtifactId(model.getArtifactId());
50          setVersion(model.getVersion());
51          setName(model.getName());
52          setUrl(model.getUrl());
53          setPackaging(model.getPackaging());
54  
55          Build build = new Build();
56          build.setFinalName(model.getArtifactId());
57          build.setDirectory(super.getBasedir() + "/target/test/unit/pom-test/target");
58          build.setSourceDirectory(getBasedir() + "/src/main/java");
59          build.setOutputDirectory(super.getBasedir() + "/target/test/unit/pom-test/target/classes");
60          build.setTestSourceDirectory(getBasedir() + "/src/test/java");
61          build.setTestOutputDirectory(super.getBasedir() + "/target/test/unit/pom-test/target/test-classes");
62          setBuild(build);
63  
64          List<String> compileSourceRoots = new ArrayList<>();
65          compileSourceRoots.add(getBasedir() + "/src/main/java");
66          setCompileSourceRoots(compileSourceRoots);
67  
68          List<String> testCompileSourceRoots = new ArrayList<>();
69          testCompileSourceRoots.add(getBasedir() + "/src/test/java");
70          setTestCompileSourceRoots(testCompileSourceRoots);
71      }
72  
73      /**
74       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBuild()
75       */
76      public Build getBuild() {
77          return build;
78      }
79  
80      /**
81       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#setBuild(org.apache.maven.model.Build)
82       */
83      public void setBuild(Build build) {
84          this.build = build;
85      }
86  
87      /**
88       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
89       */
90      public File getBasedir() {
91          return new File(super.getBasedir() + "/src/test/resources/unit/pom-test");
92      }
93  }