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.javadoc.stubs;
20  
21  import java.io.File;
22  
23  import org.apache.maven.model.Build;
24  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
25  
26  /**
27   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
28   */
29  public class FixMavenProjectStub extends MavenProjectStub {
30      public FixMavenProjectStub() {
31          readModel(new File(getBasedir(), "pom.xml"));
32  
33          addCompileSourceRoot(getBasedir().getAbsolutePath() + "/target/classes");
34          addCompileSourceRoot(getBasedir().getAbsolutePath() + "/src/main/java");
35  
36          Build build = new Build();
37          build.setDirectory(getBasedir().getAbsolutePath() + "/target");
38          build.setSourceDirectory(getBasedir().getAbsolutePath() + "/src/main/java");
39          build.setOutputDirectory(getBasedir().getAbsolutePath() + "/target/classes");
40          build.setTestSourceDirectory(getBasedir().getAbsolutePath() + "/src/test/java");
41          build.setTestOutputDirectory(getBasedir().getAbsolutePath() + "/target/test-classes");
42          setBuild(build);
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public String getArtifactId() {
48          return getModel().getArtifactId();
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public String getGroupId() {
54          String groupId = getModel().getGroupId();
55  
56          if ((groupId == null) && (getModel().getParent() != null)) {
57              groupId = getModel().getParent().getGroupId();
58          }
59  
60          return groupId;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public String getVersion() {
66          String version = getModel().getVersion();
67  
68          if ((version == null) && (getModel().getParent() != null)) {
69              version = getModel().getParent().getVersion();
70          }
71  
72          return version;
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public String getPackaging() {
78          return getModel().getPackaging();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public File getBasedir() {
84          // Using unit test dir
85          return new File(super.getBasedir() + "/target/test/unit/fix-test/");
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public File getFile() {
91          return new File(getBasedir(), "pom.xml");
92      }
93  }